/**
  * Add section
  *
  * @Route("/{id}/child", name="cp_terms_admin_section_add_child", requirements={"id": "\d+"})
  * @Template("CPTermsBundle:Section:new.html.twig")
  */
 public function addChildAction(Request $request, $id)
 {
     $section = $this->getSection($id, true);
     $count = $section->countChildren();
     $child = new Section();
     $child->insertAsLastChildOf($section);
     $form = $this->createForm(new SectionFormType(), $child, array('action' => $this->generateUrl('cp_terms_admin_section_add_child', array('id' => $id))));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $child->save();
         $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('section.add_child.success', array('%section%' => $section->getTitle(), '%child%' => $child->getTitle()), 'CPTermsBundle', $request->getLocale()));
         return $this->redirect($this->generateUrl('cp_terms_admin_show', array('id' => $section->getTermsId())));
     }
     return array('form' => $form->createView(), 'level' => $child->getLevel(), 'prefix' => sprintf('%s%d.', $request->query->get('prefix'), $count + 1));
 }
Пример #2
0
 public function getClone(Terms $terms, Section $parent = null)
 {
     $clone = new Section();
     $clone->setTerms($terms);
     $clone->setTitle($this->getTitle());
     $clone->setContent($this->getContent());
     if ($this->isRoot()) {
         $clone->makeRoot();
     } else {
         $clone->insertAsLastChildOf($parent);
     }
     $clone->save();
     if (!$this->isLeaf()) {
         $children = $this->getChildren();
         foreach ($children as $child) {
             $child->getClone($terms, $clone);
         }
     }
     return $clone;
 }