1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Superdesk Web Publisher MultiTenancy Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2015 Sourcefabric z.u. and contributors. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please see the |
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright 2015 Sourcefabric z.ú |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace SWP\Bundle\MultiTenancyBundle\Doctrine\ORM; |
16
|
|
|
|
17
|
|
|
use SWP\Bundle\StorageBundle\Doctrine\ORM\EntityRepository; |
18
|
|
|
use SWP\Component\MultiTenancy\Repository\TenantRepositoryInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Repository interface for tenants. |
22
|
|
|
*/ |
23
|
|
|
class TenantRepository extends EntityRepository implements TenantRepositoryInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
public function findOneBySubdomainAndDomain($subdomain, $domain) |
29
|
|
|
{ |
30
|
|
|
return $this |
31
|
|
|
->createQueryBuilder('t') |
32
|
|
|
->select('t', 'o', 'oc') |
33
|
|
|
->leftJoin('t.organization', 'o') |
34
|
|
|
->leftJoin('t.outputChannel', 'oc') |
35
|
|
|
->where('t.subdomain = :subdomain') |
36
|
|
|
->andWhere('t.domainName = :domainName') |
37
|
|
|
->setParameters([ |
38
|
|
|
'subdomain' => $subdomain, |
39
|
|
|
'domainName' => $domain, |
40
|
|
|
]) |
41
|
|
|
->getQuery() |
42
|
|
|
->getOneOrNullResult(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
public function findOneByDomain($domain) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
return $this |
51
|
|
|
->createQueryBuilder('t') |
52
|
|
|
->select('t', 'o', 'oc') |
53
|
|
|
->leftJoin('t.organization', 'o') |
54
|
|
|
->leftJoin('t.outputChannel', 'oc') |
55
|
|
|
->where('t.domainName = :domainName') |
56
|
|
|
->andWhere('t.subdomain IS NULL') |
57
|
|
|
->setParameter('domainName', $domain) |
58
|
|
|
->getQuery() |
59
|
|
|
->getOneOrNullResult(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
View Code Duplication |
public function findOneByCode($code) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
return $this |
68
|
|
|
->createQueryBuilder('t') |
69
|
|
|
->select('t', 'o') |
70
|
|
|
->leftJoin('t.organization', 'o') |
71
|
|
|
->leftJoin('t.outputChannel', 'oc') |
72
|
|
|
->where('t.code = :code') |
73
|
|
|
->setParameter('code', $code) |
74
|
|
|
->getQuery() |
75
|
|
|
->getOneOrNullResult(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
public function findAvailableTenants() |
82
|
|
|
{ |
83
|
|
|
return $this |
84
|
|
|
->createQueryBuilder('t') |
85
|
|
|
->select('t', 'o') |
86
|
|
|
->leftJoin('t.organization', 'o') |
87
|
|
|
->leftJoin('t.outputChannel', 'oc') |
88
|
|
|
->getQuery() |
89
|
|
|
->getArrayResult(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
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.