/** * Get steps sorted by order. * * @return Collection|Step[] */ public function getOrderedSteps() { $steps = $this->steps->toArray(); usort($steps, function (Step $stepOne, Step $stepTwo) { return $stepOne->getOrder() >= $stepTwo->getOrder() ? 1 : -1; }); return new ArrayCollection($steps); }
/** * Get roles * * @return \Doctrine\Common\Collections\Collection */ public function getRoles() { $rolesArray = $this->roles->toArray(); $stringRoles = array(); for ($i = 0; $i < sizeof($rolesArray); $i++) { $stringRoles[$i] = $rolesArray[$i]->getRolename(); } return $stringRoles; }
/** * @return array */ public function getEntities($modifyValue = true) { // Modify the value to illustrate the difference between by value and by reference if ($modifyValue) { foreach ($this->entities as $entity) { $entity->setField('Modified from getEntities getter', false); } } return $this->entities->toArray(); }
/** * @return ClientMutation[] */ public function getMutations() { $mutations = $this->mutations->toArray(); usort($mutations, function (ClientMutation $ma, ClientMutation $mb) { if ($ma->getId() === $mb->getId()) { return 0; } return $ma->getId() > $mb->getId() ? -1 : 1; }); return $mutations; }
public function __construct(PageMediaCollectionAdminType $type, Collection $mediaSet) { parent::__construct(['media_set' => $type]); $this->type = $type; $this->mediaSet = $mediaSet; $this->toDelete = $mediaSet->toArray(); }
/** * {@inheritdoc} */ public function getOptions() { if (!$this->hasParent()) { return $this->options; } return new ArrayCollection(array_merge($this->parent->getOptions()->toArray(), $this->options->toArray())); }
/** * Return the total amount of items * added to the Cart * * @return integer */ public function getTotalItemNumber() { $totalItems = array_reduce($this->cartLines->toArray(), function ($previousTotal, CartLineInterface $current) { return $previousTotal + $current->getQuantity(); }); return is_null($totalItems) ? 0 : $totalItems; }
public function serializeCollection(VisitorInterface $visitor, Collection $collection, array $type, Context $context) { $viewModelClass = null; if ($this->viewModel !== null) { $viewModelClass = get_class($this->viewModel); } // Only serialize to HalCollection when: // 1. We're not rendering a view model (viewModel is NULL). So we are respecting the defined type. // 2. We're actually rendering to Hal. // Note that we're using the class name because other view models might inherit from HalJsonModel... if ($viewModelClass == 'ZF\\Hal\\View\\HalJsonModel') { return new HalCollection($collection->toArray()); } // We change the base type, and pass through possible parameters. $type['name'] = 'array'; return $visitor->visitArray($collection->toArray(), $type, $context); }
/** * Get alternate names as a simple array * * @return string[] */ public function getAlternateNamesArray() { if (empty($this->alternateNamesArray)) { return array_map(function (AlternateName $alternateName) { return $alternateName->getName(); }, $this->alternateNames->toArray()); } return $this->alternateNamesArray; }
public function getRoles() { $rolesArray = []; foreach ($this->roles->toArray() as $role) { if ($role instanceof Role) { $rolesArray[] = $role->getRole(); } } return $rolesArray; }
/** * Transforms a collection into an array. * * @param Collection $collection A collection of entities * * @return mixed An array of entities * * @throws TransformationFailedException */ public function transform($collection) { if (null === $collection) { return array(); } if (!$collection instanceof Collection) { throw new TransformationFailedException('Expected a Doctrine\\Common\\Collections\\Collection object.'); } return $collection->toArray(); }
/** * Transforms a collection into an array. * * @param Collection $collection A collection of entities * * @return mixed An array of entities * * @throws UnexpectedTypeException */ public function transform($collection) { if (null === $collection) { return array(); } if (!$collection instanceof Collection) { throw new UnexpectedTypeException($collection, 'Doctrine\\Common\\Collections\\Collection'); } return $collection->toArray(); }
/** * Clear containers, that were not submitted */ protected function clearContainers() { if (!$this->getPresenter(FALSE) || !$this->getForm()->isSubmitted()) { return; // only if attached to presenter & submitted } foreach ($this->collection->toArray() as $entity) { if (!$this->getMapper()->getComponent($entity)) { $this->getMapper()->remove($entity); } } }
/** * Removes the specified element from the collection, if it is found. * * @param mixed $element The element to remove. * * @return boolean TRUE if this collection contained the specified element, FALSE otherwise. */ function removeElement($element) { $this->checkType($element); $this->initialize(); /** @var $eTerm EntityTerm */ foreach ($this->collection->toArray() as $eTerm) { if ($eTerm->getTerm() === $element) { $this->setDirty(true); return $this->collection->removeElement($eTerm); } } return false; }
public function serializeCollection(VisitorInterface $visitor, Collection $collection, array $type, Context $context) { // We change the base type, and pass through possible parameters. $type['name'] = 'array'; //don't include items that will produce null elements $dataArray = []; foreach ($collection->toArray() as $element) { if (!$context->isVisiting($element)) { $dataArray[] = $element; } } return $visitor->visitArray($dataArray, $type, $context); }
/** * @param object|array|Collection $entity * @param boolean $withoutFlush */ public function delete($entity, $withoutFlush = self::FLUSH) { if ($entity instanceof Collection) { return $this->delete($entity->toArray(), $withoutFlush); } if (is_array($entity)) { $repository = $this; array_map(function ($entity) use($repository) { return $repository->delete($entity, BaseRepository::NO_FLUSH); }, $entity); $this->flush($withoutFlush); return; } if (!$entity instanceof $this->_entityName) { throw new Nette\InvalidArgumentException("Entity is not instanceof " . $this->_entityName . ', ' . get_class($entity) . ' given.'); } $this->getEntityManager()->remove($entity); $this->flush($withoutFlush); }
/** * {@inheritdoc} */ public function getChildren() { if (is_array($this->children)) { return $this->children; } return $this->children->toArray(); }
/** * {@inheritdoc} */ public function getRoles() { return $this->roles->toArray(); }
/** * Get the sum of all CartLines weight. * * @return int Weight */ public function getWeight() { return array_reduce($this->cartLines->toArray(), function ($weight, CartLineInterface $cartLine) { return $weight + $cartLine->getWeight(); }, 0); }
/** * Get trabalhoTrabalho * * @return \Doctrine\Common\Collections\Collection */ public function getCandidatoTemTrabalho() { return $this->candidatoTemTrabalho->toArray(); }
/** * Get slugs related to current page * * @return Slug[] */ public function getRelatedSlugs() { return array_diff($this->slugs->toArray(), [$this->currentSlug]); }
/** * Get nCuidados * * @return \Doctrine\Common\Collections\Collection */ public function getNCuidados() { return array_map(function ($nCuidados) { return $nCuidados->getCuidado(); }, $this->nCuidados->toArray()); }
/** * @return Role[] */ public function getUserRoles() { return $this->userRoles->toArray(); }
/** * {@inheritdoc} */ public function toArray() { $this->initialize(); return $this->coll->toArray(); }
private function convertLessons(Collection $lessons) { return array_map(function (Lesson $lesson) { return LessonFactory::createUpdateCommand($lesson); }, $lessons->toArray()); }
/** * Get roles * * @return Doctrine\Common\Collections\Collection */ public function getRoles() { return $this->user_roles->toArray(); //IMPORTANTE: el mecanismo de seguridad de Sf2 requiere ésto como un array }
public function serializeCollection(VisitorInterface $visitor, Collection $collection, array $type, Context $context) { // We change the base type, and pass through possible parameters. $type['name'] = 'array'; return $visitor->visitArray($collection->toArray(), $type, $context); }
/** * @param Collection|int[] $tagIds * * @return int[] */ protected function prepareTagIds($tagIds) { if ($tagIds instanceof Collection) { return array_map(function (Tag $item) { return $item->getId(); }, $tagIds->toArray()); } elseif (!is_array($tagIds)) { return []; } return $tagIds; }
/** * Sort the collection of options by their defined sort order in the attribute * * @param Collection $optionsCollection * * @return Collection */ protected function sortOptions(Collection $optionsCollection) { $options = $optionsCollection->toArray(); usort($options, function ($first, $second) { return $first->getSortOrder() > $second->getSortOrder(); }); $sortedCollection = new ArrayCollection($options); return $sortedCollection; }
public function serializeCollection(VisitorInterface $visitor, Collection $collection, Type $type, Context $context) { return $visitor->visitArray($collection->toArray(), $type, $context); }