1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Badger\Bundle\GameBundle\Doctrine\Repository; |
4
|
|
|
|
5
|
|
|
use Badger\Component\Game\Model\AdventureInterface; |
6
|
|
|
use Badger\Component\Game\Repository\AdventureStepCompletionRepositoryInterface; |
7
|
|
|
use Badger\Component\User\Model\UserInterface; |
8
|
|
|
use Doctrine\ORM\EntityRepository; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Adrien Pétremann <[email protected]> |
12
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
13
|
|
|
*/ |
14
|
|
|
class AdventureStepCompletionRepository extends EntityRepository implements AdventureStepCompletionRepositoryInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritdoc} |
18
|
|
|
*/ |
19
|
|
View Code Duplication |
public function userAdventureCompletedSteps(UserInterface $user, AdventureInterface $adventure) |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$qb = $this->getEntityManager()->createQueryBuilder(); |
22
|
|
|
$qb->select('s') |
23
|
|
|
->from('GameBundle:AdventureStep', 's') |
24
|
|
|
->leftJoin('s.completions', 'sc') |
25
|
|
|
->where('sc.user = :user')->setParameter(':user', $user) |
26
|
|
|
->andWhere('s.adventure = :adventure')->setParameter(':adventure', $adventure) |
27
|
|
|
->andWhere('sc.pending = 0'); |
28
|
|
|
|
29
|
|
|
$queryResult = $qb->getQuery()->getResult(); |
30
|
|
|
|
31
|
|
|
return $queryResult; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
public function userAdventureClaimedSteps(UserInterface $user, AdventureInterface $adventure) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$qb = $this->getEntityManager()->createQueryBuilder(); |
40
|
|
|
$qb->select('s') |
41
|
|
|
->from('GameBundle:AdventureStep', 's') |
42
|
|
|
->leftJoin('s.completions', 'sc') |
43
|
|
|
->where('sc.user = :user')->setParameter(':user', $user) |
44
|
|
|
->andWhere('s.adventure = :adventure')->setParameter(':adventure', $adventure) |
45
|
|
|
->andWhere('sc.pending = 1'); |
46
|
|
|
|
47
|
|
|
$queryResult = $qb->getQuery()->getResult(); |
48
|
|
|
|
49
|
|
|
return $queryResult; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
View Code Duplication |
public function userCompletedSteps(UserInterface $user) |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$qb = $this->getEntityManager()->createQueryBuilder(); |
58
|
|
|
$qb->select('a as adventure, COUNT(sc) as completions') |
59
|
|
|
->from('GameBundle:Adventure', 'a') |
60
|
|
|
->leftJoin('a.steps', 's') |
61
|
|
|
->leftJoin('s.completions', 'sc') |
62
|
|
|
->where('sc.user = :user')->setParameter(':user', $user) |
63
|
|
|
->andWhere('sc.pending = 0') |
64
|
|
|
->groupBy('s.adventure'); |
65
|
|
|
|
66
|
|
|
$queryResult = $qb->getQuery()->getResult(); |
67
|
|
|
|
68
|
|
|
return $queryResult; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.