1 | <?php |
||
26 | trait RelatedEnvironmentsAttributeTrait |
||
27 | { |
||
28 | use ActiveRecordTrait; |
||
29 | |||
30 | /** |
||
31 | * Populates the named relation with the related records. |
||
32 | * Note that this method does not check if the relation exists or not. |
||
33 | * @param string $name the relation name, e.g. `orders` for a relation |
||
34 | * defined via `getOrders()` method (case-sensitive). |
||
35 | * @param ActiveRecordInterface|array|null $records the related records to be |
||
36 | * populated into the relation. |
||
37 | * @see getRelation() |
||
38 | */ |
||
39 | abstract public function populateRelation($name, $records); |
||
40 | |||
41 | /** |
||
42 | * Adds a new error to the specified attribute. |
||
43 | * @param string $attribute attribute name |
||
44 | * @param string $error new error message |
||
45 | */ |
||
46 | abstract public function addError($attribute, $error = ''); |
||
47 | |||
48 | /** |
||
49 | * @var bool |
||
50 | */ |
||
51 | public $autoSaveEnvironments = true; |
||
52 | |||
53 | /** |
||
54 | * Environments that are temporarily set during the save process |
||
55 | * |
||
56 | * @var null|array |
||
57 | */ |
||
58 | private $insertEnvironments; |
||
59 | |||
60 | /** |
||
61 | * @return string |
||
62 | */ |
||
63 | abstract protected static function environmentRecordClass(): string; |
||
64 | |||
65 | /** |
||
66 | * @param array $config |
||
67 | * @return array |
||
68 | */ |
||
69 | abstract protected function prepareEnvironmentRecordConfig(array $config = []): array; |
||
70 | |||
71 | /** |
||
72 | * @return ActiveQueryInterface |
||
73 | */ |
||
74 | abstract protected function environmentRelationshipQuery(): ActiveQueryInterface; |
||
75 | |||
76 | /** |
||
77 | * Get all of the associated environments. |
||
78 | * |
||
79 | * @param array $config |
||
80 | * @return \yii\db\ActiveQueryInterface|\yii\db\ActiveQuery |
||
81 | */ |
||
82 | public function getEnvironments(array $config = []) |
||
95 | |||
96 | /** |
||
97 | * @param array $environments |
||
98 | * @return $this |
||
99 | */ |
||
100 | public function setEnvironments(array $environments = []) |
||
128 | |||
129 | /** |
||
130 | * @param $environment |
||
131 | * @return ActiveRecord |
||
132 | */ |
||
133 | protected function resolveEnvironment($environment) |
||
159 | |||
160 | /** |
||
161 | * @param bool $force |
||
162 | * @return bool |
||
163 | * @throws \Throwable |
||
164 | * @throws \yii\db\StaleObjectException |
||
165 | */ |
||
166 | protected function saveEnvironments(bool $force = false): bool |
||
210 | |||
211 | /******************************************* |
||
212 | * EVENTS |
||
213 | *******************************************/ |
||
214 | |||
215 | /** |
||
216 | * @inheritdoc |
||
217 | */ |
||
218 | protected function beforeSaveEnvironments($insert): bool |
||
231 | |||
232 | /** |
||
233 | * We're extracting the environments that may have been explicitly set on the record. When the 'id' |
||
234 | * attribute is updated, it removes any associated relationships. |
||
235 | * |
||
236 | * @inheritdoc |
||
237 | * @throws \Throwable |
||
238 | */ |
||
239 | protected function insertInternalEnvironments($attributes = null) |
||
250 | |||
251 | /** |
||
252 | * @param null $attributes |
||
253 | * @return bool |
||
254 | * @throws \Throwable |
||
255 | * @throws \yii\db\StaleObjectException |
||
256 | */ |
||
257 | protected function upsertEnvironmentsInternal($attributes = null): bool |
||
269 | } |
||
270 |