Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function getAdjustments($type = null)
 {
     if (null === $type) {
         return $this->adjustments;
     }
     return $this->adjustments->filter(function (AdjustmentInterface $adjustment) use($type) {
         return $type === $adjustment->getType();
     });
 }
Exemple #2
0
 public function removeProduct(UuidIdentity $id)
 {
     $element = $this->lineItems->filter(function (LineItem $lineItem) use($id) {
         return $lineItem->getProduct()->getId()->getValue() === $id->getValue();
     })->first();
     if ($element) {
         $this->lineItems->removeElement($element);
     }
     return $this;
 }
 public function testFilter()
 {
     $this->_coll->add(1);
     $this->_coll->add("foo");
     $this->_coll->add(3);
     $res = $this->_coll->filter(function ($e) {
         return is_numeric($e);
     });
     $this->assertEquals(array(0 => 1, 2 => 3), $res->toArray());
 }
 /**
  * @param Collection $collection
  *
  * @return ArrayCollection
  */
 private function filterDeleted(Collection $collection) : ArrayCollection
 {
     // getValues => reset keys
     return new ArrayCollection($collection->filter(function ($entity) {
         return !$entity instanceof SoftDeletableInterface || $entity->isDeleted() === false;
     })->getValues());
 }
 /**
  * {@inheritdoc}
  */
 public function findEndBeforeNow()
 {
     $now = new \DateTime();
     return array_values($this->taskCollection->filter(function (TaskInterface $task) use($now) {
         return $task->getLastExecution() === null || $task->getLastExecution() > $now;
     })->toArray());
 }
 /**
  * {@inheritdoc}
  */
 public function findScheduled()
 {
     $dateTime = new \DateTime();
     return $this->taskExecutionCollection->filter(function (TaskExecutionInterface $execution) use($dateTime) {
         return $execution->getStatus() === TaskStatus::PLANNED && $execution->getScheduleTime() < $dateTime;
     });
 }
 /**
  * @param string $type
  * @return Collection|Attribute[]
  */
 public function getAttributesByType($type)
 {
     return $this->attributes->filter(function ($attribute) use($type) {
         /** @var Attribute $attribute */
         return $attribute->getType() == $type;
     });
 }
 /**
  * Filters a collection to get only current items
  *
  * @param Collection $collection
  *
  * @return Collection
  */
 protected function filterCurrentItems(Collection $collection)
 {
     $endDate = new DateTime();
     $format = $this->configuration->getGroupByDateFormat();
     $identifier = $endDate->format($format);
     return $collection->filter(function (ReportRow $row) use($identifier) {
         return $row->getIdentifier() === $identifier;
     });
 }
Exemple #9
0
 /**
  * {@inheritdoc}
  */
 public function getTaxons($taxonomy = null)
 {
     if (null !== $taxonomy) {
         return $this->taxons->filter(function (BaseTaxonInterface $taxon) use($taxonomy) {
             return $taxonomy === strtolower($taxon->getTaxonomy()->getName());
         });
     }
     return $this->taxons;
 }
Exemple #10
0
 /**
  * {@inheritdoc}
  */
 public function getLastPayment($state = BasePaymentInterface::STATE_NEW)
 {
     if ($this->payments->isEmpty()) {
         return false;
     }
     return $this->payments->filter(function (BasePaymentInterface $payment) use($state) {
         return $payment->getState() === $state;
     })->last();
 }
Exemple #11
0
 /**
  * {@inheritdoc}
  */
 public function getTaxons($rootTaxonCode = null)
 {
     if (null !== $rootTaxonCode) {
         return $this->taxons->filter(function (BaseTaxonInterface $taxon) use($rootTaxonCode) {
             return $rootTaxonCode === strtolower($taxon->getRoot()->getCode());
         });
     }
     return $this->taxons;
 }
 /**
  * @param EntityManager $em The entity manager
  */
 public function persist(EntityManager $em)
 {
     foreach ($this->mediaSet->filter(function (PageMedia $item) {
         return (bool) $item->getMedia();
     }) as $item) {
         $em->persist($item);
     }
     foreach ($this->toDelete as $item) {
         $callback = function ($key, PageMedia $element) use($item) {
             /** @noinspection PhpExpressionResultUnusedInspection */
             $key;
             return $element->getType() === $item->getType() && $element->getMedia();
         };
         if (false === $this->mediaSet->exists($callback)) {
             $em->remove($item);
         }
     }
 }
