<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class MemberAction extends BaseAction
{
    public function run()
    {
        throw new iSystemException('子类必须覆盖此方法');
    }
    
    public function getMember($uid)
    {
        $ugTable = UserGroups::table();
        $mTable = Members::table();
        $mfTable = Memberfields::table();
        $meTable = MemberExts::table();
        $bmTable = BookMembers::table();
        
        $sql = "SELECT m.*, mf.*,me.*,bm.bookid,ug.grouptitle,ug.grouptitle1,ug.grouptitle2,ug.gptype,ug.creditslower FROM {$mTable} m
        		INNER JOIN {$ugTable} AS ug ON ug.groupid = m.groupid
        		LEFT JOIN {$mfTable} mf ON mf.uid = m.uid
        		LEFT JOIN {$meTable} me ON me.uid = m.uid
        		LEFT JOIN {$bmTable} bm ON bm.uid = m.uid AND bm.deleted = 0
        		WHERE m.uid='$uid'";
        $member = $this->db()->setQueryString($sql)->find(true);
        empty($member) && $this->showMessage('不存在的会员');
        
        return $member;
    }
    
    public function getBookShelfs($id)
    {
        $myBookShelfs = BookShelf::single()->getAll($this->uid());
        if (!array_key_exists($id, $myBookShelfs))
        {
            throw new iSystemException('不存在的书架');
        }
        
        return $myBookShelfs;
    }
    
    protected function _iorange()
    {
        return uuid();
    }
}