コード例 #1
0
 /**
  * Tests the metadata returned by model for given content
  * @group restContentServices
  */
 public function testGetMetadataByContent()
 {
     $res = ezpRestContentModel::getMetadataByContent(ezpContent::fromNodeId(2));
     self::assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $res);
     $expectedKeys = array('objectName', 'classIdentifier', 'datePublished', 'dateModified', 'objectRemoteId', 'objectId');
     foreach ($expectedKeys as $key) {
         self::assertArrayHasKey($key, $res, "Content must contain {$key} metadata");
     }
 }
コード例 #2
0
ファイル: content.php プロジェクト: legende91/ez
 /**
  * Handles a content unique field request through an object or node ID
  *
  * Requests:
  * - GET /api/content/node/:nodeId/field/:fieldIdentifier
  * - GET /api/content/object/:objectId/field/:fieldIdentifier
  *
  * @return ezpRestMvcResult
  */
 public function doViewField()
 {
     $this->setDefaultResponseGroups(array(self::VIEWFIELDS_RESPONSEGROUP_FIELDVALUES));
     $isNodeRequested = false;
     if (isset($this->nodeId)) {
         $isNodeRequested = true;
         $content = ezpContent::fromNodeId($this->nodeId);
     } else {
         if (isset($this->objectId)) {
             $content = ezpContent::fromObjectId($this->objectId);
         }
     }
     if (!isset($content->fields->{$this->fieldIdentifier})) {
         throw new ezpContentFieldNotFoundException("'{$this->fieldIdentifier}' field is not available for this content.");
     }
     // Translation parameter
     if ($this->hasContentVariable('Translation')) {
         $content->setActiveLanguage($this->getContentVariable('Translation'));
     }
     $result = new ezpRestMvcResult();
     // Field data
     if ($this->hasResponseGroup(self::VIEWFIELDS_RESPONSEGROUP_FIELDVALUES)) {
         $result->variables['fields'][$this->fieldIdentifier] = ezpRestContentModel::attributeOutputData($content->fields->{$this->fieldIdentifier});
     }
     // Handle object/node metadata
     if ($this->hasResponseGroup(self::VIEWFIELDS_RESPONSEGORUP_METADATA)) {
         $objectMetadata = ezpRestContentModel::getMetadataByContent($content, $isNodeRequested);
         if ($isNodeRequested) {
             $nodeMetadata = ezpRestContentModel::getMetadataByLocation(ezpContentLocation::fetchByNodeId($this->nodeId));
             $objectMetadata = array_merge($objectMetadata, $nodeMetadata);
         }
         $result->variables['metadata'] = $objectMetadata;
     }
     return $result;
 }