|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BoneMvc\Module\Dragon\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use BoneMvc\Module\Dragon\Collection\DragonCollection; |
|
6
|
|
|
use BoneMvc\Module\Dragon\Entity\Dragon; |
|
7
|
|
|
use Doctrine\ORM\EntityNotFoundException; |
|
8
|
|
|
use Doctrine\ORM\EntityRepository; |
|
9
|
|
|
|
|
10
|
|
|
class DragonRepository extends EntityRepository |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @param mixed $id |
|
14
|
|
|
* @param null $lockMode |
|
15
|
|
|
* @param null $lockVersion |
|
16
|
|
|
* @return Dragon |
|
17
|
|
|
* @throws EntityNotFoundException |
|
18
|
|
|
*/ |
|
19
|
|
|
public function find($id, $lockMode = null, $lockVersion = null): Dragon |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var Dragon $dragon */ |
|
22
|
|
|
$dragon = parent::find($id, $lockMode, $lockVersion); |
|
23
|
|
|
|
|
24
|
|
|
if (!$dragon) { |
|
25
|
|
|
throw new EntityNotFoundException('Dragon not found.', 404); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
return $dragon; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param Dragon $dragon |
|
33
|
|
|
* @return $dragon |
|
|
|
|
|
|
34
|
|
|
* @throws \Doctrine\ORM\ORMException |
|
35
|
|
|
* @throws \Doctrine\ORM\OptimisticLockException |
|
36
|
|
|
*/ |
|
37
|
|
|
public function save(Dragon $dragon): Dragon |
|
38
|
|
|
{ |
|
39
|
|
|
if(!$dragon->getID()) { |
|
40
|
|
|
$this->_em->persist($dragon); |
|
41
|
|
|
} |
|
42
|
|
|
$this->_em->flush($dragon); |
|
43
|
|
|
|
|
44
|
|
|
return $dragon; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param Dragon $dragon |
|
49
|
|
|
* @throws \Doctrine\ORM\OptimisticLockException |
|
50
|
|
|
* @throws \Doctrine\ORM\ORMException |
|
51
|
|
|
*/ |
|
52
|
|
|
public function delete(Dragon $dragon): void |
|
53
|
|
|
{ |
|
54
|
|
|
$this->_em->remove($dragon); |
|
55
|
|
|
$this->_em->flush($dragon); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return mixed |
|
60
|
|
|
* @throws \Doctrine\ORM\NonUniqueResultException |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getTotalDragonCount() |
|
63
|
|
|
{ |
|
64
|
|
|
$qb = $this->createQueryBuilder('d'); |
|
65
|
|
|
$qb->select('count(d.id)'); |
|
66
|
|
|
$query = $qb->getQuery(); |
|
67
|
|
|
|
|
68
|
|
|
return (int) $query->getSingleScalarResult(); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.