/** * Get signatures informations * * @param RestoUser $_user * @return array */ private function getSignatures($_user) { $_collections = new RestoCollections($this->context, $_user, array('autoload' => true)); $_collectionsList = $_collections->getCollections(); $signatures = array(); foreach ($_collectionsList as $collection) { $signatures[$collection->name] = array('isApplicableToUser' => $collection->license->isApplicableToUser($_user), 'hasToBeSignedByUser' => $collection->license->hasToBeSignedByUser($_user)); } return $signatures; }
/** * * Process HTTP POST request on collections * * collections | Create a new {collection} * collections/{collection} | Insert new product within {collection} * * @param array $segments * @param array $data */ private function POST_collections($segments, $data) { /* * No feature allowed */ if (isset($segments[2]) ? $segments[2] : null) { RestoLogUtil::httpError(404); } if (isset($segments[1])) { $collection = new RestoCollection($segments[1], $this->context, $this->user, array('autoload' => true)); } /** * * Create new collection * * @SWG\Post( * tags={"collections"}, * path="/collections", * summary="Create collection", * description="Create new collection within database", * operationId="createCollection", * produces={"application/json"}, * @SWG\Response( * response="200", * description="Acknowledgment that collection was created" * ), * @SWG\Response( * response="403", * description="Forbidden" * ) * ) * */ if (!isset($collection)) { /* * Only a user with 'create' rights can POST a collection */ if (!$this->user->hasRightsTo(RestoUser::CREATE)) { RestoLogUtil::httpError(403); } $collections = new RestoCollections($this->context, $this->user, array('autoload' => true)); $collections->create($data); return RestoLogUtil::success('Collection ' . $data['name'] . ' created'); } else { /* * Only a user with 'update' rights on collection can POST feature */ if (!$this->user->hasRightsTo(RestoUser::UPDATE, array('collection' => $collection))) { RestoLogUtil::httpError(403); } return $this->addFeatureToCollection($collection, $data); } }
/** * @depends testInsertResource * */ public function testGetCollections() { $this->initContext(); $collections = new RestoCollections($this->context, $this->admin, array('autoload' => true)); $this->assertEquals('Example', $collections->getCollection('Example')->name); $colls = $collections->getCollections(); $this->assertEquals('Example', $colls['Example']->name); $stats = $collections->getStatistics(); $json = json_decode($collections->toJSON(false)); $this->assertEquals('*', $json->synthesis->name); /* * TODO : check for toXML function */ $xml = $collections->toXML(); /* * TODO : chek feature collection */ $featureCollection = $collections->search(); $data = file_get_contents(dirname(__FILE__) . "/../data/Land.json"); $data = json_decode($data, true); $this->assertEquals(true, $collections->create($data)); $collections->remove('Land'); }