/** * @REST\Post("/person/sendnotification") * @REST\View * @Audit\Loggable(type="CREATE") * @deprecated since version 1.0.2 */ public function sendNotificationAction(Request $request) { $token = $this->get('security.context')->getToken(); $accessToken = $this->getDoctrine()->getRepository('PROCERGSOAuthBundle:AccessToken')->findOneBy(array('token' => $token->getToken())); $client = $accessToken->getClient(); $body = json_decode($request->getContent(), 1); $chkAuth = $this->getDoctrine()->getManager()->getRepository('PROCERGSLoginCidadaoCoreBundle:Authorization')->createQueryBuilder('a')->select('cnc, p')->join('PROCERGSLoginCidadaoCoreBundle:Person', 'p', 'WITH', 'a.person = p')->join('PROCERGSOAuthBundle:Client', 'c', 'WITH', 'a.client = c')->join('PROCERGSLoginCidadaoCoreBundle:ConfigNotCli', 'cnc', 'WITH', 'cnc.client = c')->where('c.id = ' . $client->getId() . ' and p.id = :person_id and cnc.id = :config_id')->getQuery(); $rowR = array(); $em = $this->getDoctrine()->getManager(); $validator = $this->get('validator'); foreach ($body as $idx => $row) { if (isset($row['person_id'])) { $res = $chkAuth->setParameters(array('person_id' => $row['person_id'], 'config_id' => $row['config_id']))->getResult(); if (!$res) { $rowR[$idx] = array('person_id' => $row['person_id'], 'error' => 'missing authorization or configuration'); continue; } $not = new Notification(); $not->setPerson($res[0]); $not->setConfigNotCli($res[1])->setIcon(isset($row['icon']) && $row['icon'] ? $row['icon'] : $not->getConfigNotCli()->getIcon())->setTitle(isset($row['title']) && $row['title'] ? $row['title'] : $not->getConfigNotCli()->getTitle())->setShortText(isset($row['shorttext']) && $row['shorttext'] ? $row['shorttext'] : $not->getConfigNotCli()->getShortText())->setText($row['text'])->parseHtmlTemplate($not->getConfigNotCli()->getHtmlTemplate()); $errors = $validator->validate($not); if (!count($errors)) { $em->persist($not); $rowR[$idx] = array('person_id' => $row['person_id'], 'notification_id' => $not->getId()); } else { $rowR[$idx] = array('person_id' => $row['person_id'], 'error' => (string) $errors); } } } $em->flush(); return $this->handleView($this->view($rowR)); }
/** * @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"); }
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); } }