public function getAllStudentsAsMappedArray($condition = null, $userId = null) { $userId = isset($userId) ? $userId : Yii::$app->user->id; $models = Student::find()->where(['user_id' => $userId]); if (isset($condition)) { $models->andWhere($condition); } return ArrayHelper::map($models->all(), 'id', 'fullname'); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Student::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'lesson_cost' => $this->lesson_cost, 'is_active' => $this->is_active, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'lastname', $this->lastname])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'avatar', $this->avatar]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Student::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['fullname' => ['asc' => ['user.last_name' => SORT_ASC], 'desc' => ['user.last_name' => SORT_DESC]], 'groupName' => ['asc' => ['group.name' => SORT_ASC], 'desc' => ['group.name' => SORT_DESC]], 'srb']]); $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'group_id' => $this->group_id, 'education_start_date' => $this->education_start_date, 'education_end_date' => $this->education_end_date, 'srb' => $this->srb]); $query->joinWith(['user' => function ($q) { $q->where('user.first_name LIKE "%' . $this->fullname . '%" ' . 'OR user.last_name LIKE "%' . $this->fullname . '%"' . 'OR user.middle_name LIKE "%' . $this->fullname . '%"'); }]); $query->joinWith(['group' => function ($q) { $q->where('group.name LIKE "%' . $this->groupName . '%" '); }]); return $dataProvider; }
/** * Lists all Student models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Student::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
public function actionLists() { $out = []; if (isset($_POST['depdrop_parents'])) { $id = end($_POST['depdrop_parents']); $list = Student::find()->where(['group_id' => $id])->all(); $selected = null; if ($id != null && count($list) > 0) { $selected = ''; foreach ($list as $i => $student) { $out[] = ['id' => $student->id, 'name' => $student->user->fullname]; if ($i == 0) { $selected = $student->id; } } // Shows how you can preselect a value echo Json::encode(['output' => $out, 'selected' => $selected]); return; } } echo Json::encode(['output' => '', 'selected' => '']); }
public function getStudentsOrderedByLastName() { return Student::find()->joinWith('user')->select('student.*')->where(['student.group_id' => $this->id])->orderBy('user.last_name')->all(); }
public function actionStudentfromgroup() { $out = []; if (isset($_POST['depdrop_parents'])) { $parents = $_POST['depdrop_parents']; if ($parents != null) { $cat_id = $parents[0]; $ghd = \common\models\Student::find()->where(['group_id' => $cat_id])->all(); $out = \yii\helpers\ArrayHelper::map($ghd, 'id', 'user.fullname'); $arr = array(); foreach ($out as $key => $o) { $arr[$key]['id'] = $key; $arr[$key]['name'] = $o; } echo Json::encode(['output' => $arr, 'selected' => '']); return; } } echo Json::encode(['output' => '', 'selected' => '']); }
<div class="group-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'speciality_id')->dropDownList(ArrayHelper::map(Speciality::find()->all(), 'id', 'name')); ?> <?php echo $form->field($model, 'steward_student_id')->dropDownList(ArrayHelper::map(Student::find()->where(['group_id' => $model->id])->all(), 'id', 'user.fullname'), ['prompt' => '-- Выберите студента --']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Добавить' : 'Сохранить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>