Пример #1
0
    public function doCollection()
    {
        // Document need to contain the minimum require data for each collection
        // Author, title, updated, id, link

        $crit = new ezpContentCriteria();
        $crit->accept[] = ezpContentCriteria::location()->subtree( ezpContentLocation::fetchByNodeId( $this->nodeId ) );

        $retData = array();
        $baseUri = substr( $this->request->protocol, 0, strpos( $this->request->protocol, "-" ) ) . "://{$this->request->host}";

        foreach ( ezpContentRepository::query( $crit ) as $node )
        {
            $retData[] = array(
                "objectName" => $node->name,
                "author" => $node->owner->Name,
                "modified" => $node->dateModified,
                "published" => $node->datePublished,
                "classIdentifier" => $node->classIdentifier,
                "nodeUrl" => $baseUri . $this->getRouter()->generateUrl( 1, array( "nodeId" => $node->locations->node_id ) )
            );
        }

        $result = new ezcMvcResult();
        $result->variables["collection"] = $retData;
        return $result;
    }
Пример #2
0
 /**
  * Tests metadata returned by model for given location
  * @group restContentServices
  */
 public function testGetMetadataByLocation()
 {
     $res = ezpRestContentModel::getMetadataByLocation( ezpContentLocation::fetchByNodeId( 2 ) );
     self::assertType( PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $res );
     
     $expectedKeys = array(
         'nodeId',
         'nodeRemoteId',
         'fullUrl'
     );
     
     foreach( $expectedKeys as $key )
     {
         self::assertArrayHasKey( $key, $res, "Content location must contain $key metadata" );
         switch( $key )
         {
             case 'nodeId':
                 self::assertType( PHPUnit_Framework_Constraint_IsType::TYPE_INT, $res[$key], 'NodeId must be an integer' );
             break;
                
             case 'nodeRemoteId':
             case 'fullUrl':
                 self::assertType( PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $res[$key] );
             break;
         }
     }
 }
Пример #3
0
    public function doCollection()
    {
        // Document need to contain the minimum require data for each collection
        // Author, title, updated, id, link

        $crit = new ezpContentCriteria();
        $crit->accept[] = ezpContentCriteria::location()->subtree( ezpContentLocation::fetchByNodeId( $this->nodeId ) );
        $childNodes = ezpContentRepository::query( $crit );


        $result = new ezcMvcResult();

        $retData = array();
        $protIndex = strpos( $this->request->protocol, '-' );
        $baseUri = substr( $this->request->protocol, 0, $protIndex ) . "://{$this->request->host}";
        foreach( $childNodes as $node )
        {
            $childEntry = array(
                            'objectName' => $node->name,
                            'author' => $node->owner->Name,
                            'modified' => $node->dateModified,
                            'published' => $node->datePublished,
                            'classIdentifier' => $node->classIdentifier,
                            'nodeUrl' => $baseUri . $this->getRouter()->generateUrl( 1, array( 'nodeId' => $node->locations->node_id ) ) );
            $retData[] = $childEntry;
        }

        $result->variables['collection'] = $retData;
        return $result;
    }
Пример #4
0
 /**
  * Instanciates an ezpContent from an eZContentObjectTreeNode
  * @param eZContentObjectTreeNode $node
  * @return ezpContent
  */
 public static function fromNode(eZContentObjectTreeNode $node, $checkAccess = true)
 {
     $object = $node->object();
     if ($checkAccess && !$object->attribute('can_read')) {
         throw new ezpContentAccessDeniedException($object->attribute('id'));
     }
     $content = new ezpContent();
     $content->fields = ezpContentFieldSet::fromContentObject($object);
     $content->object = $object;
     $content->locations = ezpContentLocation::fromNode($node);
     return $content;
 }
 /**
  * Returns all locations for provided content as array.
  * @param ezpContent $content
  * @return array Associative array with following keys :
  *                  - fullUrl => URL for content, including server
  *                  - nodeId => NodeID for location
  *                  - remoteId => RemoteID for location
  *                  - isMain => whether location is main for provided content
  */
 public static function getLocationsByContent(ezpContent $content)
 {
     $aReturnLocations = array();
     $assignedNodes = $content->assigned_nodes;
     foreach ($assignedNodes as $node) {
         $location = ezpContentLocation::fromNode($node);
         $locationData = self::getMetadataByLocation($location);
         $locationData['isMain'] = $location->is_main;
         $aReturnLocations[] = $locationData;
     }
     return $aReturnLocations;
 }
