/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Scoutparent::find(); $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; } $query->andFilterWhere(['id' => $this->id, 'userid' => $this->userid, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'phone', $this->phone]); return $dataProvider; }
/** * Creates a new Scoutrelation model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Scoutrelation(); if ($model->load(Yii::$app->request->post())) { $thisuser = Yii::$app->user->getId(); $parent = Scoutparent::findOne(['userid' => $thisuser]); $model->parentid = $parent->id; if ($model->save()) { return $this->redirect(['scoutrelation/index']); } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Scout model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Scout(); if ($model->load(Yii::$app->request->post())) { if (!Yii::$app->user->isGuest && !Yii::$app->user->identity->getIsScout() && !Yii::$app->user->identity->getIsParent()) { $auth = Yii::$app->authManager; $authorRole = $auth->getRole('scout'); $auth->assign($authorRole, Yii::$app->user->getId()); } $model->setAttribute('userid', Yii::$app->user->getId()); if ($model->save()) { if (Yii::$app->user->identity->getIsParent()) { $scoutrelation = new Scoutrelation(); $scoutrelation->scoutid = $model->id; $thisuser = Yii::$app->user->getId(); $parent = Scoutparent::findOne(['userid' => $thisuser]); $scoutrelation->parentid = $parent->id; $scoutrelation->save(); } $post = Yii::$app->request->post(); if ($post['where'] == 'fromparent') { return $this->redirect(['/scoutrelation/create']); } else { return $this->redirect(['/site/index']); } } else { return $this->render('create', ['model' => $model]); } } else { $context = Yii::$app->request->get(); if (in_array('where', $context) && $context['where'] == 'fromparent') { return $this->render('create', ['model' => $model, 'where' => 'fromparent']); } else { return $this->render('create', ['model' => $model, 'where' => '']); } } }
/** * @return \yii\db\ActiveQuery */ public function getParent() { return $this->hasOne(Scoutparent::className(), ['id' => 'parentid']); }
/** * 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]); } }
/** * Finds the Scoutparent model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Scoutparent the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Scoutparent::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }