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