Пример #1
0
 /**
  * Add noteStatus
  *
  * @param \Tmcycyit\NotificationBundle\Entity\FastNoteStatus $noteStatus
  * @return FastNote
  */
 public function addNoteStatus(\Tmcycyit\NotificationBundle\Entity\FastNoteStatus $noteStatus)
 {
     $this->noteStatus[] = $noteStatus;
     $noteStatus->setFastNote($this);
     return $this;
 }
Пример #2
0
 /**
  *
  * This function is used to sent fast notifications
  *
  * @param $content
  * @param $title
  * @param $receivers
  * @param $fromUser
  * @param $noteType
  * @throws \Throwable
  */
 public function sendFastNoteFromUser($content, $title, $receivers, $fromUser, $noteType)
 {
     // get user
     //        $currentUser = $this->container->get('security.context')->getToken()->getUser();
     // get entity manager
     $em = $this->container->get('doctrine')->getManager();
     $fastNote = new FastNote();
     // set prepared notification
     $fastNote->setFromUser($fromUser);
     //set sender
     $fastNote->setTitle($title);
     //set title
     $fastNote->setContent($content);
     //set content
     $fastNote->setNoteType($noteType);
     // loop for receivers
     foreach ($receivers as $receiver) {
         // don`t send note himself
         if ($receiver != $fromUser) {
             $fastNoteStatus = new FastNoteStatus();
             $fastNoteStatus->setToUser($receiver);
             //set $receiver
             $fastNoteStatus->setStatus(FastNote::UN_READ);
             //set status unread
             $fastNote->addNoteStatus($fastNoteStatus);
             $em->persist($fastNoteStatus);
             //persist notification status
         }
     }
     $fastNote->setCreated(new \DateTime('now'));
     //set notifications date
     $em->persist($fastNote);
     //persist status
     $em->flush();
 }