TenantAwareFilter::addFilterConstraint()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
4
namespace Tahoe\Bundle\MultiTenancyBundle\Query\Filter\SQLFilter;
5
6
use Doctrine\ORM\Mapping\ClassMetaData,
7
    Doctrine\ORM\Query\Filter\SQLFilter;
8
9
class TenantAwareFilter extends SQLFilter
10
{
11
    public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
12
    {
13
        if (!$targetEntity->reflClass->implementsInterface('Tahoe\Bundle\MultiTenancyBundle\Model\TenantAwareInterface')) {
14
            return "";
15
        }
16
17
        // it would be easier (and probably less hackish) if I just wrote $column = "tenant_id"
18
        //$column = $targetEntity
19
        //    ->getAssociationsByTargetClass('Tahoe\Bundle\MultiTenancyBundle\Model\MultiTenantTenantInterface')
20
        //['tenant']['targetToSourceKeyColumns']['id'];
21
        $column = 'tenant_id';
22
23
        return $targetTableAlias . '.' . $column . ' = ' . $this->getParameter('tenantId');
24
    }
25
}
26