/** * 取得所有后代节点ID * * @param integer $roleId * @return array */ public function findDescendants($roleId) { $relation = array(); foreach ($this->_roleDAO->fetchAll(array('role_id > ?' => $roleId)) as $row) { $relation[$row['role_parent']][] = $row['role_id']; } if (!array_key_exists($roleId, $relation)) { $descendants = array(); } else { $descendants = $relation[$roleId]; foreach ($relation as $parent => $roles) { if (in_array($parent, $descendants)) { $descendants = array_merge($descendants, $roles); } } } return $descendants; }
/** * 取得自身及所有子角色 * * @param integer|null $count 总共取出多少数据 * @param integer $offset 从哪一行开始取数据 * @return ZtChart_Model_Db_Table_Rowset */ public function getSelfAndChildRoles($count = null, $offset = 0) { $roleDAO = new ZtChart_Model_DbTable_Role(); return $roleDAO->fetchAll($this->isAdmin() ? null : $roleDAO->select()->where('role_parent = ?', $this->_roleId)->orWhere('role_id = ?', $this->_roleId)); }