/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(Teacher $teacher) { if (!preg_match('/^img/', $teacher->image) && $teacher->image != "") { unlink($teacher->image); } $teacher->delete(); }
/** * Creates a new Teacher model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Teacher(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Run the database seeds. * * @return void */ public function run() { // $faker = Faker::create(); foreach (range(1, 50) as $index) { Teacher::create(['name' => $faker->name(), 'password' => $faker->sentence(), 'introduction' => $faker->sentence()]); } }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // $teacher = Teacher::find($id); if (!$teacher || !$teacher->status) { return view('errors.404'); } }
/** * */ private function generateTeachers() { $genderList = array(Teacher::GENDER_MALE, Teacher::GENDER_FEMALE); $prepareItemData = function ($itemNum) use($genderList) { return ['Teacher Name ' . $itemNum, $genderList[rand(0, 1)], '+79260000' . rand(100, 999)]; }; $this->loadByPortion($prepareItemData, Teacher::tableName(), ['name', 'gender', 'phone'], $this->getConfig('teachers_num')); }
/** * Run the database seeds. * * @return void */ public function run() { // $faker = Faker\Factory::create(); $teachers = Teacher::lists('id')->toarray(); $series = Series::lists('id')->toarray(); foreach (range(1, 50) as $index) { Video::create(['title' => $faker->title, 'description' => $faker->sentence(10), 'video_url' => $faker->url, 'cover_url' => $faker->url, 'user_id' => $faker->randomElement($teachers), 'series_id' => $faker->randomElement($series), 'watch_count' => $faker->randomDigit(), 'reply_count' => $faker->randomDigit(), 'favorite_count' => $faker->randomDigit()]); } }
/** * @param Post $post * @return \Illuminate\View\View */ public function show(Post $post) { $teacher = Teacher::find($post->author_id); $category_id = CategoryPost::wherePost_id($post->id)->first()->category_id; $category = Category::find($category_id)->name; $post['category_id'] = $category_id; $post['category'] = $category; $post['author'] = $teacher->name; $post['fb'] = $teacher->fb; if (!Auth::user()) { $post->increment('views'); } return $post; }
/** * @return SqlDataProvider[] */ public function findWhoHasMaxCommonStudents() { $selectedTeachersData = new SqlDataProvider(['sql' => "SELECT st1.teacher_id as t_id1, st2.teacher_id as t_id2, count(st1.student_id) as count FROM student_teacher as st1\nINNER JOIN student_teacher as st2\non st1.student_id=st2.student_id AND st1.teacher_id!=st2.teacher_id\nGROUP BY st1.teacher_id, st2.teacher_id\nORDER BY count DESC\nLIMIT 1;"]); $selectedTeachersData = $selectedTeachersData->getModels(); if (!empty($selectedTeachersData[0]) && isset($selectedTeachersData[0]['t_id1']) && isset($selectedTeachersData[0]['t_id2'])) { $tId1 = $selectedTeachersData[0]['t_id1']; $tId2 = $selectedTeachersData[0]['t_id2']; } else { return array(); } $commonStudents = new SqlDataProvider(['sql' => "SELECT s.* FROM student_teacher as st1\n LEFT JOIN student_teacher as st2 on st1.student_id=st2.student_id\nLEFT JOIN student as s on s.id=st1.student_id\nWHERE st1.teacher_id=:teacher1 AND st2.teacher_id=:teacher2;", 'params' => [':teacher1' => $tId1, ':teacher2' => $tId2]]); $teachers = Teacher::find()->andWhere(['id' => $tId1])->orWhere(['id' => $tId2]); return [$teachers, $commonStudents]; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Teacher::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(['tchr_id' => $this->tchr_id, 'tchr_active' => $this->tchr_active]); $query->andFilterWhere(['like', 'tchr_fname', $this->tchr_fname])->andFilterWhere(['like', 'tchr_lname', $this->tchr_lname])->andFilterWhere(['like', 'tchr_address', $this->tchr_address])->andFilterWhere(['like', 'tchr_postcode', $this->tchr_postcode])->andFilterWhere(['like', 'tchr_mobile', $this->tchr_mobile])->andFilterWhere(['like', 'tchr_phone', $this->tchr_phone])->andFilterWhere(['like', 'tchr_email', $this->tchr_email])->andFilterWhere(['like', 'tchr_disp_id', $this->tchr_disp_id]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Teacher::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 100], 'sort' => ['defaultOrder' => ['name' => SORT_ASC]]]); $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]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'gender', $this->gender])->andFilterWhere(['like', 'phone', $this->phone]); return $dataProvider; }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $posts = Post::whereArchive_id($id)->paginate(Input::get('itemPerPage')); for ($i = 0; $i < count($posts); $i++) { $post = $posts[$i]; $post = array_except($post, array("body")); $teacher = Teacher::find($post->author_id); $category_id = CategoryPost::wherePost_id($post->id)->first()->category_id; $category = Category::find($category_id)->name; $post['category'] = $category; $post['author'] = $teacher->name; $post['fb'] = $teacher->fb; $posts[$i] = $post; } return $posts; }
public function actionView($id = null) { if (!$id) { return $this->render('/site/error', ['name' => 'Bad request', 'message' => 'id is not defined']); } $message['class'] = ''; $message['text'] = ''; $model = new TeacherStudent(); $dataProvider = Teacher::find()->where(['id' => (int) $id]); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if (TeacherStudent::find()->where(['teacher_id' => $model->teacher_id, 'student_id' => $model->student_id])->count() == 0) { $result = $model->save(); } else { $message['class'] = 'danger'; $message['text'] = 'Ошибка. Пользователь с id ' . $model->student_id . ' уже назначен учителю с id ' . $model->teacher_id . '.'; } if (isset($result) && $result === true) { $message['class'] = 'success'; $message['text'] = 'Ваш запрос успешно выполнен. Пользователь с id ' . $model->student_id . ' назначен учителю с id ' . $model->teacher_id . '.'; } } return $this->render('view', ['dataProvider' => $dataProvider, 'model' => $model, 'message' => $message]); }
public function getUserTeacher() { return $this->hasOne(Teacher::className(), ['tchr_id' => 'usr_type_id']); }
/* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = $title; $this->params['breadcrumbs'][] = $this->title; ?> <div class="teacher-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php if ($this->context->action->id == 'index') { ?> <p> <?php echo Html::a('Добавить учителя', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php } ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', ['attribute' => 'gender', 'content' => function ($data) { return $data->getGenderName(); }, 'filter' => Teacher::getGendersList()], 'phone', 'students_count', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
/** * @return \yii\db\ActiveQuery */ public function getTmTchr() { return $this->hasOne(Teacher::className(), ['tchr_id' => 'tm_tchr_id']); }
/* @var $model app\models\Teacher */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="teacher-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'gender')->dropDownList(Teacher::getGendersList()); ?> <?php echo $form->field($model, 'phone'); ?> <?php $studentsList = Student::find()->select(['id', 'name as text'])->where(['id' => $model->students_list])->orderBy('text')->asArray()->all(); $data = []; $studentsListIdsByName = []; foreach ($studentsList as $student) { $data[$student['id']] = $student; $studentsListIdsByName[] = $student['id']; } $model->students_list = $studentsListIdsByName;
function getXoa($id) { $data['list_teachers'] = Teacher::findOrFail($id); $data['list_teachers']->delete(); return redirect()->route('teacher'); }
/** * @return \yii\db\ActiveQuery */ public function getTeacher() { return $this->hasOne(Teacher::className(), ['id' => 'teacher_id']); }
/** * @inheritdoc */ public function rules() { return [[['student_id', 'teacher_id'], 'required'], [['student_id', 'teacher_id'], 'integer'], ['student_id', 'exist', 'targetClass' => Student::className(), 'targetAttribute' => 'id', 'message' => 'Ученик с таким id не найден'], ['teacher_id', 'exist', 'targetClass' => Teacher::className(), 'targetAttribute' => 'id', 'message' => 'Учитель с таким id не найден']]; }
/** * Имена любых двух учителей, у которых максимальное количество общих учеников, и список этих общих учеников. * @return mixed */ public function actionTeachersWithMaxCommonStudents() { $title = 'Имена любых двух учителей, у которых максимальное количество общих учеников, и список этих общих учеников'; $twoTeachersMaxStudents = Teacher::getTwoHasMaxCommonStudents(); $teachers = Teacher::find()->where(['id' => $twoTeachersMaxStudents])->asArray()->all(); $teachersNames = ArrayHelper::getColumn($teachers, 'name'); $dataProvider = new ActiveDataProvider(['query' => Student::commonFromTwoTeachers($twoTeachersMaxStudents)]); $dataProvider->setSort(['defaultOrder' => ['name' => SORT_ASC]]); return $this->render('index', ['dataProvider' => $dataProvider, 'title' => $title, 'teachersNames' => $teachersNames]); }
public function about() { $teachers = Teacher::all(); return view("pages.about")->with(["pageTitle" => "About", "teachers" => $teachers]); }
echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'email')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'birth_dt')->widget(DatePicker::classname(), ['pluginOptions' => ['format' => 'dd-mm-yyyy', 'todayHighlight' => true]]); ?> <?php echo $form->field($model, 'level')->dropDownList($model->getLevelsArray()); ?> <?php echo $form->field($model, 'teachers')->widget(Select2::classname(), ['data' => \app\models\Teacher::getItemsList(), 'options' => ['multiple' => true], 'pluginOptions' => ['allowClear' => true, 'tags' => false, 'tokenSeparators' => [','], 'maximumInputLength' => 255]]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
/* @var $model app\models\UserTeacher */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="user-teacher-form"> <?php $form = ActiveForm::begin(); ?> <?php if ($model->isNewRecord) { ?> <?php echo $form->field($model, 'usr_type_id')->dropDownList(ArrayHelper::map(Teacher::find()->asArray()->all(), 'tchr_id', 'tchr_fname'), ['prompt' => '-Choose a Teacher-']); ?> <?php } ?> <?php echo $form->field($model, 'usr_id')->textInput(['readonly' => !$model->isNewRecord]); ?> <?php echo $form->field($model, 'usr_name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'usr_pass')->passwordInput(['readonly' => !$model->isNewRecord]);
/** * Updates Teacher into database * * @param Teacher $teacher * @param array $input * * @return Teacher */ public function update($teacher, $input) { $teacher->fill($input); $teacher->save(); return $teacher; }
public function index() { return Teacher::all(); }
/** * @return \yii\db\ActiveQuery */ public function getTmTchrs() { return $this->hasMany(Teacher::className(), ['tchr_id' => 'tm_tchr_id'])->viaTable('teacher_matrix', ['tm_crs_id' => 'crs_id']); }
/** * Finds the Teacher model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Teacher the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Teacher::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getTeacherStudents() { return $this->hasMany(Teacher::className(), ['id' => 'teacher_id'])->viaTable('{{%teacher_student}}', ['student_id' => 'id']); }