public function doListByClass()
 {
     $nodeId = eZINI::instance('content.ini')->variable('NodeSettings', 'RootNode');
     $openDataTools = new OCOpenDataTools();
     $class = $openDataTools->getClass($this->classIdentifier);
     if (!$class instanceof eZContentClass) {
         throw new Exception('La classe non esiste');
     }
     $classIdentifier = $class->attribute('identifier');
     $className = $class->attribute('name');
     $this->setDefaultResponseGroups(array(self::VIEWLIST_RESPONSEGROUP_METADATA));
     $result = new ezpRestMvcResult();
     $crit = new ezpContentCriteria();
     // Location criteria
     // Hmm, the following sequence is too long...
     $crit->accept[] = ezpContentCriteria::location()->subtree(ezpContentLocation::fetchByNodeId($nodeId));
     $crit->accept[] = ezpContentCriteria::depth(20);
     $crit->accept[] = new ezpContentMainNodeOnlyCriteria(true);
     $crit->accept[] = ezpContentCriteria::contentClass()->is($classIdentifier);
     // Limit criteria
     $offset = isset($this->offset) ? $this->offset : 0;
     $limit = isset($this->limit) ? $this->limit : 10;
     $crit->accept[] = ezpContentCriteria::limit()->offset($offset)->limit($limit);
     // Sort criteria
     /*
     if( isset( $this->sortKey ) )
     {
         $sortOrder = isset( $this->sortType ) ? $this->sortType : 'asc';
         $crit->accept[] = ezpContentCriteria::sorting( $this->sortKey, $sortOrder );
     }
     */
     $crit->accept[] = ezpContentCriteria::sorting('published', 'desc');
     $result->variables['nodes'] = ITOpenDataContentModel::getChildrenList($crit, $this->request, $this->getResponseGroups(), $this->getRouter());
     // REST links to children nodes
     // Little dirty since this should belong to the model layer, but I don't want to pass the router nor the full controller to the model
     $contentQueryString = $this->request->getContentQueryString(true);
     for ($i = 0, $iMax = count($result->variables['nodes']); $i < $iMax; ++$i) {
         $linkURI = $this->getRouter()->generateUrl('ezpNode', array('nodeId' => $result->variables['nodes'][$i]['nodeId']));
         $result->variables['nodes'][$i]['link'] = $this->request->getHostURI() . $linkURI . $contentQueryString;
     }
     // Handle Metadata
     if ($this->hasResponseGroup(self::VIEWLIST_RESPONSEGROUP_METADATA)) {
         $childrenCount = ITOpenDataContentModel::getChildrenCount($crit);
         $result->variables['metadata'] = array('count' => $childrenCount, 'rootNodeId' => $nodeId, 'classIdentifier' => $classIdentifier, 'className' => $className, 'limit' => $limit, 'offset' => $offset);
     }
     return $result;
 }
Exemple #2
0
 /**
  * Handles a content request to view a node children list
  * Requests :
  *   - GET /api/v1/content/node/<nodeId>/list(/offset/<offset>/limit/<limit>/sort/<sortKey>/<sortType>)
  *   - Every parameters in parenthesis are optional. However, to have offset/limit and sort, the order is mandatory
  *     (you can't provide sorting params before limit params). This is due to a limitation in the regexp route.
  *   - Following requests are valid :
  *     - /api/ezp/content/node/2/list/sort/name => will display 10 (default limit) children of node 2, sorted by ascending name
  *     - /api/ezp/content/node/2/list/limit/50/sort/published/desc => will display 50 children of node 2, sorted by descending publishing date
  *     - /api/ezp/content/node/2/list/offset/100/limit/50/sort/published/desc => will display 50 children of node 2 starting from offset 100, sorted by descending publishing date
  *
  * Default values :
  *   - offset : 0
  *   - limit : 10
  *   - sortType : asc
  */
 public function doList()
 {
     $this->setDefaultResponseGroups(array(self::VIEWLIST_RESPONSEGROUP_METADATA));
     $result = new ezpRestMvcResult();
     $crit = new ezpContentCriteria();
     // Location criteria
     // Hmm, the following sequence is too long...
     $crit->accept[] = ezpContentCriteria::location()->subtree(ezpContentLocation::fetchByNodeId($this->nodeId));
     $crit->accept[] = ezpContentCriteria::depth(1);
     // Fetch children only
     // Limit criteria
     $offset = isset($this->offset) ? $this->offset : 0;
     $limit = isset($this->limit) ? $this->limit : 10;
     $crit->accept[] = ezpContentCriteria::limit()->offset($offset)->limit($limit);
     // Sort criteria
     if (isset($this->sortKey)) {
         $sortOrder = isset($this->sortType) ? $this->sortType : 'asc';
         $crit->accept[] = ezpContentCriteria::sorting($this->sortKey, $sortOrder);
     }
     $result->variables['childrenNodes'] = ezpRestContentModel::getChildrenList($crit, $this->request, $this->getResponseGroups());
     // REST links to children nodes
     // Little dirty since this should belong to the model layer, but I don't want to pass the router nor the full controller to the model
     $contentQueryString = $this->request->getContentQueryString(true);
     for ($i = 0, $iMax = count($result->variables['childrenNodes']); $i < $iMax; ++$i) {
         $linkURI = $this->getRouter()->generateUrl('ezpNode', array('nodeId' => $result->variables['childrenNodes'][$i]['nodeId']));
         $result->variables['childrenNodes'][$i]['link'] = $this->request->getHostURI() . $linkURI . $contentQueryString;
     }
     // Handle Metadata
     if ($this->hasResponseGroup(self::VIEWLIST_RESPONSEGROUP_METADATA)) {
         $childrenCount = ezpRestContentModel::getChildrenCount($crit);
         $result->variables['metadata'] = array('childrenCount' => $childrenCount, 'parentNodeId' => $this->nodeId);
     }
     return $result;
 }