Пример #6
0
 public function doViewFields()
 {
     $this->setDefaultResponseGroups(array(self::VIEWFIELDS_RESPONSEGROUP_FIELDVALUES));
     $isNodeRequested = false;
     if (isset($this->nodeId)) {
         $content = ezpContent::fromNodeId($this->nodeId);
         $isNodeRequested = true;
     } else {
         if (isset($this->objectId)) {
             $content = ezpContent::fromObjectId($this->objectId);
         }
     }
     $result = new ezpRestMvcResult();
     // translation parameter
     if ($this->hasContentVariable('Translation')) {
         $content->setActiveLanguage($this->getContentVariable('Translation'));
     }
     // Handle field values
     if ($this->hasResponseGroup(self::VIEWFIELDS_RESPONSEGROUP_FIELDVALUES)) {
         $result->variables['fields'] = ITOpenDataContentModel::getFieldsByContent($content, $this->request, $this->getRouter());
     }
     // Handle object/node metadata
     if ($this->hasResponseGroup(self::VIEWFIELDS_RESPONSEGORUP_METADATA)) {
         $objectMetadata = ITOpenDataContentModel::getMetadataByContent($content);
         if ($isNodeRequested) {
             $nodeMetadata = ITOpenDataContentModel::getMetadataByLocation(ezpContentLocation::fetchByNodeId($this->nodeId));
             $objectMetadata = array_merge($objectMetadata, $nodeMetadata);
         }
         $result->variables['metadata'] = $objectMetadata;
     }
     return $result;
 }
Пример #7
0
 /**
  * Counts children of a given node
  * Request :
  *   - GET /api/ezp/content/node/childrenCount
  */
 public function doCountChildren()
 {
     $this->setDefaultResponseGroups(array(self::VIEWLIST_RESPONSEGROUP_METADATA));
     $result = new ezpRestMvcResult();
     if ($this->hasResponseGroup(self::VIEWLIST_RESPONSEGROUP_METADATA)) {
         $crit = new ezpContentCriteria();
         $crit->accept[] = ezpContentCriteria::location()->subtree(ezpContentLocation::fetchByNodeId($this->nodeId));
         $crit->accept[] = ezpContentCriteria::depth(1);
         // Fetch children only
         $childrenCount = ezpRestContentModel::getChildrenCount($crit);
         $result->variables['metadata'] = array('childrenCount' => $childrenCount, 'parentNodeId' => $this->nodeId);
     }
     return $result;
 }
