Passed
Push — 1.11.x ( 397ff2...44ef98 )
by Angel Fernando Quiroz
09:24
created

PortfolioAttachmentRepository::findFromComment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Entity\Repository;
6
7
use Chamilo\CoreBundle\Entity\Portfolio;
8
use Chamilo\CoreBundle\Entity\PortfolioAttachment;
9
use Chamilo\CoreBundle\Entity\PortfolioComment;
10
use Doctrine\ORM\EntityRepository;
11
use Doctrine\ORM\OptimisticLockException;
12
use Doctrine\ORM\ORMException;
13
14
/**
15
 * Class PortfolioAttachmentRepository.
16
 *
17
 * @package Chamilo\CoreBundle\Entity\Repository
18
 */
19
class PortfolioAttachmentRepository extends EntityRepository
20
{
21
    public function findFromItem(Portfolio $item): array
22
    {
23
        return $this->findBy(
24
            [
25
                'origin' => $item->getId(),
26
                'originType' => PortfolioAttachment::TYPE_ITEM,
27
            ]
28
        );
29
    }
30
31
    /**
32
     * @return array<int, PortfolioComment>
33
     */
34
    public function findFromComment(PortfolioComment $comment): array
35
    {
36
        return $this->findBy(
37
            [
38
                'origin' => $comment->getId(),
39
                'originType' => PortfolioAttachment::TYPE_COMMENT,
40
            ]
41
        );
42
    }
43
44
    /**
45
     * @throws OptimisticLockException
46
     * @throws ORMException
47
     */
48
    public function removeFromComment(PortfolioComment $comment)
49
    {
50
        $comments = $this->findFromComment($comment);
51
52
        foreach ($comments as $comment) {
53
            $this->_em->remove($comment);
54
        }
55
    }
56
}
57