コード例 #1
0
ファイル: Variant.php プロジェクト: wellcommerce/wellcommerce
 protected function synchronizeOptions(Collection $options)
 {
     $this->options->map(function (VariantOptionInterface $option) use($options) {
         if (false === $options->contains($option)) {
             $this->options->removeElement($option);
         }
     });
 }
コード例 #2
0
 public function testMap()
 {
     $this->_coll->add(1);
     $this->_coll->add(2);
     $res = $this->_coll->map(function ($e) {
         return $e * 2;
     });
     $this->assertEquals(array(2, 4), $res->toArray());
 }
コード例 #3
0
ファイル: Attribute.php プロジェクト: Newman101/WellCommerce
 /**
  * {@inheritdoc}
  */
 public function setValues(Collection $collection)
 {
     if (null !== $this->values) {
         $this->values->map(function (AttributeValueInterface $value) use($collection) {
             if (false === $collection->contains($value)) {
                 $this->removeValue($value);
             }
         });
     }
     $this->values = $collection;
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function setAttributes(Collection $attributes)
 {
     if ($this->attributes instanceof Collection) {
         $this->attributes->map(function (AttributeInterface $attribute) use($attributes) {
             if (false === $attributes->contains($attribute)) {
                 $this->removeAttribute($attribute);
             }
         });
     }
     $this->attributes = $attributes;
 }
コード例 #5
0
 /**
  * {@inheritDoc}
  */
 public function map(Closure $func)
 {
     $mapped = $this->collection->map($func);
     // validate mapped elements
     array_map($this->getIdentityExtractor(), $mapped->toArray());
     return new static($mapped);
 }
コード例 #6
0
 /**
  * Twitter requires domains without scheme
  *
  * @param Doctrine\Common\Collections\Collection
  */
 public function setDomains(Collection $domains)
 {
     $remap = $domains->map(function ($item) {
         return str_replace(array("https://", "http://"), '', $item);
     }, $domains);
     $this->domains = $remap;
 }
コード例 #7
0
 /**
  * Generates a tree for given children elements
  *
  * @param Collection $collection
  * @param Collection $children
  *
  * @return array
  */
 protected function generateTree(Collection $collection, Collection $children)
 {
     $children->map(function (AdminMenuInterface $menuItem) use($collection, &$tree) {
         $tree[] = ['routeName' => $menuItem->getRouteName(), 'cssClass' => $menuItem->getCssClass(), 'name' => $menuItem->getName(), 'children' => $this->generateTree($collection, $this->filterElements($collection, $menuItem))];
     });
     return $tree;
 }
コード例 #8
0
 protected function getCollectionValue(Collection $collection)
 {
     $value = 0;
     $collection->map(function (ReportRow $row) use(&$value) {
         $value += $row->getValue();
     });
     return $value;
 }
コード例 #9
0
 /**
  * {@inheritdoc}
  */
 public function processConfiguration(Collection $collection)
 {
     $config = [];
     $collection->map(function (PaymentMethodConfigurationInterface $configuration) use(&$config) {
         $config[$configuration->getName()] = $configuration->getValue();
     });
     return $config;
 }
コード例 #10
0
ファイル: Order.php プロジェクト: Newman101/WellCommerce
 /**
  * {@inheritdoc}
  */
 public function getShippingCostWeight()
 {
     $weight = 0;
     $this->products->map(function (OrderProduct $orderProduct) use(&$weight) {
         $weight += $orderProduct->getQuantity() * $orderProduct->getWeight();
     });
     return $weight;
 }
コード例 #11
0
ファイル: Order.php プロジェクト: igaponov/shop
 /**
  * @return Money
  */
 public function getTotal() : Money
 {
     $total = new Money(0);
     $this->lineItems->map(function (LineItem $lineItem) use(&$total) {
         $total = $total->add($lineItem->getPrice());
     });
     return $total;
 }
コード例 #12
0
 protected function syncNewAttributes(Collection $attributes)
 {
     $attributes->map(function (AttributeInterface $attribute) {
         if (false === $this->attributes->contains($attribute)) {
             $attribute->addValue($this);
         }
     });
 }
コード例 #13
0
 /**
  * Get currencies
  *
  * @return array|string[]
  */
 public function getCurrencies()
 {
     $currencies = $this->currencies->map(function (PriceListCurrency $priceListCurrency) {
         return $priceListCurrency->getCurrency();
     })->toArray();
     sort($currencies);
     return $currencies;
 }
コード例 #14
0
 protected function getAttributeValues(Collection $collection)
 {
     $values = [];
     $collection->map(function (AttributeValueInterface $value) use(&$values) {
         $values[] = ['id' => $value->getId(), 'name' => $value->translate()->getName()];
     });
     return $values;
 }
コード例 #15
0
 /**
  * Extracts information from collection and appends it to an array of attributes
  *
  * @param Collection $collection
  * @param array      $attributes
  */
 protected function extractValues(Collection $collection, &$attributes)
 {
     $collection->map(function (AttributeValueInterface $attributeValue) use(&$attributes) {
         $attribute = $attributeValue->getAttribute();
         $attributes[$attribute->getId()]['name'] = $attribute->translate()->getName();
         $attributes[$attribute->getId()]['values'][$attributeValue->getId()] = $attributeValue->translate()->getName();
     });
 }
コード例 #16
0
 /**
  * Returns product statuses
  *
  * @param int    $limit
  * @param string $orderBy
  * @param string $orderDir
  *
  * @return array
  */
 public function getProductReviewAverage(Collection $collection)
 {
     $totalRating = 0;
     $reviewsTotal = $collection->count();
     $collection->map(function (ProductReviewInterface $review) use(&$totalRating) {
         $totalRating += $review->getRating();
     });
     return $reviewsTotal > 0 ? round($totalRating / $reviewsTotal, 2) : 0;
 }
 public function transformOptions(Collection $collection = null) : array
 {
     if (null === $collection) {
         return [];
     }
     $values = [];
     $collection->map(function (VariantOptionInterface $variantOption) use(&$values) {
         $values[$variantOption->getAttribute()->getId()] = $variantOption->getAttributeValue()->getId();
     });
     return $values;
 }
コード例 #18
0
ファイル: Product.php プロジェクト: Sywooch/WellCommerce
 /**
  * {@inheritdoc}
  */
 public function setAttributes(Collection $attributes)
 {
     if (null !== $this->attributes) {
         $this->attributes->map(function (ProductAttributeInterface $productAttribute) use($attributes) {
             if (false === $attributes->contains($productAttribute)) {
                 $this->removeAttribute($productAttribute);
             }
         });
     }
     $this->attributes = $attributes;
 }
 /**
  * Transforms values collection to identifiers
  *
  * @param PersistentCollection $collection
  *
  * @return array
  */
 public function transformValues(Collection $collection = null)
 {
     if (null === $collection) {
         return [];
     }
     $values = [];
     $collection->map(function (AttributeValueInterface $attributeValue) use(&$values) {
         $values[$attributeValue->getAttribute()->getId()] = $attributeValue->getId();
     });
     return $values;
 }
コード例 #20
0
 /**
  * @param Collection $permissions
  * @param array      $secondaryPermissions
  */
 protected function mergePermissions(Collection $permissions, array $secondaryPermissions = [])
 {
     foreach ($secondaryPermissions as $rolePermissions) {
         /** @var Collection $rolePermissions */
         $rolePermissions->map(function (Permission $permission) {
             $this->add($permission, !$permission->isAllowed());
         });
     }
     $permissions->map(function (Permission $permission) {
         $this->add($permission, !$permission->isAllowed());
     });
 }
コード例 #21
0
 /**
  * {@inheritdoc}
  */
 public function setGroups(Collection $groups)
 {
     $this->groups->map(function (AttributeGroupInterface $group) use($groups) {
         if (false === $groups->contains($group)) {
             $group->removeAttribute($this);
         }
     });
     $groups->map(function (AttributeGroupInterface $group) {
         if (false === $this->groups->contains($group)) {
             $group->addAttribute($this);
         }
     });
 }
コード例 #22
0
ファイル: MenuModifier.php プロジェクト: xphere/elcodi
 /**
  * Apply menu filters to Menu
  *
  * @param Collection $menuNodes Menu nodes
  * @param string     $menuCode  Menu code
  * @param string     $stage     Stage
  *
  * @return $this Self object
  */
 private function applyModifiersToMenuNodes(Collection $menuNodes, $menuCode, $stage)
 {
     $menuNodes->map(function (NodeInterface $menuNode) use($menuCode, $stage) {
         $this->applyModifiersToMenuNodes($menuNode->getSubnodes(), $menuCode, $stage);
         $menuModifiers = $this->getElementsByMenuCodeAndStage($menuCode, $stage);
         /**
          * @var MenuModifierInterface $menuModifier
          */
         foreach ($menuModifiers as $menuModifier) {
             $menuModifier->modify($menuNode);
         }
     });
     return $this;
 }
コード例 #23
0
 /**
  * @param ConsumerContainer $consumerContainer
  * @param AMQPMessage $message
  *
  * @throws ConsumerContainerException
  * @return mixed|null
  */
 private function invoke(ConsumerContainer $consumerContainer, AMQPMessage $message)
 {
     $payload = $this->serializer->deserialize($message->body, $consumerContainer->getMessageClass(), 'json');
     try {
         $result = $consumerContainer->invoke($payload);
     } catch (Exception $e) {
         $containerException = new ConsumerContainerException($consumerContainer, $message, $payload, $e);
         if ($this->errorHandlers->isEmpty()) {
             throw $containerException;
         }
         $this->errorHandlers->map(function (ErrorHandlerInterface $handler) use($containerException) {
             $handler->handle($containerException);
         });
         return null;
     }
     return $result;
 }
コード例 #24
0
ファイル: Article.php プロジェクト: alvsgithub/Newscoop
 /**
  * Get view
  *
  * @return object
  */
 public function getView()
 {
     try {
         $view = new ArticleView(array('number' => $this->number, 'language' => $this->language->getCode(), 'languageId' => $this->language->getId(), 'title' => $this->name, 'updated' => $this->updated, 'published' => $this->published, 'indexed' => $this->indexed, 'onFrontPage' => $this->onFrontPage, 'onSection' => $this->onSection, 'type' => $this->type, 'webcode' => $this->getWebcode(), 'publication_number' => $this->publication ? $this->publication->getId() : null, 'issue_number' => $this->issue ? $this->issue->getNumber() : null, 'section_number' => $this->section ? $this->section->getNumber() : null, 'keywords' => array_filter(explode(',', $this->keywords))));
     } catch (EntityNotFoundException $e) {
         return new ArticleView();
     }
     $view->authors = $this->authors->map(function ($author) {
         return $author->getView()->name;
     })->toArray();
     $view->topics = $this->topics->map(function ($topic) {
         return $topic->getView()->name;
     })->toArray();
     $this->addFields($view);
     return $view;
 }
コード例 #25
0
 /**
  * {@inheritdoc}
  */
 public function map(\Closure $func)
 {
     return $this->inner->map($func);
 }
コード例 #26
0
 /**
  * {@inheritdoc}
  */
 public function map(Closure $func)
 {
     $this->initialize();
     return $this->coll->map($func);
 }
コード例 #27
0
 private function duplicateTranslatableEntities(Collection $entities, array $properties, LocaleInterface $targetLocale)
 {
     $entities->map(function (LocaleAwareInterface $entity) use($properties, $targetLocale) {
         $this->duplicateTranslatableEntity($entity, $properties, $targetLocale);
     });
 }
コード例 #28
0
 /**
  * @param Email $email
  * @param AutoResponseRule[]|Collection $rules
  *
  * @return EmailModel[]|Collection
  */
 protected function createReplyEmailModels(Email $email, Collection $rules)
 {
     return $rules->map(function (AutoResponseRule $rule) use($email) {
         $emailModel = $this->emailBuilder->createReplyEmailModel($email, true);
         $emailModel->setFrom($rule->getMailbox()->getEmail());
         $emailModel->setTo([$email->getFromEmailAddress()->getEmail()]);
         $emailModel->setContexts(array_merge([$email], $emailModel->getContexts()));
         $this->applyTemplate($emailModel, $rule->getTemplate(), $email);
         return $emailModel;
     });
 }
コード例 #29
0
ファイル: Product.php プロジェクト: wellcommerce/wellcommerce
 protected function synchronizeVariants(Collection $variants)
 {
     $this->variants->map(function (VariantInterface $variant) use($variants) {
         if (false === $variants->contains($variant)) {
             $this->removeVariant($variant);
         }
     });
 }
コード例 #30
0
 public function traverse(OrderInterface $order)
 {
     $this->visitors->map(function (OrderVisitorInterface $visitor) use($order) {
         $visitor->visitOrder($order);
     });
 }