Exemplo n.º 1
0
 public function actionHoliday()
 {
     if (isset($_GET['date'])) {
         $qry_year = $_GET['date'];
     } else {
         $qry_year = date('Y');
         //年份
     }
     //$year=date('Y');
     $month = date('n');
     //月份
     $day = date('d');
     //天數
     $months = array('一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月');
     //月數
     if (isset($_POST['qry_year'])) {
         $qry_year = $_POST['qry_year'];
     }
     //取輸入年份的資料
     /*defalut annual calendar vacation background color is red*/
     if (isset($_POST['vacation'])) {
         $_varr = array();
         //假日array()
         for ($reihe = 1; $reihe <= 3; $reihe++) {
             for ($spalte = 1; $spalte <= 4; $spalte++) {
                 $this_month = ($reihe - 1) * 4 + $spalte;
                 $erster = date('w', mktime(0, 0, 0, $this_month, 1, $qry_year));
                 $insgesamt = date('t', mktime(0, 0, 0, $this_month, 1, $qry_year));
                 $i = 1;
                 //月份期不足10補0使用
                 if ($this_month < 10) {
                     $this_month = '0' . $this_month;
                 }
                 while ($i <= $insgesamt) {
                     $rest = ($i + $erster - 1) % 7;
                     //日期不足10補0使用
                     if ($i < 10) {
                         $i = '0' . $i;
                     }
                     $holiday = "{$qry_year}{$this_month}{$i}";
                     $vacation = $this->isWeekend($holiday);
                     //判斷是否為星期六、日
                     //是六日、則被$_varr變數存入
                     if ($vacation == true) {
                         array_push($_varr, $holiday);
                     }
                     $i++;
                 }
             }
         }
         for ($i = 0; $i < count($_varr); $i++) {
             //從DB判斷日期是否存在
             $judgement = TbaHoliday::model()->findByAttributes(array(), $conditon = " holiday = '{$_varr[$i]}' ");
             $holiday_model = new TbaHoliday();
             // object instance
             //if假日不存在新增至DB
             if (!isset($judgement)) {
                 $holiday_model->holiday = $_varr[$i];
                 $holiday_model->save();
             }
         }
         //CVarDumper::dump( isWeekend('2014-01-06'),10,true);
     }
     if (isset($_GET['update'])) {
         if (isset($_GET['holiday'])) {
             $qry_year = $_GET['date'];
             //得到年分
             $holiday = $_GET['holiday'];
             //取得所點選日期
             //從DB判斷日期是否存在
             $judgement = TbaHoliday::model()->findByAttributes(array(), $conditon = " holiday = '{$holiday}' ");
             $holiday_model = new TbaHoliday();
             // object instance
             //if日期存在則抓出id
             if (isset($judgement)) {
                 $model = TbaHoliday::model()->findByPk($judgement->id);
             }
             //日期不是空值
             if (isset($model)) {
                 $this->loadModel($judgement->id)->delete();
             } else {
                 $holiday_model->holiday = $holiday;
                 $holiday_model->save();
             }
             $this->redirect(array('holiday', 'date' => $qry_year));
             //跳轉回holiday頁面
             // CVarDumper::dump( $model,10,true);
         } else {
             Yii::app()->user->setFlash('error', '資料錯誤!');
         }
     }
     $sql = "SELECT holiday FROM tba_holiday where MID(holiday,1,4) = '{$qry_year}'";
     $_arr = Yii::app()->db->createCommand($sql)->queryAll();
     //將雙層array轉成單層array()
     $result = array();
     for ($i = 0; $i < count($_arr); $i++) {
         array_push($result, $_arr[$i]['holiday']);
     }
     $this->render('holiday', array('qry_year' => $qry_year, 'month' => $month, 'day' => $day, 'months' => $months, 'result' => $result));
 }
Exemplo n.º 2
0
 /**
  * 查詢JIT假日, 回傳曰期是否存在,
  * @param String $date - 年月 ( 201405 )
  * @return boolean - 是否為日期
  */
 function getHolidayByDate($date)
 {
     //預設false
     $existholiday = false;
     //從DB判斷日期是否存在
     $judge = TbaHoliday::model()->findByAttributes(array(), $conditon = " holiday = '{$date}' ");
     //當$judge存在,則$existholiday為true
     if (isset($judge)) {
         $existholiday = true;
     }
     return $existholiday;
 }