Completed
Push — master ( ef8e90...6637e7 )
by Vitaly
06:16
created

EntityTable   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 2
c 3
b 0
f 1
lcom 1
cbo 2
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A findEntityIDs() 0 11 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: nazarenko
5
 * Date: 22.03.2016
6
 * Time: 11:40
7
 */
8
namespace samsoncms\api\query;
9
10
use samsoncms\api\Material;
11
use samsonframework\orm\QueryInterface;
12
13
/**
14
 * Class for querying nested entity tables.
15
 *
16
 * @package samsoncms\api\query
17
 */
18
class EntityTable extends Entity
19
{
20
    /** @var int Parent entity identifier */
21
    protected $parentID;
22
23
    /**
24
     * Generic constructor.
25
     *
26
     * @param int $parentID Parent entity identifier
27
     * @param QueryInterface $query Database query instance
28
     * @param string $locale Query localization
29
     */
30
    public function __construct($parentID, QueryInterface $query = null, $locale = null)
31
    {
32
        $this->parentID = $parentID;
33
34
        parent::__construct($query, $locale);
35
    }
36
37
    /**
38
     * Prepare entity identifiers.
39
     *
40
     * @param array $entityIDs Collection of identifier for filtering
41
     *
42
     * @return array Collection of entity identifiers
43
     */
44
    protected function findEntityIDs(array $entityIDs = array())
45
    {
46
        // Get parent logic
47
        $entityIDs = parent::findEntityIDs($entityIDs);
48
49
        // Filter entity identifiers by parent
50
        return $this->query->entity(Material::class)
51
            ->where(Material::F_PRIMARY, $entityIDs)
52
            ->where(Material::F_PARENT, $this->parentID)
53
            ->fields(Material::F_PRIMARY);
54
    }
55
}
56