public function add($data = array())
 {
     $isPublished = $data['is_published'] ? $this->constants->get('published_category') : $this->constants->get('unpublished_category');
     $category = new Category();
     $category->setName($data['name']);
     $category->setIsPublished($isPublished);
     $category->setIsDefault($this->constants->get('admin_category'));
     $this->entityManager->persist($category);
     $this->entityManager->flush();
     return array('success' => true);
 }
 private function saveInterests($interests)
 {
     $egInterests = $this->getDoctrine()->getRepository('BugglMainBundle:EGuideToCategory')->findBy(array('e_guide' => $this->eguide));
     $em = $this->getDoctrine()->getEntityManager();
     $categories = array();
     if ($egInterests) {
         foreach ($egInterests as $interest) {
             $em->remove($interest);
             $em->flush();
         }
     }
     foreach ($interests as $newInterest) {
         $category = $this->getDoctrine()->getRepository('BugglMainBundle:Category')->findOneByName($newInterest);
         if (!$category) {
             $category = new Category();
             $category->setName($newInterest);
             $category->setIsPublished(1);
             $category->setIsDefault(1);
             $em->persist($category);
             $em->flush();
         }
         $obj = new EGuideToCategory();
         $obj->setEGuide($this->eguide);
         $obj->setCategory($category);
         $em->persist($obj);
         $em->flush();
         /**
          * @author vfgtaboada <*****@*****.**>
          */
         $categories[] = $obj->getCategory()->getName();
     }
     /**
      * @author vfgtaboada <*****@*****.**>
      */
     $categories = implode(', ', $categories);
     $this->eguide->setCategoryNames($categories);
     $em->persist($this->eguide);
     $em->flush();
     /********************/
 }