+ * Добавление в случае необходимости состояния
+ * @param array $options
+ * string 'name' - Наименование состояния
+ * @return mixed
+ */
+ public function addIfNeed($options)
+ {
+ $result = [
+ 'id' => FALSE,
+ 'error' => Yii::t('status', 'Status: Key field "status" missing: ') . print_r($options, TRUE),
+ ];
+ if (is_array($options) && isset($options[ 'status' ]))
+ $model = Status::find()
+ ->where([ 'like', 'name', $options[ 'status' ]])
+ ->all();
+ if (count($model) > 0)
+ {
+ $result[ 'id' ] = $model[0]->id;
+ $result [ 'error' ] = '';
+ }
+ else
+ {
+ $model = new Status();
+ $model->name = $options[ 'status' ];
+ if ($model->validate() && $model->save())
+ {
+ $result[ 'id' ] = $model->id;
+ $result[ 'error' ] = '';
+ }
+ else
+ {
+ $result[ 'error' ] = Yii::t('status', 'Failed to add entry "{status}": ', $options) . print_r($model->errors, TRUE);
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * Показ всех состояний предметов/оборудования.