public function actionCreate()
 {
     $model = new Semesters('insert');
     $call_lists = CHtml::listData(CallLists::model()->findAll(), 'id', 'name');
     if (Yii::app()->request->isPostRequest) {
         $semester = Yii::app()->request->getParam('Semesters');
         $model->setAttributes($semester);
         if ($model->save()) {
             Yii::app()->user->setFlash('success', 'Семестр успешно создан');
             $this->redirect(['index']);
         }
     }
     $this->render('form', ['model' => $model, 'call_lists' => $call_lists]);
 }
示例#2
0
 public function dateCheck($attribute)
 {
     $time = strtotime($this->{$attribute});
     if ($this->isNewRecord && $time < strtotime(date('Y-m-d'))) {
         $this->addError($attribute, 'Нельзя установить дату меньше сегоднешней');
     } elseif (($semester = Semesters::model()->find('start_date <= :date AND end_date >= :date', [':date' => $this->{$attribute}])) && $semester->id !== $this->id) {
         $this->addError($attribute, 'Уже есть семестр который перекрывают данную дату');
     }
 }
 public function actionCreate()
 {
     $model = new Holiday('insert');
     $semester = Semesters::model()->actual();
     if (Yii::app()->request->isPostRequest) {
         $holiday = Yii::app()->request->getParam('Holiday');
         $model->setAttributes($holiday);
         if ($model->save()) {
             Yii::app()->user->setFlash('success', 'Выходной успешно создан');
             $this->redirect(['index']);
         }
     }
     $this->render('form', ['model' => $model, 'semester' => $semester]);
 }
示例#4
0
 public function dateCheck($attribute)
 {
     /** @var Semesters $semester */
     $semester = Semesters::model()->actual();
     $time = strtotime($this->{$attribute});
     if ($time < strtotime(date('Y-m-d'))) {
         $this->addError($attribute, 'Нельзя установить дату меньше сегоднешней');
         return false;
     } elseif (date('N', $time) == 7) {
         $this->addError($attribute, 'Нельзя установить дату на воскресенье');
         return false;
     }
     if ($time < strtotime($semester->start_date) || $time > strtotime($semester->end_date)) {
         $this->addError($attribute, 'Дата не может быть за пределами текущего семестра');
     }
 }
示例#5
0
 /**
  * Данная функция фильтрует группы по наполненности расписания для текущего семестра
  *
  * @param bool $bool Параметр указыкает какие группы нужны. true - заполненные, false - не заполненные
  * @return Group
  */
 public function filled($bool = true)
 {
     $schedule_table = ScheduleElement::model()->tableName();
     $semester = Semesters::model()->actual();
     if ($semester) {
         $criteria = $this->getDbCriteria();
         $criteria->params[':semester_id'] = $semester->id;
         for ($i = 1; $i <= 2; $i++) {
             for ($j = 1; $j <= 6; $j++) {
                 $sql = "(SELECT COUNT(*) FROM `{$schedule_table}` WHERE `{$schedule_table}`.`week_number` = {$i} AND `{$schedule_table}`.`week_day` = {$j} AND `{$schedule_table}`.`group_id` = `t`.`id` AND `{$schedule_table}`.`semester_id` = :semester_id) " . ($bool ? ">" : "=") . " 0";
                 $criteria->addCondition($sql, $bool ? 'AND' : 'OR');
             }
         }
     }
     return $this;
 }
示例#6
0
<?php

/* @var $this CoursesController */
/* @var $model Courses */
/* @var $form CActiveForm */
$dataProgram = Programs::model()->findAll();
$optionArrayProgram = CHtml::listData($dataProgram, 'program_Id', 'program_Name');
$dataSemester = Semesters::model()->findAll();
$optionArraySemester = CHtml::listData($dataSemester, 'semester_Id', 'semesterInfo');
?>

<div class="form">

<?php 
$form = $this->beginWidget('CActiveForm', array('id' => 'courses-form', 'enableAjaxValidation' => false));
?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php 
echo $form->errorSummary($model);
?>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'program_Id');
?>
		<?php 
echo $form->dropDownList($model, 'program_Id', $optionArrayProgram);
?>
		<?php 
