protected function gavno()
 {
     $position = [];
     $list = \Schedule::model()->findAllBySql('select * from spbp_listner_schedule a
             join spbp_listner_position b on a.position_id = b.id
             join spbp_form_form c on b.form_id = c.id
             where a.number = c.number AND a.end_time < now() AND b.status = 1');
     foreach ($list as $value) {
         $a = \Position::model()->findByPk($value->position_id);
         array_push($position, $a);
     }
     return $position;
 }
 /**
  * Возвращает модель по указанному идентификатору
  * Если модель не будет найдена - возникнет HTTP-исключение.
  *
  * @param integer идентификатор нужной модели
  *
  * @return void
  */
 public function loadModel($id)
 {
     $model = Schedule::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('ListnerModule.listner', 'Запрошенная страница не найдена.'));
     }
     return $model;
 }
Beispiel #3
0
 public function actionGet_data()
 {
     $sid = '';
     if (isset($_POST['sid'])) {
         $sid = str_replace(',', ' or id = ', $_POST['sid']);
     }
     if ($sid == '') {
         echo 1;
     }
     $criteria = new CDbCriteria();
     $criteria->condition = 'id =' . $sid;
     if ($_POST['searchPhrase'] != '') {
         $criteria->addCondition(' day like ' . '"%' . $_POST['searchPhrase'] . '%" or  eat like ' . '"%' . $_POST['searchPhrase'] . '%" or live like ' . '"%' . $_POST['searchPhrase'] . '%"', 'AND');
     }
     if (isset($_POST['sort']['id'])) {
         $criteria->order = " id  {$_POST['sort']['id']} ";
     } else {
         if (isset($_POST['sort']['day'])) {
             $criteria->order = "day {$_POST['sort']['day']} ";
         } else {
             if (isset($_POST['sort']['eat'])) {
                 $criteria->order = "eat {$_POST['sort']['eat']} ";
             } else {
                 if (isset($_POST['sort']['live'])) {
                     $criteria->order = "live {$_POST['sort']['live']} ";
                 }
             }
         }
     }
     $criteria->limit = $_POST['rowCount'];
     $criteria->offset = (intval($_POST['current']) - 1) * $_POST['rowCount'];
     $model = Schedule::model()->findAll($criteria);
     $count = count($model);
     //      var_dump($model);
     $arr = array();
     foreach ($model as $o) {
         $json = array('id' => intval($o->id), 'day' => $o->day, 'eat' => $o->eat, 'live' => $o->live);
         array_push($arr, $json);
     }
     //      var_dump( $arr);
     echo json_encode(array('rowCount' => $_POST['rowCount'], 'current' => $_POST['current'], 'rows' => $arr, 'total' => $count));
 }
 public function actionChange($id)
 {
     if (Yii::app()->request->isAjaxRequest) {
         $model = \Schedule::model()->findByPk($id);
         if ($model->is_active == 1) {
             $price = $model->position->form->price / $model->position->form->number;
             $model->is_active = 0;
             $model->update();
             $outflow = new Outflow();
             $outflow->price = $price;
             $outflow->based = "Отмена урока от " . $model->start_time;
             $outflow->note = $model->id;
             $outflow->branch_id = $model->position->listner->branch_id;
             $outflow->date = date('Y-m-d');
             $outflow->receiver = 'admin';
             $outflow->save();
         } elseif ($model->is_active == 0) {
             $model->is_active = 1;
             $model->update();
             $outflow = Outflow::model()->find("note='{$id}'");
             $outflow->delete();
         }
         echo CJSON::encode($model->is_active);
     } else {
         throw new CHttpException(404, Yii::t('ListnerModule.listner', 'Запрошенная страница не найдена.'));
     }
 }
 /**
  ** Schedule Functions
  **/
 public function actionListSchedules($server_id)
 {
     $this->check($server_id);
     $cmds = Schedule::model()->findAllByAttributes(array('server_id' => (int) $server_id));
     $this->ls('Schedule', $cmds);
 }
 public function actionGetSchedules($param1, $param2)
 {
     $startTime = date('Y-m-d', strtotime($_GET['start']));
     $endTime = date('Y-m-d', strtotime("+1 week", strtotime($startTime)));
     $arr = [];
     $arrs = [];
     /*        if ($param1 == "1") {
                       $array = \Yii::app()->db->createCommand()
                           ->select('b.id, c.code, z.lastname, b.start_time, b.end_time, b.room_id, d.name,d.color,asd.name as pizda')
                           ->from('spbp_user_user a')
                           ->join('spbp_user_teacher f','a.id = f.user_id')
                           ->join('spbp_listner_position c', 'c.teacher_id = f.id')
                           ->join('spbp_listner_schedule b', 'c.id = b.position_id')
                           ->join('spbp_listner_listner z','z.id = c.listner_id')
                           ->join('spbp_subject_subject d', 'd.id = c.subject_id')
                           ->join('spbp_listner_group asd', 'asd.id = b.group_id')
                           ->where('f.id =:id',array(":id"=>$param2))
                           ->queryAll();
                   }else if($param1=="2"){
                       $array = \Yii::app()->db->createCommand()
                           ->select('b.id, c.code, a.last_name as lastname, b.start_time, b.end_time, b.room_id, d.name,d.color,asd.name as pizda')
                           ->from('spbp_user_user a')
                           ->join('spbp_user_teacher f','a.id = f.user_id')
                           ->join('spbp_listner_position c', 'c.teacher_id = f.id')
                           ->join('spbp_listner_schedule b', 'c.id = b.position_id')
                           ->join('spbp_subject_subject d', 'd.id = c.subject_id')
                           ->join('spbp_listner_group asd', 'asd.id = b.group_id')
                           ->where('a.id =:id',array(":id"=>$param2))
                           ->queryAll();
                   }else if(($param1==0)&&($param2==0)){
                   $array = \Yii::app()->db->createCommand()
                       ->select('b.id, c.code, concat(a.last_name," - ",z.lastname) as lastname, b.start_time, b.end_time, b.room_id, d.name,d.color, asd.name as pizda')
                       ->from('spbp_user_user a')
                       ->join('spbp_user_teacher f','a.id = f.user_id')
                       ->join('spbp_listner_position c', 'c.teacher_id = f.id')
                       ->join('spbp_listner_listner z','z.id = c.listner_id')
                       ->join('spbp_listner_schedule b', 'c.id = b.position_id')
                       ->join('spbp_subject_subject d', 'd.id = c.subject_id')
                       ->join('spbp_listner_group asd', 'asd.id = b.group_id')
                       ->queryAll();
               }*/
     $schdls = \Schedule::model()->findAll("start_time between '{$startTime}' and '{$endTime}'");
     foreach ($schdls as $row) {
         $arrs['id'] = $row['id'];
         $arrs['resourceId'] = $row['room_id'];
         $arrs['start'] = $row['start_time'];
         $arrs['end'] = $row['end_time'];
         if ($param1 == "1") {
             if ($row['position_id']) {
                 $ponos = \Position::model()->find('teacher_id=:id and id=:id2', [":id" => $param2, ":id2" => $row['position_id']]);
                 $arrs['title'] = '(' . $ponos->code . ')';
                 $arrs['desc'] = $ponos->listner->name;
                 $arrs['subj'] = '(' . $ponos->subject->name . ')';
                 $arrs['height'] = '100px';
                 $arrs['backgroundColor'] = $ponos->subject->color;
             } else {
                 if ($row['group_id']) {
                     $ponos = \Group::model()->find('teacher_id=:id and id = :id2', [":id" => $param2, ':id2' => $row['group_id']]);
                     $arrs['title'] = '(' . $ponos->name . ')';
                     $arrs['desc'] = '';
                     $arrs['subj'] = '(' . $ponos->subject->name . ')';
                     $arrs['height'] = '100px';
                     $arrs['backgroundColor'] = $ponos->subject->color;
                 }
             }
         } else {
             if ($param1 == "2") {
                 if ($row['position_id']) {
                     $ponos = \Position::model()->find('listner_id=:id and id=:id2', [":id" => $param2, ":id2" => $row['position_id']]);
                     $arrs['title'] = '(' . $ponos->code . ')';
                     $arrs['desc'] = $ponos->teacher->user->last_name;
                     $arrs['subj'] = '(' . $ponos->subject->name . ')';
                     $arrs['height'] = '100px';
                     $arrs['backgroundColor'] = $ponos->subject->color;
                 } else {
                     if ($row['group_id']) {
                         $ponos = \Group::model()->find('id =:id2', [':id2' => $row['group_id']]);
                         $arrs['title'] = '(гр ' . $ponos->name . ')';
                         $arrs['desc'] = $ponos->teacher->user->last_name . '  ' . $ponos->teacher->user->first_name;
                         $arrs['subj'] = '(' . $ponos->subject->name . ')';
                         $arrs['height'] = '100px';
                         $arrs['backgroundColor'] = $ponos->subject->color;
                     }
                 }
             } else {
                 if ($param1 == 0 && $param2 == 0) {
                     if ($row['position_id']) {
                         $ponos = \Position::model()->findByPk($row['position_id']);
                         $arrs['title'] = '(' . $ponos->code . ')';
                         $arrs['desc'] = $ponos->listner->name;
                         $arrs['subj'] = '(' . $ponos->subject->name . ')';
                         $arrs['height'] = '100px';
                         $arrs['backgroundColor'] = $ponos->subject->color;
                     } else {
                         if ($row['group_id']) {
                             $ponos = \Group::model()->findByPk($row['group_id']);
                             $arrs['title'] = '(' . $ponos->name . ')';
                             $arrs['desc'] = $ponos->teacher->user->last_name . '  ' . $ponos->teacher->user->first_name;
                             $arrs['subj'] = '(' . $ponos->subject->name . ')';
                             $arrs['height'] = '100px';
                             $arrs['backgroundColor'] = $ponos->subject->color;
                         }
                     }
                 }
             }
         }
         //
         //            $arrs['title'] = '('.$row['code'].')';
         //            $arrs['desc'] = $row['lastname'];
         //            $arrs['subj'] = '('.$row['name'].')';
         //            $arrs['height'] = '100px';
         //            $arrs['backgroundColor']='#'.$row['color'];
         //            $arrs['group']=$row['pizda'];
         array_push($arr, $arrs);
     }
     echo \CJSON::encode($arr);
 }
 public function loadModel($id)
 {
     $model = Schedule::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('mc', 'The requested page does not exist.'));
     }
     return $model;
 }
    public function run()
    {
        $htmlOptions = $this->htmlOptions;
        $tableOptions = $this->tableOptions;
        $model = $this->model;
        $name = $this->name;
        if (!isset($htmlOptions['class'])) {
            $htmlOptions['class'] = 'table-responsive';
        } else {
            $htmlOptions['class'] .= ' table-responsive';
        }
        $htmlOptions['id'] = 'schedules';
        if (!isset($tableOptions['class'])) {
            $tableOptions['class'] = 'table table-condensed';
        } else {
            $tableOptions['class'] .= ' table table-condensed';
        }
        echo CHtml::openTag('div', $htmlOptions);
        echo CHtml::openTag('table', $tableOptions);
        echo CHtml::openTag('thead');
        echo CHtml::openTag('tr');
        echo CHtml::tag('th', array(), '第几天');
        echo CHtml::tag('th', array(), '赛区');
        echo CHtml::tag('th', array(), '开始时间');
        echo CHtml::tag('th', array(), '结束时间');
        echo CHtml::tag('th', array(), '项目');
        echo CHtml::tag('th', array(), '分组');
        echo CHtml::tag('th', array(), '轮次');
        echo CHtml::tag('th', array(), '赛制');
        echo CHtml::tag('th', array(), '及格线(秒)');
        echo CHtml::tag('th', array(), '还原时限(秒)');
        echo CHtml::tag('th', array(), '人数');
        echo CHtml::closeTag('tr');
        echo CHtml::closeTag('thead');
        $schedules = $model->{$name};
        $schedules[] = Schedule::model()->attributes;
        $events = Events::getScheduleEvents();
        foreach ($events as $key => $value) {
            $events[$key] = Yii::t('event', $value);
        }
        $formats = Formats::getAllFormats();
        foreach ($formats as $key => $value) {
            $formats[$key] = Yii::t('common', $value);
        }
        $rounds = Rounds::getAllRounds();
        foreach ($rounds as $key => $value) {
            $rounds[$key] = Yii::t('Rounds', $value);
        }
        $stages = Schedule::getStages();
        echo CHtml::openTag('tbody');
        foreach ($schedules as $key => $value) {
            extract($value);
            echo CHtml::openTag('tr');
            echo CHtml::tag('td', array(), CHtml::activeNumberField($model, "{$name}[day][]", array('value' => $day ?: 1, 'min' => 1, 'max' => 4)));
            echo CHtml::tag('td', array(), CHtml::dropDownList(CHtml::activeName($model, "{$name}[stage][]"), $stage, $stages));
            echo CHtml::tag('td', array(), CHtml::activeTextField($model, "{$name}[start_time][]", array('value' => $start_time ? date('H:i', $start_time) : '', 'class' => 'datetime-picker', 'data-date-format' => 'hh:ii', 'data-max-view' => '1', 'data-start-view' => '1')));
            echo CHtml::tag('td', array(), CHtml::activeTextField($model, "{$name}[end_time][]", array('value' => $end_time ? date('H:i', $end_time) : '', 'class' => 'datetime-picker', 'data-date-format' => 'hh:ii', 'data-max-view' => '1', 'data-start-view' => '1')));
            echo CHtml::tag('td', array(), CHtml::dropDownList(CHtml::activeName($model, "{$name}[event][]"), $event, $events, array('prompt' => '')));
            echo CHtml::tag('td', array(), CHtml::activeTextField($model, "{$name}[group][]", array('value' => $group)));
            echo CHtml::tag('td', array(), CHtml::dropDownList(CHtml::activeName($model, "{$name}[round][]"), $round, $rounds, array('prompt' => '')));
            echo CHtml::tag('td', array(), CHtml::dropDownList(CHtml::activeName($model, "{$name}[format][]"), $format, $formats, array('prompt' => '')));
            echo CHtml::tag('td', array(), CHtml::activeNumberField($model, "{$name}[cut_off][]", array('value' => $cut_off, 'max' => 3600)));
            echo CHtml::tag('td', array(), CHtml::activeNumberField($model, "{$name}[time_limit][]", array('value' => $time_limit, 'max' => 3600)));
            echo CHtml::tag('td', array(), CHtml::activeNumberField($model, "{$name}[number][]", array('value' => $number)));
            echo CHtml::closeTag('tr');
        }
        echo CHtml::closeTag('tbody');
        echo CHtml::closeTag('table');
        echo CHtml::closeTag('div');
        Yii::app()->clientScript->registerScript('SchedulesForm', <<<EOT
  \$(document).on('focus', '#schedules table tbody tr:last-child', function() {
    \$(this).clone().insertAfter(this);
    \$('.datetime-picker').datetimepicker({
      autoclose: true
    });
  });
EOT
);
    }
