コード例 #1
0
ファイル: TeacherController.php プロジェクト: rakeen/creative
 /**
  * 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();
 }
コード例 #2
0
 /**
  * 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]);
     }
 }
コード例 #3
0
 /**
  * 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()]);
     }
 }
コード例 #4
0
 /**
  * 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');
     }
 }
コード例 #5
0
 /**
  *
  */
 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'));
 }
コード例 #6
0
 /**
  * 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()]);
     }
 }
コード例 #7
0
ファイル: PostsController.php プロジェクト: rakeen/creative
 /**
  * @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;
 }
コード例 #8
0
ファイル: Teacher.php プロジェクト: Olga--Trushina/teachers
 /**
  * @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];
 }
コード例 #9
0
ファイル: TeacherSearch.php プロジェクト: AtaBashir/ams
 /**
  * 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;
 }
コード例 #10
0
ファイル: TeacherSearch.php プロジェクト: proteye/skyeng
 /**
  * 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;
 }
コード例 #11
0
 /**
  * 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;
 }
コード例 #12
0
 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]);
 }
コード例 #13
0
ファイル: UserTeacher.php プロジェクト: AtaBashir/ams
 public function getUserTeacher()
 {
     return $this->hasOne(Teacher::className(), ['tchr_id' => 'usr_type_id']);
 }
コード例 #14
0
ファイル: index.php プロジェクト: kmarenov/yii2-app-test
/* @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>
コード例 #15
0
ファイル: TeacherMatrix.php プロジェクト: AtaBashir/ams
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTmTchr()
 {
     return $this->hasOne(Teacher::className(), ['tchr_id' => 'tm_tchr_id']);
 }
コード例 #16
0
ファイル: _form.php プロジェクト: kmarenov/yii2-app-test
/* @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;
コード例 #17
0
ファイル: TeacherController.php プロジェクト: b0yblake1/duan
 function getXoa($id)
 {
     $data['list_teachers'] = Teacher::findOrFail($id);
     $data['list_teachers']->delete();
     return redirect()->route('teacher');
 }
コード例 #18
0
ファイル: TeacherStudent.php プロジェクト: proteye/skyeng
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTeacher()
 {
     return $this->hasOne(Teacher::className(), ['id' => 'teacher_id']);
 }
コード例 #19
0
 /**
  * @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 не найден']];
 }
コード例 #20
0
 /**
  * Имена любых двух учителей, у которых максимальное количество общих учеников, и список этих общих учеников.
  * @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]);
 }
コード例 #21
0
ファイル: PageController.php プロジェクト: rakeen/creative
 public function about()
 {
     $teachers = Teacher::all();
     return view("pages.about")->with(["pageTitle" => "About", "teachers" => $teachers]);
 }
コード例 #22
0
ファイル: _form.php プロジェクト: proteye/skyeng
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>
コード例 #23
0
ファイル: _form.php プロジェクト: AtaBashir/ams
/* @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]);
コード例 #24
0
 /**
  * Updates Teacher into database
  *
  * @param Teacher $teacher
  * @param array $input
  *
  * @return Teacher
  */
 public function update($teacher, $input)
 {
     $teacher->fill($input);
     $teacher->save();
     return $teacher;
 }
コード例 #25
0
 public function index()
 {
     return Teacher::all();
 }
コード例 #26
0
ファイル: Course.php プロジェクト: AtaBashir/ams
 /**
  * @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']);
 }
コード例 #27
0
ファイル: TeacherController.php プロジェクト: AtaBashir/ams
 /**
  * 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.');
     }
 }
コード例 #28
0
ファイル: Student.php プロジェクト: proteye/skyeng
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTeacherStudents()
 {
     return $this->hasMany(Teacher::className(), ['id' => 'teacher_id'])->viaTable('{{%teacher_student}}', ['student_id' => 'id']);
 }