MessageRepository   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 40
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A flush() 0 5 1
A save() 0 9 2
A getUnreadMessagesFromThreadForParticipant() 0 12 1
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