/**
  * @Route("/new", name="lc_dev_not_new")
  * @Template()
  */
 public function newAction(Request $request)
 {
     $category = new Category();
     $category->setMailTemplate("%title%\r\n%shorttext%\r\n");
     $category->setMailSenderAddress($this->getUser()->getEmail());
     $category->setEmailable(true);
     $category->setMarkdownTemplate("%title%\r\n--\r\n\r\n> %shorttext%\r\n\r\n");
     $form = $this->container->get('form.factory')->create($this->container->get('procergs_logincidadao.category.form.type'), $category);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $manager = $this->getDoctrine()->getManager();
         $manager->persist($category);
         $manager->flush();
         return $this->redirect($this->generateUrl('lc_dev_not_edit', array('id' => $category->getId())));
     }
     return array('form' => $form->createView());
 }
 /**
  * @Route("/populate/{id}", name="lc_admin_app_populate")
  * @Template()
  */
 public function populateAction($id)
 {
     $em = $this->getDoctrine()->getManager();
     $clientManager = $this->container->get('fos_oauth_server.client_manager');
     $em->beginTransaction();
     $input = 'Lorem Ipsum ';
     $person = $em->getRepository('PROCERGSLoginCidadaoCoreBundle:Person')->find($id);
     foreach (range(1, 1) as $val1) {
         $client = new Client();
         $client->setPerson($person);
         $client->setName("Sample client {$val1} " . uniqid());
         $client->setDescription('Sample client');
         $client->setSiteUrl("http://localhost");
         $client->setRedirectUris(array('http://localhost'));
         $client->setLandingPageUrl('http://localhost');
         $client->setTermsOfUseUrl('http://localhost');
         $client->setAllowedGrantTypes(Client::getAllGrants());
         $client->setPublished(0);
         $client->setVisible(0);
         $clientManager->updateClient($client);
         $list = array();
         foreach (range(1, 20) as $val2) {
             $cm = "Sample category {$val2} ";
             $category = new Category();
             $category->setClient($client);
             $category->setName($cm . uniqid());
             $category->setDefaultIcon('glyphicon glyphicon-envelope');
             $category->setDefaultTitle($cm . " title");
             $category->setDefaultShortText($cm . " shorttext");
             $category->setMailTemplate("%title%\r\n%shorttext%\r\n");
             $category->setMailSenderAddress($person->getEmail());
             $category->setEmailable(true);
             $category->setMarkdownTemplate("%title%\r\n--\r\n\r\n> %shorttext%\r\n\r\n");
             $category->setHtmlTemplate(MarkdownExtra::defaultTransform($category->getMarkdownTemplate()));
             $em->persist($category);
             foreach (range(1, 20) as $val3) {
                 $r = rand(1, 19);
                 $msg = array();
                 if ($r % 2) {
                     $msg['title'] = str_repeat($input, $r);
                     $msg['shorttext'] = str_repeat($input, $r);
                 }
                 $not = new Notification();
                 $not->setPerson($person);
                 $not->setCategory($category);
                 $not->setIcon($category->getDefaultIcon());
                 $not->setTitle(isset($msg['title']) ? $msg['title'] : $category->getDefaultTitle());
                 $not->setShortText(isset($msg['shorttext']) ? $msg['shorttext'] : $category->getDefaultShortText());
                 $not->parseHtmlTemplate($category->getHtmlTemplate());
                 $em->persist($not);
                 $list[] =& $not;
             }
             $list[] =& $category;
         }
         $em->flush();
         $em->clear($client);
         foreach ($list as &$entityes) {
             $em->clear($entityes);
         }
     }
     $em->commit();
     return new Response("ok");
 }