/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Lesson::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['id', 'groupName' => ['asc' => ['group.name' => SORT_ASC], 'desc' => ['group.name' => SORT_DESC], 'label' => 'groupName'], 'disciplineName' => ['asc' => ['discipline.name' => SORT_ASC], 'desc' => ['discipline.name' => SORT_DESC], 'label' => 'disciplineName'], 'teacherFullname' => ['asc' => ['user.last_name' => SORT_ASC, 'user.first_name' => SORT_ASC, 'user.middle_name' => SORT_ASC], 'desc' => ['user.last_name' => SORT_DESC, 'user.first_name' => SORT_DESC, 'user.middle_name' => SORT_DESC], 'label' => 'teacherFullname'], 'lessonTypeName' => ['asc' => ['lesson_type.name' => SORT_ASC], 'desc' => ['lesson_type.name' => SORT_DESC], 'label' => 'lessonTypeName'], 'week', 'day', 'time', 'auditory']]); $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, 'ghd_id' => $this->ghd_id, 'lesson_type_id' => $this->lesson_type_id, 'week' => $this->week, 'day' => $this->day, 'time' => $this->time, 'date' => $this->date]); $query->andFilterWhere(['like', 'auditory', $this->auditory]); $query->joinWith('groupHasDiscipline')->joinWith(['groupHasDiscipline.group' => function ($q) { $q->where('group.name LIKE "%' . $this->groupName . '%" '); }]); $query->joinWith('groupHasDiscipline')->joinWith(['groupHasDiscipline.discipline' => function ($q) { $q->where('discipline.name LIKE "%' . $this->disciplineName . '%" '); }]); $query->joinWith('teacherHasDiscipline')->joinWith('teacherHasDiscipline.teacher')->joinWith(['teacherHasDiscipline.teacher.user' => function ($q) { $q->where('user.first_name LIKE "%' . $this->teacherFullname . '%" ' . 'OR user.last_name LIKE "%' . $this->teacherFullname . '%"' . 'OR user.middle_name LIKE "%' . $this->teacherFullname . '%"'); }]); $query->joinWith(['lessonType' => function ($q) { $q->where('lesson_type.name LIKE "%' . $this->lessonTypeName . '%" '); }]); return $dataProvider; }
echo Html::encode($this->title); ?> </h1> <p> <?php // Html::encode("Общее расписание"); ?> </p> <?php $ghd_id_arr = array(); foreach ($ghd as $grouphasdisc) { array_push($ghd_id_arr, $grouphasdisc->id); } $lessons = Lesson::find()->where(['ghd_id' => $ghd_id_arr])->orderBy('week ASC, day ASC, time ASC')->all(); $schedule = array(); for ($week = 1; $week <= 2; $week++) { $schedule[$week][] = Html::beginTag('table', ['class' => 'table table-bordered center-align']); $schedule[$week][] = Html::beginTag('tr'); $schedule[$week][] = Html::tag('th', 'День недели', ['class' => 'center-align']); $schedule[$week][] = Html::tag('th', 'Неделя - ' . $week, ['class' => 'center-align', 'colspan' => '4']); for ($day = 1; $day <= 6; $day++) { $schedule[$week][] = Html::beginTag('tr'); $schedule[$week][] = Html::tag('th', Lesson::getDayName($day), ['class' => 'center-align lesson-day', 'colspan' => '5']); $schedule[$week][] = Html::beginTag('tr'); $schedule[$week][] = Html::tag('th', "Предмет", ['class' => 'center-align']); $schedule[$week][] = Html::tag('th', 'Время', ['class' => 'center-align']); $schedule[$week][] = Html::tag('th', 'Преподаватель', ['class' => 'center-align']); $schedule[$week][] = Html::tag('th', 'Аудитория', ['class' => 'center-align']); $schedule[$week][] = Html::tag('th', 'Тип занятия', ['class' => 'center-align']);
public function getLesson() { return Lesson::find()->all(); }
</h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <div class="btn-group"> <?php echo Html::button('Добавить занятие', ['value' => Url::to(['//lesson/create']), 'class' => 'btn btn-success modalButton']); ?> <?php echo Html::button('Управление типами', ['value' => Url::to(['//lesson-type/index']), 'class' => 'btn btn-primary modalButton']); ?> </div> <?php Pjax::begin(['enablePushState' => false]); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'options' => ['class' => 'table-responsive'], 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'groupName', 'disciplineName', ['attribute' => 'lessonTypeName', 'filter' => ArrayHelper::map(\common\models\LessonType::find()->all(), 'name', 'name')], 'teacherFullname', ['attribute' => 'week', 'filter' => [1 => 1, 2 => 2]], ['attribute' => 'day', 'value' => function ($model) { return $model->dayRealName; }, 'filter' => Lesson::getDaysList()], ['attribute' => 'time', 'filter' => ArrayHelper::map(Lesson::find()->select('time')->distinct()->all(), 'time', 'time')], 'auditory', ['class' => 'common\\components\\ActionColumn']]]); ?> <?php Pjax::end(); ?> </div> <?php Modal::begin(['header' => '', 'id' => 'modal', 'size' => 'modal-lg']); echo "<div id='modalContent'></div>"; Modal::end();
public static function getLessonsList($arr) { $group = isset($arr['group']) ? $arr['group'] : null; $teacher = isset($arr['teacher']) ? $arr['teacher'] : null; if ($group !== null) { if (!isset($arr['semester'])) { $semester = Group::findOne($group)->currentSemester; } else { $semester = GroupSemesters::find()->where(['group_id' => $arr['group'], 'semester_number' => $arr['semester']])->one(); } if (!$semester) { return false; } $lessons = Lesson::find()->joinWith('groupHasDiscipline', true, "INNER JOIN")->where(['group_has_discipline.group_id' => $group])->andWhere(['group_has_discipline.semester_number' => $semester->semester_number])->orderBy('week ASC, day ASC, time ASC')->all(); return $lessons; } elseif ($teacher !== null) { $lessons = Lesson::find()->select('lesson.*')->innerJoin("teacher_has_discipline thd", "`thd`.`id` = `lesson`.`thd_id`")->innerJoin("group_has_discipline ghd", '`ghd`.`id` = `lesson`.`ghd_id`')->innerJoin("group g", '`g`.`id` = `ghd`.`group_id`')->innerJoin("group_semesters gs", '`gs`.`group_id` = `g`.`id` AND `ghd`.`semester_number` = `gs`.`semester_number`')->where(['<=', 'gs.begin_date', date('U')])->andWhere(['>=', 'gs.end_date', date('U')])->andWhere(['thd.teacher_id' => $teacher])->orderBy('week ASC, day ASC, time ASC, id ASC')->all(); return $lessons; } }
use yii\grid\GridView; use yii\bootstrap\Nav; use yii\bootstrap\Tabs; use yii\helpers\Url; use yii\bootstrap\Modal; use common\widgets\Schedule; use common\models\Lesson; use common\widgets\CommentsWidget; use yii\helpers\Markdown; /* @var $this yii\web\View */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = $model->discipline->name . ":" . $model->group->name; $this->params['breadcrumbs'][] = ['label' => $model->group->name, 'url' => Url::to(['//group/view', 'id' => $model->group->id])]; $this->params['breadcrumbs'][] = $this->title; $this->beginBlock('schedule'); $lessons = Lesson::find()->where(['ghd_id' => $model->id])->all(); echo Tabs::widget(['options' => ['class' => 'nav nav-pills nav-justified'], 'items' => [['label' => 'Неделя - 1', 'content' => Schedule::widget(['scenario' => 'group', 'lessons' => $lessons, 'week' => 1])], ['label' => 'Неделя - 2', 'content' => Schedule::widget(['scenario' => 'group', 'lessons' => $lessons, 'week' => 2])]]]); $this->endBlock('schedule'); $this->beginBlock('desk'); echo CommentsWidget::widget(['class_name' => $model::className(), 'item_id' => $model->id]); $this->endBlock('desk'); ?> <div class="group-has-discipline-index"> <h2><?php echo Html::encode($this->title); ?> </h2> <div class='row'> <div class="col-md-3"> <?php