/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Scout::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, 'patrolid' => $this->patrolid, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'phone', $this->phone]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getScout() { return $this->hasOne(Scout::className(), ['id' => 'scoutid']); }
/** * 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]); } }
/** * @return \yii\db\ActiveQuery */ public function getScouts() { return $this->hasMany(Scout::className(), ['patrolid' => 'id']); }
use yii\helpers\ArrayHelper; use app\models\Scout; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model app\models\Scoutrelation */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="scoutrelation-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'scoutid')->dropDownList(ArrayHelper::map(Scout::find()->all(), 'id', 'name'), ['prompt' => 'Choose a Scout'])->label('Scout'); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Link to Scout' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <div class="form-group"> <?php echo Html::a('Not Listed', ['/scout/create', 'where' => 'fromparent'], ['class' => 'btn btn-success']); ?> </div>
/** * 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.'); } }