예제 #1
0
 /**
  * {@inheritdoc}
  *
  * @param \Bpi\RestMediaTypeBundle\Document $document
  */
 public function transform(\Bpi\RestMediaTypeBundle\Document $document)
 {
     $entity = $document->createEntity('category');
     $document->appendEntity($entity);
     $entity->addProperty($document->createProperty('group', 'string', 'category'));
     $entity->addProperty($document->createProperty('name', 'string', $this->getCategory()));
 }
예제 #2
0
 /**
  * {@inheritdoc}
  * @return Bpi\ApiBundle\Domain\Aggregate\Params
  */
 public function extract()
 {
     $entity = $this->doc->getEntity('params');
     $params = new DomainParams();
     $params->add(new Editable($entity->property('editable')->getValue()));
     $params->add(new Authorship($entity->property('authorship')->getValue()));
     return $params;
 }
예제 #3
0
 public function testChangeOwnerOnAddEntity()
 {
     $doc = new Document();
     $doc2 = new Document();
     $bar = $doc2->createEntity('bar');
     $doc->appendEntity($bar);
     $this->assertTrue($bar->isOwner($doc));
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function transform(Document $document)
 {
     $agencyInternal = false === $this->internal ? '0' : '1';
     $entity = $document->currentEntity();
     $entity->addProperty($document->createProperty('agency_id', 'string', $this->public_id));
     $entity->addProperty($document->createProperty('agency_name', 'string', $this->name));
     $entity->addProperty($document->createProperty('agency_internal', 'boolean', $agencyInternal));
 }
예제 #5
0
 /**
  *
  * {@inheritdoc}
  * @return \Bpi\ApiBundle\Domain\Entity\Author
  */
 public function extract()
 {
     $author = $this->doc->getEntity('author');
     $firstname = $author->hasProperty('firstname') ? $author->property('firstname')->getValue() : null;
     $lastname = $author->hasProperty('lastname') ? $author->property('lastname')->getValue() : null;
     if (is_null($lastname) && !is_null($firstname)) {
         $lastname = $firstname;
         unset($firstname);
     }
     return new DomainAuthor(new AgencyId($author->property('agency_id')->getValue()), $author->property('local_id')->getValue(), $lastname, $firstname);
 }
예제 #6
0
 /**
  * {@inheritdoc}
  * @return Bpi\ApiBundle\Domain\Factory\ResourceBuilder
  */
 public function extract()
 {
     $entity = $this->doc->getEntity('resource');
     $builder = new ResourceBuilder();
     $fs = new Filesystem(new MemoryAdapter());
     $entity->walk(function ($e) use($builder, $fs) {
         if ($e->typeOf(Property::TYPE_ASSET)) {
             $file = new File($e->getName(), $fs);
             $file->setContent($e->getValue());
             $builder->addFile($file);
         }
     });
     return $builder->title($entity->property('title')->getValue())->body($entity->property('body')->getValue())->teaser($entity->property('teaser')->getValue())->ctime(new \DateTime($entity->property('ctime')->getValue()));
 }
예제 #7
0
 /**
  *
  * {@inheritdoc}
  * @return DomainProfile
  */
 public function extract()
 {
     $entity = $this->doc->getEntity('profile');
     $builder = new Builder();
     $builder->audience(new Audience($entity->property('audience')->getValue()))->category(new Category($entity->property('category')->getValue()));
     // optional yearwheel property
     if ($entity->hasProperty('yearwheel')) {
         $builder->yearwheel(new Yearwheel($entity->property('yearwheel')->getValue()));
     }
     // optional tags property
     if ($entity->hasProperty('tags')) {
         $builder->tags($entity->property('tags')->getValue());
     }
     return $builder->build();
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function transform(Document $document)
 {
     try {
         $entity = $document->currentEntity();
     } catch (\RuntimeException $e) {
         $entity = $document->createEntity('entity', 'statistics');
         $document->appendEntity($entity);
     }
     $fields = array('push', 'syndicate');
     foreach ($fields as $field) {
         $value = 0;
         if (isset($this->stats[$field])) {
             $value = $this->stats[$field];
         }
         $entity->addProperty($document->createProperty($field, 'string', $value));
     }
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 public function transform(Document $document)
 {
     try {
         $entity = $document->currentEntity();
     } catch (\RuntimeException $e) {
         $entity = $document->createEntity('entity', 'author');
         $document->appendEntity($entity);
     }
     $entity->addProperty($document->createProperty('author', 'string', $this->getFullName()));
     if ($this->agency instanceof \Bpi\ApiBundle\Domain\Aggregate\Agency) {
         $this->agency->transform($document);
     }
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 public function transform(Document $document)
 {
     try {
         $entity = $document->currentEntity();
     } catch (\RuntimeException $e) {
         $entity = $document->createEntity('entity', 'profile');
         $document->appendEntity($entity);
     }
     if ($this->yearwheel instanceof Yearwheel) {
         $entity->addProperty($document->createProperty('yearwheel', 'string', $this->yearwheel->name()));
     }
     if ($this->tags && $this->tags->count()) {
         $entity->addProperty($document->createProperty('tags', 'string', implode(', ', $this->tags->toArray())));
     }
 }
예제 #11
0
 /**
  * {@inheritdoc}
  *
  * @param \Bpi\RestMediaTypeBundle\Document $document
  */
 public function transform(\Bpi\RestMediaTypeBundle\Document $document)
 {
     $document->currentEntity()->addProperty($document->createProperty($this->name, 'yearwheel', $this->name));
 }
예제 #12
0
 /**
  * {@inheritdoc}
  */
 public function transform(Document $document)
 {
     try {
         $entity = $document->currentEntity();
     } catch (\RuntimeException $e) {
         $entity = $document->createEntity('entity', 'resource');
         $document->appendEntity($entity);
     }
     // Add assets to presentation.
     $i = 1;
     foreach ($this->assets as $asset) {
         $assetUrl = $document->generateRoute("get_asset", array('filename' => $asset['file'], 'extension' => $asset['extension']), true);
         $entity->addProperty($document->createProperty('asset' . $i, 'asset', $assetUrl));
         $i++;
     }
     $copyleft = '<p>' . $this->copyleft . '</p>';
     $entity->addProperty($document->createProperty('title', 'string', $this->title));
     $entity->addProperty($document->createProperty('body', 'string', $this->body->getFlattenContent() . $copyleft));
     $entity->addProperty($document->createProperty('teaser', 'string', $this->teaser));
     $entity->addProperty($document->createProperty('creation', 'dateTime', $this->ctime));
     $entity->addProperty($document->createProperty('type', 'string', $this->type));
     foreach ($this->materials as $material) {
         $entity->addProperty($document->createProperty('material', 'string', (string) $material));
     }
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function transform(Document $document)
 {
     $entity = $document->createEntity('entity');
     $entity->addProperty($document->createProperty('id', 'string', $this->getId()));
     $entity->addProperty($document->createProperty('pushed', 'dateTime', $this->ctime));
     $entity->addProperty($document->createProperty('editable', 'boolean', (int) $this->params->filter(function ($e) {
         if ($e instanceof Editable) {
             return true;
         }
     })->first()->isPositive()));
     $document->appendEntity($entity);
     $document->setCursorOnEntity($entity);
     $this->author->transform($document);
     $entity->addProperty($document->createProperty('category', 'string', $this->getCategory()->getCategory()));
     $entity->addProperty($document->createProperty('audience', 'string', $this->getAudience()->getAudience()));
     $entity->addProperty($document->createProperty('syndications', 'string', null === $this->getSyndications() ? 0 : $this->getSyndications()));
     $this->profile->transform($document);
     $this->resource->transform($document);
 }