map() public method

{@inheritDoc}
public map ( Closure $func )
$func Closure
Example #1
1
 /**
  * @param $locale
  * @param null $id
  * @param bool $showHome
  * @param bool $showChildren
  * @return \Doctrine\ORM\QueryBuilder|mixed
  */
 public function getParentPagesQuery($locale, $id = null, $showHome = false, $showChildren = false)
 {
     $qb = $this->createQueryBuilder('p');
     if (!$showHome) {
         $qb->where($qb->expr()->isNull('p.isHome') . ' OR p.isHome <> 1');
     }
     if ($id) {
         if (!$showChildren) {
             /** @var $page PageInterface */
             $page = $this->find($id);
             $collection = new ArrayCollection($page->getAllChildren());
             $childrenIds = $collection->map(function (PageInterface $p) {
                 return $p->getId();
             });
             if ($childrenIds->count()) {
                 $qb->andWhere($qb->expr()->notIn('p.id', $childrenIds->toArray()));
             }
         }
         $qb->andWhere($qb->expr()->neq('p.id', $id));
     }
     $qb->andWhere('p.locale = :locale');
     $qb->orderBy('p.path', 'ASC');
     $qb->setParameter(':locale', $locale);
     return $qb;
 }
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     if (!$this->isEnabled()) {
         return;
     }
     $limit = $this->container->getParameter('fixtures_product_limit');
     $faker = $this->getFakerGenerator();
     $names = [];
     for ($i = 0; $i < $limit; $i++) {
         $sentence = $faker->unique()->sentence(3);
         $name = substr($sentence, 0, strlen($sentence) - 1);
         $names[$name] = $name;
     }
     $products = new ArrayCollection();
     foreach ($names as $name) {
         $products->add($this->createRandomProduct($name, $manager));
     }
     $manager->flush();
     $products->map(function (ProductInterface $product) {
         $product->getCategories()->map(function (CategoryInterface $category) {
             $category->setProductsCount($category->getProducts()->count());
             $category->setChildrenCount($category->getChildren()->count());
         });
     });
     $manager->flush();
 }
 /**
  * @return ArrayCollection|string[]
  */
 public function getKnownJobs()
 {
     $data = new ArrayCollection($this->findAll());
     return $data->map(function (CronJobInterface $o) {
         return $o->getCommand();
     });
 }
 public function map(Closure $func)
 {
     if (null === $this->entries) {
         $this->__load___();
     }
     return $this->entries->map($func);
 }
Example #5
0
 /**
  * Returns headers collection as string.
  *
  * @todo: Should implement SerializableInterface
  * So we can call serializer on it. Without this freaky __toString method.
  *
  * This is shit. No time. Have to have working prototype.
  *
  * @return string
  */
 public function __toString()
 {
     /**
      * Walk through array and make it strings
      *
      * @var ArrayCollection
      */
     $collection = $this->collection->map(function ($element) {
         return $element->stringify();
     });
     /**
      * Each header in new line, Use Stringify thingy?
      */
     return implode("\n\r", $collection->toArray());
 }
Example #6
0
 /**
  * Returns a summary of the votes up/down/total
  *
  * @return \stdClass
  */
 public function getVoteSum()
 {
     $votesStats = new \stdClass();
     $votesStats->up = 0;
     $votesStats->down = 0;
     $votesStats->total = 0;
     $counter = function ($vote) use($votesStats) {
         if ($vote->getValue()) {
             $votesStats->up++;
         } else {
             $votesStats->down++;
         }
         $votesStats->total += $vote->getValue();
     };
     $this->votes->map($counter);
     return $votesStats;
 }
 /**
  * @return ArrayCollection
  *
  * @Assert\NotBlank()
  */
 public function getMemberUids()
 {
     return $this->memberUids->map(function ($member) {
         return $member->get();
     })->getValues();
 }
Example #8
0
 /**
  * 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;
 }
Example #9
0
 public function testReferenceMany()
 {
     $colPush = new ArrayCollection(array(new GH453ReferencedDocument(), new GH453ReferencedDocument(), new GH453ReferencedDocument()));
     $colSet = $colPush->map(function ($v) {
         return clone $v;
     });
     $colSetArray = $colPush->map(function ($v) {
         return clone $v;
     });
     $colAddToSet = $colPush->map(function ($v) {
         return clone $v;
     });
     $dm = $this->dm;
     $colPush->forAll(function ($k, $v) use($dm) {
         $dm->persist($v);
         return true;
     });
     $colSet->forAll(function ($k, $v) use($dm) {
         $dm->persist($v);
         return true;
     });
     $colSetArray->forAll(function ($k, $v) use($dm) {
         $dm->persist($v);
         return true;
     });
     $colAddToSet->forAll(function ($k, $v) use($dm) {
         $dm->persist($v);
         return true;
     });
     $doc = new GH453Document();
     $doc->referenceManyPush = $colPush;
     $doc->referenceManySet = $colSet;
     $doc->referenceManySetArray = $colSetArray;
     $doc->referenceManyAddToSet = $colAddToSet;
     $this->dm->persist($doc);
     $this->dm->flush();
     $this->dm->clear();
     // No need to assert the value of the referenced document structure
     $this->assertBsonArray($doc->id, 'referenceManyPush');
     $this->assertBsonArray($doc->id, 'referenceManySet');
     $this->assertBsonArray($doc->id, 'referenceManySetArray');
     $this->assertBsonArray($doc->id, 'referenceManyAddToSet');
     // Check that the value is changed properly
     unset($colPush[1], $colSet[1], $colSetArray[1], $colAddToSet[1]);
     $doc->referenceManyPush = $colPush;
     $doc->referenceManySet = $colSet;
     $doc->referenceManySetArray = $colSetArray;
     $doc->referenceManyAddToSet = $colAddToSet;
     /* Merging must be done after re-assigning the collections, as the
      * referenced documents must be re-persisted through the merge cascade.
      */
     $doc = $this->dm->merge($doc);
     $this->dm->flush();
     $this->dm->clear();
     $this->assertBsonArray($doc->id, 'referenceManyPush');
     $this->assertBsonObject($doc->id, 'referenceManySet');
     $this->assertBsonArray($doc->id, 'referenceManySetArray');
     $this->assertBsonArray($doc->id, 'referenceManyAddToSet');
 }
 /**
  * @param ArrayCollection $emails
  *
  * @return string[]
  */
 protected function toBatch(ArrayCollection $emails, $deep = true)
 {
     return $emails->map(function ($email) use($deep) {
         return array('email' => $deep ? array('email' => $email) : $email, 'email_type' => 'html');
     })->toArray();
 }
