/** * Sort a category tree based on the received order recursively. * * @param array $categoriesOrder The category order * @param Category|null $parentCategory The parent category in case is not a root category. * * @return bool If the order process has finished right. */ protected function sortCategoriesTree(array $categoriesOrder, $parentCategory = null) { $counter = 0; foreach ($categoriesOrder as $categoryInfo) { $category = $this->categoryRepository->findOneBy(['id' => $categoryInfo['id']]); if (is_null($category)) { return false; } $category->setPosition($counter); if ($parentCategory) { $category->setPosition($counter); $category->setRoot(false); $category->setParent($parentCategory); } else { $category->setPosition($counter); $category->setRoot(true); $category->setParent(null); } ++$counter; if (isset($categoryInfo['subtree']) && !$this->sortCategoriesTree($categoryInfo['subtree'], $category)) { return false; } } return true; }
public function findByTag($tag, $current_page = 1, $limit = 5) { $query = $this->entity_repository->createQueryBuilder('a')->innerJoin('App\\Entity\\Feed', 'f')->where('f.tag = :tag')->setParameter(':tag', $tag)->orderBy('a.created_at', 'DESC')->getQuery(); return $this->paginate($query, $current_page, $limit); }
/** * @return WriterAbstraction */ public function log() { return ObjectRepository::getLogger($this); }
/** * Get link page localization * @return Localization */ public function getPageLocalization() { throw new \Exception('Dont use me bro.'); if (empty($this->pageId)) { return; } if (!is_null($this->pageLocalization)) { return $this->pageLocalization; } $em = ObjectRepository::getEntityManager($this); $pageData = null; $localizationEntity = Localization::CN(); $localeId = ObjectRepository::getLocaleManager($this)->getCurrent()->getId(); $criteria = array('master' => $this->pageId, 'locale' => $localeId); // Now master page ID is stored, still the old implementation is working $dql = "SELECT l, m, p FROM {$localizationEntity} l\n\t\t\t\tJOIN l.master m\n\t\t\t\tLEFT JOIN l.path p\n\t\t\t\tWHERE (l.master = :master AND l.locale= :locale)\n\t\t\t\tOR l.id = :master"; try { $pageData = $em->createQuery($dql)->setParameters($criteria)->getSingleResult(); } catch (NoResultException $noResult) { // Special case for group page selection when no localization exists in database $master = $em->find(GroupPage::CN(), $this->pageId); if ($master instanceof GroupPage) { $pageData = $master->getLocalization($localeId); } } // Cache the result $this->pageLocalization = $pageData; return $pageData; }
/** * @covers Kunstmaan\MediaBundle\Helper\FolderManager::getParents */ public function testGetParents() { $this->repository->expects($this->once())->method('getPath')->with($this->equalTo($this->folder)); $this->assertEquals($this->parents, $this->object->getParents($this->folder)); }
/** * @return ArrayCollection<Feed> */ public function findAll() { $feeds = new ArrayCollection($this->entity_repository->findAll()); return $feeds; }