示例#7
0
 public function actionAutopost()
 {
     $semester = Semesters::model()->actual();
     if (!$semester) {
         throw new CException('Нет семестра');
     }
     $tomorrow_date = (new DateTime())->add(new DateInterval("P1D"))->format('Y-m-d');
     $tomorrow_time = strtotime($tomorrow_date);
     if (date('N', $tomorrow_time) == 7) {
         throw new CException('Завтра выходной');
     }
     $current_hour = date('G');
     $week_number = ($semester->week_number + date('W', $tomorrow_time) - date('W', strtotime($semester->start_date))) % 2 ? 1 : 2;
     $week_day = date('N', $tomorrow_time);
     /** @var GroupAutopost[] $autoposts */
     if (!($autoposts = GroupAutopost::model()->with(['group' => ['with' => ['schedule_elements' => ['condition' => 'week_number = :week_number AND week_day = :week_day AND semester_id = :semester_id', 'params' => [':week_number' => $week_number, ':week_day' => $week_day, ':semester_id' => $semester->id]]]]])->findAllByAttributes(['hour' => $current_hour, 'status' => GroupAutopost::STATUS_ACTIVE]))) {
         throw new CException('Нет групп для автопостинга');
     }
     foreach ($autoposts as $autopost) {
         $replaces = CHtml::listData(GroupReplace::model()->with(['subject', 'classroom', 'teacher'])->findAllByAttributes(['group_id' => $autopost->group_id, 'date' => $tomorrow_date]), 'number', function ($model) {
             return array_merge($model->attributes, ['teacher' => $model->teacher, 'classroom' => $model->classroom, 'subject' => $model->subject]);
         });
         $schedule_elements = CHtml::listData($autopost->group->schedule_elements, 'number', function ($model) {
             return array_merge($model->attributes, ['teacher' => $model->teacher, 'classroom' => $model->classroom, 'subject' => $model->subject]);
         });
         $schedule = $replaces + $schedule_elements;
         ksort($schedule);
         $schedule_text = 'Расписание на завтра:' . PHP_EOL;
         $schedule_count = 0;
         /** @var $holiday Holiday */
         if ($holiday = Holiday::model()->findByAttributes(['date' => $tomorrow_date])) {
             $schedule_text .= 'Выходной - ' . $holiday->name;
         } else {
             if ($schedule) {
                 foreach ($schedule as $subject) {
                     if (isset($subject['cancel']) && $subject['cancel']) {
                         continue;
                     }
                     $schedule_count++;
                     $schedule_text .= $subject['number'] . ') ' . $subject['subject']->name;
                     if ($subject['teacher']) {
                         $schedule_text .= ', ' . $subject['teacher']->lastname . ' ' . mb_substr($subject['teacher']->firstname, 0, 1, "UTF-8") . '.' . mb_substr($subject['teacher']->middlename, 0, 1, "UTF-8") . '.';
                     }
                     if ($subject['classroom']) {
                         $schedule_text .= ' (' . $subject['classroom']->name . ')';
                     }
                     if (isset($subject['comment']) && strlen($subject['comment'])) {
                         $schedule_text .= ' - ' . $subject['comment'];
                     }
                     $schedule_text .= PHP_EOL;
                 }
             }
             if (!$schedule || $schedule_count == 0) {
                 $schedule_text .= 'Пар нет' . PHP_EOL;
             }
         }
         $schedule_text .= 'Данные предоставлены проектом @studyschedule (Расписание ККЭП)';
         $params = http_build_query(['owner_id' => $autopost->page_id, 'message' => $schedule_text, 'from_group' => 1, 'access_token' => $autopost->access_token]);
         echo "----" . $autopost->group->number . "----" . PHP_EOL;
         $response = file_get_contents('https://api.vk.com/method/wall.post?' . $params);
         if ($response) {
             $answer = json_decode($response, true);
             var_dump($answer);
             if (isset($answer['error'])) {
                 $autopost->status = GroupAutopost::STATUS_DISABLE;
                 $autopost->save();
                 $email = $autopost->group->owner->email;
                 $mail = new YiiMailer("autopost", ['group' => $autopost->group]);
                 $mail->setFrom(isset(Yii::app()->params->YiiMailer->Username) ? Yii::app()->params->YiiMailer->Username : Yii::app()->params->adminEmail, 'Система управления учебным расписанием');
                 $mail->setTo($email);
                 $mail->setSubject('Ошибка автопостинга в ВКонтакте');
                 $mail->send();
             }
         } else {
             echo 'Error when send request...';
         }
         echo PHP_EOL;
     }
 }