Beispiel #9
0
 public function actionModify()
 {
     $routeId = intval($_GET['route_id']) ? intval($_GET['route_id']) : '';
     if (!$routeId) {
         exit;
     }
     $route = Route::model()->find('id=:id', array(':id' => $routeId));
     if (!$route) {
         exit;
     }
     $scheduleId = $route->schedule;
     $arr = explode(',', $scheduleId);
     $str = str_replace(',', ' or id = ', $scheduleId);
     //echo $str;
     $criteria = new CDbCriteria();
     // 创建CDbCriteria对象
     $criteria->condition = 'id = ' . $str;
     // 设置查询条件
     // echo $criteria->condition;
     $model = Schedule::model()->findAll($criteria);
     $boat = Boat::model()->findAll();
     $area = Area::model()->findAll();
     $company = Company::model()->findAll();
     $port = Port::model()->findAll();
     $continent = Continent::model()->findAll();
     $this->render('modify', array('route' => $route, 'days' => $route->days, 'boat' => $boat, 'area' => $area, 'port' => $port, 'company' => $company, 'continent' => $continent));
 }
Beispiel #10
0
 public function resume()
 {
     $success = false;
     if (!$this->hasAttribute('suspended')) {
         $this->addError('suspended', Yii::t('mc', 'Attribute not found, database up to date?'));
     } else {
         $this->suspended = 0;
         $success = $this->save(false);
     }
     Yii::log('Resumed server ' . $this->id);
     $scheds = Schedule::model()->findAllByAttributes(array('server_id' => $this->id, 'status' => Schedule::Suspended));
     foreach ($scheds as $sched) {
         $sched->status = Schedule::Scheduled;
         $sched->save(false);
     }
     return $success;
 }
