Exemplo n.º 1
0
 /**
  * Allows to get all users who don't have reply to specified doodle.
  * @param jc\DoodleBundle\Entity\Doodle $doodle Doodle we want to get users who don't have reply.
  * @return List of users who don't have reply to specified doodle.
  */
 public function getMissingUserForDoodle($doodle)
 {
     try {
         // Get all user who are not admin and who doesn't exist in doodle reply list
         $queryBuilder = $this->_em->createQueryBuilder()->select('u')->from('jcUserBundle:User', 'u');
         $queryBuilder->where('u.profil = :adminRole')->andWhere('u.enabled = :enabled')->setParameter('adminRole', 'ROLE_USER')->setParameter('enabled', true);
         // If doodle already contains reply => exclude users who have reply
         if (count($doodle->getReplyList()) > 0) {
             $idToExclude = array();
             foreach ($doodle->getReplyList() as $doodleReply) {
                 $idToExclude[] = $doodleReply->getUser()->getId();
             }
             $queryBuilder->andWhere($queryBuilder->expr()->notIn('u.id', $idToExclude));
         }
         $query = $queryBuilder->getQuery();
         return $query->getResult();
     } catch (Exception $ex) {
         return array();
     }
 }
Exemplo n.º 2
0
 /**
  * Allows to get all users who don't have reply to specified doodle.
  * @param jc\DoodleBundle\Entity\Doodle $doodle Doodle we want to get users who don't have reply.
  * @return List of users who don't have reply to specified doodle.
  */
 public function getMissingUserForDoodle($doodle)
 {
     try {
         // Get admin role to build condition later
         $adminRole = $this->_em->createQuery('SELECT r FROM jcUserBundle:Role r WHERE r.code = :adminCode')->setParameter('adminCode', 'ROLE_ADMIN')->getSingleResult();
         // Get all user who are not admin and who doesn't exist in doodle reply list
         $queryBuilder = $this->_em->createQueryBuilder()->select('u')->from('jcUserBundle:User', 'u');
         $queryBuilder = $queryBuilder->where(':adminRole NOT MEMBER OF u.internalRoles')->setParameter('adminRole', $adminRole);
         // If doodle already contains reply => exclude users who have reply
         if (count($doodle->getReplyList()) > 0) {
             $idToExclude = array();
             foreach ($doodle->getReplyList() as $doodleReply) {
                 $idToExclude[] = $doodleReply->getUser()->getId();
             }
             $queryBuilder->andWhere($queryBuilder->expr()->notIn('u.id', $idToExclude));
         }
         $query = $queryBuilder->getQuery();
         return $query->getResult();
     } catch (Exception $ex) {
         return array();
     }
 }
Exemplo n.º 3
0
 /**
  * Allows to send doodle by mail to specified user list.
  * @param jc\DoodleBundle\Entity\Doodle $doodle Doodle to send to specified users.
  * @param array $userList List os users (as jc\UserBundle\Entity\User) we want to send doodle.
  * @return boolean TRUE in case of success, FALSE either.
  */
 public function sendDoodle($doodle, $userList)
 {
     $mailList = $this->extractMailList($userList);
     try {
         $messageContent = $doodle->getSent() ? $this->templating->render('jcMailBundle:mail:doodleReminder.html.twig', array('doodle' => $doodle)) : $this->templating->render('jcMailBundle:mail:doodleNew.html.twig', array('doodle' => $doodle));
         $subject = $doodle->getTitle();
         if (strlen($this->prefix) > 0) {
             $subject = '[' . $this->prefix . '] - ' . $subject;
         }
         // Create mail and send it
         $mail = \Swift_Message::newInstance()->setSubject($subject)->setFrom($this->fromMail, $this->fromName)->setBcc($mailList)->setContentType('text/html')->setBody($messageContent);
         $this->mailer->send($mail);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }