public function retrieveUsers($date) { $users = new \Doctrine\Common\Collections\ArrayCollection(); $articleRepo = $this->getManager()->getRepository('AppBundle:Article'); $articles = $articleRepo->findWithNotifications($date); foreach ($articles as $article) { if ($article->getAnswers()->count()) { foreach ($article->getAnswers() as $answer) { if ($answer->getCreated() < $date && !$answer->getEmailSent()) { if (!$users->contains($answer->getUser())) { $users->add($answer->getUser()); } $answer->setEmailSent(true); $this->getEntityManager()->persist($answer); $this->getEntityManager()->flush($answer); } } } if ($article->getRatings()->count()) { foreach ($article->getRatings() as $rating) { if ($rating->getCreated() < $date && $rating->getEmailSent()) { if (!$users->contains($rating->getUser())) { $users->add($rating->getUser()); } $rating->setEmailSent(true); $this->getEntityManager()->persist($rating); $this->getEntityManager()->flush($rating); } } } } return $users; }
public function testGetAddRemoveRoles() { $roles = new \Doctrine\Common\Collections\ArrayCollection(); $roles->add($this->getMock('Usermanager\\Entity\\Role')); $roles->add($this->getMock('Usermanager\\Entity\\Role')); $this->assertCount(0, $this->entity->getRoles()); $this->entity->addRoles($roles); $this->assertCount(2, $this->entity->getRoles()); $this->entity->removeRoles($roles); $this->assertCount(0, $this->entity->getRoles()); }
private function mockRepository() { $productRepository = $this->getMockBuilder('\\Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $productRepository->expects($this->any())->method('find')->will($this->returnValue($this->mockProduct())); $products = new Doctrine\Common\Collections\ArrayCollection(); $products->add($this->mockProduct()); $products->add($this->mockProduct()); $products->add($this->mockProduct()); $productRepository->expects($this->any())->method('findAll')->will($this->returnValue($products)); return $productRepository; }
public function testGetAddRemovePermissions() { $permissions = new \Doctrine\Common\Collections\ArrayCollection(); $permissions->add($this->getMock('Usermanager\\Entity\\Permission')); $permissions->add($this->getMock('Usermanager\\Entity\\Permission')); $this->assertCount(0, $this->entity->getPermissions()); $this->entity->addPermissions($permissions); $this->assertCount(2, $this->entity->getPermissions()); $this->entity->removePermissions($permissions); $this->assertCount(0, $this->entity->getPermissions()); }
/** * @test */ public function setQuestionsWorks() { $question1 = new MultipleChoiceQuestion(); $question2 = new MultipleChoiceQuestion(); $questions = new \Doctrine\Common\Collections\ArrayCollection(); $questions->add($question1); $questions->add($question2); $exercise = new MultipleChoiceSameAnswerExercise(); $exercise->setQuestions($questions); $this->assertEquals(2, $exercise->getMaxScore()); }
/** * Tests if a returned collection of UserEntity objects is of the correct type and * of the correct length. */ public function testGetUserEntityCollectionSucessful() { $expectedUserEntityCollection = new \Doctrine\Common\Collections\ArrayCollection(); $expectedUserEntityCollection->add(new Entity\UserEntity()); $expectedUserEntityCollection->add(new Entity\UserEntity()); $expectedUserEntityCollection->add(new Entity\UserEntity()); $mockUserRepository = $this->getMockUserRepository(); $mockUserRepository->method('getUserEntityCollection')->will($this->returnValue($expectedUserEntityCollection)); $userManager = new UserManager(); $userManager->setUserRepository($mockUserRepository); $userEntityCollection = $userManager->getUserEntityCollection(); $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $userEntityCollection); $this->assertEquals(count($userEntityCollection), count($expectedUserEntityCollection)); }
public function reverseTransform($string) { if ($this->options['multiple']) { if (!$string) { $result = new \Doctrine\Common\Collections\ArrayCollection(); } else { $items = explode(',', $string); $result = new \Doctrine\Common\Collections\ArrayCollection(); $repo = $this->repository; foreach ($items as $item) { $id = preg_replace('/^([0-9]+)\\:.*/', '$1', $item); $itemEntity = $repo->findOneById((int) $id); if (is_object($itemEntity)) { $result->add($itemEntity); } } } } else { if (!$string) { $result = null; } else { $id = preg_replace('/^([0-9]+)\\:.*/', '$1', $string); $itemEntity = $this->repository->findOneById((int) $id); if (is_object($itemEntity)) { $result = $itemEntity; } } } return $result; }
/** * * @param string $string String to transform * * @return Tag $tag * */ public function reverseTransform($string) { $tags = new \Doctrine\Common\Collections\ArrayCollection(); $arrayOfTags = explode(",", $string); foreach ($arrayOfTags as $nameOfTag) { $result = $this->om->getRepository('AcmeBlogBundle:Tag')->findOneByName($nameOfTag); if (!$result) { //Action when tag don't exist $tag = new Tag(); $tag->setName($nameOfTag); $tags->add($tag); } else { $tags->add($result); } } return $tags; }
/** * @return \Doctrine\Common\Collections\ArrayCollection */ public function getRootMenuItems() { $rootItems = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($this->menuItems as &$m) { if ($m->parent == null) { $rootItems->add($m); } } return $rootItems; }
/** * Takes a pile of commits, then puts together all the repositories that are affected by * at least one of the given commits. * * @param \TYPO3\Flow\Persistence\QueryResultInterface the pile of commits * @return \Doctrine\Common\Collections\ArrayCollection the resulting stack of repositories */ public function extractTheRepositoriesFromAStackOfCommits(\TYPO3\Flow\Persistence\QueryResultInterface $commits) { $result = new \Doctrine\Common\Collections\ArrayCollection(); if ($commits->count()) { foreach ($commits as $commit) { if (!$result->contains($commit->getRepository())) { $result->add($commit->getRepository()); } } } return $result; }
/** * Transforms a string (number) to an object (issue). * * @param string $number * * @return Issue|null * * @throws TransformationFailedException if object (issue) is not found. */ public function reverseTransform($tags) { if (!$tags) { return null; } $tags = explode($this->separator, $tags); $ret = array(); $collection = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($tags as $t) { if ($tmp = $this->om->getRepository(MyTag::class)->findOneBy(['name' => $t])) { $collection->add($tmp); } else { $tag = new MyTag(); $tag->setName($t); $this->om->persist($tag); $this->om->flush(); /*Add ne tag to collection*/ $collection->add($tag); } } return $collection; }
/** * @dataProvider questionDataProvider * @param array $data */ public function testGetQuestions($data) { $exercise = new DragAndDropWordToQuestionExercise(); $questions = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($data as $row) { $question = new DragAndDropQuestion(); $question->setQuestion($row['question']); $question->setAnswer($row['answer']); $questions->add($question); } $this->assertNull($exercise->setQuestions($questions)); $this->assertSame($questions, $exercise->getQuestions()); }
/** * @dataProvider questionsDataProvider * @param array $data */ public function testSetQuestions($data) { $exercise = new SpellingAndGrammarCommaExercise(); $questions = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($data as $row) { $question = new SpellingAndGrammarCommaQuestion(); $question->setQuestionWithComma($row['questionWithComma']); $question->setQuestionWithoutComma($row['questionWithoutComma']); $questions->add($question); } $this->assertNull($exercise->setQuestions($questions)); $this->assertSame($questions, $exercise->getQuestions()); }
/** * @test * @author Christopher Hlubek <*****@*****.**> */ public function entityReferencesReturnsSimpleAndArrayReferences() { $baseEntity = new \TYPO3\CouchDB\Tests\Functional\Fixtures\Domain\Model\TestEntity(); $simpleReferencedEntity = new \TYPO3\CouchDB\Tests\Functional\Fixtures\Domain\Model\TestEntity(); $baseEntity->setRelatedEntity($simpleReferencedEntity); $arrayReferencedEntity = new \TYPO3\CouchDB\Tests\Functional\Fixtures\Domain\Model\TestEntity(); $relatedEntities = new \Doctrine\Common\Collections\ArrayCollection(); $relatedEntities->add($arrayReferencedEntity); $relatedEntities->add($baseEntity); $baseEntity->setRelatedEntities($relatedEntities); $this->persistenceManager->add($baseEntity); $baseIdentifier = $this->persistenceManager->getIdentifierByObject($baseEntity); $simpleReferenceIdentifier = $this->persistenceManager->getIdentifierByObject($simpleReferencedEntity); $arrayReferenceIdentifier = $this->persistenceManager->getIdentifierByObject($arrayReferencedEntity); $this->persistenceManager->persistAll(); $identifiers = $this->design->entityReferences($simpleReferenceIdentifier); $this->assertEquals(1, count($identifiers)); $this->assertEquals($baseIdentifier, $identifiers[0]); $identifiers = $this->design->entityReferences($arrayReferenceIdentifier); $this->assertEquals(1, count($identifiers)); $this->assertEquals($baseIdentifier, $identifiers[0]); $identifiers = $this->design->entityReferences($baseIdentifier); $this->assertEquals(0, count($identifiers)); }
/** * Transforms a string (id) to an object (media). * * @param string $id * * @return Media|null * * @throws TransformationFailedException if object (media) is not found. */ public function reverseTransform($array) { $medias = new \Doctrine\Common\Collections\ArrayCollection(); if (!$array || !preg_match('#^[0-9]+(;[0-9])*$#', $array)) { return $medias; } $ids = explode(';', $array); foreach ($ids as $id) { $media = $this->objectManager->getRepository($this->mediaClass)->find($id); if (null === $media) { throw new TransformationFailedException(sprintf('Media "%s" is not found !', $id)); } $medias->add($media); } return $medias; }
/** * Transforms a string (id) to an object (PlaceImage). * * @param string $ids * * @return PlaceImage[]|null * * @throws TransformationFailedException if object (PlaceImage) is not found. */ public function reverseTransform($ids) { //var_dump($ids);die('transformer'); if (!$ids) { return null; } $ids = explode($this->separator, $ids); $collection = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($ids as $id) { if ($tmp = $this->om->getRepository(PlaceHallImage::class)->findOneBy(['id' => $id])) { //var_dump($tmp);die(); $collection->add($tmp); } } return $collection; }
/** * @param \BoilerAppAccessControl\Entity\AuthAccessEntity $oAuthAccess * @return \Doctrine\Common\Collections\ArrayCollection */ public function getLatestActivityLogs(\BoilerAppAccessControl\Entity\AuthAccessEntity $oAuthAccess) { $oLatestsActivityLogs = new \Doctrine\Common\Collections\ArrayCollection(); while ($oLatestsActivityLogs->count() < 5) { $oCriteria = new \Doctrine\Common\Collections\Criteria(null, array('entity_create' => 'DESC'), null, 1); $aCriteria = array(); if ($oLatestsActivityLogs->count()) { $oLastLog = $oLatestsActivityLogs->last(); $oCriteria->andWhere(\Doctrine\Common\Collections\Criteria::expr()->neq('log_session_id', $oLastLog->getLogSessionId()))->andWhere(\Doctrine\Common\Collections\Criteria::expr()->lt('entity_create', $oLastLog->getEntityCreate())); } if (!($oLogs = $this->matching($oCriteria)) || !$oLogs->count()) { break; } $oLatestsActivityLogs->add($oLogs->current()); } return $oLatestsActivityLogs; }
/** * Count the total of rows * * @return int */ public function getAdverts($start, $end, $section = null) { if ($count == 0) { $count2 = 0; $qb2 = $this->getQueryBuilder()->join('a.located', 'l')->where('l.name = :section')->andWhere('a.from <= :start')->andWhere('a.to >= :end')->andWhere('a.active = :active')->setParameters(array('section' => $section, 'start' => $start, 'end' => $end, 'active' => true)); $query = $qb2->getQuery(); } //->orderBy('s.day', 'ASC') $adverts = array(); if (is_object($query)) { $adverts = $query->getResult(); } $arr = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($adverts as $ad) { $arr->add($ad); } return $arr; }
public function onFlush(OnFlushEventArgs $args) { if (PHP_SAPI === 'cli') { return; } $this->em = $args->getEntityManager(); $eventManager = $this->em->getEventManager(); $eventManager->removeEventListener('onFlush', $this); $this->uow = $this->em->getUnitOfWork(); $histories = new \Doctrine\Common\Collections\ArrayCollection(); $this->hmeta = $this->em->getClassMetadata('DLigo\\Animaltool\\Domain\\Model\\HistoryChange'); $user = $this->session->getUser(); $this->userId = $this->persistenceManager->getIdentifierByObject($user); $this->userLabel = $user->__toString(); foreach ($this->uow->getScheduledEntityInsertions() as $entity) { $meta = $this->em->getClassMetadata(get_class($entity)); $this->putAnimal($entity, $meta); $history = array('entity' => $entity, 'changes' => $this->uow->getEntityChangeSet($entity), 'meta' => $meta, 'type' => 'INSERT'); $histories->add($history); $this->em->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $entity); } foreach ($this->uow->getScheduledEntityDeletions() as $entity) { $meta = $this->em->getClassMetadata(get_class($entity)); $this->putAnimal($entity, $meta); $history = array('entity' => $entity, 'changes' => null, 'meta' => $meta, 'type' => 'DELETE'); $histories->add($history); } foreach ($this->uow->getScheduledEntityUpdates() as $key => $entity) { $meta = $this->em->getClassMetadata(get_class($entity)); $this->putAnimal($entity, $meta); $history = array('entity' => $entity, 'changes' => $this->uow->getEntityChangeSet($entity), 'meta' => $meta, 'type' => 'UPDATE'); $histories->add($history); $this->uow->computeChangeSet($meta, $entity); } foreach ($histories as $h) { $this->processHistory($h); } $eventManager->addEventListener('onFlush', $this); }
public function __clone() { if ($this->id) { $this->id = null; $newWordResponses = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($this->wordResponses as $wordResponse) { $newWordResponse = clone $wordResponse; $newWordResponse->setHole($this); $newWordResponses->add($newWordResponse); } $this->wordResponses = $newWordResponses; } }
/** * @covers Core\Entity\SubjectRound::addTeacher * @covers Core\Entity\SubjectRound::removeTeacher */ public function testAddRemoveTeacher() { $sr = new SubjectRound(); $this->assertEquals(0, $sr->getTeacher()->count()); $mockTeacher = $this->getMockBuilder('Core\\Entity\\Teacher')->getMock(); $teachers = new \Doctrine\Common\Collections\ArrayCollection(); $teachers->add($mockTeacher); $sr->addTeacher($teachers); $this->assertEquals(1, $sr->getTeacher()->count()); $this->assertEquals($mockTeacher, $sr->getTeacher()->first()); $sr->removeTeacher($teachers); $this->assertEquals(0, $sr->getTeacher()->count()); }
/** * Get exploitations * * @return \Doctrine\Common\Collections\Collection */ public function getExploitations() { $exploitations = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($this->apiculteurExploitations as $apiculteurExploitation) { $exploitations->add($apiculteurExploitation->getExploitation()); } return $exploitations; }
/** * @test */ public function reconstituteCollectionWorks() { $mockObject1 = new \stdClass(); $mockObject2 = new \stdClass(); $objectsAsArray = ['some object' => ['object1 data'], 'some other object' => ['object2 data']]; $objectSerializer = $this->getAccessibleMock(ObjectSerializer::class, ['reconstituteObject'], [], '', false); $objectSerializer->expects($this->at(0))->method('reconstituteObject')->with('some object', ['object1 data'])->will($this->returnValue($mockObject1)); $objectSerializer->expects($this->at(1))->method('reconstituteObject')->with('some other object', ['object2 data'])->will($this->returnValue($mockObject2)); $objectSerializer->_set('objectsAsArray', $objectsAsArray); $dataArray = ['some object', 'some other object']; $expectedResult = new \Doctrine\Common\Collections\ArrayCollection(); $expectedResult->add($mockObject1); $expectedResult->add($mockObject2); $this->assertEquals($expectedResult, $objectSerializer->_call('reconstituteCollection', 'Doctrine\\Common\\Collections\\ArrayCollection', $dataArray), 'The Collection was not reconstituted correctly.'); }
/** * Helper function to set the association data of a ORM\OneToMany association of doctrine. * <br><br> * The <b>$data</b> parameter contains the data for the collection property. It can contains an array of * models or data arrays. If the $data parameter is set to null the associated collection will cleared. * <br><br> * The <b>$model</b> parameter expects the full name of the associated model. * For example: * <ul> * <li>We are in the Customer model in the setOrders() function.</li> * <li>Here we want to set the Order objects over the "setOneToMany" function</li> * <li>So we passed as $model parameter: <b>"\Shopware\Models\Order\Order"</b></li> * </ul> * <br> * The <b>$property</b> parameter expect the name of the association property. * For example: * <ul> * <li>In the setOrders() function of the customer model we would expects <b>"orders"</b>.</li> * </ul> * <br> * The <b>$reference</b> property expect the name of the property on the other side of the association. * For example: * <ul> * <li>In the setOrders() function we want to fill the orders data.</li> * <li>To set the reference between customer and orders we set in the orders object the "customer"</li> * <li>To set the customer we use the "$order->setCustomer()" function.</li> * <li>So the parameter expect <b>"customer"</b></li> * </ul> * * @param array|null $data Model data, example: an array of \Shopware\Models\Order\Order * @param string $model Full namespace of the association model, example: '\Shopware\Models\Order\Order' * @param string $property Name of the association property, example: 'orders' * @param string $reference Name of the reference property, example: 'customer' * @return \Shopware\Components\Model\ModelEntity */ public function setOneToMany($data, $model, $property, $reference = null) { $getterFunction = "get" . ucfirst($property); $setterFunction = null; if ($reference !== null) { $setterFunction = "set" . ucfirst($reference); } //to remove the whole one to many association, u can pass null as parameter. if ($data === null) { $this->{$getterFunction}()->clear(); return $this; } //if no array passed or if false passed, return if (!is_array($data)) { return $this; } //create a new collection to collect all updated and created models. $updated = new \Doctrine\Common\Collections\ArrayCollection(); //iterate all passed items foreach ($data as $item) { //to get the right collection item use the internal helper function if (is_array($item) && isset($item['id']) && $item['id'] !== null) { $attribute = $this->getArrayCollectionElementById($this->{$getterFunction}(), $item['id']); if (!$attribute instanceof $model) { $attribute = new $model(); } //if the item is an array without an id, create a new model. } elseif (is_array($item)) { $attribute = new $model(); //if the item is no array, it could be an instance of the expected object. } else { $attribute = $item; } //check if the object correctly initialed. If this is not the case continue. if (!$attribute instanceof $model) { continue; } //if the current item is an array, use the from array function to set the data. if (is_array($item)) { $attribute->fromArray($item); } //after the attribute filled with data, set the association reference and add the model to the internal collection. if ($setterFunction !== null) { $attribute->{$setterFunction}($this); } if (!$this->{$getterFunction}()->contains($attribute)) { $this->{$getterFunction}()->add($attribute); } //add the model to the updated collection to have an flag which models updated. $updated->add($attribute); } //after all passed data items added to the internal collection, we have to iterate the items //to remove all old items which are not updated. foreach ($this->{$getterFunction}() as $attr) { //the updated collection contains all updated and created models. if (!$updated->contains($attr)) { $this->{$getterFunction}()->removeElement($attr); } } return $this; }
public function appendContribution($contribution) { $this->contributions->add($contribution); }
protected function cloneProducts($products, $newCart) { $newProducts = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($products as $product) { // dump($newCart); $newProduct = clone $product; $newProducts->add($newProduct); } dump($newProducts); return $newProducts; }
/** * Helper function returns total count of the passed query builder * * @param \Doctrine\ORM\Query $dataQuery * @return int|null */ private function getStatisticListTotalCount(\Doctrine\ORM\Query $dataQuery) { //userCurrencyFactor has not to be part of the count parameters $originalParameters = $dataQuery->getParameters(); $countParameters = new \Doctrine\Common\Collections\ArrayCollection(); /** @var \Doctrine\ORM\Query\Parameter $parameter */ foreach ($originalParameters as $parameter) { if ($parameter->getName() === 'userCurrencyFactor') { continue; } $countParameters->add($parameter); } $dataQuery->setParameters($countParameters); $totalCount = Shopware()->Models()->getQueryCount($dataQuery); $dataQuery->setParameters($originalParameters); return $totalCount; }
/** * @api * @return \Doctrine\Common\Collections\ArrayCollection */ public function getResult() { $result = $this->execute(); $list = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($result as $row) { $entry = array(); foreach ($row as $key => $value) { $entry[$key] = $this->convertValue($value); } $list->add($entry); } return $list; }
/** * @param array $data * @param \Shopware\Models\Article\Article $article * @throws \Shopware\Components\Api\Exception\CustomValidationException * @return array */ protected function prepareVariants($data, ArticleModel $article) { unset($data['details']); if (!isset($data['variants'])) { return $data; } $variants = array(); foreach ($data['variants'] as $variantData) { if (isset($variantData['id'])) { $variant = $this->getManager()->getRepository('Shopware\Models\Article\Detail')->findOneBy(array( 'id' => $variantData['id'], 'articleId' => $article->getId() )); if (!$variant) { throw new ApiException\CustomValidationException(sprintf("Variant by id %s not found", $variantData['id'])); } } elseif (isset($variantData['number'])) { $variant = $this->getManager()->getRepository('Shopware\Models\Article\Detail')->findOneBy(array( 'number' => $variantData['number'], 'articleId' => $article->getId() )); } if (!$variant) { $variant = new \Shopware\Models\Article\Detail(); $variant->setKind(2); } $variantData = $this->prepareVariantAssociatedData($variantData); $variantData = $this->prepareVariantPricesAssociatedData($data, $variantData, $article, $variant); $variantData = $this->prepareVariantAttributeAssociatedData($variantData, $article, $variant); $variant->fromArray($variantData); if (isset($variantData['configuratorOptions']) && is_array($variantData['configuratorOptions'])) { $configuratorSet = $article->getConfiguratorSet(); if (!$configuratorSet && !isset($data['configuratorSet'])) { throw new ApiException\CustomValidationException('A configuratorset has to be defined'); } /** @var \Shopware\Models\Article\Configurator\Set $configuratorSet */ if ($configuratorSet) { $availableGroups = $configuratorSet->getGroups(); } else { $configuratorSet = $data['configuratorSet']; $availableGroups = $configuratorSet->getGroups(); } $assignedOptions = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($variantData['configuratorOptions'] as $configuratorOption) { $group = $configuratorOption['group']; $option = $configuratorOption['option']; /** @var \Shopware\Models\Article\Configurator\Group $availableGroup */ foreach ($availableGroups as $availableGroup) { if ($availableGroup->getName() == $group) { $optionExists = false; /** @var \Shopware\Models\Article\Configurator\Option $availableOption */ foreach ($availableGroup->getOptions() as $availableOption) { if ($availableOption->getName() == $option) { $assignedOptions->add($availableOption); $optionExists = true; break; } } if (!$optionExists) { $optionModel = new \Shopware\Models\Article\Configurator\Option(); $optionModel->setPosition(0); $optionModel->setName($option); $optionModel->setGroup($availableGroup); $this->getManager()->persist($optionModel); $assignedOptions->add($optionModel); } } } } $variant->setConfiguratorOptions($assignedOptions); } if (count($variant->getConfiguratorOptions()) === 0) { throw new \Exception('No Configurator Options assigned'); } if ($variantData['isMain'] || $variantData['standard']) { $newMain = $variant; $newMain->setKind(1); // todo@dn Check if has configurator - delete else $oldMain = $data['mainDetail']; $oldMain['kind'] = 2; $data['mainDetail'] = $newMain; // $variant = $oldMain; } $variants[] = $variant; } $data['details'] = $variants; unset($data['variants']); return $data; }
/** * Set authors for article, if author doesn't exist it gets created * * @param \Newscoop\Entity\Article $article Article * @param \Newscoop\IngestPluginBundle\Entity\Feed\Entry $entry Entity */ protected function setArticleAuthors(\Newscoop\Entity\Article $article, \Newscoop\IngestPluginBundle\Entity\Feed\Entry $entry) { $repository = $this->em->getRepository('\\Newscoop\\Entity\\Author'); $doctrineCollection = new \Doctrine\Common\Collections\ArrayCollection(); $authors = $entry->getAuthors(); if (count($authors) > 0) { foreach ($authors as $author) { $authorEntity = $repository->findBy(array('first_name' => $author['firstname'], 'last_name' => $author['lastname'])); if ($authorEntity === null) { $authorEntity = new \Newscoop\Entity\Author($author['firstname'], $author['lastname']); } $doctrineCollection->add($authorEntity); } $article->setArticleAuthors($doctrineCollection); } }