예제 #1
0
 /**
  * Updates an existing Order model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $model1 = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model->order_amount = number_format($model->number_bales * 4.5, 2, '.', '');
     }
     if ($model1->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['/order/index', 'id' => $model->id]);
     } else {
         if (Yii::$app->user->identity->getIsScout()) {
             $thisuser = Yii::$app->user->getId();
             $scout = Scout::findOne(['userid' => $thisuser]);
             $scoutlist = ArrayHelper::map(Scout::findAll(['id' => $scout->id]), 'id', 'name');
         } elseif (Yii::$app->user->identity->getIsLeader()) {
             $scoutlist = ArrayHelper::map(Scout::find()->all(), 'id', 'name');
         } elseif (Yii::$app->user->identity->getIsParent()) {
             $thisuser = Yii::$app->user->getId();
             $thisparent = Scoutparent::findOne(['userid' => $thisuser]);
             $myscouts = Scoutrelation::find()->where(['parentid' => $thisparent->id])->all();
             $scoutlist = ArrayHelper::map(Scout::find()->where(['id' => ArrayHelper::getColumn($myscouts, 'scoutid')])->all(), 'id', 'name');
         }
         return $this->render('update', ['model' => $model, 'scoutlist' => $scoutlist]);
     }
 }
예제 #2
0
 /**
  * Finds the Scout model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Scout the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Scout::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }