/** * Get parameters. * * @return array */ public function getParameters() { if (!$this->parameters instanceof ArrayCollection) { return []; } return $this->parameters->toArray(); }
/** * Set comma state on oxford candidate word and * implode words back together * * @return string */ public function __toString() { $this->getOxfordItems()->map(function (Word $word) { $word->setComma($this->getOxford()); }); return implode(' ', $this->words->toArray()); }
public function toArray() { if (null === $this->entries) { $this->__load___(); } return $this->entries->toArray(); }
/** * Returns fields as an array * * @return array */ public function toArray() { /** * @todo: DO we bother that we have objects inside */ return $this->collection->toArray(); }
function getDescendants($result = null) { if ($result == null) { $result = array(); } $result = array_merge($result, $this->entries->toArray()); foreach ($this->children as $c) { $result = $c->getDescendants($result); } return $result; }
/** * @param array $criteria * * @param array $orderBy * @param null $limit * @param null $offset * * @return mixed */ public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) { return array_filter($this->entities->toArray(), function ($entity) use($criteria) { $conditions = []; foreach ($criteria as $key => $value) { $conditions[] = $entity->{$key}() == $value; } return array_reduce($conditions, function ($carry, $condition) { return $carry && $condition; }, true); }); }
public function getRoleById($roleId) { $roles = $this->roles->toArray(); foreach ($this->getGroups() as $group) { $roles = array_merge($roles, $group->getRoles()); } foreach ($roles as $r) { if ($r->getId() == $roleId) { return true; } } return false; }
/** * @return Team[] */ public function getStandings() { /** @var Team[] $teams */ $teams = $this->teams->toArray(); $points = array(); $goalsDifference = array(); $goalsFor = array(); foreach ($teams as $k => $team) { $points[$k] = $team->getPoints(); $goalsDifference[$k] = $team->getGoalsDifference(); $goalsFor[$k] = $team->getGoalsFor(); } array_multisort($points, SORT_DESC, $goalsDifference, SORT_DESC, $goalsFor, SORT_DESC, $teams); return $teams; }
public function getQBAliasReference($class, $attribute = NULL) { if (!is_object($class)) { throw new \Exception("object must be of type object, type %s given.", gettype($class)); } $class_name = get_class($class); // get alias of class $alias = NULL; foreach ($this->qb_alias_reference->toArray() as $_class => $_alias) { if (isset($_alias[$class_name])) { $alias = $_alias[$class_name]; } } // if not found if ($alias === NULL) { // if empty, set new if ($this->qb_alias_reference->count() == 0) { $alias = 'a'; // get last and then count up } else { $lastAlias = $this->qb_alias_reference->last(); $alias = ++$lastAlias[key($lastAlias)]; } // add new $this->qb_alias_reference->add(array($class_name => $alias)); } return $attribute === NULL ? $alias : $alias . '.' . $attribute; }
/** * Return the last draft saved. * * @return Revision */ public function getLastSavedDraftRevision() { if (!empty($this->lastSavedDraft)) { return $this->lastSavedDraft; } $published = $this->publishedRevision; $staged = $this->stagedRevision; $arrayCollection = $this->revisions->toArray(); /** @var \Rcm\Entity\Revision $revision */ $revision = end($arrayCollection); if (empty($revision)) { return null; } $found = false; while (!$found) { if (empty($revision)) { break; } elseif (!empty($published) && $published->getRevisionId() == $revision->getRevisionId()) { $found = false; } elseif (!empty($staged) && $staged->getRevisionId() == $revision->getRevisionId()) { $found = false; } elseif ($revision->wasPublished()) { $found = false; } else { $found = true; } if (!$found) { $revision = prev($arrayCollection); } } return $this->lastSavedDraft = $revision; }
/** * Get ordered threads * * @return ArrayCollection */ public function getOrderedThreads() { $threads = $this->threads->toArray(); usort($threads, function (ForumThread $a, ForumThread $b) { if ($b->getStickied() === true && $a->getStickied() === false) { return 1; } if ($b->getStickied() === false && $a->getStickied() === false) { if ($b->getPosts()->count() > 0 && $a->getPosts()->count() === 0) { return 1; } if ($b->getPosts()->count() === 0 && $a->getPosts()->count() > 0) { return -1; } if ($b->getPosts()->count() === 0 && $a->getPosts()->count() === 0) { return 0; } if ($b->getPosts()->last()->getDateCreated() > $a->getPosts()->last()->getDateCreated()) { return 1; } if ($b->getPosts()->last()->getDateCreated() < $a->getPosts()->last()->getDateCreated()) { return -1; } } return 0; }); return $threads; }
/** * @param ArrayCollection $tasks * * @return HasTasksInterface */ public function setTasks(ArrayCollection $tasks) { foreach ($tasks->toArray() as $task) { $this->addTask($task); } return $this; }
public function indexAction() { $user = new User(); $rol = new RolSistema(); $opciones = new ArrayCollection(); //new OpcionSistema(); $user = $this->get('security.context')->getToken()->getUser(); if ($user != 'anon.' && $user->getAuditDeleted() == false) { $roles = $user->getRols(); if (isset($roles)) { foreach ($roles as $rol) { //$opciones = $rol->getOpcionesSistema(); $opciones = new ArrayCollection(array_merge_maintain_keys($opciones->toArray(), $rol->getOpcionesSistema()->toArray())); } $peticion = $this->getRequest(); $sesion = $peticion->getSession(); $sesion->set('opciones', $opciones); return $this->render('MinSalSCABundle:Default:index.html.twig', array('opciones' => $opciones)); } } else { if ($user != 'anon.' && $user->getAuditDeleted() == true) { $this->get('session')->setFlash('notice', 'El usuario "' . $user->getUsername() . '" se encuentra inactivo'); $this->getRequest()->getSession()->set('notice', 'El usuario "' . $user->getUsername() . '" se encuentra inactivo'); return new RedirectResponse($this->generateUrl('fos_user_security_logout')); //return $this->redirect($this->generateUrl('fos_user_security_logout')); } return $this->render('MinSalSCABundle:Default:index.html.twig'); } }
/** * Method for trying load objects via factory */ public function loadExistsObjects() { $ids = array_column($this->exists->toArray(), 'id'); // Try loading objects by ids via factory $loaded = $this->factory->load($ids); if (count($loaded)) { /** @var TransformableInterface $object */ foreach ($loaded as $object) { foreach ($this->exists as $item) { // If object has id equivalent item id then item has new description for that object if ($object->getId() == $item['id']) { // Populate object from item description $this->bindContent($item, $object, $this->map); // Validate and retrieve errors if exists if ($errors = $this->validate($object)) { $this->errors->add(array('item' => $item['number'], 'errors' => $errors)); } else { $this->result->add($object); } // Clean internal "exists" collection for memory free $this->exists->removeElement($item); } } } } // Join not found item in db into "new" collection foreach ($this->exists as $item) { $this->new->add($item); // Clean internal "exists" collection $this->exists->removeElement($item); } }
/** * Add thread to collection * * @param Thread $thread * @return Blacklist */ public function addThread($thread) { if (!in_array($thread, $this->threads->toArray())) { $this->threads->add($thread); } return $this; }
/** * Get Sorted Values * * This method wraps all values in an array, sorted by the attribute's sort * property. * * We use this to render a whole set of form types, which should be displayed * in some order. When you want to be able to get a form field by it's name * and place it on a custom place, use the getNamedValues() method. * * @return array */ public function getSortedValues() { $values = $this->values->toArray(); usort($values, function ($value1, $value2) { return $value1->getAttribute()->getSort() < $value2->getAttribute()->getSort() ? 1 : -1; }); return $values; }
/** * Pick and hit a random bee among the one still alive. * * @return $this */ public function hitRandom() { $bees = $this->aliveBeeCollection->toArray(); /** @var Bee $bee */ $bee = $bees[array_rand($bees, 1)]; $bee->hit(); $this->entityManagerInterface->persist($bee); $this->entityManagerInterface->flush($bee); if ($bee->isDead()) { if ($bee instanceof QueenBee) { $this->aliveBeeCollection = new ArrayCollection(); } else { $this->aliveBeeCollection->removeElement($bee); } } return $this; }
/** * Retourne la liste des groupes de l'utilisateur * * @return array */ public function getGroups() { $groups = $this->groups->toArray(); foreach ($groups as $group) { $groups = array_merge($groups, $group->getGroups()); } return $groups; }
/** * {@inheritDoc} */ public function toArray() { $data = []; /** @var aeopSKUProperty $element */ foreach (parent::toArray() as $element) { $data[] = $element->toArray(); } return $data; }
public function testGetStartTransitions() { $startTransition = new Transition(); $startTransition->setName('start_transition'); $startTransition->setStart(true); $startTransitions = new ArrayCollection(array($startTransition)); $workflow = $this->createWorkflow('test_workflow', array(), $startTransitions->toArray()); $this->assertEquals($startTransitions, $this->workflowManager->getStartTransitions($workflow)); }
/** * @param ArrayCollection $ingredients * @return ArrayCollection */ public function expandIngredients(ArrayCollection $ingredients) { $moreIngredients = $ingredients->toArray(); foreach ($ingredients as $ingredient) { $moreIngredients = array_merge($moreIngredients, $ingredient->getParentsAndChildren()->toArray()); } $moreIngredients = new ArrayCollection($moreIngredients); return $moreIngredients; }
/** * @param ArrayCollection $data * * @return ArrayCollection */ public function reverseTransform($data) { $fields = $data->toArray(); uasort($fields, function (FieldTypeInterface $field1, FieldTypeInterface $field2) { return $field1->getPosition() >= $field2->getPosition() ? 1 : -1; }); $fields = array_values($fields); return new ArrayCollection($fields); }
/** * {@inheritDoc} */ public function getRoles() { $roles = (array) $this->roles; /** @var AbstractGroup $group */ foreach ($this->groups->toArray() as $group) { $roles = array_merge($roles, $group->getRoles()); } return array_unique($roles); }
protected function execute(InputInterface $input, OutputInterface $output) { /* @var MailChimpApi $mailchimp */ /* @var TicketRepository $ticketRepo */ /* @var EventRepository $eventRepo */ $mailchimp = $this->getContainer()->get('mailchimp'); // There is no "clear subscribers" api endpoint, so we have to batch unsubscribe the non-participants $output->writeln('Fetching subscribers …'); $subscribers = new ArrayCollection(); $page = 0; do { $result = $mailchimp->listsMembers(array('id' => $input->getArgument('list'), 'opts' => array('start' => $page++))); foreach ($result->data as $subscriber) { $subscribers->add(strtolower($subscriber->email)); } } while (count($result->data) > 0); $output->writeln(sprintf("%d subscribers in list.", $subscribers->count())); $eventRepo = $this->getContainer()->get('bcrm.backend.repo.event'); $ticketRepo = $this->getContainer()->get('bcrm.backend.repo.ticket'); $participants = new ArrayCollection(); foreach ($ticketRepo->getTicketsForEvent($eventRepo->getNextEvent()->getOrThrow(new BadMethodCallException('No event.'))) as $ticket) { if ($participants->contains(strtolower($ticket->getEmail()))) { continue; } $participants->add(strtolower($ticket->getEmail())); } // Unsubscribe former participants $unsubscribe = new ArrayCollection(array_diff($subscribers->toArray(), $participants->toArray())); $output->writeln(sprintf('Unsubscribing %d participants.', $unsubscribe->count())); $result = $mailchimp->listsBatch_unsubscribe(array('id' => $input->getArgument('list'), 'batch' => $this->toBatch($unsubscribe, false), 'delete_member' => true, 'send_goodbye' => false)); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) { $output->writeln(print_r($result, true)); } if ($result->error_count > 0) { throw new CommandException(sprintf('Failed to unsubscribe %d participants!', $result->error_count)); } // Subscribe new participiants $newSubcsribers = new ArrayCollection(array_diff($participants->toArray(), $subscribers->toArray())); $output->writeln(sprintf('Subscribing %d new participants.', $newSubcsribers->count())); $result = $mailchimp->listsBatch_subscribe(array('id' => $input->getArgument('list'), 'batch' => $this->toBatch($newSubcsribers), 'double_optin' => false)); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) { $output->writeln(print_r($result, true)); } }
/** * @Route("/my-books", name="my-books") * @Template() */ public function myBooksAction() { if ($this->container->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY')) { $books = $this->getUser()->getBooks(); $books = new ArrayCollection(array_merge($books->toArray(), $this->getUser()->getEditedBooks()->toArray())); } else { $books = array(); } return array('books' => $books); }
protected function saveItemsToProcess() { $items = $this->itemProcessCollection->toArray(); if (!$items) { return; } foreach ($items as $item) { $this->entityManager->persist($item); } }
/** * Returns the user roles * * @return array The roles */ public function getRoles() { $roles = $this->roles->toArray(); foreach ($this->getGroups() as $group) { $roles = array_merge($roles, $group->getRoles()); } // we need to make sure to have at least one role $roles[] = static::ROLE_DEFAULT; return array_unique($roles); }
/** * {@inheritDoc} */ public function toArray() { $elements = parent::toArray(); $array = []; foreach ($elements as $key => $element) { if ($element instanceof \Kaikmedia\GalleryModule\Settings\AbstractFeatureSetting) { $array[$key] = $element->toArray(); } } return $array; }
/** * @return \Doctrine\Common\Collections\ArrayCollection */ public function getHistoryGiftsByDate() { $points = $this->historyGifts->toArray(); usort($points, function ($a, $b) { if ($a->getDate() == $b->getDate()) { return 0; } return $a->getDate() > $b->getDate() ? -1 : 1; }); return $points; }
/** * {@inheritDoc} */ public function toArray() { $elements = parent::toArray(); $array = []; foreach ($elements as $key => $element) { if ($element instanceof AbstractFeature) { $array[$key] = $element->toArray(); } } return $array; }