Example #1
0
 /**
  * Send notification to clank that user have new emails
  *
  * @param PostFlushEventArgs $args
  */
 public function postFlush(PostFlushEventArgs $args)
 {
     $usersWithNewEmails = [];
     if (!$this->processEmailUsersEntities) {
         return;
     }
     /** @var EmailUser $entity */
     foreach ($this->processEmailUsersEntities as $item) {
         $status = $item['status'];
         $entity = $item['entity'];
         $em = $args->getEntityManager();
         $ownerIds = $this->determineOwners($entity, $em);
         foreach ($ownerIds as $ownerId) {
             if (array_key_exists($ownerId, $usersWithNewEmails) === true) {
                 $new = $usersWithNewEmails[$ownerId]['new'];
                 if ($status === self::ENTITY_STATUS_NEW) {
                     $usersWithNewEmails[$ownerId]['new'] = $new + 1;
                 }
             } else {
                 $usersWithNewEmails[$ownerId] = ['entity' => $entity, 'new' => $status === self::ENTITY_STATUS_NEW ? 1 : 0];
             }
         }
     }
     if ($usersWithNewEmails) {
         $this->processor->send($usersWithNewEmails);
     }
     $this->processEmailUsersEntities = [];
 }
 /**
  * Send notification to clank that user have new emails
  */
 public function postFlush()
 {
     $usersWithNewEmails = [];
     if (!$this->processEmailUsersEntities) {
         return;
     }
     /** @var EmailUser $entity */
     foreach ($this->processEmailUsersEntities as $entity) {
         $status = $entity['status'];
         $entity = $entity['entity'];
         if (!$entity->getOwner()) {
             continue;
         }
         $ownerId = $entity->getOwner()->getId();
         if (array_key_exists($ownerId, $usersWithNewEmails) === true) {
             $new = $usersWithNewEmails[$ownerId]['new'];
             if ($status === self::ENTITY_STATUS_NEW) {
                 $usersWithNewEmails[$ownerId]['new'] = $new + 1;
             }
         } else {
             $usersWithNewEmails[$ownerId] = ['entity' => $entity, 'new' => $status === self::ENTITY_STATUS_NEW ? 1 : 0];
         }
     }
     if ($usersWithNewEmails) {
         $this->processor->send($usersWithNewEmails);
     }
     $this->processEmailUsersEntities = [];
 }
Example #3
0
 /**
  * Get new Unread Emails for email notification
  *
  * @Template("OroEmailBundle:Notification:button.html.twig")
  */
 public function placeholderLastAction()
 {
     $currentOrganization = $this->get('oro_security.security_facade')->getOrganization();
     $maxEmailsDisplay = $this->container->getParameter('oro_email.flash_notification.max_emails_display');
     $emailNotificationManager = $this->get('oro_email.manager.notification');
     return ['clank_event' => WebSocketSendProcessor::getUserTopic($this->getUser(), $currentOrganization), 'emails' => json_encode($emailNotificationManager->getEmails($this->getUser(), $maxEmailsDisplay)), 'count' => $emailNotificationManager->getCountNewEmails($this->getUser())];
 }
Example #4
0
 /**
  * Return unique identificator for clank event. This identification
  * is used in notification widget to show message about new emails
  *
  * @return string
  */
 public function getEmailClankEvent()
 {
     if (!$this->securityFacade->hasLoggedUser()) {
         return '';
     }
     $currentOrganization = $this->securityFacade->getOrganization();
     $currentUser = $this->securityFacade->getLoggedUser();
     return WebSocketSendProcessor::getUserTopic($currentUser, $currentOrganization);
 }
 public function testSendFailure()
 {
     $this->topicPublisher->expects($this->never())->method('send');
     $this->processor->send([]);
 }