Exemple #13
0
 /**
  * @return LocalizedFallbackValue
  */
 public function getDefaultTitle()
 {
     $titles = $this->titles->filter(function (LocalizedFallbackValue $title) {
         return null === $title->getLocale();
     });
     if ($titles->count() != 1) {
         throw new \LogicException('There must be only one default title');
     }
     return $titles->first();
 }
Exemple #14
0
 /**
  * @param string|null $state
  *
  * @return BasePaymentInterface|null
  */
 public function getLastPayment($state = null)
 {
     if ($this->payments->isEmpty()) {
         return null;
     }
     $payment = $this->payments->filter(function (BasePaymentInterface $payment) use($state) {
         return null === $state || $payment->getState() === $state;
     })->last();
     return $payment !== false ? $payment : null;
 }
Exemple #15
0
 /**
  * {@inheritdoc}
  */
 public function getLastNewPayment()
 {
     if ($this->payments->isEmpty()) {
         return null;
     }
     $payment = $this->payments->filter(function (BasePaymentInterface $payment) {
         return $payment->getState() === BasePaymentInterface::STATE_NEW;
     })->last();
     return $payment !== false ? $payment : null;
 }
Exemple #16
0
 /**
  * @param Option $option
  * @return $this
  */
 public function deleteOption(Option $option)
 {
     $productOptions = $this->productOptions->filter(function (ProductOption $productOption) use($option) {
         return $productOption->getOption()->getId() == $option->getId();
     });
     if ($productOptions->count()) {
         $this->productOptions->removeElement($productOptions->first());
     }
     return $this;
 }
Exemple #17
0
 /**
  *
  * @return Collection|Array $reports
  */
 public function getReports($ac = false)
 {
     $reports = $this->reports ? $this->reports->filter(function ($report) {
         try {
             return $report ? $report->getActive() : false;
         } catch (\Exception $e) {
             return false;
         }
     }) : new ArrayCollection();
     return $ac ? $reports : $reports->getValues();
 }
 /**
  * {@inheritdoc}
  */
 public function filter(Collection $objects, array $context = [])
 {
     if (!isset($context['identifier'])) {
         throw new \Exception('"identifier" is required in the context.');
     }
     $identifier = $context['identifier'];
     $scopeCode = isset($context['scopeCode']) ? $context['scopeCode'] : null;
     $localeCodes = isset($context['localeCodes']) ? $context['localeCodes'] : [];
     return $objects->filter(function ($value) use($identifier, $scopeCode, $localeCodes) {
         if (!$value instanceof ProductValueInterface) {
             throw new \Exception('This filter only handles objects of type "ProductValueInterface"');
         }
         return $value !== $identifier && ($scopeCode === null || !$value->getAttribute()->isScopable() || $value->getAttribute()->isScopable() && $value->getScope() === $scopeCode) && (count($localeCodes) === 0 || !$value->getAttribute()->isLocalizable() || $value->getAttribute()->isLocalizable() && in_array($value->getLocale(), $localeCodes));
     });
 }
