1 | <?php |
||
22 | class CalculatedModelFields |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $mapping; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $mapping_schema; |
||
34 | |||
35 | /** |
||
36 | * @var CalculatedModelFieldsFactory |
||
37 | */ |
||
38 | private $factory; |
||
39 | |||
40 | /** |
||
41 | * CalculatedModelFields constructor. |
||
42 | * @param CalculatedModelFieldsFactory $factory |
||
43 | */ |
||
44 | public function __construct(CalculatedModelFieldsFactory $factory) |
||
48 | /** |
||
49 | * @param bool $refresh |
||
50 | * @return array top-level-keys are model names (eg "Event") |
||
51 | * next-level are the calculated field names AND method names on classes |
||
52 | * which perform calculations, values are the fully qualified classnames which do the calculations |
||
53 | * These callbacks should accept as arguments: |
||
54 | * the wpdb row results, |
||
55 | * the WP_Request object, |
||
56 | * the controller object |
||
57 | */ |
||
58 | public function mapping($refresh = false) |
||
65 | |||
66 | |||
67 | /** |
||
68 | * Generates a new mapping between model calculated fields and their callbacks |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | protected function generateNewMapping() |
||
92 | |||
93 | |||
94 | /** |
||
95 | * Generates the schema for each calculation index in the calculation map. |
||
96 | * |
||
97 | * @return array |
||
98 | * @throws UnexpectedEntityException |
||
99 | */ |
||
100 | protected function generateNewMappingSchema() |
||
118 | |||
119 | |||
120 | /** |
||
121 | * Gets the known calculated fields for model |
||
122 | * |
||
123 | * @param EEM_Base $model |
||
124 | * @return array allowable values for this field |
||
125 | */ |
||
126 | public function retrieveCalculatedFieldsForModel(EEM_Base $model) |
||
134 | |||
135 | |||
136 | /** |
||
137 | * Returns the JsonSchema for the calculated fields on the given model. |
||
138 | * @param EEM_Base $model |
||
139 | * @return array |
||
140 | */ |
||
141 | public function getJsonSchemaForModel(EEM_Base $model) |
||
159 | |||
160 | |||
161 | /** |
||
162 | * Retrieves the value for this calculation |
||
163 | * |
||
164 | * @param EEM_Base $model |
||
165 | * @param string $field_name |
||
166 | * @param array $wpdb_row |
||
167 | * @param $rest_request |
||
168 | * @param BaseController $controller |
||
169 | * @return mixed|null |
||
170 | * @throws RestException |
||
171 | * @throws UnexpectedEntityException |
||
172 | */ |
||
173 | public function retrieveCalculatedFieldValue( |
||
198 | } |
||
199 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.