Пример #8
0
 public function doList()
 {
     $crit = new ezpContentCriteria();
     // Hmm, the following sequence is too long...
     $crit->accept[] = ezpContentCriteria::location()->subtree(ezpContentLocation::fetchByNodeId($this->nodeId));
     $childNodes = ezpContentRepository::query($crit);
     // Need paging here
     $result = new ezcMvcResult();
     $retData = array();
     // To be moved to URI convenience methods
     $protIndex = strpos($this->request->protocol, '-');
     $baseUri = substr($this->request->protocol, 0, $protIndex) . "://{$this->request->host}";
     foreach ($childNodes as $node) {
         $childEntry = array('objectName' => $node->name, 'classIdentifier' => $node->classIdentifier, 'nodeUrl' => $baseUri . $this->getRouter()->generateUrl(1, array('nodeId' => $node->locations->node_id)));
         $retData[] = $childEntry;
     }
     $result->variables['childNodes'] = $retData;
     return $result;
 }
 public static function attributeOutputData(ezpContentField $field, ezpRestRequest $currentRequest = null, ezcMvcRouter $router = null)
 {
     $attributeValue = $stringValue = array();
     switch ($field->data_type_string) {
         case 'ezxmltext':
             $html = $field->content->attribute('output')->attribute('output_text');
             $attributeValue = array($html);
             $stringValue = array(strip_tags($html));
             break;
         case 'ezimage':
             if ($field->hasContent()) {
                 $strRepImage = $field->toString();
                 $delimPos = strpos($strRepImage, '|');
                 if ($delimPos !== false) {
                     $strRepImage = substr($strRepImage, 0, $delimPos);
                 }
                 $attributeValue = array(self::getHostURIFromRequest($currentRequest) . '/' . $strRepImage);
                 $stringValue = array($field->toString());
             }
             break;
         case 'ezbinaryfile':
             if ($field->hasContent()) {
                 $file = $field->content();
                 $filePath = "content/download/{$field->attribute('contentobject_id')}/{$field->attribute('id')}/{$field->content()->attribute('original_filename')}";
                 $attributeValue = array(self::getHostURIFromRequest($currentRequest) . '/' . $filePath);
                 $stringValue = array($field->toString());
             } else {
                 $attributeValue = array(null);
                 $stringValue = array(null);
             }
             break;
         case 'ezobjectrelationlist':
             $attributeValue = array();
             $stringValueArray = array();
             if ($currentRequest && $router) {
                 if ($field->hasContent()) {
                     $relations = $field->content();
                     foreach ($relations['relation_list'] as $relation) {
                         $id = $relation['contentobject_id'];
                         $object = eZContentObject::fetch($id);
                         if ($object instanceof eZContentObject && $object->attribute('main_node') instanceof eZContentObjectTreeNode) {
                             if ($object->attribute('can_read')) {
                                 $content = ezpContent::fromObject($object);
                                 $objectMetadata = OCOpenDataContentModel::getMetadataByContent($content);
                                 $contentQueryString = $currentRequest->getContentQueryString(true);
                                 try {
                                     if ($content->main_node) {
                                         $node = $content->main_node;
                                         $location = ezpContentLocation::fromNode($node);
                                         $objectMetadata = array_merge($objectMetadata, self::getMetadataByLocation($location));
                                         $stringValueArray[] = $id;
                                     } else {
                                         throw new Exception("Node not found for object id #{$id}");
                                     }
                                 } catch (Exception $e) {
                                 }
                                 $objectMetadata['link'] = self::getHostURIFromRequest($currentRequest) . $router->generateUrl('ezpObject', array('objectId' => $id)) . $contentQueryString;
                                 $attributeValue[] = $objectMetadata;
                             }
                             //else
                             //{
                             //    $attributeValue[] = "Access not allowed for content $id";
                             //}
                         }
                     }
                 }
             }
             $stringValue = array(implode('-', $stringValueArray));
             break;
         case 'ezobjectrelation':
             $attributeValue = array();
             $stringValue = array($field->toString());
             if ($currentRequest && $router) {
                 if ($field->hasContent()) {
                     $relation = $field->content();
                     if ($relation->attribute('can_read')) {
                         $id = $relation->attribute('id');
                         $content = ezpContent::fromObject($relation);
                         $objectMetadata = OCOpenDataContentModel::getMetadataByContent($content);
                         $objectMetadata['link'] = self::getHostURIFromRequest($currentRequest) . $router->generateUrl('ezpObject', array('objectId' => $id));
                         $attributeValue[] = $objectMetadata;
                     }
                 }
             }
             break;
         default:
             $datatypeBlacklist = self::getDatatypeBlackList();
             if (isset($datatypeBlacklist[$field->data_type_string])) {
                 $attributeValue = array(null);
                 $stringValue = array(null);
             } elseif ($field->hasContent()) {
                 $attributeValue = array($field->toString());
                 $stringValue = array($field->toString());
             }
             break;
     }
     if (count($attributeValue) == 0) {
         $attributeValue = false;
     } elseif (count($attributeValue) == 1) {
         $attributeValue = current($attributeValue);
     }
     if (count($stringValue) == 0) {
         $stringValue = false;
     } elseif (count($stringValue) == 1) {
         $stringValue = current($stringValue);
     }
     $return = array('name' => $field->contentclass_attribute_name, 'description' => $field->contentclass_attribute->attribute('description'), 'identifier' => $field->contentclass_attribute_identifier, 'id' => (int) $field->id, 'classattribute_id' => (int) $field->contentclassattribute_id, 'type' => $field->data_type_string, 'value' => $attributeValue, 'string_value' => $stringValue);
     return $return;
 }