|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PlaygroundGame\Mapper; |
|
4
|
|
|
|
|
5
|
|
|
use PlaygroundGame\Mapper\AbstractMapper; |
|
6
|
|
|
|
|
7
|
|
|
class MissionGame extends AbstractMapper |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* refresh : supprimer une entite missionGame |
|
11
|
|
|
* @param PlaygroundGame\Entity\MissionGame $entity missionGame |
|
12
|
|
|
* |
|
13
|
|
|
*/ |
|
14
|
|
|
public function refresh($entity) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->em->refresh($entity); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* getEntityRepository : recupere l'entite missionGame |
|
21
|
|
|
* |
|
22
|
|
|
* @return \Doctrine\ORM\EntityRepository $missionGame |
|
23
|
|
|
*/ |
|
24
|
|
|
public function getEntityRepository() |
|
25
|
|
|
{ |
|
26
|
|
|
if (null === $this->er) { |
|
27
|
|
|
$this->er = $this->em->getRepository('PlaygroundGame\Entity\MissionGame'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
return $this->er; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function getNextGame($mission, $currentPosition) |
|
34
|
|
|
{ |
|
35
|
|
|
if (!is_object($mission)) { |
|
36
|
|
|
return false; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
if (!is_integer($currentPosition)) { |
|
40
|
|
|
return false; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$select = "SELECT mg.id"; |
|
45
|
|
|
$from = "FROM PlaygroundGame\Entity\MissionGame mg"; |
|
46
|
|
|
$where = "WHERE mg.mission = :mission"; |
|
47
|
|
|
$where .= " AND mg.position > :currentPosition"; |
|
48
|
|
|
$order = "ORDER BY mg.position ASC"; |
|
49
|
|
|
|
|
50
|
|
|
$query = $select.' '.$from.' '.$where.' '.$order; |
|
51
|
|
|
|
|
52
|
|
|
$query = $this->em->createQuery($query); |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
$query->setParameter('mission', (int) $mission->getId()); |
|
56
|
|
|
$query->setParameter('currentPosition', (int) $currentPosition); |
|
57
|
|
|
$query->setMaxResults(1); |
|
58
|
|
|
|
|
59
|
|
|
$nextGame = $query->getResult(); |
|
60
|
|
|
|
|
61
|
|
|
if(empty($nextGame)) { |
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $this->findById($nextGame[0]['id']); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|