@@ -27,8 +27,8 @@ |
||
27 | 27 | */ |
28 | 28 | public function init() |
29 | 29 | { |
30 | - if(!$this->parentClassName){ |
|
31 | - throw new InvalidConfigException('parentClassName must be set for '.static::class); |
|
30 | + if (!$this->parentClassName) { |
|
31 | + throw new InvalidConfigException('parentClassName must be set for ' . static::class); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** @var MyActiveRecord $parent */ |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * @return static[] |
14 | 14 | */ |
15 | - public static function getModels(){ |
|
15 | + public static function getModels() { |
|
16 | 16 | return []; |
17 | 17 | } |
18 | 18 | |
@@ -20,9 +20,9 @@ discard block |
||
20 | 20 | * @param $id |
21 | 21 | * @return static |
22 | 22 | */ |
23 | - public static function getById($id){ |
|
23 | + public static function getById($id) { |
|
24 | 24 | $models = static::getModels(); |
25 | - if(isset($models[$id])){ |
|
25 | + if (isset($models[$id])) { |
|
26 | 26 | return new static($models[$id]); |
27 | 27 | } |
28 | 28 | return null; |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | * @param $key |
32 | 32 | * @return static |
33 | 33 | */ |
34 | - public static function getByKey($key){ |
|
35 | - $arr = MyArrayHelper::indexByColumn(static::getModels(),static::$keyColumn); |
|
34 | + public static function getByKey($key) { |
|
35 | + $arr = MyArrayHelper::indexByColumn(static::getModels(), static::$keyColumn); |
|
36 | 36 | |
37 | - if(isset($arr[$key])){ |
|
37 | + if (isset($arr[$key])) { |
|
38 | 38 | return new static($arr[$key]); |
39 | 39 | } |
40 | 40 | return null; |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class StatusModel extends StaticModel implements StatusInterface |
14 | 14 | { |
15 | - const STATUS_CREATED = "created"; |
|
15 | + const STATUS_CREATED = "created"; |
|
16 | 16 | |
17 | 17 | /** @var integer $id*/ |
18 | 18 | public $id; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | return [ |
28 | 28 | self::STATUS_CREATED => [ |
29 | 29 | 'id' => self::STATUS_CREATED, |
30 | - 'label' => Yii::t('app','Created'), |
|
30 | + 'label' => Yii::t('app', 'Created'), |
|
31 | 31 | ], |
32 | 32 | |
33 | 33 | ]; |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | |
50 | - public static function isStatus($id){ |
|
51 | - return (!self::getById($id)==false); |
|
50 | + public static function isStatus($id) { |
|
51 | + return (!self::getById($id) == false); |
|
52 | 52 | } |
53 | 53 | |
54 | - public static function getStatusLabel($id){ |
|
54 | + public static function getStatusLabel($id) { |
|
55 | 55 | $status = self::getById($id); |
56 | - if(!empty($status)) { |
|
56 | + if (!empty($status)) { |
|
57 | 57 | return $status->label; |
58 | 58 | } |
59 | 59 | return null; |
@@ -18,7 +18,7 @@ |
||
18 | 18 | /** |
19 | 19 | * @return User |
20 | 20 | */ |
21 | - public function getUserClass(){ |
|
21 | + public function getUserClass() { |
|
22 | 22 | |
23 | 23 | return new $this->userClassName; |
24 | 24 | } |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | public function save($runValidation = true, $attributeNames = null) |
47 | 47 | { |
48 | 48 | // if there is no user Id, we use the default ID 1 |
49 | - if(!isset(Yii::$app->user) || empty(Yii::$app->user->identity)){ |
|
49 | + if (!isset(Yii::$app->user) || empty(Yii::$app->user->identity)) { |
|
50 | 50 | $userId = 1; |
51 | - }else{ |
|
51 | + } else { |
|
52 | 52 | $userId = Yii::$app->user->identity->getId(); |
53 | 53 | } |
54 | - if ($this->isNewRecord){ |
|
54 | + if ($this->isNewRecord) { |
|
55 | 55 | $this->{$this->timeClosedCol} = $this->dateHelper->getEndOfTime(); |
56 | 56 | $this->{$this->userCreatedCol} = $userId; |
57 | 57 | $this->{$this->timeCreatedCol} = $this->dateHelper->getDatetime6(); |
@@ -89,37 +89,37 @@ discard block |
||
89 | 89 | * {@inheritdoc} |
90 | 90 | */ |
91 | 91 | public function delete() { |
92 | - if($this->is_logicDelete){ |
|
92 | + if ($this->is_logicDelete) { |
|
93 | 93 | $this->beforeDelete(); |
94 | 94 | // don't put new data if deleting |
95 | 95 | $this->setAttributes($this->oldAttributes); |
96 | 96 | |
97 | 97 | // delete logically |
98 | - if($this->userUpdatedCol){ |
|
99 | - $this->{$this->userUpdatedCol} =Yii::$app->user->identity->getId(); |
|
98 | + if ($this->userUpdatedCol) { |
|
99 | + $this->{$this->userUpdatedCol} = Yii::$app->user->identity->getId(); |
|
100 | 100 | } |
101 | - if($this->userClosedCol){ |
|
102 | - $this->{$this->userClosedCol} =Yii::$app->user->identity->getId(); |
|
101 | + if ($this->userClosedCol) { |
|
102 | + $this->{$this->userClosedCol} = Yii::$app->user->identity->getId(); |
|
103 | 103 | } |
104 | 104 | |
105 | - if($this->timeUpdatedCol){ |
|
106 | - $this->{$this->timeUpdatedCol} = $this->dateHelper->getDatetime6(); |
|
105 | + if ($this->timeUpdatedCol) { |
|
106 | + $this->{$this->timeUpdatedCol} = $this->dateHelper->getDatetime6(); |
|
107 | 107 | } |
108 | 108 | |
109 | - if($this->timeClosedCol){ |
|
110 | - $this->{$this->timeClosedCol} = $this->dateHelper->getDatetime6(); |
|
109 | + if ($this->timeClosedCol) { |
|
110 | + $this->{$this->timeClosedCol} = $this->dateHelper->getDatetime6(); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | // don't validate on deleting |
114 | - if($this->save(false)){ |
|
114 | + if ($this->save(false)) { |
|
115 | 115 | self::updateClosingTime(parent::tableName()); |
116 | 116 | $this->afterDelete(); |
117 | 117 | return true; |
118 | - }else { |
|
118 | + } else { |
|
119 | 119 | throw new yii\base\UserException('Error deleting model'); |
120 | 120 | } |
121 | 121 | |
122 | - }else{ |
|
122 | + } else { |
|
123 | 123 | // otherwise regular delete |
124 | 124 | parent::delete(); |
125 | 125 | return true; |
@@ -128,30 +128,30 @@ discard block |
||
128 | 128 | } |
129 | 129 | |
130 | 130 | |
131 | - public static function bulkCopy($objects,$replaceParams) { |
|
131 | + public static function bulkCopy($objects, $replaceParams) { |
|
132 | 132 | /** |
133 | 133 | * @var yii\db\ActiveRecord $model |
134 | 134 | */ |
135 | 135 | $model = new static; |
136 | - if(!empty($objects)){ |
|
136 | + if (!empty($objects)) { |
|
137 | 137 | $rows = []; |
138 | 138 | $cols = []; |
139 | 139 | foreach ($objects as $object) { |
140 | - if(!empty($object->attributes)){ |
|
140 | + if (!empty($object->attributes)) { |
|
141 | 141 | $row = $object->attributes; |
142 | 142 | $cols = $model->attributes(); |
143 | - foreach($replaceParams as $key =>$value){ |
|
143 | + foreach ($replaceParams as $key =>$value) { |
|
144 | 144 | // remove primary keys (assuming auto-increment) |
145 | - foreach ($model->primaryKey as $pk){ |
|
145 | + foreach ($model->primaryKey as $pk) { |
|
146 | 146 | unset($row[$pk]); |
147 | 147 | } |
148 | 148 | // remove pk fields from cols |
149 | 149 | $cols = array_diff($cols, $model->primaryKey); |
150 | 150 | $row[$key] = $value; |
151 | 151 | } |
152 | - $rows[]=$row; |
|
153 | - } else { |
|
154 | - throw new InvalidParamException('Missing object attributes in '. get_called_class().' '.__FUNCTION__); |
|
152 | + $rows[] = $row; |
|
153 | + } else { |
|
154 | + throw new InvalidParamException('Missing object attributes in ' . get_called_class() . ' ' . __FUNCTION__); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | } |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @var \yii\db\ActiveRecord |
174 | 174 | */ |
175 | 175 | $model = new static; |
176 | - if(!empty($params)){ |
|
176 | + if (!empty($params)) { |
|
177 | 177 | |
178 | 178 | $baseParams = [ |
179 | 179 | $model->timeClosedCol=>$dateHelper->getDatetime6(), |
@@ -184,13 +184,13 @@ discard block |
||
184 | 184 | |
185 | 185 | $conditions = []; |
186 | 186 | $conditions[] = 'and'; |
187 | - $conditions[] = ['>',static::tableName().".`".$model->timeClosedCol.'`',$dateHelper->getDatetime6()]; |
|
187 | + $conditions[] = ['>', static::tableName() . ".`" . $model->timeClosedCol . '`', $dateHelper->getDatetime6()]; |
|
188 | 188 | $conditions[] = $params; |
189 | - \Yii::$app->db->createCommand()->update(parent::tableName(), $baseParams,$conditions)->execute(); |
|
189 | + \Yii::$app->db->createCommand()->update(parent::tableName(), $baseParams, $conditions)->execute(); |
|
190 | 190 | self::updateClosingTime(static::tableName()); |
191 | 191 | |
192 | - }else{ |
|
193 | - throw new yii\base\InvalidArgumentException('No conditions defined for '. get_called_class().' '.__FUNCTION__); |
|
192 | + } else { |
|
193 | + throw new yii\base\InvalidArgumentException('No conditions defined for ' . get_called_class() . ' ' . __FUNCTION__); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | */ |
204 | 204 | public function rules() { |
205 | 205 | return [ |
206 | - [[$this->userCreatedCol, $this->userUpdatedCol, $this->timeCreatedCol,$this->timeUpdatedCol, $this->timeClosedCol], 'required'], |
|
206 | + [[$this->userCreatedCol, $this->userUpdatedCol, $this->timeCreatedCol, $this->timeUpdatedCol, $this->timeClosedCol], 'required'], |
|
207 | 207 | [[$this->userCreatedCol, $this->userUpdatedCol, $this->userClosedCol], 'integer'], |
208 | - [[$this->timeCreatedCol,$this->timeUpdatedCol, $this->timeClosedCol], 'safe'], |
|
208 | + [[$this->timeCreatedCol, $this->timeUpdatedCol, $this->timeClosedCol], 'safe'], |
|
209 | 209 | ]; |
210 | 210 | } |
211 | 211 | /** |
@@ -230,15 +230,15 @@ discard block |
||
230 | 230 | public static function find() { |
231 | 231 | $child = new static; |
232 | 232 | $lastClosingTime = static::lastClosingTime(parent::tableName()); |
233 | - $query =parent::find() |
|
234 | - ->andFilterWhere(['>',static::tableName().".`".$child->timeClosedCol.'`',$lastClosingTime]); |
|
233 | + $query = parent::find() |
|
234 | + ->andFilterWhere(['>', static::tableName() . ".`" . $child->timeClosedCol . '`', $lastClosingTime]); |
|
235 | 235 | return $query; |
236 | 236 | } |
237 | 237 | |
238 | 238 | |
239 | - public static function getCount($filter = null){ |
|
239 | + public static function getCount($filter = null) { |
|
240 | 240 | $query = self::find(); |
241 | - if($filter){ |
|
241 | + if ($filter) { |
|
242 | 242 | $query->andFilterWhere($filter); |
243 | 243 | } |
244 | 244 | return $query->count(); |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | public static function query() { |
252 | 252 | $child = new static; |
253 | 253 | $dateHelper = new DateHelper(); |
254 | - return (new Query())->andFilterWhere(['>',parent::tableName().".`".$child->timeClosedCol.'`', $dateHelper->getDatetime6()]); |
|
254 | + return (new Query())->andFilterWhere(['>', parent::tableName() . ".`" . $child->timeClosedCol . '`', $dateHelper->getDatetime6()]); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * @return bool|static |
262 | 262 | * @throws yii\base\UserException |
263 | 263 | */ |
264 | - public static function copy($model, $map){ |
|
264 | + public static function copy($model, $map) { |
|
265 | 265 | /** |
266 | 266 | * @var \yii\db\ActiveRecord |
267 | 267 | */ |
@@ -270,9 +270,9 @@ discard block |
||
270 | 270 | foreach ($map as $key => $value) { |
271 | 271 | $newModel->{$key} = $value; |
272 | 272 | } |
273 | - if($newModel->save()){ |
|
273 | + if ($newModel->save()) { |
|
274 | 274 | return $newModel; |
275 | - }else{ |
|
275 | + } else { |
|
276 | 276 | throw new yii\base\UserException('Error copying model'); |
277 | 277 | } |
278 | 278 | } |
@@ -281,15 +281,15 @@ discard block |
||
281 | 281 | * @param string $tableName |
282 | 282 | * @return mixed|string |
283 | 283 | */ |
284 | - private static function lastClosingTime($tableName){ |
|
284 | + private static function lastClosingTime($tableName) { |
|
285 | 285 | $dateHelper = new DateHelper(); |
286 | 286 | |
287 | - if(!self::hasClosing($tableName)){ |
|
287 | + if (!self::hasClosing($tableName)) { |
|
288 | 288 | self::createClosingRow($tableName); |
289 | 289 | } |
290 | 290 | /** @var Closing $closing */ |
291 | 291 | $closing = Closing::findOne($tableName); |
292 | - if($closing){ |
|
292 | + if ($closing) { |
|
293 | 293 | return $closing->last_closing_time; |
294 | 294 | } |
295 | 295 | return $dateHelper->getDatetime6(); |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @param string $tableName |
300 | 300 | * @return bool |
301 | 301 | */ |
302 | - private static function hasClosing($tableName){ |
|
302 | + private static function hasClosing($tableName) { |
|
303 | 303 | $closing = Closing::findOne($tableName); |
304 | 304 | return !($closing == null); |
305 | 305 | } |
@@ -308,9 +308,9 @@ discard block |
||
308 | 308 | * @param $tableName |
309 | 309 | * @return Closing |
310 | 310 | */ |
311 | - private static function createClosingRow($tableName){ |
|
311 | + private static function createClosingRow($tableName) { |
|
312 | 312 | |
313 | - if(!self::hasClosing($tableName)){ |
|
313 | + if (!self::hasClosing($tableName)) { |
|
314 | 314 | $dateHelper = new DateHelper(); |
315 | 315 | $closing = new Closing([ |
316 | 316 | 'table_name'=>$tableName, |
@@ -322,8 +322,8 @@ discard block |
||
322 | 322 | return null; |
323 | 323 | } |
324 | 324 | |
325 | - private static function updateClosingTime($tableName){ |
|
326 | - if(!self::hasClosing($tableName)){ |
|
325 | + private static function updateClosingTime($tableName) { |
|
326 | + if (!self::hasClosing($tableName)) { |
|
327 | 327 | self::createClosingRow($tableName); |
328 | 328 | } |
329 | 329 | /** @var Closing $closing */ |
@@ -29,16 +29,16 @@ discard block |
||
29 | 29 | * @return boolean |
30 | 30 | * @throws NotSupportedException |
31 | 31 | */ |
32 | - public function isActive(){ |
|
32 | + public function isActive() { |
|
33 | 33 | /** @var StatusModel $statusModel */ |
34 | 34 | $statusModel = new self::$statusModelClass; |
35 | - if (method_exists($statusModel,'isActive')) { |
|
35 | + if (method_exists($statusModel, 'isActive')) { |
|
36 | 36 | return $statusModel::isActive($this->currentStatus->id); |
37 | 37 | } |
38 | - throw new NotSupportedException('isActive missing for: '.self::$statusModelClass); |
|
38 | + throw new NotSupportedException('isActive missing for: ' . self::$statusModelClass); |
|
39 | 39 | } |
40 | 40 | |
41 | - protected function addStatus($status){ |
|
41 | + protected function addStatus($status) { |
|
42 | 42 | /** @var HasStatusModel $hasStatus */ |
43 | 43 | $hasStatus = new static::$hasStatusClassName; |
44 | 44 | $hasStatus->status = $status; |
@@ -52,14 +52,14 @@ discard block |
||
52 | 52 | public function afterSave($insert, $changedAttributes) |
53 | 53 | { |
54 | 54 | |
55 | - if($insert){ |
|
55 | + if ($insert) { |
|
56 | 56 | // add a created status im the status history if some other status is assigned |
57 | - if($this->status != StatusModel::STATUS_CREATED){ |
|
57 | + if ($this->status != StatusModel::STATUS_CREATED) { |
|
58 | 58 | $this->addStatus(StatusModel::STATUS_CREATED); |
59 | 59 | } |
60 | 60 | $this->addStatus($this->status); |
61 | - }else{ |
|
62 | - if(isset($changedAttributes['status'])){ |
|
61 | + } else { |
|
62 | + if (isset($changedAttributes['status'])) { |
|
63 | 63 | $this->addStatus($this->status); |
64 | 64 | } |
65 | 65 | } |
@@ -107,16 +107,16 @@ discard block |
||
107 | 107 | * @param integer[] $model_ids |
108 | 108 | * @throws ErrorException |
109 | 109 | */ |
110 | - public static function bulkSetStatus($status, $model_ids){ |
|
110 | + public static function bulkSetStatus($status, $model_ids) { |
|
111 | 111 | $query = new Query(); |
112 | 112 | /** @var StatusModel $class */ |
113 | 113 | $class = new static::$statusModelClass; |
114 | 114 | |
115 | - if(!$class::isStatus($status)){ |
|
115 | + if (!$class::isStatus($status)) { |
|
116 | 116 | throw new ErrorException('Invalid Status'); |
117 | 117 | } |
118 | 118 | $query->createCommand() |
119 | - ->update(static::tableName(),['status'=>$status],['in',static::primaryKey()[0],$model_ids]) |
|
119 | + ->update(static::tableName(), ['status'=>$status], ['in', static::primaryKey()[0], $model_ids]) |
|
120 | 120 | ->execute(); |
121 | 121 | } |
122 | 122 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | public $doCheck = true; |
24 | 24 | |
25 | 25 | /** @var string[] $alwaysSkipCheckAttributes */ |
26 | - private static $alwaysSkipCheckAttributes = ['settings','itemClass','typeRelationName','valueField','doCheck','skipCheckAttributes']; |
|
26 | + private static $alwaysSkipCheckAttributes = ['settings', 'itemClass', 'typeRelationName', 'valueField', 'doCheck', 'skipCheckAttributes']; |
|
27 | 27 | |
28 | 28 | |
29 | 29 | /** @var string[] $skipCheckAttributes extended attributed that we skip in checking */ |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | { |
34 | 34 | parent::init(); |
35 | 35 | |
36 | - if(!$this->itemClass){ |
|
36 | + if (!$this->itemClass) { |
|
37 | 37 | throw new yii\base\InvalidArgumentException('ItemClass must be defined'); |
38 | 38 | } |
39 | 39 | $this->checkSettings(); |
@@ -45,17 +45,17 @@ discard block |
||
45 | 45 | /** |
46 | 46 | * Check if all defined attributes exist in settings[] and throw an error if its missing |
47 | 47 | */ |
48 | - protected function checkSettings(){ |
|
49 | - if($this->doCheck){ |
|
50 | - $skipAttributes = array_merge($this->skipCheckAttributes,self::$alwaysSkipCheckAttributes); |
|
51 | - $checkAttributes = array_diff(array_keys($this->attributes),$skipAttributes); |
|
48 | + protected function checkSettings() { |
|
49 | + if ($this->doCheck) { |
|
50 | + $skipAttributes = array_merge($this->skipCheckAttributes, self::$alwaysSkipCheckAttributes); |
|
51 | + $checkAttributes = array_diff(array_keys($this->attributes), $skipAttributes); |
|
52 | 52 | |
53 | - if(!empty($checkAttributes)){ |
|
54 | - foreach ($checkAttributes as $checkAttribute){ |
|
55 | - $class =$this->itemClass; |
|
53 | + if (!empty($checkAttributes)) { |
|
54 | + foreach ($checkAttributes as $checkAttribute) { |
|
55 | + $class = $this->itemClass; |
|
56 | 56 | |
57 | - if(!$class::getByKey($checkAttribute)){ |
|
58 | - throw new yii\base\InvalidConfigException('Key "'.$checkAttribute.'" is missing in '.$class); |
|
57 | + if (!$class::getByKey($checkAttribute)) { |
|
58 | + throw new yii\base\InvalidConfigException('Key "' . $checkAttribute . '" is missing in ' . $class); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | } |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | public function beforeValidate() { |
67 | - foreach ($this->attributes as $key => $value){ |
|
68 | - if ($value === ""){ |
|
67 | + foreach ($this->attributes as $key => $value) { |
|
68 | + if ($value === "") { |
|
69 | 69 | $this->$key = NULL; |
70 | 70 | } |
71 | 71 | } |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | public function loadStrings() { |
77 | - if(!empty($this->settings)){ |
|
77 | + if (!empty($this->settings)) { |
|
78 | 78 | foreach ($this->settings as $key => $setting) { |
79 | 79 | // only accept keys that are described in the model |
80 | 80 | $type = SurveyLanguagesettingType::getByKey($key); |
81 | - if($type){ |
|
81 | + if ($type) { |
|
82 | 82 | $this->{$key} = $setting->{$this->valueField}; |
83 | 83 | } |
84 | 84 | } |
@@ -24,8 +24,8 @@ |
||
24 | 24 | |
25 | 25 | public function init() |
26 | 26 | { |
27 | - if(!static::$hasStatusClassName){ |
|
28 | - throw new InvalidConfigException('hasStatusClassName must be set for '.static::class); |
|
27 | + if (!static::$hasStatusClassName) { |
|
28 | + throw new InvalidConfigException('hasStatusClassName must be set for ' . static::class); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | parent::init(); |
@@ -8,6 +8,6 @@ |
||
8 | 8 | public $success = false; |
9 | 9 | |
10 | 10 | /** @var string[] $errors Error messages (if any) */ |
11 | - public $errors = []; |
|
11 | + public $errors = []; |
|
12 | 12 | |
13 | 13 | } |
14 | 14 | \ No newline at end of file |