/** * @param Element $entity Элемент, разделы котрого необходимо получить * @return array Возвращает массив содержащий коллекцию разделов и их айдишники (в том числе NULL) */ private function getElementSections($entity) { $em = $this->getDoctrine()->getManager(); $sectionsId = array(); $entitySections = $entity->getSection(); $sections = new ArrayCollection(); $countEntitySections = count($entitySections); if ($countEntitySections > 0) { foreach ($entitySections as $o) { ///echo '<pre>' . print_r($o->getId(), true) . '</pre>'; if ($o->getSection()) { $sectionsId[] = $o->getSection()->getId(); } else { $sections->add(null); } } if ($sectionsId) { $sectionsById = $em->getRepository('NovuscomCMFBundle:Section')->findBy(array('id' => $sectionsId)); foreach ($sectionsById as $s) { $sections->add($s); } } } return $sections; }