1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: VITALYIEGOROV |
5
|
|
|
* Date: 08.12.15 |
6
|
|
|
* Time: 23:11 |
7
|
|
|
*/ |
8
|
|
|
namespace samsoncms\api\query; |
9
|
|
|
|
10
|
|
|
use samson\activerecord\dbQuery; |
11
|
|
|
use samsoncms\api\Field; |
12
|
|
|
use samsoncms\api\CMS; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Retrieve materials by additional fields. |
16
|
|
|
* @package samsoncms\api |
17
|
|
|
*/ |
18
|
|
|
class MaterialField extends Base |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* MaterialField constructor |
22
|
|
|
* @param array $filteringIDs Collection of entity identifiers for filtering |
23
|
|
|
*/ |
24
|
|
|
public function __construct($filteringIDs = array()) |
25
|
|
|
{ |
26
|
|
|
parent::__construct( |
27
|
|
|
new dbQuery(), |
28
|
|
|
'\samsoncms\api\Material', |
29
|
|
|
Field::$_primary, |
30
|
|
|
CMS::MATERIAL_FIELD_RELATION_ENTITY, |
31
|
|
|
$filteringIDs |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get current entity identifiers collection by relation identifier ans its value. |
37
|
|
|
* |
38
|
|
|
* @param string $relationID Relation entity identifier |
39
|
|
|
* @param mixed $relationValue Relation entity value |
40
|
|
|
* @param array $filteringIDs Collection of entity identifiers for filtering query |
41
|
|
|
* @return array Collection of entity identifiers filtered by navigation identifier. |
42
|
|
|
*/ |
43
|
|
|
public function idsByRelationID($relationID, $relationValue = null, array $filteringIDs = array()) |
44
|
|
|
{ |
45
|
|
|
$return = array(); |
|
|
|
|
46
|
|
|
|
47
|
|
|
/** @var Field $fieldRecord We need to have field record */ |
48
|
|
|
$fieldRecord = null; |
49
|
|
|
if (Field::byID($this->query, $relationID, $fieldRecord)) { |
|
|
|
|
50
|
|
|
// Get material identifiers by field |
51
|
|
|
$this->query->entity($this->relationIdentifier) |
52
|
|
|
->where(self::DELETE_FLAG_FIELD, 1) |
53
|
|
|
->where($this->relationPrimary, $relationID) |
54
|
|
|
->where($fieldRecord->valueFieldName(), $relationValue); |
55
|
|
|
|
56
|
|
|
// Add material identifier filter if passed |
57
|
|
|
if (isset($filteringIDs)) { |
58
|
|
|
$this->query->where($this->primaryField, $filteringIDs); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// Perform database query and get only material identifiers collection |
62
|
|
|
$return = $this->query->fields($this->primaryField); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $return; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|