Esempio n. 1
0
 /**
  * @param Cond $cond
  *
  * @throws \Model\Exception\ErrorException
  * @return array|mixed|string
  */
 public function fetchAll(Cond $cond = null)
 {
     $entity = $cond->getEntityName();
     $entity = $entity ? $entity : $this->getRawName();
     $prepareCallbackFunction = 'prepareCollection';
     $pager = null;
     try {
         $select = $this->prepareSelect($cond, $entity);
         if ($cond->checkCond(Cond::SHOW_QUERY) || $cond->checkCond(Cond::SHOW_QUERY_EXTENDED)) {
             echo '<!--' . $select . "-->\n";
         }
         if ($cond->getCond('return_query')) {
             return (string) $select;
         } else {
             $items = $select->query()->fetchAll();
         }
         if ($cond->checkCond(Cond::PAGE)) {
             $pager = new Paginator(new ArraySet($items));
             $pager->setCurrentPageNumber($cond->getCond('page'));
             $pager->setItemCountPerPage($cond->getCond('items_per_page'));
             $pager->setTotalItemCount($this->fetchCount($cond));
         }
     } catch (\Exception $e) {
         $items = array();
     }
     if ($cond->checkCond(Cond::WITHOUT_PREPARE)) {
         return $items;
     } else {
         return call_user_func(array($this, $prepareCallbackFunction), $items, $cond, $pager);
     }
 }
Esempio n. 2
0
 /**
  * @param string       $name
  * @param AbstractCond $cond
  * @return AbstractCond
  */
 public function addChild($name, AbstractCond $cond)
 {
     $cond->setParent($this);
     $this->childList[(string) $name] = $cond;
     return $this;
 }