Doctrine\Common\Collections\ArrayCollection::map PHP Method

map() public method

{@inheritDoc}
public map ( Closure $func )
$func Closure
    public function map(Closure $func)
    {
        return $this->createFrom(array_map($func, $this->elements));
    }

Usage Example

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;
 }
All Usage Examples Of Doctrine\Common\Collections\ArrayCollection::map