Exemple #1
0
 /**
  * Get all the categories except the current one and it's children
  * @param Category $category
  * @return array Categories array handy for setting form select options [id] => intent+title
  */
 protected function getAllButChildren(Category $category)
 {
     $childIds = [];
     if (!empty($category->getId())) {
         $categoryChildren = $this->categoryRepo->getChildren($category);
         foreach ($categoryChildren as $child) {
             $childIds[] = $child->getId();
         }
     }
     $allButOwnCategs = [];
     foreach ($this->categoriesAsOptions as $id => $categs) {
         if ($id != $category->getId() && !in_array($id, $childIds)) {
             $allButOwnCategs[$id] = $this->categoriesAsOptions[$id];
         }
     }
     return $allButOwnCategs;
 }
Exemple #2
0
 protected function addEmptyContent(Category $category)
 {
     $contentIDs = [];
     $languagesService = $this->getServiceLocator()->get('language');
     foreach ($category->getContent() as $content) {
         $contentIDs[] = $content->getLang()->getId();
     }
     $languages = $languagesService->getActiveLanguages();
     foreach ($languages as $language) {
         if (!in_array($language->getId(), $contentIDs)) {
             new CategoryContent($category, $language);
         }
     }
 }
Exemple #3
0
 public function getChildren(Category $category)
 {
     $qb = $this->createQueryBuilder('c');
     $qb->select('c')->join('c.parents', 'p')->where('p.id=' . $category->getId());
     return $qb->getQuery()->getResult();
 }
 /**
  * @depends testGetChildrenCategories
  * @depends testAddCategoryPost2
  * @param Category $childCategory
  * @param $lastInsertedId
  */
 public function testChangeChild($childCategory, $lastInsertedId)
 {
     $childId = $childCategory->getId();
     $categoryClassName = get_class(new Category());
     $this->mockLogin();
     $form = new CategoryForm($this->entityManager);
     $this->dispatch('/admin/category/' . $childId, Request::METHOD_PUT, ['sort' => 5, 'content[0][title]' => urlencode('Some title'), 'parent' => $lastInsertedId, 'category_csrf' => $form->get('category_csrf')->getValue()]);
     $this->assertEquals(200, $this->getResponse()->getStatusCode());
     //check if the child category has changed it's direct parent
     $childCategory = $this->entityManager->find($categoryClassName, $childId);
     $this->assertEquals($lastInsertedId, $childCategory->getParent());
     //check all the parents of the child category
     $parentIDs = [];
     foreach ($childCategory->getParents() as $parent) {
         $parentIDs[] = $parent->getId();
     }
     $this->assertTrue(in_array($lastInsertedId, $parentIDs));
     //check the child's child parents
     $childChild = $this->entityManager->getRepository($categoryClassName)->getChildren($childCategory)[0];
     $childParentIDs = [];
     foreach ($childChild->getParents() as $descendants) {
         $childParentIDs[] = $descendants->getId();
     }
     $this->assertTrue(in_array($lastInsertedId, $childParentIDs));
     $this->assertEquals($childCategory->getId(), $childChild->getParent());
     //test the direct parent
 }