1 | <?php |
||
34 | abstract class ElementMetric extends ActiveRecordWithId implements SavableMetricInterface |
||
35 | { |
||
36 | use ElementAttribute; |
||
37 | |||
38 | /** |
||
39 | * The default score weight |
||
40 | */ |
||
41 | const WEIGHT = 1; |
||
42 | |||
43 | /** |
||
44 | * The default metric version |
||
45 | */ |
||
46 | const VERSION = '1.0'; |
||
47 | |||
48 | /** |
||
49 | * The table alias |
||
50 | */ |
||
51 | const TABLE_ALIAS = 'scorecard_element_metrics'; |
||
52 | |||
53 | /** |
||
54 | * The Active Query class |
||
55 | */ |
||
56 | const ACTIVE_QUERY_CLASS = ElementMetricQuery::class; |
||
57 | |||
58 | /** |
||
59 | * @inheritdoc |
||
60 | */ |
||
61 | protected $getterPriorityAttributes = ['elementId', 'score', 'dateCalculated']; |
||
62 | |||
63 | /** |
||
64 | * @return float |
||
65 | */ |
||
66 | abstract protected function calculateScore(): float; |
||
67 | |||
68 | /** |
||
69 | * @inheritdoc |
||
70 | */ |
||
71 | public static function populateRecord($record, $row) |
||
79 | |||
80 | /** |
||
81 | * @inheritdoc |
||
82 | * @throws \yii\base\InvalidConfigException |
||
83 | * @return ElementMetricQuery |
||
84 | */ |
||
85 | public static function find() |
||
99 | |||
100 | /** |
||
101 | * @inheritdoc |
||
102 | */ |
||
103 | public function resetScore() |
||
108 | |||
109 | /** |
||
110 | * @inheritdoc |
||
111 | */ |
||
112 | public function beforeSave($insert) |
||
119 | |||
120 | /** |
||
121 | * @inheritdoc |
||
122 | */ |
||
123 | public static function instantiate($row) |
||
128 | |||
129 | /** |
||
130 | * @inheritdoc |
||
131 | */ |
||
132 | public function rules() |
||
184 | |||
185 | |||
186 | /******************************************* |
||
187 | * METRIC INTERFACE |
||
188 | *******************************************/ |
||
189 | |||
190 | /** |
||
191 | * @inheritdoc |
||
192 | * @throws \ReflectionException |
||
193 | */ |
||
194 | public static function displayName(): string |
||
203 | |||
204 | /** |
||
205 | * @inheritdoc |
||
206 | */ |
||
207 | public function getWeight(): float |
||
211 | |||
212 | /** |
||
213 | * @inheritdoc |
||
214 | */ |
||
215 | public function getVersion(): string |
||
219 | |||
220 | /** |
||
221 | * @inheritdoc |
||
222 | */ |
||
223 | public function getScore(): float |
||
231 | |||
232 | /** |
||
233 | * @return DateTime |
||
234 | */ |
||
235 | public function getDateCalculated(): DateTime |
||
253 | |||
254 | /** |
||
255 | * @return DateTime |
||
256 | */ |
||
257 | protected function defaultDateCalculated(): DateTime |
||
263 | |||
264 | |||
265 | /******************************************* |
||
266 | * SETTINGS |
||
267 | *******************************************/ |
||
268 | |||
269 | /** |
||
270 | * @param string $attribute |
||
271 | * @return mixed |
||
272 | */ |
||
273 | public function getSettingsValue(string $attribute) |
||
281 | |||
282 | /** |
||
283 | * @param string $attribute |
||
284 | * @param $value |
||
285 | * @return $this |
||
286 | */ |
||
287 | public function setSettingsValue(string $attribute, $value) |
||
297 | |||
298 | |||
299 | /******************************************* |
||
300 | * CONFIGURATION |
||
301 | *******************************************/ |
||
302 | |||
303 | /** |
||
304 | * @return array |
||
305 | */ |
||
306 | public function toConfig(): array |
||
310 | } |
||
311 |