Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $id = ArrayHelper::getValue($params, 'id');
     if ($id > 0) {
         $query = DtDefsheetDevices::find()->Where(['dt_defsheets_id' => $id]);
     } else {
         $query = DtDefsheetDevices::find();
     }
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['dt_defsheets_id' => $this->dt_defsheets_id, 'devices_id' => $this->devices_id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'reason', $this->reason]);
     return $dataProvider;
 }
 /**
  * Finds the DtDefsheetDevices model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $dt_defsheets_id
  * @param integer $devices_id
  * @return DtDefsheetDevices the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($dt_defsheets_id, $devices_id)
 {
     if (($model = DtDefsheetDevices::findOne(['dt_defsheets_id' => $dt_defsheets_id, 'devices_id' => $devices_id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 3
0
 /**
  * Сохраняем документ Акт Списания. Перемещаем все выбранные устройства в "Неисправное оборудование"
  * @param $id
  * @return int
  * @throws NotFoundHttpException
  */
 public function actionSave($id)
 {
     $model = $this->findModel($id);
     $list_devices = DtDefsheetDevices::findAll(['dt_defsheets_id' => $id]);
     //var_dump($list_devices);
     $succ = false;
     foreach ($list_devices as $device) {
         /* @var $mod_device Devices */
         $mod_device = $device->devices;
         if ($mod_device->setTowp(127)) {
             $succ = true;
         }
     }
     if ($succ) {
         $model->employee_name = 'name';
         //костыль, ибо требует заполнить, а со сценариями не хочется заморачиваться
         $model->status = 1;
         if ($model->save()) {
             Yii::$app->session->setFlash('success', 'Документ успешно сохранён');
         } else {
             $str_err = '';
             foreach ($model->errors as $error) {
                 $str_err .= implode(' ', $error) . '<br>';
             }
             Yii::$app->session->setFlash('error', 'Ошибка при сохранении документа: <br>' . $str_err);
         }
     } else {
         Yii::$app->session->setFlash('error', 'Произошла ошибка при обработке табличной части');
     }
     return $this->redirect(['dt-defsheets/view', 'id' => $id]);
 }