カレンダーフォーム

WBOY
WBOYオリジナル
2016-07-25 08:50:37986ブラウズ
";
  • }
  • public function getEndTR() {
  • $this->retunrhtml .= "
  • ";
  • }
  • protected function getDay() {
  • return $this->day;
  • }
  • protected function getMonth() {
  • return $this->month;
  • }
  • protected function get Year() {
  • return $this->年;
  • }
  • 保護された関数 isWeekend() {
  • return $this->weekend;
  • }
  • 保護された関数 isCurrent() {
  • return $this->currentdate;
  • }
  • public function getTDHref() {
  • return $this ->getDay();
  • }
  • public function getTD() {
  • $class = '';
  • $td = "td";
  • if ($this->isCurrent()) {
  • $class = '今日';
  • }
  • $this->retunrhtml .= "<$td class="$class">" 。 $this->getTDHref() 。 "";
  • }
  • public function getTDWeekend() {
  • $class = '';
  • $td = "td";
  • if ($this->isCurrent()) {
  • $class = '今日';
  • }
  • $this->retunrhtml .= "<$td class="$class">" 。 $this->getTDHref() 。 "";
  • }
  • 保護関数 makeCodeMonth($year, $month) {
  • $this->makeWeeks($year, $month);
  • $this->getCalendarHeader();
  • for ($i = 0; $i week); $i++) {
  • $this->getBeginTR();
  • for ($j = 0; $j
  • if (!empty($this->week[$i][$j])) {
  • $this->day = $this->week[$i][$j];
  • $this->currentdate = 0;
  • if ($this->year == date('Y') && $this->month == date('m') && $this->day = = date('j')) {
  • $this->currentdate = 1;
  • }
  • if ($j == 5 || $j == 6) {
  • $this->weekend = 1;
  • $ this->getTDWeekend();
  • }
  • else {
  • $this->weekend = 0;
  • $this->getTD();
  • }
  • }
  • else {
  • $this->returnrhtml .= "
  • ";
  • }
  • }
  • $this->getEndTR();
  • }
  • $this->getCalendarFooter();
  • }
  • public function getCodeMonth() {
  • $this->makeCodeMonth($this->year, $this->month);
  • return $this->retunrhtml;
  • }
  • public function showCodeMonth() {
  • echo $this-> getCodeMonth();
  • }
  • }
  • class TechCalendarForm extends CalendarForm {
  • public function getTDHref() {
  • if ($this->isWeekend()) {
  • $font = "";
  • }
  • else {
  • $font = "";
  • }
  • return "" . $font .parent::getDay() . "";
  • }
  • }复制代码
  • 使用例:
    $cal = new CalendarForm(2012, 5);
    $cal->showCodeMonth();
    1. class CalendarForm {
    2. protected $year;
    3. protected $month;
    4. protected $day;
    5. protected $weekend;
    6. protected $currentdate;
    7. protected $dayofmonth;
    8. protected $day_count;
    9. protected $num;
    10. protected $week = array();
    11. protected $retunrhtml = "";
    12. function __construct($year, $month) {
    13. $this->makeWeeks($year, $month);
    14. }
    15. パブリック関数 set YearMonth($year, $month) {
    16. $this->year = $year;
    17. $this->month = $month;
    18. }
    19. プライベート関数 replaceDayCount() {
    20. $this-> day_count = 1;
    21. }
    22. プライベート関数 setFirstWeek() {
    23. $this->num = 0;
    24. }
    25. パブリック関数 getDayOfMonth($year, $month) {
    26. $this->resetDayCount();
    27. return date('t', mktime(0, 0, 0, $month, $this->day_count, $year));
    28. }
    29. プライベート関数 setDayOfMonth($year, $month) {
    30. $this-> ;dayofmonth = $this->getDayOfMonth($year, $month);
    31. }
    32. private function getDayOfWeek() {
    33. return date('w', mktime(0, 0, 0, $this->month, $this->day_count, $this->year));
    34. }
    35. public function getNextMonth() {
    36. return date('m', mktime(0, 0, 0, $this->month, 28) , $this->year) + 432000);
    37. }
    38. public function getNext Year() {
    39. return date('Y', mktime(0, 0, 0, $this->month, 28, $this- >年) + 432000);
    40. }
    41. public function getPrevMonth() {
    42. return date('m', mktime(0, 0, 0, $this->month, 1, $this->year) - 432000);
    43. }
    44. public function getPrev Year() {
    45. return date('Y', mktime(0, 0, 0, $this->month, 1, $this->year) - 432000);
    46. }
    47. プライベート関数 makeWeeks($year, $month) {
    48. $this->set YearMonth($year, $month);
    49. $this->setDayOfMonth($this->year, $this-> ;month);
    50. $this->setFirstWeek();
    51. $this->num = 0;
    52. for ($i = 0; $i $dayofweek = $this->getDayOfWeek();
    53. $dayofweek = $dayofweek - 1;
    54. if ($dayofweek == -1) {
    55. $dayofweek = 6;
    56. }
    57. if ($dayofweek == $i) {
    58. $this->week[$this->num][$i] = $this->day_count;
    59. $this->day_count++;
    60. }
    61. else {
    62. $this- >week[$this->num][$i] = "";
    63. }
    64. }
    65. while (TRUE) {
    66. $this->num++;
    67. for ($i = 0; $i $this->week[$this->num][$i] = $this->day_count;
    68. $this->day_count++;
    69. if ($this->day_count > ; $this->dayofmonth) {
    70. Break;
    71. }
    72. }
    73. if ($this->day_count > $this->dayofmonth) {
    74. Break;
    75. }
    76. }
    77. }
    78. public function getCalendarHeader () {
    79. $this->retunrhtml =
    80. "" .
    81. 」 .
    82. "
    83. " 。 $this->month 。 「/」。 $今年>年。 "" .
    84. "
    85. " .
    86. "
    87. " .
    88. "
    89. " .
    90. "
    91. " .
    92. "
    93. " .
    94. "
    95. " .
    96. "
    97. " .
    98. "
    99. " .
    100. "
    101. ";
    102. }
    103. public function getCalendarFooter() {
    104. $this->retunrhtml .= "
    105. 月曜日 火曜日 水曜日 木曜日 金曜日 土曜日 日曜日
      ";
    106. }
    107. public function getBeginTR( ) {
    108. $this->retunrhtml .= "
     


    声明:
    この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。