Heim  >  Artikel  >  Backend-Entwicklung  >  日历表格

日历表格

WBOY
WBOYOriginal
2016-07-25 08:50:37918Durchsuche
";
  • }
  • public function getEndTR() {
  • $this->retunrhtml .= "
  • ";
  • }
  • protected function getDay() {
  • return $this->day;
  • }
  • protected function getMonth() {
  • return $this->month;
  • }
  • protected function getYear() {
  • return $this->year;
  • }
  • protected function isWeekend() {
  • return $this->weekend;
  • }
  • protected function isCurrent() {
  • return $this->currentdate;
  • }
  • public function getTDHref() {
  • return $this->getDay();
  • }
  • public function getTD() {
  • $class = '';
  • $td = "td";
  • if ($this->isCurrent()) {
  • $class = 'today';
  • }
  • $this->retunrhtml .= "" . $this->getTDHref() . "$td>";
  • }
  • public function getTDWeekend() {
  • $class = '';
  • $td = "td";
  • if ($this->isCurrent()) {
  • $class = 'today';
  • }
  • $this->retunrhtml .= "" . $this->getTDHref() . "$td>";
  • }
  • protected function 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->retunrhtml .= "
  • ";
  • }
  • }
  • $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. public function setYearMonth($year, $month) {
    16. $this->year = $year;
    17. $this->month = $month;
    18. }
    19. private function resetDayCount() {
    20. $this->day_count = 1;
    21. }
    22. private function setFirstWeek() {
    23. $this->num = 0;
    24. }
    25. public function getDayOfMonth($year, $month) {
    26. $this->resetDayCount();
    27. return date('t', mktime(0, 0, 0, $month, $this->day_count, $year));
    28. }
    29. private function 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 getNextYear() {
    39. return date('Y', mktime(0, 0, 0, $this->month, 28, $this->year) + 432000);
    40. }
    41. public function getPrevMonth() {
    42. return date('m', mktime(0, 0, 0, $this->month, 1, $this->year) - 432000);
    43. }
    44. public function getPrevYear() {
    45. return date('Y', mktime(0, 0, 0, $this->month, 1, $this->year) - 432000);
    46. }
    47. private function makeWeeks($year, $month) {
    48. $this->setYearMonth($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. "
    84. " .
    85. "
    86. " .
    87. "
    88. " .
    89. "
    90. " .
    91. "
    92. " .
    93. "
    94. " .
    95. "
    96. " .
    97. "
    98. " .
    99. "
    100. " .
    101. "
    102. ";
    103. }
    104. public function getCalendarFooter() {
    105. $this->retunrhtml .= "
    106. " . $this->month . "/" . $this->year . "
      Monday Tuesday Wednesday Thursday Friday Saturday Sunday
      ";
    107. }
    108. public function getBeginTR() {
    109. $this->retunrhtml .= "
     


    Stellungnahme:
    Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
    Vorheriger Artikel:MySQL的备份 Nächster Artikel:计算地图上两点间的距离