示例#8
0
 public function actionIndex()
 {
     /** @var Semesters $semester */
     $semester = Semesters::model()->actual();
     $this->render('index', ['group_count' => Group::model()->filled()->count(), 'replace_count' => GroupReplace::model()->count('date >= :start_semester AND date <= :end_semester', [':start_semester' => $semester->start_date, ':end_semester' => $semester->end_date]), 'ics_count' => IcsAnalytics::model()->count('time LIKE :date', [':date' => date('Y-m-d') . '%'])]);
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Semesters the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Semesters::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
示例#10
0
 public function getCurrentWeekNumber()
 {
     $semester = Semesters::model()->actual();
     $week_number = (date('W') - date('W', strtotime($semester->start_date))) % ($semester->week_number + 1) + 1;
     return $week_number;
 }
 public function actionIndex($group = false)
 {
     /** @var Group $group */
     if ($group != false && !($group = Group::model()->filled()->findByAttributes(['number' => $group]))) {
         throw new CHttpException(404, 'Данной группы не найден');
     }
     /** @var Semesters $semester */
     $semester = Semesters::model()->actual();
     $current_date = date('Y-m-d');
     $current_time = strtotime($current_date);
     if (!$semester) {
         throw new CHttpException(404, 'Сейчас нет семестра :-(');
     }
     $group_list = CHtml::listData(Group::model()->filled()->findAll(), 'number', 'number');
     $schedule = [];
     if ($group) {
         $time_one_day = 60 * 60 * 24;
         for ($i = $current_time; $i <= $current_time + $time_one_day * 7; $i = $i + $time_one_day) {
             $week_day = date('N', $i);
             $date = date('d.n.Y', $i);
             /** @var Holiday $holiday */
             if (($holiday = Holiday::model()->findByAttributes(['date' => date('Y-m-d', $i)])) || $week_day == 7) {
                 $schedule[$date] = ['holiday' => true];
                 if ($holiday) {
                     $schedule[$date]['name'] = $holiday->name;
                 }
                 continue;
             }
             $schedule[$date] = [];
             $week_number = ($semester->week_number + (date('W', $i) - date('W', strtotime($semester->start_date)))) % 2 ? 1 : 2;
             $schedule_elements = ScheduleElement::model()->findAllByAttributes(['group_id' => $group->id, 'semester_id' => $semester->id, 'week_number' => $week_number, 'week_day' => $week_day]);
             $numbers = [1, 2, 3, 4, 5];
             /** @var ScheduleElement $schedule_element */
             foreach ($schedule_elements as $schedule_element) {
                 unset($numbers[array_search($schedule_element->number, $numbers)]);
                 /** @var GroupReplace $replace */
                 $replace = GroupReplace::model()->findByAttributes(['date' => date('Y-m-d', $i), 'number' => $schedule_element->number, 'group_id' => $group->id]);
                 if ($replace && $replace->cancel) {
                     $schedule[$date][$schedule_element->number] = ['cancel' => true, 'replace' => true];
                 } elseif ($replace) {
                     $schedule[$date][$schedule_element->number] = ['subject' => $replace->subject->name, 'replace' => true, 'comment' => $replace->comment];
                     if ($replace->teacher_id) {
                         $schedule[$date][$schedule_element->number]['teacher'] = $replace->teacher->lastname . ' ' . mb_substr($replace->teacher->firstname, 0, 1, "UTF-8") . '.' . mb_substr($replace->teacher->middlename, 0, 1, "UTF-8") . '.';
                     }
                     if ($replace->classroom_id) {
                         $schedule[$date][$schedule_element->number]['classroom'] = $replace->classroom->name;
                     }
                 } else {
                     $schedule[$date][$schedule_element->number] = ['subject' => $schedule_element->subject->name];
                     if ($schedule_element->teacher_id) {
                         $schedule[$date][$schedule_element->number]['teacher'] = $schedule_element->teacher->lastname . ' ' . mb_substr($schedule_element->teacher->firstname, 0, 1, "UTF-8") . '.' . mb_substr($schedule_element->teacher->middlename, 0, 1, "UTF-8") . '.';
                     }
                     if ($schedule_element->classroom_id) {
                         $schedule[$date][$schedule_element->number]['classroom'] = $schedule_element->classroom->name;
                     }
                 }
             }
             if (count($numbers)) {
                 foreach ($numbers as $number) {
                     /** @var GroupReplace $replace */
                     $replace = GroupReplace::model()->findByAttributes(['date' => date('Y-m-d', $i), 'number' => $number, 'group_id' => $group->id]);
                     if ($replace && $replace->cancel) {
                         $schedule[$date][$replace->number] = ['cancel' => true, 'replace' => true];
                     } elseif ($replace) {
                         $schedule[$date][$replace->number] = ['subject' => $replace->subject->name, 'replace' => true];
                         if ($replace->teacher_id) {
                             $schedule[$date][$replace->number]['teacher'] = $replace->teacher->lastname . ' ' . mb_substr($replace->teacher->firstname, 0, 1, "UTF-8") . '.' . mb_substr($replace->teacher->middlename, 0, 1, "UTF-8") . '.';
                         }
                         if ($replace->classroom_id) {
                             $schedule[$date][$replace->number]['classroom'] = $replace->classroom->name;
                         }
                     }
                 }
             }
             ksort($schedule[$date]);
         }
     }
     Yii::app()->clientScript->registerMetaTag('noarchive', 'robots');
     $this->render('index', ['group' => $group ? $group->number : false, 'group_list' => $group_list, 'schedule' => $schedule]);
 }
示例#12
0
 public function actionUpdateReplace($replace_id)
 {
     $semester = Semesters::model()->actual();
     if (!$semester) {
         throw new CHttpException(404, 'Сейчас нет семестра :-(');
     }
     /** @var GroupReplace $model */
     $model = GroupReplace::model()->findByPk($replace_id);
     if (!$model || strtotime($model->date) < strtotime(date('Y-m-d'))) {
         throw new CHttpException(404, 'Замена не найдена');
     }
     $classrooms = CHtml::listData(Classrooms::model()->byName()->findAll(), 'id', 'name');
     $subjects = CHtml::listData(Subjects::model()->byName()->findAll(), 'id', 'name');
     $teachers = CHtml::listData(Teachers::model()->byLastName()->findAll(), 'id', function ($model) {
         return join(' ', [$model->lastname, $model->firstname, $model->middlename]);
     });
     if (Yii::app()->request->isPostRequest) {
         $replace = Yii::app()->request->getParam('GroupReplace');
         $model->setAttributes($replace);
         $model->setAttributes(['group_id' => self::$group->id]);
         if ($model->save()) {
             Yii::app()->user->setFlash('success', 'Замена успешна обновлена');
             $this->redirect(['replaces', 'id' => self::$group->number]);
         }
     }
     $this->render('replace/form', ['semester' => $semester, 'model' => $model, 'teachers' => $teachers, 'subjects' => $subjects, 'classrooms' => $classrooms, 'numbers' => [1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5]]);
 }
示例#13
0
 public function actionGroup($id)
 {
     if (!isset($_SERVER['HTTP_USER_AGENT'])) {
         throw new CHttpException(403, 'У вас нет useragent, поэтому сюда вам нельзя');
     }
     /** @var Semesters $semester */
     if (!($semester = Semesters::model()->with(['call_list', 'call_list_short'])->actual())) {
         throw new CHttpException(404, 'Сейчас нет семестра :-(');
     }
     // Аналитика
     if (!($unique_ics_id = Yii::app()->session->get('unique_ics_id', false))) {
         $unique_ics_id = uniqid();
         Yii::app()->session->add('unique_ics_id', $unique_ics_id);
     }
     $analytics = new IcsAnalytics();
     $analytics->setAttributes(['useragent' => $_SERVER['HTTP_USER_AGENT'], 'group' => $id, 'time' => date("Y-m-d H:i:s"), 'ip' => get_client_ip(), 'unique_id' => $unique_ics_id]);
     $analytics->save();
     // Даты
     $count_days = 24;
     $current_date = date('Y-m-d');
     $period_interval = new DateInterval('P1D');
     $period_start = new DateTime($current_date);
     $period_start->modify('-' . floor($count_days / 2) . ' days');
     $period_end = new DateTime($current_date);
     $period_end->modify('+' . floor($count_days / 2) . ' days');
     $period = new DatePeriod($period_start, $period_interval, $period_end);
     $period_dates = [];
     $semester_start = new DateTime($semester->start_date);
     $semester_end = new DateTime($semester->end_date);
     /** @var DateTime $period_date */
     foreach ($period as $period_date) {
         $period_dates[] = $period_date->format('Y-m-d');
     }
     // Загрузка группы с расписанием и заменами за нужный период
     /** @var Group $group */
     if (!($group = Group::model()->filled()->with(['schedule_elements' => ['with' => ['teacher' => ['alias' => 's_teacher'], 'classroom' => ['alias' => 's_classroom'], 'subject' => ['alias' => 's_subject']], 'condition' => 'semester_id = :semester_id', 'params' => [':semester_id' => $semester->id]], 'replaces' => ['together' => false, 'with' => ['teacher' => ['alias' => 'r_teacher'], 'classroom' => ['alias' => 'r_classroom'], 'subject' => ['alias' => 'r_subject']], 'condition' => 'date >= :start_date AND date <= :end_date', 'params' => [':start_date' => $period_start->format('Y-m-d'), ':end_date' => $period_end->format('Y-m-d')]]])->findByAttributes(['number' => $id]))) {
         throw new CHttpException(404, 'Группа не найдена или незаполнена');
     }
     // Преобразование массивов
     /** @var CallListsElements[] $call_list */
     $call_list = CHtml::listData($semester->call_list()->elements, 'number', function ($model) {
         return $model;
     });
     /** @var CallListsElements[] $call_list_short */
     $call_list_short = CHtml::listData($semester->call_list_short()->elements, 'number', function ($model) {
         return $model;
     });
     $schedule_elements = [];
     for ($i = 1; $i <= 2; $i++) {
         for ($j = 1; $j <= 6; $j++) {
             $schedule_elements[$i][$j] = CHtml::listData(array_filter($group->schedule_elements, function ($model) use(&$i, &$j) {
                 return $model->week_number == $i && $model->week_day == $j;
             }), 'number', function ($model) {
                 return $model;
             });
             ksort($schedule_elements[$i][$j], SORT_NUMERIC);
         }
         ksort($schedule_elements[$i], SORT_NUMERIC);
     }
     $replaces = [];
     foreach ($group->replaces as $replace) {
         $replaces[$replace->date][$replace->number] = $replace;
     }
     $calendar = new Calendar();
     $calendar->setProdId('-//Sc0Rp1D//KKEP//RU');
     $calendar->setTimezone(new DateTimeZone('Europe/Moscow'));
     $calendar->setCustomHeaders(['X-PUBLISHED-TTL' => 'PT1H', 'REFRESH-INTERVAL' => 'VALUE=DURATION:PT1H']);
     $holidays = CHtml::listData(Holiday::model()->findAllByAttributes(['date' => $period_dates]), 'date', 'name');
     $short_days = CHtml::listData(ShortDay::model()->findAllByAttributes(['date' => $period_dates]), 'date', 'name');
     /** @var DateTime $period_element */
     foreach ($period as $period_element) {
         $week_day = $period_element->format('N');
         $date_formatted = $period_element->format('Y-m-d');
         if ($period_element < $semester_start || $week_day == 7 || array_key_exists($date_formatted, $holidays)) {
             continue;
         }
         if ($period_element > $semester_end) {
             break;
         }
         if ($week_day == 6 || array_key_exists($date_formatted, $short_days)) {
             $current_call_list = $call_list_short;
         } else {
             $current_call_list = $call_list;
         }
         $week_number = ($semester->week_number + ($period_element->format('W') - $semester_start->format('W'))) % 2 ? 1 : 2;
         /** @var ScheduleElement $schedule_element */
         foreach ((isset($replaces[$date_formatted]) ? $replaces[$date_formatted] : []) + $schedule_elements[$week_number][$week_day] as $schedule_element) {
             if (isset($schedule_element->cancel) && $schedule_element->cancel) {
                 continue;
             }
             $event = new CalendarEvent();
             $start_time = clone $period_element;
             $call_list_start = explode(':', $current_call_list[$schedule_element->number]->start_time);
             $call_list_end = explode(':', $current_call_list[$schedule_element->number]->end_time);
             $start_time->setTime($call_list_start[0], $call_list_start[1]);
             $event->setStart($start_time);
             $end_time = clone $period_element;
             $end_time->setTime($call_list_end[0], $call_list_end[1]);
             $event->setEnd($end_time);
             $event->setSummary($schedule_element->subject->name);
             $event->setUid(md5($date_formatted . ' ' . $current_call_list[$schedule_element->number]->start_time));
             if ($schedule_element->classroom_id || $schedule_element->teacher_id) {
                 $location = new Location();
                 $desc = [];
                 if ($schedule_element->teacher_id) {
                     $desc[] = $schedule_element->teacher->lastname . ' ' . mb_substr($schedule_element->teacher->firstname, 0, 1, "UTF-8") . '.' . mb_substr($schedule_element->teacher->middlename, 0, 1, "UTF-8") . '.';
                 }
                 if ($schedule_element->classroom_id) {
                     $desc[] = $schedule_element->classroom->name;
                 }
                 $location->setName(implode(' | ', $desc));
                 $event->addLocation($location);
             }
             if ($schedule_element instanceof GroupReplace && strlen($schedule_element->comment)) {
                 $event->setDescription($schedule_element->comment);
             }
             $calendar->addEvent($event);
         }
     }
     $calendarExport = new CalendarExport(new CalendarStream(), new Formatter());
     $calendarExport->addCalendar($calendar);
     //header('Content-Type: text/calendar; charset=utf-8');
     echo $calendarExport->getStream();
 }