public function setUp() { /** @todo merge this into common domain fixtures */ $this->nodes = new \stdClass(); $this->resources = new \stdClass(); $this->authors = new \stdClass(); $util = new Util(); $resource_builder = $util->createResourceBuilder(); $this->resources->alpha = $resource_builder->body('alpha_body')->teaser('alpha_teaser')->title('alpha_title')->ctime(new \DateTime("-1 day"))->copyleft(new Copyleft('copyleft'))->build(); $this->resources->bravo = $resource_builder->body('bravo_body')->teaser('bravo_teaser')->title('bravo_title')->ctime(new \DateTime("+1 day"))->build(); $this->authors->alpha = new Author(new AgencyId(mt_rand()), mt_rand(), 'alpha_author'); $profile_alpha = new Profile(); $profile_bravo = new Profile(); $builder = new NodeBuilder(); $this->nodes->alpha = $builder->author($this->authors->alpha)->profile($profile_alpha)->resource($this->resources->alpha)->params(new Params(array('autorship' => new Authorship(1), 'editable' => new Editable(1))))->category(new Category('Other'))->audience(new Audience('All'))->build(); $this->nodes->bravo = $builder->author($this->authors->alpha)->profile($profile_bravo)->resource($this->resources->bravo)->params(new Params(array('autorship' => new Authorship(0), 'editable' => new Editable(1))))->category(new Category('Other'))->audience(new Audience('All'))->build(); }
/** * * @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; }