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\Material; |
12
|
|
|
use samsoncms\api\Field; |
13
|
|
|
use samsoncms\api\CMS; |
14
|
|
|
use samsonframework\orm\Condition; |
15
|
|
|
use samsonframework\orm\ArgumentInterface; |
16
|
|
|
use samsonframework\orm\ConditionInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Material to additional fields relation query. |
20
|
|
|
* @package samsoncms\api |
21
|
|
|
*/ |
22
|
|
|
class MaterialField extends Relational |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* MaterialField constructor |
26
|
|
|
* @param array $filteringIDs Collection of entity identifiers for filtering |
27
|
|
|
* @param string $identifier Entity identifier |
28
|
|
|
*/ |
29
|
|
|
public function __construct($filteringIDs = array(), $identifier = Material::class) |
30
|
|
|
{ |
31
|
|
|
parent::__construct( |
32
|
|
|
$GLOBALS['__core']->getContainer()->get('query'), |
33
|
|
|
$identifier, |
34
|
|
|
Material::F_PRIMARY, |
35
|
|
|
Field::F_PRIMARY, |
36
|
|
|
CMS::MATERIAL_FIELD_RELATION_ENTITY, |
37
|
|
|
$filteringIDs |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get current entity identifiers collection by relation identifier ans its value. |
43
|
|
|
* |
44
|
|
|
* @param string $relationID Relation entity identifier |
45
|
|
|
* @param mixed|Condition $relationValue Relation entity value or relation condition |
46
|
|
|
* @param array $filteringIDs Collection of entity identifiers for filtering query |
47
|
|
|
* @param string $locale Locale for requests |
48
|
|
|
* @return array Collection of entity identifiers filtered by navigation identifier. |
49
|
|
|
*/ |
50
|
|
|
public function idsByRelationID($relationID, $relationValue = null, array $filteringIDs = array(), $locale = null) |
51
|
|
|
{ |
52
|
|
|
$return = array(); |
53
|
|
|
|
54
|
|
|
/** @var Field $fieldRecord We need to have field record */ |
55
|
|
|
$fieldRecord = null; |
56
|
|
|
if (Field::byID($this->query, $relationID, $fieldRecord)) { |
|
|
|
|
57
|
|
|
// Get material identifiers by field |
58
|
|
|
$this->query->entity($this->relationIdentifier) |
59
|
|
|
->where(\samsoncms\api\MaterialField::F_DELETION, 1) |
60
|
|
|
->where($this->relationPrimary, $relationID); |
61
|
|
|
|
62
|
|
|
if ($relationValue instanceof ConditionInterface) { |
63
|
|
|
$this->query->whereCondition($relationValue); |
64
|
|
|
} else { |
65
|
|
|
$this->query->where($fieldRecord->valueFieldName(), $relationValue); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// Add material identifier filter if passed |
69
|
|
|
if (count($filteringIDs)) { |
70
|
|
|
$this->query->where($this->primaryField, $filteringIDs); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// If field is localized |
74
|
|
|
if ((int)$fieldRecord->local === 1) { |
75
|
|
|
// Add localization filter |
76
|
|
|
$this->query->where(\samsoncms\api\MaterialField::F_LOCALE, $locale); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
// Perform database query and get only material identifiers collection |
80
|
|
|
$return = $this->query->fields($this->primaryField); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $return; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.