/**
  * @Route("/add-from-category/{id}")
  * @Method({"GET, POST"})
  */
 public function addFromCategoryAction($id)
 {
     $breadcrumbs = array(array('name' => get_lang('Curriculum'), 'url' => array('route' => 'curriculum_user.controller:indexAction', 'routeParameters' => array('course' => $this->getCourse()->getCode()))), array('name' => get_lang('Categories'), 'url' => array('route' => 'curriculum_category.controller:indexAction', 'routeParameters' => array('course' => $this->getCourse()->getCode()))), array('name' => get_lang('AddItems')));
     $this->setBreadcrumb($breadcrumbs);
     $request = $this->getRequest();
     $formType = $this->getFormType();
     $entity = new CurriculumItem();
     $category = $this->get('orm.em')->getRepository('Chamilo\\CoreBundle\\Entity\\CurriculumCategory')->find($id);
     $entity->setCategory($category);
     $form = $this->get('form.factory')->create($formType, $entity);
     if ($request->getMethod() == 'POST') {
         $form->bind($request);
         if ($form->isValid()) {
             /** @var CurriculumCategory $item */
             $item = $form->getData();
             $em = $this->getManager();
             $em->persist($item);
             $em->flush();
             $this->get('session')->getFlashBag()->add('success', "Added");
             $url = $this->createUrl('list_link');
             return $this->redirect($url);
         }
     }
     $template = $this->get('template');
     $template->assign('links', $this->generateLinks());
     $template->assign('form', $form->createView());
     $template->assign('parent_id', $id);
     $response = $template->render_template($this->getTemplatePath() . 'add_from_category.tpl');
     return new Response($response, 200, array());
 }
 /**
  * Get all users that are registered in the course. No matter the status
  *
  * @param \Chamilo\CoreBundle\Entity\CurriculumItem $course
  * @return bool
  */
 public function isAllowToInsert(\Chamilo\CoreBundle\Entity\CurriculumItem $item, \Chamilo\UserBundle\Entity\User $user)
 {
     $max = $item->getMaxRepeat();
     $count = $this->createQueryBuilder('a')->select('COUNT(a)')->where('a.itemId = :itemId')->andWhere('a.userId = :userId')->setParameters(array('itemId' => $item->getId(), 'userId' => $user->getUserId()))->getQuery()->getSingleScalarResult();
     return $count <= $max ? true : false;
 }