示例#1
0
 function __construct()
 {
     $args = func_get_args();
     if (!empty($args)) {
         parent::__construct($args[0]);
         $this->timerOptions = array();
         if (strtolower(trim($this->getType())) == TIMER_D) {
             $this->parseTimerLine($this->getElementLine());
             $this->rebuildElementLine();
         } else {
             throw new Exception("This is not a timer line!");
         }
     } else {
         parent::__construct();
         $this->setType(TIMER_D);
         $this->setDaysOfWeek(".......");
         $this->parseDates("01/01-12/31");
         $this->parseStartTime("00:01");
         $this->parseStopTime("23:59");
         $this->setStartMacro("null");
         $this->setStopMacro("null");
         $this->timerOptions = array();
         $this->rebuildElementLine();
     }
 }
示例#2
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;
 }
示例#3
0
 /**
  * Constructor
  *
  * @args[0] represents label, delay and command
  */
 function __construct()
 {
     $args = func_get_args();
     if (!empty($args)) {
         parent::__construct($args[0]);
         if (strtolower(trim($this->getType())) == MACRO_D) {
             $this->parseMacroLine($this->getElementLine());
             $this->rebuildElementLine();
         } else {
             throw new Exception("This is not a macro line!");
         }
     } else {
         parent::__construct();
         $this->setType(MACRO_D);
         $this->label = 'macro_x';
         $this->delay = '0';
         $this->command = 'off junk';
         $this->rebuildElementLine();
     }
 }
示例#4
0
 /**
  * Constructor
  *
  * @args[0] represents label (alias or houseUnitCode), command (on/off), execute macro
  */
 function __construct()
 {
     $args = func_get_args();
     if (!empty($args)) {
         parent::__construct($args[0]);
         if (strtolower(trim($this->getType())) == TRIGGER_D) {
             $this->parseTriggerLine($this->getElementLine());
             $this->rebuildElementLine();
         } else {
             throw new Exception("This is not a Trigger line!");
         }
     } else {
         parent::__construct();
         $this->setType(TRIGGER_D);
         $this->label = 'trigger_x';
         $this->command = 'off';
         $this->macroLabel = 'junk';
         $this->rebuildElementLine();
     }
 }
 public static function createElement($lineData)
 {
     try {
         $anElement = new ScheduleElement($lineData);
         switch (strtolower(trim($anElement->getType()))) {
             case TIMER_D:
                 try {
                     $aTimer = new Timer($lineData);
                     return $aTimer;
                 } catch (Exception $e) {
                     // if the line is commented out, make it a comment as it is meant to be.
                     // It is not a a disabled timer.
                     if (!$anElement->isEnabled()) {
                         $anElement->setType(COMMENT_D);
                         return $anElement;
                     }
                     throw $e;
                 }
                 break;
             case MACRO_D:
                 try {
                     $aMacro = new Macro($lineData);
                     return $aMacro;
                 } catch (Exception $e) {
                     // if the line is commented out, make it a comment as it is meant to be.
                     // It is not a a disabled macro.
                     if (!$anElement->isEnabled()) {
                         $anElement->setType(COMMENT_D);
                         return $anElement;
                     }
                     throw $e;
                 }
                 break;
             case TRIGGER_D:
                 try {
                     $aTrigger = new Trigger($lineData);
                     return $aTrigger;
                 } catch (Exception $e) {
                     // if the line is commented out, make it a comment as it is meant to be.
                     // It is not a a disabled trigger.
                     if (!$anElement->isEnabled()) {
                         $anElement->setType(COMMENT_D);
                         return $anElement;
                     }
                     throw $e;
                 }
                 break;
             case CONFIG_D:
                 return $anElement;
                 break;
             case SECTION_D:
                 return $anElement;
                 break;
             case COMMENT_D:
                 return $anElement;
                 break;
         }
     } catch (Exception $e) {
         throw $e;
     }
 }
示例#6
0
    echo "&nbsp;&nbsp;&nbsp;&nbsp;The return of Timer element isEnabled [" . $anElement->isEnabled() . "]<br/>";
} catch (Exception $e) {
    echo "&nbsp;&nbsp;&nbsp;&nbsp;E!: " . $e->getMessage() . "<br/>";
}
echo "* Test ScheduleElement - macro<br/>";
try {
    $anElement = new ScheduleElement($macroLine);
    echo "&nbsp;&nbsp;&nbsp;&nbsp;The return of schedule element getElementLine [" . $anElement->getElementLine() . "]<br/>";
    echo "&nbsp;&nbsp;&nbsp;&nbsp;The return of schedule element getType [" . $anElement->getType() . "]<br/>";
    echo "&nbsp;&nbsp;&nbsp;&nbsp;The return of Timer element isEnabled [" . $anElement->isEnabled() . "]<br/>";
} catch (Exception $e) {
    echo "&nbsp;&nbsp;&nbsp;&nbsp;E!: " . $e->getMessage() . "<br/>";
}
echo "* Test ScheduleElement - trigger<br/>";
try {
    $anElement = new ScheduleElement($triggerLine);
    echo "&nbsp;&nbsp;&nbsp;&nbsp;The return of schedule element getElementLine [" . $anElement->getElementLine() . "]<br/>";
    echo "&nbsp;&nbsp;&nbsp;&nbsp;The return of schedule element getType [" . $anElement->getType() . "]<br/>";
    echo "&nbsp;&nbsp;&nbsp;&nbsp;The return of Timer element isEnabled [" . $anElement->isEnabled() . "]<br/>";
} catch (Exception $e) {
    echo "&nbsp;&nbsp;&nbsp;&nbsp;E!: " . $e->getMessage() . "<br/>";
}
echo "* Test Timer with passed in line <br/>";
try {
    $timer = new Timer($testLine);
    echo "&nbsp;&nbsp;&nbsp;&nbsp;The return of Timer getElementLine [" . $timer->getElementLine() . "]<br/>";
    echo "&nbsp;&nbsp;&nbsp;&nbsp;The return of Timer element getType [" . $timer->getType() . "]<br/>";
    echo "&nbsp;&nbsp;&nbsp;&nbsp;The return of Timer element isEnabled [" . $timer->isEnabled() . "]<br/>";
} catch (Exception $e) {
    echo "&nbsp;&nbsp;&nbsp;&nbsp;E!: " . $e->getMessage() . "<br/>";
}
 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]);
 }
示例#8
0
 public function actionDeleteScheduleElement($element_id, $confirm = 0)
 {
     $semester = Semesters::model()->actual();
     if (!$semester) {
         throw new CHttpException(404, 'Сейчас нет семестра :-(');
     }
     $model = ScheduleElement::model()->with('teacher', 'classroom', 'subject')->findByPk($element_id);
     if (!$model || $model->semester_id != $semester->id) {
         throw new CHttpException(404, 'Элемент не найден');
     }
     if ($confirm) {
         $model->delete();
         Yii::app()->user->setFlash('success', 'Элемент успешно удален');
         $this->redirect(['schedule', 'id' => self::$group->number]);
     }
     $this->render('schedule/delete', ['model' => $model]);
 }