/** * Returns the count of objects matching the given sql clause * * @param string $where The sql where-clause * * @return int Count of matching entries */ public function count($where = null) { return Phprojekt_ActiveRecord_Abstract::count($where); }
/** * Override count function to account for rights. * * @param string $where A where clause to count a subset of the results. * * @return integer Count of results. */ public function count($where = null) { if (Phprojekt_Auth::isAdminUser()) { return parent::count($where); } $db = Phprojekt::getInstance()->getDb(); $rawTable = $this->getTableName(); $table = $db->quoteIdentifier($rawTable); $select = $db->select()->from($rawTable, array('COUNT(*)')); if (!is_null($where)) { $select->where($where); } $select->join(array('ir' => 'item_rights'), "ir.item_id = {$table}.id", array())->where('ir.module_id = :thisModule')->where('ir.user_id = :effectiveUser')->where("{$table}.owner_id = :effectiveUser OR (ir.access & :right) = :right")->bind(array(':thisModule' => Phprojekt_Module::getId($this->getModelName()), ':effectiveUser' => Phprojekt_Auth_Proxy::getEffectiveUserId(), ':right' => Phprojekt_Acl::READ)); return $select->query()->fetchColumn(); }
/** * Returns the number of the models of the given type in this subtree. * * @param $model The activeRecord module used to get the data. * @param $where The clause to determine matching objects. Optional. */ public function getRecordsCount(Phprojekt_ActiveRecord_Abstract $model, $where = null) { $projectIds = array_keys($this->_index); if (empty($projectIds)) { return 0; } if (!is_null($where)) { $where .= ' AND '; } $where .= $model->getAdapter()->quoteInto('project_id IN (?)', $projectIds); return $model->count($where); }