1
|
|
|
<?php |
2
|
|
|
namespace samsoncms\api; |
3
|
|
|
|
4
|
|
|
use samsonframework\orm\QueryInterface; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* SamsonCMS additional field value table entity class |
8
|
|
|
* @package samson\cms |
9
|
|
|
*/ |
10
|
|
|
class MaterialField extends \samson\activerecord\materialfield |
11
|
|
|
{ |
12
|
|
|
/** @var integer Primary key */ |
13
|
|
|
public $FieldID; |
14
|
|
|
|
15
|
|
|
/** @var bool Internal existence flag */ |
16
|
|
|
public $Active; |
17
|
|
|
|
18
|
|
|
/** @var integer Material identifier */ |
19
|
|
|
public $MaterialID; |
20
|
|
|
|
21
|
|
|
/** @var string Additional field value */ |
22
|
|
|
public $Value; |
23
|
|
|
|
24
|
|
|
/** @var string Additional field value */ |
25
|
|
|
public $numeric_value; |
26
|
|
|
|
27
|
|
|
/** @var string Additional field value */ |
28
|
|
|
public $key_value; |
29
|
|
|
|
30
|
|
|
/** @var string Additional field locale */ |
31
|
|
|
public $locale; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get identifiers collection by field identifier and its value. |
35
|
|
|
* Method is optimized for performance. |
36
|
|
|
* |
37
|
|
|
* @param QueryInterface $query Database query instance |
38
|
|
|
* @param string $materialID Additional field identifier |
39
|
|
|
* @param string $fieldValue Additional field value for searching |
|
|
|
|
40
|
|
|
* @param array|null $return Variable where request result would be returned |
41
|
|
|
* @param array $materialIDs Collection of material identifiers for filtering query |
|
|
|
|
42
|
|
|
* @return bool|array True if material entities has been found and $return is passed |
43
|
|
|
* or identifiers collection if only two parameters is passed. |
44
|
|
|
*/ |
45
|
|
|
public static function idsByMaterialId(QueryInterface $query, $materialID, &$return = array()) |
46
|
|
|
{ |
47
|
|
|
// Get material identifiers by field |
48
|
|
|
$return = $query->entity(CMS::MATERIAL_FIELD_RELATION_ENTITY) |
|
|
|
|
49
|
|
|
->where('MaterialID', $materialID) |
50
|
|
|
->where('Active', 1) |
51
|
|
|
->fields(); |
52
|
|
|
|
53
|
|
|
// If only one argument is passed - return null, otherwise bool |
54
|
|
|
return func_num_args() > 2 ? sizeof($return) : $return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Find additional field value database record by its material and field identifiers. |
59
|
|
|
* This is generic method that should be used in nested classes to find its |
60
|
|
|
* records by some its primary key value. |
61
|
|
|
* |
62
|
|
|
* @param QueryInterface $query Query object instance |
63
|
|
|
* @param string $materialID Material identifier |
64
|
|
|
* @param self[]|null $return Variable to return found database record |
65
|
|
|
* @param string $locale Locale identifier |
66
|
|
|
* @return bool|null|self[] Field instance or null if 3rd parameter not passed |
67
|
|
|
*/ |
68
|
|
View Code Duplication |
public static function byMaterialID( |
|
|
|
|
69
|
|
|
QueryInterface $query, |
70
|
|
|
$materialID, |
71
|
|
|
&$return = null, |
72
|
|
|
$locale = DEFAULT_LOCALE |
73
|
|
|
) { |
74
|
|
|
$return = $query->entity(get_called_class()) |
75
|
|
|
->where('MaterialID', $materialID) |
76
|
|
|
->where('FieldID', $fieldID) |
|
|
|
|
77
|
|
|
->where('locale', $locale) |
78
|
|
|
->exec(); |
79
|
|
|
|
80
|
|
|
// If only one argument is passed - return null, otherwise bool |
81
|
|
|
return func_num_args() > 1 ? $return == null : $return; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Find additional field value database record by its material and field identifiers. |
86
|
|
|
* This is generic method that should be used in nested classes to find its |
87
|
|
|
* records by some its primary key value. |
88
|
|
|
* |
89
|
|
|
* @param QueryInterface $query Query object instance |
90
|
|
|
* @param string $materialID Material identifier |
91
|
|
|
* @param string $fieldID Additional field identifier |
92
|
|
|
* @param self[]|null $return Variable to return found database record |
93
|
|
|
* @param string $locale Locale identifier |
94
|
|
|
* @return bool|null|self[] Field instance or null if 3rd parameter not passed |
95
|
|
|
*/ |
96
|
|
View Code Duplication |
public static function byFieldIDAndMaterialID( |
|
|
|
|
97
|
|
|
QueryInterface $query, |
98
|
|
|
$materialID, |
99
|
|
|
$fieldID, |
100
|
|
|
&$return = null, |
101
|
|
|
$locale = DEFAULT_LOCALE |
102
|
|
|
) { |
103
|
|
|
$return = $query->entity(get_called_class()) |
104
|
|
|
->where('MaterialID', $materialID) |
105
|
|
|
->where('FieldID', $fieldID) |
106
|
|
|
->where('locale', $locale) |
107
|
|
|
->exec(); |
108
|
|
|
|
109
|
|
|
// If only one argument is passed - return null, otherwise bool |
110
|
|
|
return func_num_args() > 1 ? $return == null : $return; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.