public function safeUp()
 {
     $this->addColumn('{{group_replace}}', 'owner', 'string NOT NULL');
     $replaces = GroupReplace::model()->findAll();
     foreach ($replaces as $replace) {
         $log = ActiveRecordLog::model()->findByAttributes(['model' => 'GroupReplace', 'idModel' => $replace->id, 'action' => 'CREATE']);
         if ($log) {
             $log = explode(' ', $log->description);
             $replace->owner = $log[1];
             $replace->save();
         }
     }
 }
Пример #2
0
 public function numberCheck($attribute)
 {
     if (($replace = GroupReplace::model()->findByAttributes(['group_id' => $this->group_id, 'date' => $this->date, $attribute => $this->{$attribute}])) && ($this->isNewRecord || $replace->id != $replace->id)) {
         $this->addError($attribute, 'На данную дату и пару уже есть замена');
         $this->addError('date', 'На данную дату и пару уже есть замена');
     }
 }
Пример #3
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;
     }
 }
Пример #4
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') . '%'])]);
 }
Пример #5
0
 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]);
 }
Пример #6
0
 public function actionDeleteReplace($replace_id, $confirm = 0)
 {
     /** @var GroupReplace $model */
     $model = GroupReplace::model()->findByPk($replace_id);
     if (!$model || strtotime($model->date) < strtotime(date('Y-m-d'))) {
         throw new CHttpException(404, 'Элемент не найден');
     }
     if ($confirm) {
         if ($model->delete()) {
             Yii::app()->user->setFlash('success', 'Замена успешна удален');
         } else {
             Yii::app()->user->setFlash('error', 'Ошибка удаления замены');
         }
         $this->redirect(['replaces', 'id' => self::$group->number]);
     }
     $this->render('replace/delete', ['model' => $model]);
 }