1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Badger\Bundle\GameBundle\Doctrine\Repository; |
4
|
|
|
|
5
|
|
|
use Badger\Bundle\UserBundle\Entity\User; |
6
|
|
|
use Badger\Component\Game\Repository\QuestCompletionRepositoryInterface; |
7
|
|
|
use Badger\Component\Game\Repository\TagSearchableRepositoryInterface; |
8
|
|
|
use Badger\Component\User\Model\UserInterface; |
9
|
|
|
use Doctrine\DBAL\Connection; |
10
|
|
|
use Doctrine\ORM\EntityRepository; |
11
|
|
|
use Doctrine\ORM\Query; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author Adrien Pétremann <[email protected]> |
15
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
16
|
|
|
*/ |
17
|
|
|
class QuestCompletionRepository extends EntityRepository implements |
18
|
|
|
QuestCompletionRepositoryInterface, |
19
|
|
|
TagSearchableRepositoryInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function findByTags(array $tags) |
25
|
|
|
{ |
26
|
|
|
$tagIds = []; |
27
|
|
|
foreach ($tags as $tag) { |
28
|
|
|
$tagIds[] = $tag->getId(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$qb = $this->createQueryBuilder('qc'); |
32
|
|
|
$qb->leftJoin('qc.quest', 'q') |
33
|
|
|
->leftJoin('q.tags', 't') |
34
|
|
|
->where('t.id IN (:ids)')->setParameter('ids', $tagIds, Connection::PARAM_STR_ARRAY) |
35
|
|
|
->orderBy('qc.completionDate', 'desc') |
36
|
|
|
->setMaxResults(15) |
37
|
|
|
->groupBy('qc.id'); |
38
|
|
|
|
39
|
|
|
return $qb->getQuery()->getResult(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
public function getQuestIdsClaimedByUser(UserInterface $user) |
46
|
|
|
{ |
47
|
|
|
$qb = $this->getEntityManager()->createQueryBuilder(); |
48
|
|
|
$qb->select('quest.id') |
49
|
|
|
->from('GameBundle:QuestCompletion', 'completion') |
50
|
|
|
->leftJoin('completion.quest', 'quest') |
51
|
|
|
->where('completion.user = :user') |
52
|
|
|
->andWhere('completion.pending = 1') |
53
|
|
|
->setParameter('user', $user); |
54
|
|
|
|
55
|
|
|
$queryResult = $qb->getQuery()->getScalarResult(); |
56
|
|
|
|
57
|
|
|
return array_column($queryResult, 'id'); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|