| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 6 | * |
|---|
| 7 | * http://www.lockon.co.jp/ |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or |
|---|
| 10 | * modify it under the terms of the GNU General Public License |
|---|
| 11 | * as published by the Free Software Foundation; either version 2 |
|---|
| 12 | * of the License, or (at your option) any later version. |
|---|
| 13 | * |
|---|
| 14 | * This program is distributed in the hope that it will be useful, |
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | * GNU General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU General Public License |
|---|
| 20 | * along with this program; if not, write to the Free Software |
|---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | /* 日時表示用クラス */ |
|---|
| 25 | class SC_Date |
|---|
| 26 | { |
|---|
| 27 | public $start_year; |
|---|
| 28 | public $month; |
|---|
| 29 | public $day; |
|---|
| 30 | public $end_year; |
|---|
| 31 | |
|---|
| 32 | public static $arrHoliday = NULL; |
|---|
| 33 | public static $arrRegularHoliday = NULL; |
|---|
| 34 | |
|---|
| 35 | // コンストラクタ |
|---|
| 36 | public function __construct($start_year='', $end_year='') |
|---|
| 37 | { |
|---|
| 38 | if ($start_year) $this->setStartYear($start_year); |
|---|
| 39 | if ($end_year) $this->setEndYear($end_year); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | public function setStartYear($year) |
|---|
| 43 | { |
|---|
| 44 | $this->start_year = $year; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | public function getStartYear() |
|---|
| 48 | { |
|---|
| 49 | return $this->start_year; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | /** |
|---|
| 53 | * @param string $endYear |
|---|
| 54 | */ |
|---|
| 55 | public function setEndYear($endYear) |
|---|
| 56 | { |
|---|
| 57 | $this->end_year = $endYear; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | public function getEndYear() |
|---|
| 61 | { |
|---|
| 62 | return $this->end_year; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | public function setMonth($month) |
|---|
| 66 | { |
|---|
| 67 | $this->month = $month; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | public function setDay($day) |
|---|
| 71 | { |
|---|
| 72 | $this->day = $day; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | /** |
|---|
| 76 | * 年プルダウン用の配列を返す |
|---|
| 77 | * FIXME $default_year に一致いる行が無かった場合、先頭か末尾に付加すべきと思われる。 |
|---|
| 78 | * @param string $year XMLファイル名 |
|---|
| 79 | * @param bool|string $default_year |
|---|
| 80 | * false 「選択なし」は含めない。 |
|---|
| 81 | * true 「選択なし」は含める。 |
|---|
| 82 | * string 「選択なし」は指定された値の下に付加する。 |
|---|
| 83 | * @param string $default_key |
|---|
| 84 | */ |
|---|
| 85 | public function getYear($year = '', $default_year = false, $default_key = '----') |
|---|
| 86 | { |
|---|
| 87 | if ($year) $this->setStartYear($year); |
|---|
| 88 | |
|---|
| 89 | $year = $this->start_year; |
|---|
| 90 | if (! $year) $year = DATE('Y'); |
|---|
| 91 | |
|---|
| 92 | $end_year = $this->end_year; |
|---|
| 93 | if (! $end_year) $end_year = (DATE('Y') + 3); |
|---|
| 94 | |
|---|
| 95 | $year_array = array(); |
|---|
| 96 | |
|---|
| 97 | if ($default_year === true) { |
|---|
| 98 | $year_array[$default_key] = '----'; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | for ($i = $year; $i <= $end_year; $i++) { |
|---|
| 102 | $year_array[$i] = $i; |
|---|
| 103 | if ($default_year !== true && strlen($default_year) >= 1 && $i == $default_year) { |
|---|
| 104 | $year_array[$default_key] = '----'; |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | return $year_array; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | public function getZeroYear($year = '') |
|---|
| 112 | { |
|---|
| 113 | if ($year) $this->setStartYear($year); |
|---|
| 114 | |
|---|
| 115 | $year = $this->start_year; |
|---|
| 116 | if (! $year) $year = DATE('Y'); |
|---|
| 117 | |
|---|
| 118 | $end_year = $this->end_year; |
|---|
| 119 | if (! $end_year) $end_year = (DATE('Y') + 3); |
|---|
| 120 | |
|---|
| 121 | $year_array = array(); |
|---|
| 122 | |
|---|
| 123 | for ($i = $year; $i <= $end_year; $i++) { |
|---|
| 124 | $key = substr($i, -2); |
|---|
| 125 | $year_array[$key] = $key; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | return $year_array; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | public function getZeroMonth() |
|---|
| 132 | { |
|---|
| 133 | $month_array = array(); |
|---|
| 134 | for ($i=1; $i <= 12; $i++) { |
|---|
| 135 | $val = sprintf('%02d', $i); |
|---|
| 136 | $month_array[$val] = $val; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | return $month_array; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | public function getMonth($default = false) |
|---|
| 143 | { |
|---|
| 144 | $month_array = array(); |
|---|
| 145 | |
|---|
| 146 | if ($default) $month_array[''] = '--'; |
|---|
| 147 | |
|---|
| 148 | for ($i=0; $i < 12; $i++) { |
|---|
| 149 | $month_array[$i + 1 ] = $i + 1; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | return $month_array; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | public function getDay($default = false) |
|---|
| 156 | { |
|---|
| 157 | $day_array = array(); |
|---|
| 158 | |
|---|
| 159 | if ($default) $day_array[''] = '--'; |
|---|
| 160 | |
|---|
| 161 | for ($i=0; $i < 31; $i++) { |
|---|
| 162 | $day_array[ $i + 1 ] = $i + 1; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | return $day_array; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | public function getHour() |
|---|
| 169 | { |
|---|
| 170 | $hour_array = array(); |
|---|
| 171 | for ($i=0; $i<=23; $i++) { |
|---|
| 172 | $hour_array[$i] = $i; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | return $hour_array; |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | public function getMinutes() |
|---|
| 179 | { |
|---|
| 180 | $minutes_array = array(); |
|---|
| 181 | for ($i=0; $i<=59; $i++) { |
|---|
| 182 | $minutes_array[$i] = $i; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | return $minutes_array; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | public function getMinutesInterval() |
|---|
| 189 | { |
|---|
| 190 | $minutes_array = array('00'=>'00', '30'=>'30'); |
|---|
| 191 | |
|---|
| 192 | return $minutes_array; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | /** |
|---|
| 196 | * 休日の判定. |
|---|
| 197 | * |
|---|
| 198 | * @param integer $year |
|---|
| 199 | * @param integer $month |
|---|
| 200 | * @param integer $day |
|---|
| 201 | * @return boolean 休日の場合はtrue |
|---|
| 202 | */ |
|---|
| 203 | public function isHoliday($year, $month, $day) |
|---|
| 204 | { |
|---|
| 205 | if (is_null(SC_Date_Ex::$arrHoliday)) $this->setArrHoliday(); |
|---|
| 206 | if (is_null(SC_Date_Ex::$arrRegularHoliday)) $this->setRegularHoliday(); |
|---|
| 207 | |
|---|
| 208 | if (!empty(SC_Date_Ex::$arrHoliday[$month])) { |
|---|
| 209 | if (in_array($day, SC_Date_Ex::$arrHoliday[$month])) { |
|---|
| 210 | return true; |
|---|
| 211 | } |
|---|
| 212 | } |
|---|
| 213 | if (!empty(SC_Date_Ex::$arrRegularHoliday)) { |
|---|
| 214 | $day = date('w', mktime(0, 0, 0, $month, $day, $year)); |
|---|
| 215 | if (in_array($day, SC_Date_Ex::$arrRegularHoliday)) { |
|---|
| 216 | return true; |
|---|
| 217 | } |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | return false; |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | /** |
|---|
| 224 | * 休日情報をスタティック変数にセット. |
|---|
| 225 | * |
|---|
| 226 | * @return void |
|---|
| 227 | */ |
|---|
| 228 | private function setArrHoliday() |
|---|
| 229 | { |
|---|
| 230 | $objHoliday = new SC_Helper_Holiday_Ex(); |
|---|
| 231 | $holiday = $objHoliday->getList(); |
|---|
| 232 | $arrHoliday = array(); |
|---|
| 233 | foreach ($holiday AS $val) { |
|---|
| 234 | $arrHoliday[$val['month']][] = $val['day']; |
|---|
| 235 | } |
|---|
| 236 | SC_Date_Ex::$arrHoliday = $arrHoliday; |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | /** |
|---|
| 240 | * 定休日情報をスタティック変数にセット. |
|---|
| 241 | * |
|---|
| 242 | * @return void |
|---|
| 243 | */ |
|---|
| 244 | private function setRegularHoliday() |
|---|
| 245 | { |
|---|
| 246 | $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
|---|
| 247 | SC_Date_Ex::$arrRegularHoliday = explode('|', $arrInfo['regular_holiday_ids']); |
|---|
| 248 | } |
|---|
| 249 | } |
|---|