/** * Get a paged list of entities of a particular type * * @param int $pageNumber The page number for pagination * @param int $pageSize The page size for pagination * @param array $orderBy The order by clause * * @return array An array of BaseEntityAbstract */ public function findAll($searchActiveOnly = true, $pageNumber = null, $pageSize = DaoQuery::DEFAUTL_PAGE_SIZE, $orderBy = array()) { $results = Dao::findAll($this->_query->setSelectActiveOnly($searchActiveOnly), $pageNumber, $pageSize, $orderBy); $this->_pageStats = Dao::getPageStats(); $this->resetQuery(); return $results; }
/** * Retrieve an entity from the database by its primary key * * @param DaoQuery $qry The dao query * @param int $id The ID of the entity * @param int $outputFormat The result output format: object, xml, array... * * @return BaseEntityAbstract|null */ public static function findById(DaoQuery $qry, $id, $outputFormat = self::AS_OBJECTS) { self::connect(); DaoMap::loadMap($qry->getFocusClass()); $results = self::findByCriteria($qry->setSelectActiveOnly(false), '`' . DaoMap::$map[strtolower($qry->getFocusClass())]['_']['alias'] . '`.`id`=?', array($id), null, DaoQuery::DEFAUTL_PAGE_SIZE, array(), $outputFormat); if (is_array($results) && sizeof($results) > 0) { return $results[0]; } if ($results instanceof SimpleXMLElement) { return $results; } return null; }
/** * Lazy load a many-to-one relationship * * @param string $property The property that we are trying to load * * @return BaseEntityAbstract */ protected function loadManyToOne($property) { $this->__loadDaoMap(); if (is_null($this->{$property})) { //if the proerty is allow to have null value, then let it be if (DaoMap::$map[strtolower(get_class($this))][$property]['nullable']) { $this->{$property} = null; return $this; } //if the property is one of these, as when we are trying to save them, we don't have the iniated value if (in_array($property, array('createdBy', 'updatedBy'))) { $this->{$property} = Core::getUser(); } else { throw new Exception('Property (' . get_class($this) . '::' . $property . ') must be initialised to integer or proxy prior to lazy loading.', 1); } } // Load the DAO map for this entity $cls = DaoMap::$map[strtolower(get_class($this))][$property]['class']; if (!$this->{$property} instanceof BaseEntityAbstract) { throw new DaoException('The property(' . $property . ') for "' . get_class($this) . '" is NOT a BaseEntity!'); } $qry = new DaoQuery($cls); $qry->setSelectActiveOnly(false); $this->{$property} = Dao::findById($qry, $this->{$property}->getId()); return $this; }