$name = $request['name'][$i]; if (!empty($date) && !empty($name)) { $holidayData[] = array('holiday_date' => $date, 'holiday_name' => $name); } } ksort($holidayData); //データ登録処理 if (count($holidayData) > 0) { //登録 if (!$holidayObj->updateHoliday($target_year, $holidayData)) { throw new Exception("休日データ登録時にエラーが発生しました。"); } //キャッシュデータ削除 exec("rm " . DATA_PATH . "calendar/*"); $param['message'] = "データの登録が完了しました。"; } } //休日情報の読み込み $holidayData = $holidayObj->getData($target_year); //パラメータセット $param['data'] = $holidayData; $param['edit_cnt'] = $holidayObj->getEditCnt(); $param['year_list'] = $holidayObj->getYearList(); $param['target_year'] = $target_year; //レンダリング renderTemplate('maintenance/holiday/index.tpl', $param); } catch (Exception $e) { $param['errors'][] = "システムエラーが発生しました。"; renderTemplate('error.tpl', $param); exit; }
/** * 1か月分の日報取得 * * @param */ function getTotalDailyReport($id, $year, $month) { /* $date = $year; $date .= sprintf('%02d', $month); $term_id = $this->getTermIdArray($date); $start = reset($term_id); $end = end($term_id); $sql = 'SELECT te.week_num, te.start_date, te.end_date, re.title, re.`comment`, re.holiday_flg, re.sort_order, te.start_date + re.sort_order as date' . ' FROM m_term te inner join t_report re on te.id = re.term_id WHERE year = :year' . ' AND staff_id = :id AND te.id BETWEEN :start AND :end ORDER BY start_date, sort_order'; // $sql = 'SELECT te.week_num, te.start_date, te.end_date, re.title, re.`comment`, re.holiday_flg, re.sort_order' // . ' FROM m_term te inner join t_report re on te.id = re.term_id WHERE year = :year' // . ' AND month = :month AND staff_id = :id ORDER BY start_date, sort_order'; $searchParam = array( 'id' => $id, 'year' => $year, 'start' => $start['id'], 'end' => $end['id'] ); */ $sql = "SELECT " . "mr.* " . "FROM " . "( " . "SELECT " . "te.week_num, " . "te.start_date, " . "te.end_date, " . "re.title, " . "re.`comment`, " . "re.holiday_flg, " . "re.sort_order, " . "DATE_FORMAT(DATE_ADD( date(te.start_date), interval re.sort_order day ), '%Y%m%d') AS DATE " . "FROM " . "m_term te " . "INNER JOIN t_report re ON te.id = re.term_id " . "WHERE " . "(te.end_date >= :start_date AND te.start_date <= :end_date) AND " . "re.staff_id = :staff_id " . ") AS mr " . "WHERE " . "mr.DATE BETWEEN :start_date AND :end_date " . "ORDER BY " . "mr.DATE ASC "; $time = mktime(0, 0, 0, intval($month), 1, intval($year)); $start_date = date("Ym01", $time); $end_date = date("Ymt", $time); $searchParam = array('staff_id' => $id, 'start_date' => $start_date, 'end_date' => $end_date); $conn = DbControl::getInstance(); $conn->dbConnect(DbControl::SLAVE_DB); $res = $conn->dbExecFetchAll(DbControl::SLAVE_DB, $sql, $searchParam); $tmp = array(); foreach ($res as $row) { $tmp[$row['DATE']] = $row; } $res = $tmp; include_once "maintenance/class.Holiday.php"; $holidays = Holiday::getData($year); $monthy_data = array(); for ($i = intval($start_date); $i <= intval($end_date); $i++) { if (array_key_exists($i, $res)) { $monthly_data[] = $res["{$i}"]; } else { $monthly_data[]['DATE'] = $i; } } foreach ($monthly_data as $mkey => $mval) { foreach ($holidays as $hkey => $hval) { if ($mval['DATE'] != $hval['holiday_date']) { $date = $mval['DATE']; $sort_order = $this->startMon(date('w', strtotime("{$date}"))); if ($sort_order >= 5) { $monthly_data[$mkey]['holiday_flg'] = 1; } } else { $monthly_data[$mkey]['holiday_flg'] = 1; } } } #var_dump($holidays);exit; #var_dump($monthly_data); #exit; #var_dump($res);exit; // $lastday = date("t", mktime(0,0,0,$month,1,$year)); // $date = '/^'.$date.'/'; // if(count($res) > 0) { // for($i=0;$i<count($res);$i++) { // if(!preg_match($date, $res[$i]['date'])) { // } // } // } // $holiday = $this->setHolidaySortOrder($year, sprintf('%02d', $month)); // for($i=0;$i<count($holiday);$i++) { // $holiday_flg[$holiday[$i]['week_num']][$holiday[$i]['sort_order']] = $holiday[$i]; // } // //指定月の初めの曜日を取得 // $week_val = $this->startMon(date('w',strtotime("$year/$month/1"))); // $num =$week_val; // if($num == 5 || $num == 6) { // $wnum = 0; // } else { // $wnum = 1; // } // for($d=0;($d <= $lastday-1);$d++){ // if(isset($res[$d]['sort_order']) && $num != $res[$d]['sort_order']) { // //日にちが違う場合 // if($num >=5) { // //休日 // $this->array_insert($res, array('sort_order' =>$num, 'holiday_flg' => 1), $d); // } else { // //平日 // if(isset($holiday_flg[$wnum][$num])) { // $this->array_insert($res, array('sort_order' =>$num, 'holiday_flg' => 1), $d); // } else { // $this->array_insert($res, array('sort_order' =>$num, 'holiday_flg' => 0), $d); // } // } // } elseif(isset($res[$d]['sort_order']) && $num == $res[$d]['sort_order']) { // if($wnum != $res[$d]['week_num']) { // //日にち一緒だけど、週が違う // //配列追加 // if($num >= 5) { // //休日 // $this->array_insert($res, array('sort_order' =>$num, 'holiday_flg' => 1), $d); // } else { // //平日 // if(isset($holiday_flg[$wnum][$num])) { // $this->array_insert($res, array('sort_order' =>$num, 'holiday_flg' => 1), $d); // } else { // $this->array_insert($res, array('sort_order' =>$num, 'holiday_flg' => 0), $d); // } // } // } // } elseif(!isset($res[$d]['sort_order'])) { // if($num >= 5) { // //休日 // $res[$d] = array('sort_order' =>$num, 'holiday_flg' => 1); // } else { // //平日 // // echo $wnum.'-----'.$num.'<br>'; // if(isset($holiday_flg[$wnum][$num])) { // $res[$d] = array('sort_order' =>$num, 'holiday_flg' => 1); // } else { // $res[$d] = array('sort_order' =>$num, 'holiday_flg' => 0); // } // } // } // if($num == 6) { // $num = 0; // $wnum++; // } else { // $num++; // } // } // データベースを切断する $conn->dbClose(DbControl::SLAVE_DB); return $monthly_data; }