コード例 #1
0
ファイル: Params.php プロジェクト: rimi-itk/bpi-web-service
 /**
  * {@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;
 }
コード例 #2
0
 /**
  *
  * @param  \Bpi\ApiBundle\Domain\Entity\Author $author
  * @param  Resource $resource
  * @param  \Bpi\ApiBundle\Domain\Entity\Profile $profile
  * @param  \Bpi\ApiBundle\Domain\Aggregate\Params $params
  * @throws \LogicException
  * @return \Bpi\ApiBundle\Domain\Aggregate\Node
  */
 public function push(Author $author, ResourceBuilder $resource_builder, $category, $audience, Profile $profile, Params $params)
 {
     $authorship = $params->filter(function ($e) {
         if ($e instanceof Authorship) {
             return true;
         }
     })->first();
     $this->assignCopyleft($author, $resource_builder, $authorship);
     $resource = $resource_builder->build();
     // Find dublicates
     $dublicates = $resource->findSimilar($this->manager->getRepository('BpiApiBundle:Aggregate\\Node'));
     if (count($dublicates)) {
         throw new \LogicException('Found similar resource');
     }
     $builder = new NodeBuilder();
     $builder->author($author)->profile($profile)->resource($resource)->params($params);
     // Set default category.
     if (empty($category)) {
         $category = 'Other';
     }
     // Find category entity.
     $category = $this->manager->getRepository('BpiApiBundle:Entity\\Category')->findOneBy(array('category' => $category));
     $builder->category($category);
     // Set default audience.
     if (empty($audience)) {
         $audience = 'All';
     }
     // Find audience entity.
     $audience = $this->manager->getRepository('BpiApiBundle:Entity\\Audience')->findOneBy(array('audience' => $audience));
     $builder->audience($audience);
     $node = $builder->build();
     $log = new History($node, $author->getAgencyId(), new \DateTime(), 'push');
     $this->manager->getRepository('BpiApiBundle:Aggregate\\Node')->save($node);
     $this->manager->persist($log);
     $this->manager->flush();
     $this->manager->getRepository('BpiApiBundle:Entity\\Facet')->prepareFacet($node);
     return $node;
 }