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; }
/** * 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; } } }
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; }
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; }
/** * 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; }
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; }