Exemplo n.º 1
0
 /**
  * Updates an existing Device model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public static function actionUpdate($id, $param_data = null)
 {
     // update all the devices of a user as per user_id
     if ($param_data) {
         $new_exp = DeviceController::getCurrentExpiration($param_data);
         $time = TimeAmountOptions::find()->where(['id' => $param_data['time_amount_id']])->one()->getAttribute('key');
         if (Device::updateAll(['expiration' => $new_exp], ['user_id' => $param_data['user_id']]) && RadCheckController::actionUpdate(null, $param_data, $new_exp)) {
             Yii::$app->getSession()->setFlash('success', $time . ' added to your account.');
             return $new_exp;
         }
         Yii::$app->getSession()->setFlash('error', 'Unable to add ' . $time . ' to your account.');
         return false;
     }
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }