1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the MilioooMessageBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Michiel boeckaert <[email protected]> |
7
|
|
|
* This source file is subject to the MIT license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Miliooo\MessagingBundle\Entity; |
12
|
|
|
|
13
|
|
|
use Doctrine\ORM\EntityRepository; |
14
|
|
|
use Miliooo\Messaging\Model\MessageInterface; |
15
|
|
|
use Miliooo\Messaging\Repository\MessageRepositoryInterface; |
16
|
|
|
use Miliooo\Messaging\User\ParticipantInterface; |
17
|
|
|
use Miliooo\Messaging\Model\ThreadInterface; |
18
|
|
|
use Doctrine\ORM\Query\Expr\Join; |
19
|
|
|
use Miliooo\Messaging\Model\MessageMetaInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Doctrine ORM Repository class for messages |
23
|
|
|
* |
24
|
|
|
* @author Michiel Boeckaert <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class MessageRepository extends EntityRepository implements MessageRepositoryInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function save(MessageInterface $message, $flush = true) |
32
|
|
|
{ |
33
|
|
|
$em = $this->getEntityManager(); |
34
|
|
|
$em->persist($message); |
35
|
|
|
|
36
|
|
|
if ($flush) { |
37
|
|
|
$em->flush(); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function getUnreadMessagesFromThreadForParticipant(ParticipantInterface $participant, ThreadInterface $thread) |
45
|
|
|
{ |
46
|
|
|
return $this->createQueryBuilder('m') |
47
|
|
|
->select('m', 'mm') |
48
|
|
|
->leftJoin('m.messageMeta', 'mm', Join::WITH, 'mm.participant = :participant') |
49
|
|
|
->setParameter('participant', $participant) |
50
|
|
|
->where('mm.readStatus != '.MessageMetaInterface::READ_STATUS_READ) |
51
|
|
|
->andWhere('m.thread = :thread') |
52
|
|
|
->setParameter('thread', $thread) |
53
|
|
|
->getQuery() |
54
|
|
|
->execute(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function flush() |
61
|
|
|
{ |
62
|
|
|
$em = $this->getEntityManager(); |
63
|
|
|
$em->flush(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|