/** * @param AuthorizationService $authorizationService * @param AbstractConversationEntity $context * * @return bool */ public function assert(AuthorizationService $authorizationService, $context = null) { if (!$context instanceof AbstractConversationEntity) { throw new InvalidArgumentException(); } /* @var MessageUserInterface $user */ $user = $authorizationService->getIdentity(); /* @var ArrayCollection $participants */ $participants = $context->getParticipants(); if ($participants->contains($user)) { return true; } return $authorizationService->isGranted('administrator'); }
/** * NamedConversationEntity constructor. * @param array $data */ public function __construct(array $data) { parent::__construct(); $this->createdAt = new DateTime(); $this->updatedAt = new DateTime(); $this->name = $data['name']; $this->slug = ConversationService::slugify($data['name']); }
/** * DirectConversationEntity constructor. * @param array $participants */ public function __construct(array $participants) { parent::__construct(); $this->createdAt = new DateTime(); $this->updatedAt = new DateTime(); array_map(function (MessageUserInterface $u) { AbstractConversationEntity::addParticipant($this, $u); }, $participants); }
/** * {@inheritdoc} */ public function removeParticipant(AbstractConversationEntity $conversation, MessageUserInterface $participant) { if ($conversation->getType() === DirectConversationEntity::TYPE) { throw IllegalOperationException::editingParticipantsOnDirectConversation(); } AbstractConversationEntity::removeParticipant($conversation, $participant); $eventArgs = ['conversation' => $conversation, 'participant' => $participant]; $this->getEventManager()->trigger(new ConversationEvent(ConversationEvent::PARTICIPANT_REMOVED, $this, $eventArgs)); $this->objectManager->flush(); }
public function getByConversation(AbstractConversationEntity $conversation) { $builder = $this->createQueryBuilder('messages'); $builder->leftJoin('messages.conversation', 'conversation')->andWhere($builder->expr()->eq('conversation.id', ':conversationId'))->orderBy('messages.createdAt', 'DESC')->setParameter('conversationId', $conversation->getId()); return new ZendPaginator(new DoctrinePaginator(new Paginator($builder->getQuery()))); }