| @@ -1,102 +1,182 @@ | ||
| 1 | -<?php | |
| 2 | -class calendarData { | |
| 3 | - | |
| 4 | - var $_year; | |
| 5 | - var $_month; | |
| 6 | - var $_day; | |
| 7 | - var $_row; | |
| 8 | - | |
| 9 | - var $_date; | |
| 10 | - var $_datetext; | |
| 11 | - | |
| 12 | - function calendarData() { | |
| 13 | - $this->_row = 0; | |
| 14 | - } | |
| 15 | - | |
| 16 | - function setToday($year, $month, $day) { | |
| 17 | - $this->_year = $year; | |
| 18 | - $this->_month = $month; | |
| 19 | - $this->_day = $day; | |
| 20 | - } | |
| 21 | - | |
| 22 | - function getDate($row, $d) {return $this->_date[$row][$d];} | |
| 23 | - function getDateText($row, $d) {return $this->_datetext[$row][$d];} | |
| 24 | - function getRow() {return $this->_row;} | |
| 25 | - | |
| 26 | - function setCalendarData() { | |
| 27 | - | |
| 28 | - $day = 1; // 当月開始日に設定 | |
| 29 | - $firstw = getWeek($this->_year, $this->_month, $day); // 当月開始日の曜日 | |
| 30 | - $lastday = getLastDay($this->_year, $this->_month); // 当月最終日 | |
| 31 | - $lastw = getWeek($this->_year, $this->_month, $lastday); // 当月最終日の曜日 | |
| 32 | - | |
| 33 | - // 1週目 | |
| 34 | - for ($d = 0; $d <= 6; $d++) { | |
| 35 | - if ($firstw == $d) { | |
| 36 | - $this->_date[0][$d] = sprintf("%04d-%02d-%02d", $this->_year, $this->_month, $day); | |
| 37 | - $this->_datetext[0][$d] = $day; | |
| 38 | - } elseif ($firstw < $d) { | |
| 39 | - list($this->_year, $this->_month, $day) = getNextDay($this->_year, $this->_month, $day); | |
| 40 | - $this->_date[0][$d] = sprintf("%04d-%02d-%02d", $this->_year, $this->_month, $day); | |
| 41 | - $this->_datetext[0][$d] = $day; | |
| 42 | - } else { | |
| 43 | - $this->_date[0][$d] = ""; | |
| 44 | - $this->_datetext[0][$d] = ""; | |
| 45 | - } | |
| 46 | - } | |
| 47 | - // 2~4週目 | |
| 48 | - for ($d = 0; $d <= 6; $d++) { | |
| 49 | - list($this->_year, $this->_month, $day) = getNextDay($this->_year, $this->_month, $day); | |
| 50 | - $this->_date[1][$d] = sprintf("%04d-%02d-%02d", $this->_year, $this->_month, $day); | |
| 51 | - $this->_datetext[1][$d] = $day; | |
| 52 | - } | |
| 53 | - for ($d = 0; $d <= 6; $d++) { | |
| 54 | - list($this->_year, $this->_month, $day) = getNextDay($this->_year, $this->_month, $day); | |
| 55 | - $this->_date[2][$d] = sprintf("%04d-%02d-%02d", $this->_year, $this->_month, $day); | |
| 56 | - $this->_datetext[2][$d] = $day; | |
| 57 | - } | |
| 58 | - for ($d = 0; $d <= 6; $d++) { | |
| 59 | - list($this->_year, $this->_month, $day) = getNextDay($this->_year, $this->_month, $day); | |
| 60 | - $this->_date[3][$d] = sprintf("%04d-%02d-%02d", $this->_year, $this->_month, $day); | |
| 61 | - $this->_datetext[3][$d] = $day; | |
| 62 | - } | |
| 63 | - // 5週目 | |
| 64 | - for ($d = 0; $d <= 6; $d++) { | |
| 65 | - if ($lastday == $day) { | |
| 66 | - break; | |
| 67 | - } else { | |
| 68 | - list($this->_year, $this->_month, $day) = getNextDay($this->_year, $this->_month, $day); | |
| 69 | - $this->_date[4][$d] = sprintf("%04d-%02d-%02d", $this->_year, $this->_month, $day); | |
| 70 | - $this->_datetext[4][$d] = $day; | |
| 71 | - } | |
| 72 | - } | |
| 73 | - if ($d <= 6) { | |
| 74 | - while ($d <= 6) { | |
| 75 | - $this->_date[4][$d] = ""; | |
| 76 | - $this->_datetext[4][$d] = ""; | |
| 77 | - $d++; | |
| 78 | - } | |
| 79 | - } else { | |
| 80 | - // 6週目 | |
| 81 | - for ($d = 0; $d <= 6; $d++) { | |
| 82 | - if ($lastday == $day) { | |
| 83 | - break; | |
| 84 | - } else { | |
| 85 | - list($this->_year, $this->_month, $day) = getNextDay($this->_year, $this->_month, $day); | |
| 86 | - $this->_date[5][$d] = sprintf("%04d-%02d-%02d", $this->_year, $this->_month, $day); | |
| 87 | - $this->_datetext[5][$d] = $day; | |
| 88 | - } | |
| 89 | - } | |
| 90 | - if ($d > 0) { | |
| 91 | - while ($d <= 6) { | |
| 92 | - $this->_date[5][$d] = ""; | |
| 93 | - $this->_datetext[5][$d] = ""; | |
| 94 | - $d++; | |
| 95 | - } | |
| 96 | - } | |
| 97 | - } | |
| 98 | - | |
| 99 | - $this->_row = count($this->_date); | |
| 100 | - } | |
| 101 | -} | |
| 102 | -?> | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Calendar class | |
| 4 | + * | |
| 5 | + * @package Welcart | |
| 6 | + */ | |
| 7 | +class calendarData { | |
| 8 | + | |
| 9 | + /** | |
| 10 | + * Year | |
| 11 | + * | |
| 12 | + * @var string | |
| 13 | + */ | |
| 14 | + public $_year; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * Month | |
| 18 | + * | |
| 19 | + * @var string | |
| 20 | + */ | |
| 21 | + public $_month; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * Day | |
| 25 | + * | |
| 26 | + * @var string | |
| 27 | + */ | |
| 28 | + public $_day; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * Row weeks | |
| 32 | + * | |
| 33 | + * @var string | |
| 34 | + */ | |
| 35 | + public $_row; | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * Date | |
| 39 | + * | |
| 40 | + * @var string | |
| 41 | + */ | |
| 42 | + public $_date; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Date text | |
| 46 | + * | |
| 47 | + * @var string | |
| 48 | + */ | |
| 49 | + public $_datetext; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * Constructor | |
| 53 | + */ | |
| 54 | + public function __construct() { | |
| 55 | + $this->_row = 0; | |
| 56 | + $this->_date = array(); | |
| 57 | + $this->_datetext = array(); | |
| 58 | + } | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * Set Today | |
| 62 | + * | |
| 63 | + * @param int $year Year. | |
| 64 | + * @param int $month Month. | |
| 65 | + * @param int $day Day. | |
| 66 | + * @return void | |
| 67 | + */ | |
| 68 | + public function setToday( $year, $month, $day ) { | |
| 69 | + $this->_year = $year; | |
| 70 | + $this->_month = $month; | |
| 71 | + $this->_day = $day; | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * Get date | |
| 76 | + * | |
| 77 | + * @param int $row Row. | |
| 78 | + * @param int $d Day. | |
| 79 | + * @return string | |
| 80 | + */ | |
| 81 | + public function getDate( $row, $d ) { | |
| 82 | + return $this->_date[ $row ][ $d ]; | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Get date text | |
| 87 | + * | |
| 88 | + * @param int $row Row. | |
| 89 | + * @param int $d Day. | |
| 90 | + * @return string | |
| 91 | + */ | |
| 92 | + public function getDateText( $row, $d ) { | |
| 93 | + return $this->_datetext[ $row ][ $d ]; | |
| 94 | + } | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * Get row | |
| 98 | + * | |
| 99 | + * @return int | |
| 100 | + */ | |
| 101 | + public function getRow() { | |
| 102 | + return $this->_row; | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * Set Calendar | |
| 107 | + */ | |
| 108 | + public function setCalendarData() { | |
| 109 | + $day = 1; /* 当月開始日に設定 */ | |
| 110 | + $firstw = getWeek( $this->_year, $this->_month, $day ); /* 当月開始日の曜日 */ | |
| 111 | + $lastday = getLastDay( $this->_year, $this->_month ); /* 当月最終日 */ | |
| 112 | + $lastw = getWeek( $this->_year, $this->_month, $lastday ); /* 当月最終日の曜日 */ | |
| 113 | + | |
| 114 | + /* 1週目 */ | |
| 115 | + for ( $d = 0; $d <= 6; $d++ ) { | |
| 116 | + if ( (int) $firstw === $d ) { | |
| 117 | + $this->_date[0][ $d ] = sprintf( '%04d-%02d-%02d', $this->_year, $this->_month, $day ); | |
| 118 | + $this->_datetext[0][ $d ] = $day; | |
| 119 | + } elseif ( $firstw < $d ) { | |
| 120 | + list( $this->_year, $this->_month, $day ) = getNextDay( $this->_year, $this->_month, $day ); | |
| 121 | + $this->_date[0][ $d ] = sprintf( '%04d-%02d-%02d', $this->_year, $this->_month, $day ); | |
| 122 | + $this->_datetext[0][ $d ] = $day; | |
| 123 | + } else { | |
| 124 | + $this->_date[0][ $d ] = ''; | |
| 125 | + $this->_datetext[0][ $d ] = ''; | |
| 126 | + } | |
| 127 | + } | |
| 128 | + /* 2~4週目 */ | |
| 129 | + for ( $d = 0; $d <= 6; $d++ ) { | |
| 130 | + list( $this->_year, $this->_month, $day ) = getNextDay( $this->_year, $this->_month, $day ); | |
| 131 | + $this->_date[1][ $d ] = sprintf( '%04d-%02d-%02d', $this->_year, $this->_month, $day ); | |
| 132 | + $this->_datetext[1][ $d ] = $day; | |
| 133 | + } | |
| 134 | + for ( $d = 0; $d <= 6; $d++ ) { | |
| 135 | + list( $this->_year, $this->_month, $day ) = getNextDay( $this->_year, $this->_month, $day ); | |
| 136 | + $this->_date[2][ $d ] = sprintf( '%04d-%02d-%02d', $this->_year, $this->_month, $day ); | |
| 137 | + $this->_datetext[2][ $d ] = $day; | |
| 138 | + } | |
| 139 | + for ( $d = 0; $d <= 6; $d++ ) { | |
| 140 | + list( $this->_year, $this->_month, $day ) = getNextDay( $this->_year, $this->_month, $day ); | |
| 141 | + $this->_date[3][ $d ] = sprintf( '%04d-%02d-%02d', $this->_year, $this->_month, $day ); | |
| 142 | + $this->_datetext[3][ $d ] = $day; | |
| 143 | + } | |
| 144 | + /* 5週目 */ | |
| 145 | + for ( $d = 0; $d <= 6; $d++ ) { | |
| 146 | + if ( (int) $lastday === (int) $day ) { | |
| 147 | + break; | |
| 148 | + } else { | |
| 149 | + list( $this->_year, $this->_month, $day ) = getNextDay( $this->_year, $this->_month, $day ); | |
| 150 | + $this->_date[4][ $d ] = sprintf( '%04d-%02d-%02d', $this->_year, $this->_month, $day ); | |
| 151 | + $this->_datetext[4][ $d ] = $day; | |
| 152 | + } | |
| 153 | + } | |
| 154 | + if ( 0 < $d && $d <= 6 ) { | |
| 155 | + while ( $d <= 6 ) { | |
| 156 | + $this->_date[4][ $d ] = ''; | |
| 157 | + $this->_datetext[4][ $d ] = ''; | |
| 158 | + $d++; | |
| 159 | + } | |
| 160 | + } elseif ( 0 !== $d ) { | |
| 161 | + /* 6週目 */ | |
| 162 | + for ( $d = 0; $d <= 6; $d++ ) { | |
| 163 | + if ( (int) $lastday === (int) $day ) { | |
| 164 | + break; | |
| 165 | + } else { | |
| 166 | + list( $this->_year, $this->_month, $day ) = getNextDay( $this->_year, $this->_month, $day ); | |
| 167 | + $this->_date[5][ $d ] = sprintf( '%04d-%02d-%02d', $this->_year, $this->_month, $day ); | |
| 168 | + $this->_datetext[5][ $d ] = $day; | |
| 169 | + } | |
| 170 | + } | |
| 171 | + if ( $d > 0 ) { | |
| 172 | + while ( $d <= 6 ) { | |
| 173 | + $this->_date[5][ $d ] = ''; | |
| 174 | + $this->_datetext[5][ $d ] = ''; | |
| 175 | + $d++; | |
| 176 | + } | |
| 177 | + } | |
| 178 | + } | |
| 179 | + | |
| 180 | + $this->_row = ( is_array( $this->_date ) ) ? count( $this->_date ) : 0; | |
| 181 | + } | |
| 182 | +} | |