Exemple #19
0
 /**
  * Get ordered widgets for column
  *
  * @param int $column
  * @param bool $appendGreater
  * @param bool $appendLesser
  * @return array
  */
 public function getOrderedColumnWidgets($column, $appendGreater = false, $appendLesser = false)
 {
     $elements = $this->widgets->filter(function ($element) use($column, $appendGreater, $appendLesser) {
         /** @var WidgetModel $element */
         $actualColumn = current($element->getLayoutPosition());
         return $actualColumn == $column || $appendGreater && $actualColumn > $column || $appendLesser && $actualColumn < $column;
     });
     $result = $elements->getValues();
     usort($result, function ($first, $second) {
         /** @var WidgetModel $first */
         /** @var WidgetModel $second */
         $firstPosition = $first->getLayoutPosition();
         $secondPosition = $second->getLayoutPosition();
         return $firstPosition[1] - $secondPosition[1];
     });
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function filter(Collection $objects, array $context = [])
 {
     $locales = isset($context['locales']) ? $context['locales'] : [];
     $channels = isset($context['channels']) ? $context['channels'] : [];
     return $objects->filter(function ($value) use($locales, $channels) {
         if (!$value instanceof ProductValueInterface) {
             throw new \Exception('This filter only handles objects of type "ProductValueInterface"');
         }
         $attribute = $value->getAttribute();
         if (!empty($locales) && $attribute->isLocalizable() && !in_array($value->getLocale(), $locales)) {
             return false;
         }
         if (!empty($channels) && $attribute->isScopable() && !in_array($value->getScope(), $channels)) {
             return false;
         }
         return true;
     });
 }
Exemple #21
0
 /**
  * {@inheritdoc}
  */
 public function getAvailableVariants()
 {
     return $this->variants->filter(function (BaseVariantInterface $variant) {
         return !$variant->isMaster() && $variant->isAvailable();
     });
 }
Exemple #22
0
 /**
  * @param int $originId
  *
  * @return Address|false
  */
 public function getAddressByOriginId($originId)
 {
     return $this->addresses->filter(function (Address $item) use($originId) {
         return $item->getOriginId() === $originId;
     })->first();
 }
 /**
  * {@inheritdoc}
  */
 public function filter(Closure $p)
 {
     $this->initialize();
     return $this->coll->filter($p);
 }
Exemple #24
0
 /**
  * {@inheritdoc}
  */
 public function getOAuthAccount($provider)
 {
     if ($this->oauthAccounts->isEmpty()) {
         return null;
     }
     $filtered = $this->oauthAccounts->filter(function (UserOAuthInterface $oauth) use($provider) {
         return $provider === $oauth->getProvider();
     });
     if ($filtered->isEmpty()) {
         return null;
     }
     return $filtered->current();
 }
Exemple #25
0
 /**
  * @param Collection|Schedule[] $schedules
  * @param string $name
  * @param array $arguments
  *
  * @return Collection
  */
 protected function matchSchedules(Collection $schedules, $name, array $arguments = [])
 {
     return $schedules->filter(function (Schedule $schedule) use($name, $arguments) {
         return $schedule->getCommand() === $name && $schedule->getArguments() == $arguments;
     });
 }
 /**
  * {@inheritdoc}
  */
 public function findScheduled()
 {
     return $this->tasks->filter(function (TaskInterface $task) {
         return !$task->isCompleted() && $task->getExecutionDate() <= new \DateTime();
     });
 }
Exemple #27
0
 /**
  * @return LocalizedFallbackValue
  * @throws \LogicException
  */
 public function getDefaultDescription()
 {
     $descriptions = $this->descriptions->filter(function (LocalizedFallbackValue $description) {
         return null === $description->getLocale();
     });
     if ($descriptions->count() !== 1) {
         throw new \LogicException('There must be only one default description');
     }
     return $descriptions->first();
 }
 /**
  * Get start transitions
  *
  * @return Collection
  */
 public function getStartTransitions()
 {
     return $this->transitions->filter(function (Transition $transition) {
         return $transition->isStart();
     });
 }
Exemple #29
0
 /**
  * Get field
  *
  * @param string $field
  *
  * @return AbstractAuditField|false
  */
 public function getField($field)
 {
     return $this->fields->filter(function (AbstractAuditField $auditField) use($field) {
         return $auditField->getField() === $field;
     })->first();
 }
 /**
  * Filters the collection and returns only children elements for given parent element
  *
  * @param Collection              $collection
  * @param AdminMenuInterface|null $parent
  *
  * @return Collection
  */
 protected function filterElements(Collection $collection, AdminMenuInterface $parent = null)
 {
     $children = $collection->filter(function (AdminMenuInterface $menuItem) use($parent) {
         return $menuItem->getParent() === $parent;
     });
     return $children;
 }