setParent() public method

public setParent ( Sulu\Bundle\CategoryBundle\Entity\CategoryInterface $parent = null )
$parent Sulu\Bundle\CategoryBundle\Entity\CategoryInterface
Exemplo n.º 1
0
 public function initOrm()
 {
     $this->db('ORM')->purgeDatabase();
     /* First Category
        -------------------------------------*/
     $category = new Category();
     $category->setKey('first-category-key');
     $category->setDefaultLocale('en');
     // name for first category (en)
     $categoryTrans = new CategoryTranslation();
     $categoryTrans->setLocale('en');
     $categoryTrans->setTranslation('First Category');
     $categoryTrans->setCategory($category);
     $category->addTranslation($categoryTrans);
     // name for first category (de)
     $categoryTrans = new CategoryTranslation();
     $categoryTrans->setLocale('de');
     $categoryTrans->setTranslation('Erste Kategorie');
     $categoryTrans->setCategory($category);
     $category->addTranslation($categoryTrans);
     $this->category1 = $category;
     // meta for first category
     $categoryMeta = new CategoryMeta();
     $categoryMeta->setLocale('en');
     $categoryMeta->setKey('description');
     $categoryMeta->setValue('Description of Category');
     $categoryMeta->setCategory($category);
     $category->addMeta($categoryMeta);
     $this->meta1 = $categoryMeta;
     $this->em->persist($category);
     /* Second Category
        -------------------------------------*/
     $category2 = new Category();
     $category2->setKey('second-category-key');
     $category2->setDefaultLocale('en');
     $this->category2 = $category2;
     // name for second category
     $categoryTrans2 = new CategoryTranslation();
     $categoryTrans2->setLocale('de');
     $categoryTrans2->setTranslation('Zweite Kategorie');
     $categoryTrans2->setCategory($category2);
     $category2->addTranslation($categoryTrans2);
     // meta for second category
     $categoryMeta2 = new CategoryMeta();
     $categoryMeta2->setLocale('de');
     $categoryMeta2->setKey('description');
     $categoryMeta2->setValue('Beschreibung der zweiten Kategorie');
     $categoryMeta2->setCategory($category2);
     $category2->addMeta($categoryMeta2);
     // meta without locale for second category
     $categoryMeta3 = new CategoryMeta();
     $categoryMeta3->setKey('noLocaleKey');
     $categoryMeta3->setValue('noLocaleValue');
     $categoryMeta3->setCategory($category2);
     $category2->addMeta($categoryMeta3);
     $this->em->persist($category2);
     /* Third Category (child of first)
        -------------------------------------*/
     $category3 = new Category();
     $category3->setParent($category);
     $category3->setDefaultLocale('en');
     $this->category3 = $category3;
     // name for third category
     $categoryTrans3 = new CategoryTranslation();
     $categoryTrans3->setLocale('en');
     $categoryTrans3->setTranslation('Third Category');
     $categoryTrans3->setCategory($category3);
     $category3->addTranslation($categoryTrans3);
     // meta for third category
     $categoryMeta4 = new CategoryMeta();
     $categoryMeta4->setLocale('de');
     $categoryMeta4->setKey('another');
     $categoryMeta4->setValue('Description of third Category');
     $categoryMeta4->setCategory($category3);
     $category3->addMeta($categoryMeta4);
     $this->em->persist($category3);
     /* Fourth Category (child of third)
        -------------------------------------*/
     $category4 = new Category();
     $category4->setParent($category3);
     $category4->setDefaultLocale('en');
     $this->category4 = $category4;
     // name for fourth category
     $categoryTrans4 = new CategoryTranslation();
     $categoryTrans4->setLocale('en');
     $categoryTrans4->setTranslation('Fourth Category');
     $categoryTrans4->setCategory($category4);
     $category4->addTranslation($categoryTrans4);
     // meta for fourth category
     $categoryMeta5 = new CategoryMeta();
     $categoryMeta5->setLocale('de');
     $categoryMeta5->setKey('anotherkey');
     $categoryMeta5->setValue('Description of fourth Category');
     $categoryMeta5->setCategory($category4);
     $category4->addMeta($categoryMeta5);
     $this->em->persist($category4);
     $this->em->flush();
 }