コード例 #1
0
ファイル: DrupalApi.php プロジェクト: pdiveris/api_ht
 /**
  * Return 'all'
  * It is possible to supply a list of fields to be returned.
  * If not, then all fields are selected - see if tht works
  *
  * @param array $fields
  * @return mixed|void
  */
 public function all($fields = array())
 {
     $class = '\\Jisc\\api\\Service\\Hairdressing\\' . self::$model;
     if (self::$model == 'Item') {
         /************************************ ITEM **********************************************************/
         $statement = Db\Models\Node::where('nid', 'in', " (select replace(link_path, 'node/', '') from menu_links where hidden=0 and menu_name='primary-links' and depth >2 order by plid,p1,p2,p3)");
         $statement->select($fields);
         if (isset($this->options['offset'])) {
             $statement->offset($this->options['offset']);
         }
         if (isset($this->options['limit'])) {
             $statement->limit($this->options['limit']);
         }
         $result = $statement->get();
         $context = new Context(array('totalCount' => count($result->getItems()), 'offset' => Db\Models\Node::getOffset(), 'limit' => Db\Models\Node::getLimit(), 'query' => Db\Models\Node::getQuery(), 'queryDate' => Db\Models\Node::getQueryDateTime()));
         $data = array();
         foreach ($result->getItems() as $item) {
             $item = new Item(array_merge((array) $item, array('expand' => array_diff(static::$expandable, $this->expandRequested))), $this->expandRequested);
             $data[] = $item;
         }
     } else {
         /******************************************** COMMUNITY or COLLECTION *********************************************/
         $depth = 0;
         if (self::$model == 'Community') {
             $depth = 1;
         } elseif (self::$model == 'Collection') {
             $depth = 2;
         }
         /*** Run query ***/
         $result = Db\Models\MenuLink::where('menu_name', '=', "'primary-links'")->andWhere('depth', '=', $depth)->andWhere('hidden', '=', 0)->andWhere('has_children', '=', 1)->get();
         $context = new Context(array('totalCount' => count($result->getItems()), 'offset' => Db\Models\MenuLink::getOffset(), 'limit' => Db\Models\MenuLink::getLimit(), 'query' => Db\Models\MenuLink::getQuery(), 'queryDate' => Db\Models\Node::getQueryDateTime()));
         foreach ($result->getItems() as $item) {
             $model = new $class();
             $model->id = str_replace('node/', '', $item->link_path);
             // Drupal clever non-link 'node/1'=>1. Why?
             $model->handle = $item->link_path;
             $model->link = self::$servicePoint . '/' . $model->type . '/' . $model->id;
             $model->name = $item->link_title;
             $model->expand = array_diff(static::$expandable, $this->expandRequested);
             $model->countItems = self::getSiblingsCount($item->mlid, $depth, array(3, 4));
             //  "metadata", "collections", "parentCommunity", "subCommunities", "logo", "all"
             foreach ($this->expandRequested as $expand) {
                 $method = "populate" . ucfirst($expand);
                 $model->{$method}();
             }
             $data[] = $model;
         }
     }
     $ret = new \Jisc\api\Service\DataCollection($data, $context);
     return $ret;
 }