/** * @param string $colors * @return void */ public function indexAction($colors = null) { $oldColors = new \Doctrine\Common\Collections\ArrayCollection($this->colorRepository->findAll()->toArray()); $colorNames = ""; if ($colors === null) { foreach ($oldColors as $color) { if (!empty($colorNames)) { $colorNames .= "\n"; } $colorNames .= $color->getName(); } } else { $colorNames = $colors; foreach (explode("\n", $colors) as $colorName) { $colorName = trim($colorName); if (empty($colorName)) { continue; } $color = $this->colorRepository->findOneByName($colorName); if (empty($color)) { $color = new Color($colorName); $this->colorRepository->add($color); } if ($oldColors) { $oldColors->removeElement($color); } } if ($oldColors) { foreach ($oldColors as $color) { $this->colorRepository->remove($color); } } } $this->view->assign('colors', $colorNames); }
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; }
public function denormalize(array $input, $context = null) { $collection = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($array as $key => $value) { $collection->set($key, parent::normalize($input)); } return new PersistentCollection($this->getEntityManager(), $this->getClassMetadata()->getName(), $collection); }
/** * @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; }
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()); }
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()); }
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; }
/** * 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; }
/** * @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()); }
/** * @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()); }
/** * 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)); }
private function menuArrayToEntities($menuArray, \Doctrine\ORM\EntityManager $em, MenuElement $parent = null, $locale) { $collection = new \Doctrine\Common\Collections\ArrayCollection(); $repo = $em->getRepository('SKCMSCoreBundle:MenuElement'); $repo->setDefaultLocale($locale); foreach ($menuArray as $menuElement) { // //dump($menuElement); // die(); $element = null; if (isset($menuElement->elementId)) { $element = $repo->find($menuElement->elementId); $element->setTranslatableLocale($locale); $em->refresh($element); } if (null === $element) { $element = new MenuElement(); } $element->setName($menuElement->name); $element->setEntityId($menuElement->targetId); $element->setEntityClass($menuElement->entityClass); $element->setPosition($menuElement->position); if (isset($menuElement->children) && count($menuElement->children)) { $element->setChildren($this->menuArrayToEntities($menuElement->children, $em, $element, $locale)); } $collection->add($element); if (null !== $parent) { $element->setParent($parent); } $em->persist($element); } return $collection; }
/** * 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; }
public function getList() { $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $albumRepo = $em->getRepository('\\Application\\Entity\\Album'); $albums = $albumRepo->findAll(); $collection = new \Doctrine\Common\Collections\ArrayCollection($albums); $data = $collection->map(function ($a) { // if this is a comment, map each element as an array, and the container as an array $a->comments = $a->comments->map(function ($p) { return $p->toArray(); })->toArray(); // map each of the elements within the collection as an array return $a->toArray(); })->toArray(); // result will stil be an array collection, that needs to be cast to an array return new JsonModel(array('data' => $data)); }
/** * * @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; }
/** * 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 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 findAll() { $albums = $this->objectRepository->findAll(); $collection = new \Doctrine\Common\Collections\ArrayCollection($albums); $arrays = $collection->map(function ($a) { $a->songs = $a->songs->map(function ($p) { return $p->toArray(); })->toArray(); return $a->toArray(); })->toArray(); //**************************************************************************************** $fractal = new Manager(); $resource = new Resource\Collection($arrays, function (array $array) { $songs = array(); for ($i = 0; $i < count($array['songs']); $i++) { $songs[$i]['href'] = '/album/' . $array['id'] . '/' . $array['songs'][$i]['songTitle']; } return ['id' => (int) $array['id'], 'title' => $array['title'], 'artist' => $array['artist'], '_embedded' => ['songs' => $array['songs'], '_links' => ['rel' => $songs]], '_links' => [['rel' => 'self', 'uri' => '/albums/' . $array['id']]]]; }); $result = $fractal->createData($resource)->toArray(); 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; }
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 hasLanguage(Language $language) { $result = false; if (count($this->article_languages->toArray()) > 0) { foreach ($this->article_languages as $plTemp) { if ($language->getId() == $plTemp->getLanguage()->getId()) { $result = true; break; } } } return $result; }
protected function getUsersInSelectionExtractor() { return function (array $selection) { $Users = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($selection as $record) { /* @var $record record_adapter */ foreach ($record->get_caption()->get_fields() as $caption_field) { foreach ($caption_field->get_values() as $value) { if (!$value->getVocabularyType()) { continue; } if ($value->getVocabularyType()->getType() !== 'User') { continue; } $user = $value->getRessource(); $Users->set($user->getId(), $user); } } } return $Users; }; }
public function setDefaultConfig($key, $value, $type, $section = "default") { $valueArray = new \Doctrine\Common\Collections\ArrayCollection(); $valueArray->set('value', $value); $valueArray->set('section', $section); $valueArray->set('key', $key); $valueArray->set('type', $type); $this->configList->set($section . '.' . $key, $valueArray); }
/** * @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)); }
/** * @param \SimpleXMLElement $obj * @param null $parent * @return \Doctrine\Common\Collections\ArrayCollection */ protected function getItems(\SimpleXMLElement $obj, $parent = null) { $returnChildren = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($obj->children() as $objData) { $id = $this->blockParser->getXmlAttr($objData, 'id'); $menuItemTranslation = $this->db->createQueryBuilder()->select("menu, translation")->from('\\Fraym\\Menu\\Entity\\MenuItemTranslation', 'translation')->join('translation.menuItem', 'menu')->where('menu.id = :id AND translation.locale = :localeId AND translation.active = 1')->setParameter('id', $id)->setParameter('localeId', $this->route->getCurrentMenuItemTranslation()->locale->id)->getQuery()->getOneOrNullResult(); $this->db->free(); if ($menuItemTranslation) { $menuItem = clone $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuItemTranslation->menuItem->id); $children = $this->getItems($objData, $menuItem); $menuItem->parent = $parent; $menuItem->children = $children; $returnChildren->set($menuItem->id, $menuItem); } } return $returnChildren; }
/** * @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; }
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()); }