Пример #1
0
 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;
 }
 public function setClassIdentifier($classIdentifier)
 {
     if ($classIdentifier) {
         if (method_exists('OCOpenDataTools', 'getClassBlacklist')) {
             $classBlacklist = OCOpenDataTools::getClassBlacklist();
             if (isset($classBlacklist[$classIdentifier])) {
                 throw new InvalidArgumentException("Class {$classIdentifier} not allowed");
             }
         }
         $this->mainClass = eZContentClass::fetchByIdentifier($classIdentifier);
         if (!$this->mainClass instanceof eZContentClass) {
             throw new InvalidArgumentException("Class {$classIdentifier} not found");
         }
         if ($this->ini->hasGroup('SettingsForClassIdentifier_' . $classIdentifier)) {
             $this->setOptions($this->ini->group('SettingsForClassIdentifier_' . $classIdentifier));
         }
     } else {
         throw new InvalidArgumentException("Class not found");
     }
 }
 public static function getRealFieldIdentifier($fieldName, $classIdentifier)
 {
     return OCOpenDataTools::getRealFieldIdentifier($fieldName, $classIdentifier);
 }