/** * Returns the authorization items of the specific type and user. * Overloads the parent method to allow for sorting. * @param integer $type the item type (0: operation, 1: task, 2: role). Defaults to null, * meaning returning all items regardless of their type. * @param mixed $userId the user ID. Defaults to null, meaning returning all items even if * they are not assigned to a user. * @param boolean $sort whether to sort the items according to their weights. * @return array the authorization items of the specific type. */ public function getAuthItems($type = null, $userId = null, $sort = true) { // We need to sort the items. if ($sort === true) { if ($type === null && $userId === null) { $sql = "SELECT name,t1.type,description,t1.bizrule,t1.data,weight\r\n\t\t\t\t\tFROM {$this->db->quoteTableName($this->itemTable)} t1\r\n\t\t\t\t\tLEFT JOIN {$this->db->quoteTableName($this->rightsTable)} t2 ON name=itemname\r\n\t\t\t\t\tORDER BY t1.type DESC, weight ASC"; $command = $this->db->createCommand($sql); } else { if ($userId === null) { $sql = "SELECT name,t1.type,description,t1.bizrule,t1.data,weight\r\n\t\t\t\t\tFROM {$this->db->quoteTableName($this->itemTable)} t1\r\n\t\t\t\t\tLEFT JOIN {$this->db->quoteTableName($this->rightsTable)} t2 ON name=itemname\r\n\t\t\t\t\tWHERE t1.type=:type\r\n\t\t\t\t\tORDER BY t1.type DESC, weight ASC"; $command = $this->db->createCommand($sql); $command->bindValue(':type', $type); } else { if ($type === null) { $sql = "SELECT name,t1.type,description,t1.bizrule,t1.data,weight\r\n\t\t\t\t\tFROM {$this->db->quoteTableName($this->itemTable)} t1\r\n\t\t\t\t\tLEFT JOIN {$this->db->quoteTableName($this->assignmentTable)} t2 ON name=t2.itemname\r\n\t\t\t\t\tLEFT JOIN {$this->db->quoteTableName($this->rightsTable)} t3 ON name=t3.itemname\r\n\t\t\t\t\tWHERE userid=:userid\r\n\t\t\t\t\tORDER BY t1.type DESC, weight ASC"; $command = $this->db->createCommand($sql); $command->bindValue(':userid', $userId); } else { $sql = "SELECT name,t1.type,description,t1.bizrule,t1.data,weight\r\n\t\t\t\t\tFROM {$this->db->quoteTableName($this->itemTable)} t1\r\n\t\t\t\t\tLEFT JOIN {$this->db->quoteTableName($this->assignmentTable)} t2 ON name=t2.itemname\r\n\t\t\t\t\tLEFT JOIN {$this->db->quoteTableName($this->rightsTable)} t3 ON name=t3.itemname\r\n\t\t\t\t\tWHERE t1.type=:type AND userid=:userid\r\n\t\t\t\t\tORDER BY t1.type DESC, weight ASC"; $command = $this->db->createCommand($sql); $command->bindValue(':type', $type); $command->bindValue(':userid', $userId); } } } $items = array(); foreach ($command->queryAll() as $row) { $items[$row['name']] = new CAuthItem($this, $row['name'], $row['type'], $row['description'], $row['bizrule'], unserialize($row['data'])); } } else { $items = parent::getAuthItems($type, $userId); } return $items; }