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

EntityTable::findEntityIDs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 6
nc 1
nop 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