Ejemplo n.º 1
0
 public function bulkAddAction(Request $request, $bundle, $entity)
 {
     $ah = $this->get('itf.admin_helper');
     $ah->setBundle($bundle);
     $ah->setEntity($entity);
     $entity = $ah->getEntityInstance($entity);
     // setup reponse
     $response = ControllerResponse::create($this)->setBundle($bundle)->setEntityName($entity)->setTemplate('ITFAdminBundle:Admin:edit.html.twig');
     // get entity
     $em = $this->getDoctrine()->getManager();
     $entity = new \ITF\AdminBundle\Admin\Entity($entity, $this);
     if (!$entity) {
         throw $this->createNotFoundException(sprintf('Unable to find %e entity.', $entity->getName()));
     }
     // set id
     $response->setEntityId($entity->getEntity()->getId());
     // if tree
     if ($this->get('itf.admin.annotation_reader')->isGedmoTree($entity->getEntity())) {
         /* @var AbstractTreeRepository $repo */
         $repo = $ah->getEntityRepositoryReference($entity->getName());
         //pre($this->get('itf.admin.tree')->getFlatTree($repo, 29));
         // create bulk add form
         $bulkadd_form = $this->createFormBuilder(null, array())->add('parent', 'entity', array('class' => $repo->getClassName()))->add('bulk_add', 'textarea', array('attr' => array('rows' => 10)))->add('submit', 'submit', array('attr' => array('class' => 'btn btn-success')))->getForm();
         // post
         if ($request->isMethod('POST')) {
             $bulkadd_form->handleRequest($request);
             // get mapped data
             $bulkadd_parent = $bulkadd_form->get('parent')->getData();
             $bulkadd_entries = $bulkadd_form->get('bulk_add')->getData();
             $bulkadd_entries = preg_split('/[\\r\\n]+/', $bulkadd_entries, -1, PREG_SPLIT_NO_EMPTY);
             // go through entries
             if (count($bulkadd_entries) > 0 && is_object($bulkadd_parent)) {
                 $entry_class = get_class($bulkadd_parent);
                 foreach ($bulkadd_entries as $entry) {
                     $newEntry = new $entry_class();
                     $newEntry->setLabel($entry)->setParent($bulkadd_parent);
                     $em->persist($newEntry);
                 }
                 $em->flush();
             }
         }
         // add data
         $response->addData('bulkadd_form', $bulkadd_form->createView());
         // add tree to return array
         $response->setFuncType('bulkadd')->setTreeHtml($this->get('itf.admin.tree')->getTreeListHTML($repo))->setTemplate('@ITFAdmin/Admin/tree/index.html.twig');
     }
     return $response->createResponse();
 }
Ejemplo n.º 2
0
 /**
  * @param Request $request
  * @param $bundle
  * @param $entity
  *
  * @return Response
  */
 public function searchAction(Request $request, $bundle, $entity)
 {
     $ah = $this->get('itf.admin_helper');
     $ah->setBundle($bundle);
     $ah->setEntity($entity);
     // setup reponse
     $response = ControllerResponse::create($this)->setBundle($bundle)->setEntityName($entity)->setTemplate('@ITFAdmin/Admin/search.html.twig');
     // search
     $searcher = $this->get('itf.admin.search');
     $form = $searcher->createSearchForm($ah->getEntityInstance($entity));
     if ($searcher->isSubmitted($request)) {
         // map request data to field mappings
         $searcher->mapRequestData($request);
         // get result
         $session = $this->get('session');
         //$session->getFlashBag()->add('search_operators', $searcher->getOperators());
         $session->set('search_operators', $searcher->getOperators());
         $response->setData(array('search' => true));
         // table id
         if (empty($table_id)) {
             $table_id = 'dt-' . $entity . time();
         }
         $response->setTableId($table_id);
         // init datatable
         $this->_datatable($bundle, $entity, $response->getTableId());
     }
     $response->setForm($form->createView());
     return $response->createResponse();
 }