/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Scoutrelation::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, 'parentid' => $this->parentid, 'scoutid' => $this->scoutid, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); return $dataProvider; }
/** * Lists all Scoutrelation models. * @return mixed */ public function actionIndex() { $searchModel = new ScoutrelationSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = Null; if (Yii::$app->user->identity->getIsParent()) { $thisuser = Yii::$app->user->getId(); $parent = Scoutparent::findOne(['userid' => $thisuser]); $scoutrelations = Scoutrelation::find()->where(['parentid' => $parent->id])->all(); $dataProvider = new ActivedataProvider(['query' => Scoutrelation::find()->where(['parentid' => $parent->id]), 'pagination' => ['pageSize' => 20]]); } return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
/** * 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]); } }