Completed
Push — 5.6 ( 8cee39...f37855 )
by Jeroen
19s queued 11s
created

MediaRepository::getPicture()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 9
cp 0
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Kunstmaan\MediaBundle\Repository;
4
5
use Doctrine\ORM\EntityNotFoundException;
6
use Doctrine\ORM\EntityRepository;
7
use Kunstmaan\MediaBundle\Entity\Media;
8
9
/**
10
 * MediaRepository
11
 */
12
class MediaRepository extends EntityRepository
13
{
14
    /**
15
     * @param Media $media
16
     */
17
    public function save(Media $media)
18
    {
19
        $em = $this->getEntityManager();
20
        $em->persist($media);
21
        $em->flush();
22
    }
23
24
    /**
25
     * @param Media $media
26
     */
27
    public function delete(Media $media)
28
    {
29
        $em = $this->getEntityManager();
30
        $media->setDeleted(true);
31
        $em->persist($media);
32
        $em->flush();
33
    }
34
35
    /**
36
     * @param int $mediaId
37
     *
38
     * @return object
39
     *
40
     * @throws EntityNotFoundException
41
     */
42
    public function getMedia($mediaId)
43
    {
44
        $media = $this->find($mediaId);
45
        if (!$media) {
46
            throw new EntityNotFoundException();
47
        }
48
49
        return $media;
50
    }
51
52
    /**
53
     * Finds all Media  that has their deleted flag set to 1
54
     * and have their remove_from_file_system flag set to 0
55
     *
56
     * @return object[]
57
     */
58
    public function findAllDeleted()
59
    {
60
        return $this->findBy(['deleted' => true, 'removedFromFileSystem' => false]);
61
    }
62
}
63