Example #11
0
 /**
  * @param ArrayCollection $groups
  *
  * @return array
  */
 protected function getGroupsCode(ArrayCollection $groups)
 {
     return $groups->map(function (GroupInterface $group) {
         return $group->getCode();
     })->toArray();
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function getLocaleCodes()
 {
     return $this->locales->map(function ($locale) {
         return $locale->getCode();
     })->toArray();
 }
 /**
  * @return array
  * @Assert\Count(min="1",minMessage="member not set")
  */
 public function getMembers()
 {
     return $this->members->map(function ($value) {
         return $value->get();
     })->getValues();
 }
Example #14
0
 /**
  * Combine the Passwd and Group collections
  *
  * @param object $passwd The passwd collection
  * @param object $group The group collection
  *
  * @return object The userInfo collection
  */
 private function combinePasswdAndGroup(Collection $passwd, Collection $group)
 {
     $userInfo = new Collection();
     /**
      * Iterate over all the users in the passwd collection
      */
     $passwd->map(function ($user) use($group, $userInfo) {
         /**
          * Get the groups this user is a member of
          */
         $groupItems = $group->filter(function ($group) use($user) {
             if (in_array($user["username"], $group["users"])) {
                 return true;
             }
             return false;
         });
         /**
          * Get only the group names and store them
          */
         $groups = [];
         foreach ($groupItems as $groupItem) {
             if ($groupItem["name"] != "") {
                 $groups[] = $groupItem["name"];
             }
         }
         /**
          * Add the secondary groups to the user's groups array
          */
         $user["groups"] = $groups;
         /**
          * Get the main group for the current user
          */
         $mainGroup = $this->getGroupById($user["gid"])["name"];
         /**
          * Add the user's main group to the groups list if it isn't already
          */
         if (!in_array($mainGroup, $user["groups"])) {
             $user["groups"][] = $mainGroup;
         }
         /**
          * Finally, add the user to the userInfo collection
          */
         $userInfo->add($user);
     });
     return $userInfo;
 }
 function map(\Closure $func)
 {
     return $this->fields->map($func);
 }
Example #16
0
 /**
  * @return string[]
  */
 protected function getFolderDirections()
 {
     return array_unique($this->folders->map(function (EmailFolder $folder) {
         return $folder->getDirection();
     })->toArray());
 }
Example #17
0
 /**
  * @inheritdoc
  */
 public function isDirectingCourse($courseId)
 {
     return $this->directedCourses->map(function (CourseInterface $course) {
         return $course->getId();
     })->contains($courseId);
 }
Example #18
0
 /**
  * Role collection
  *
  * @return Value\Role[]
  */
 public function getRoles()
 {
     return $this->roles->map(function (Role $role) {
         return $role->render();
     })->toArray();
 }
Example #19
0
 /**
  * @param Cart            $cart
  * @param ArrayCollection $cartItems imported items
  *
  * @return CartStrategy
  */
 protected function updateCartItems(Cart $cart, ArrayCollection $cartItems)
 {
     $importedOriginIds = $cartItems->map(function ($item) {
         return $item->getOriginId();
     })->toArray();
     // insert new and update existing items
     /** $item - imported cart item */
     foreach ($cartItems as $item) {
         $originId = $item->getOriginId();
         $existingItem = $cart->getCartItems()->filter(function ($item) use($originId) {
             return $item->getOriginId() == $originId;
         })->first();
         if ($existingItem) {
             $this->strategyHelper->importEntity($existingItem, $item, ['id', 'cart']);
             $item = $existingItem;
         }
         if (!$item->getCart()) {
             $item->setCart($cart);
         }
         if (!$cart->getCartItems()->contains($item)) {
             $cart->getCartItems()->add($item);
         }
     }
     // delete cart items that not exists in remote cart
     $deletedCartItems = $cart->getCartItems()->filter(function ($item) use($importedOriginIds) {
         return !in_array($item->getOriginId(), $importedOriginIds);
     });
     foreach ($deletedCartItems as $item) {
         $cart->getCartItems()->removeElement($item);
     }
     return $this;
 }
Example #20
0
 /**
  * Applies the given function to each element in the collection and returns
  * a new collection with the elements returned by the function.
  *
  * @param Closure $func
  *
  * @return Collection
  */
 public function map(Closure $func)
 {
     return $this->collection->map($func);
 }
 /**
  * @return array
  */
 public function getAuthRoles()
 {
     return $this->authRoles->map(function ($value) {
         return $value->get();
     })->toArray();
 }
 /** {@inheritDoc} */
 public function map(Closure $func)
 {
     $this->initialize();
     return $this->collection->map($func);
 }