Пример #1
0
 /**
  *
  */
 public function findAll($filters = array(), $options = array())
 {
     $data = array();
     if (isset($filters['filterList']) && $filters['filterList'] instanceof \App_ListFilter) {
         $data['filterList'] = $filters['filterList'];
     } else {
         $data['filterList'] = new \App_ListFilter();
     }
     $filterList = $data['filterList'];
     $filterList->addExtraData('organizationId', self::$organizationId);
     if (isset($options['maxFirstPages'])) {
         $data['maxFirstPages'] = $options['maxFirstPages'];
         unset($options['maxFirstPages']);
     }
     $data['paging'] = $options;
     if (!isset($data['paging']['count'])) {
         $data['paging']['count'] = static::DEFAULT_ITEMS_PER_PAGE;
     }
     if ($filterList->getGrouping() == null || $filterList->getGroup() && !$filterList->getHighlighting()) {
         $iter = new SimIterator($data);
         $result = new StreamResultModel();
         $result->setIterator($iter);
         return $result;
     }
     $dataList = $this->_findAllEricsson($data);
     if (isset($dataList['items'])) {
         $items = $dataList['items'];
         foreach ($items as $id => $data) {
             $items[$id] = new SimModel($data);
         }
         $result = new Model\ListResultModel();
         $result->setItems($items);
         if ($dataList['count'] !== null) {
             $result->setCount($dataList['count']);
         }
         return $result;
     } else {
         $result = new Model\GroupListModel();
         foreach ($dataList as $group) {
             if (isset($group['label'])) {
                 $groupModel = new Model\GroupResultModel();
                 $groupModel->setLabel($group['label']);
                 $groupModel->setCount(isset($group['count']) ? $group['count'] : 0);
                 $items = array();
                 if (!empty($group['items'])) {
                     $items = $group['items'];
                     foreach ($items as $id => $data) {
                         $items[$id] = new SimModel($data);
                     }
                 }
                 $groupModel->setItems($items);
                 $result->addGroup($groupModel);
             }
         }
         return $result;
     }
 }