Beispiel #11
0
 protected function afterSave()
 {
     if (Yii::app() instanceof CConsoleApplication) {
         return;
     }
     $isAdmin = Yii::app()->user->checkRole(User::ROLE_DELEGATE);
     //处理代表和主办
     foreach (array('organizer', 'delegate') as $attribute) {
         $attributeId = $attribute . '_id';
         $oldValues = array_values(CHtml::listData($this->{$attribute}, $attributeId, $attributeId));
         $newValues = array_values((array) $this->{$attribute . 's'});
         sort($oldValues);
         sort($newValues);
         if ($oldValues != $newValues) {
             $modelName = 'Competition' . ucfirst($attribute);
             foreach ($oldValues as $value) {
                 if (!in_array($value, $newValues) && $isAdmin) {
                     $modelName::model()->deleteAllByAttributes(array('competition_id' => $this->id, $attributeId => $value));
                 }
             }
             foreach ($newValues as $value) {
                 if (!in_array($value, $oldValues)) {
                     $model = new $modelName();
                     $model->competition_id = $this->id;
                     $model->{$attribute . '_id'} = $value;
                     $model->save();
                 }
             }
         }
     }
     //处理赛程
     $schedules = $this->schedules;
     if (!empty($schedules['start_time'])) {
         Schedule::model()->deleteAllByAttributes(array('competition_id' => $this->id));
         foreach ($schedules['start_time'] as $key => $startTime) {
             if (empty($startTime) || !isset($schedules['end_time'][$key]) || empty($schedules['end_time'][$key])) {
                 continue;
             }
             $model = new Schedule();
             $model->competition_id = $this->id;
             $model->start_time = strtotime($startTime);
             $model->end_time = strtotime($schedules['end_time'][$key]);
             $model->day = $schedules['day'][$key];
             $model->stage = $schedules['stage'][$key];
             $model->event = $schedules['event'][$key];
             $model->group = $schedules['group'][$key];
             $model->round = $schedules['round'][$key];
             $model->format = $schedules['format'][$key];
             $model->number = intval($schedules['number'][$key]);
             $model->cut_off = intval($schedules['cut_off'][$key]);
             $model->time_limit = intval($schedules['time_limit'][$key]);
             $model->save(false);
         }
     }
     //处理地址
     $oldLocations = $this->location;
     foreach ($this->locations as $key => $value) {
         if (isset($oldLocations[$key])) {
             $location = $oldLocations[$key];
         } else {
             $location = new CompetitionLocation();
             $location->competition_id = $this->id;
             $location->location_id = $key;
         }
         $location->attributes = $value;
         $location->save(false);
     }
     if ($this->isOld()) {
         $this->old->save(false);
     }
 }
 /**
  * @param $id
  *      准备修改的预约id
  * @param $time_modify
  *      修改后的时间
  * @param $modify_time_count
  *      准备修改的时间段的已安排预约数
  */
 private function maintainSchedule($id, $time_modify, $modify_time_count)
 {
     define("AM_AVAILABLE", 0x4);
     //上午可用
     define("AM_NOT_AVAILABLE", 0x3);
     //上午不可用
     define("PM_AVAILABLE", 0x2);
     //下午可用
     define("PM_NOT_AVAILABLE", 0x5);
     //下午不可用
     define("NT_AVAILABLE", 0x1);
     //傍晚可用
     define("NT_NOT_AVAILABLE", 0x6);
     //傍晚不可用
     $aptm_model = Aptm::model();
     $schedule_model = Schedule::model();
     //取得修改前的日期的tbl_schedule的flag
     $query = 'select * from tbl_appointment where pk_aptm_id=' . $id;
     $aptm_info = $aptm_model->findBySql($query);
     $date_original = '0000';
     $hour_original = 0;
     if (isset($aptm_info)) {
         $time_original = $aptm_info->aptm_time;
         $date_original = date('md', strtotime("{$time_original}"));
         $hour_original = date('H', strtotime("{$time_original}"));
         //            echo "<br>"."time_original: ".$aptm_info->aptm_time;  //log
     }
     $query = 'select * from tbl_schedule where sch_date=' . $date_original;
     $schedule_info_before = $schedule_model->findBySql($query);
     //变更修改前的flag
     //对于修改前的预约来说,肯定是减少,所以只需要无脑的把flag去掉就行(变为1)
     if (isset($schedule_info_before)) {
         //            echo "<br>"."schedule_info_before: ".$schedule_info_before->sch_flag;  //log
         if ($hour_original < 12) {
             $schedule_info_before->sch_flag |= AM_AVAILABLE;
         } elseif ($hour_original >= 12 && $hour_original < 17) {
             $schedule_info_before->sch_flag |= PM_AVAILABLE;
         } elseif ($hour_original >= 17) {
             $schedule_info_before->sch_flag |= NT_AVAILABLE;
         } else {
         }
         //            echo "<br>"."schedule_info_before_change: ".$schedule_info_before->sch_flag;  //log
     }
     //因为变更前后有可能是同一天,所以要先save一下
     $schedule_info_before->save();
     //取得修改后的日期的tbl_schedule的flag
     //        echo "<br>"."time_modify: ".$time_modify;   //log
     $date_modify = date('md', strtotime("{$time_modify}"));
     $query = 'select * from tbl_schedule where sch_date=' . $date_modify;
     $schedule_info_after = $schedule_model->findBySql($query);
     //变更修改后的flag
     //对于修改后的预约来说,需要看同一时间段的预约是否会到4个,如果到了4个才需要修改flag
     if (isset($schedule_info_after)) {
         //            echo "<br>"."schedule_info_after: ".$schedule_info_after->sch_flag;  //log
         //            echo "<br>"."modify_time_count: ".$modify_time_count;  //log
         if ($modify_time_count >= 3) {
             $hour_modify = date('H', strtotime("{$time_modify}"));
             if ($hour_modify < 12) {
                 $schedule_info_after->sch_flag &= AM_NOT_AVAILABLE;
             } elseif ($hour_modify >= 12 && $hour_modify < 17) {
                 $schedule_info_after->sch_flag &= PM_NOT_AVAILABLE;
             } elseif ($hour_modify >= 17) {
                 $schedule_info_after->sch_flag &= NT_NOT_AVAILABLE;
             } else {
             }
         }
         //            echo "<br>"."schedule_info_after_change: ".$schedule_info_after->sch_flag;  //log
     }
     $schedule_info_after->save();
     return;
 }