コード例 #1
0
 /**
  * Gets threads created by a participant
  *
  * @param ParticipantInterface $participant
  * @return array of ThreadInterface
  */
 public function findThreadsCreatedBy(ParticipantInterface $participant)
 {
     return $this->repository->createQueryBuilder('t')->innerJoin('t.createdBy', 'p')->where('p.id = :participant_id')->setParameter('participant_id', $participant->getId())->getQuery()->execute();
 }
コード例 #2
0
 /**
  * Gets threads created by a participant
  *
  * @param ParticipantInterface $participant
  * @return array of ThreadInterface
  */
 public function findThreadsCreatedBy(ParticipantInterface $participant)
 {
     return $this->repository->createQueryBuilder()->field('createdBy.$id')->equals(new \MongoId($participant->getId()))->getQuery()->execute();
 }
コード例 #3
0
ファイル: Message.php プロジェクト: gpuck/FOSMessageBundle
 /**
  * Get the MessageMetadata for a participant.
  *
  * @param ParticipantInterface $participant
  * @return MessageMetadata
  */
 public function getMetadataForParticipant(ParticipantInterface $participant)
 {
     foreach ($this->metadata as $meta) {
         if ($meta->getParticipant()->getId() == $participant->getId()) {
             return $meta;
         }
     }
     return null;
 }
コード例 #4
0
 /**
  * Tells how many unread messages this participant has
  *
  * @param ParticipantInterface $participant
  * @return int the number of unread messages
  */
 public function getNbUnreadMessageByParticipant(ParticipantInterface $participant)
 {
     $builder = $this->repository->createQueryBuilder('m');
     return (int) $builder->select($builder->expr()->count('mm.id'))->innerJoin('m.metadata', 'mm')->innerJoin('mm.participant', 'p')->where('p.id = :participant_id')->setParameter('participant_id', $participant->getId())->andWhere('m.sender != :sender')->setParameter('sender', $participant->getId())->andWhere('mm.isRead = :isRead')->setParameter('isRead', false, \PDO::PARAM_BOOL)->getQuery()->getSingleScalarResult();
 }
コード例 #5
0
 /**
  * Marks messages as read/unread
  * by updating directly the storage
  *
  * @param ParticipantInterface $participant
  * @param boolean $isRead
  * @param \Closure $condition
  */
 protected function markIsReadByCondition(ParticipantInterface $participant, $isRead, \Closure $condition)
 {
     $queryBuilder = $this->repository->createQueryBuilder();
     $condition($queryBuilder);
     $queryBuilder->update()->field('metadata.participant.$id')->equals(new \MongoId($participant->getId()));
     /* If marking the message as read for a participant, we should pull
      * their ID out of the unreadForParticipants array. The same is not
      * true for the inverse. We should only add a participant ID to this
      * array if the message is not considered spam.
      */
     if ($isRead) {
         $queryBuilder->field('unreadForParticipants')->pull($participant->getId());
     }
     $queryBuilder->field('metadata.$.isRead')->set((bool) $isRead)->getQuery(array('multiple' => true))->execute();
     /* If marking the message as unread for a participant, add their ID to
      * the unreadForParticipants array if the message is not spam. This must
      * be done in a separate query, since the criteria is more selective.
      */
     if (!$isRead) {
         $queryBuilder = $this->repository->createQueryBuilder();
         $condition($queryBuilder);
         $queryBuilder->update()->field('metadata.participant.$id')->equals(new \MongoId($participant->getId()))->field('isSpam')->equals(false)->field('unreadForParticipants')->addToSet($participant->getId())->getQuery(array('multiple' => true))->execute();
     }
 }