Ejemplo n.º 1
0
 /**
  * @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");
 }
Ejemplo n.º 2
0
 private function sendBroadcast(Broadcast $broadcast, $shortText, $title)
 {
     $helper = $this->get('notifications.helper');
     $html = $broadcast->getHtmlTemplate();
     foreach ($broadcast->getReceivers() as $person) {
         $notification = new Notification();
         $notification->setIcon($broadcast->getCategory()->getDefaultIcon());
         //$notification->setCallbackUrl("url");
         $notification->setShortText($shortText);
         $notification->setTitle($title);
         $notification->setHtmlTemplate($html);
         $notification->setPerson($person);
         $notification->setSender($broadcast->getCategory()->getClient());
         $notification->setCategory($broadcast->getCategory());
         $notification->setMailTemplate($broadcast->getMailTemplate());
         $helper->send($notification);
     }
 }