Passed
Pull Request — master (#6835)
by Angel Fernando Quiroz
17:36 queued 08:49
created

PortfolioAttachmentRepository::findFromComment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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