国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Développement PHP pour créer un calendrier simple et une classe CLASS

Plus t?t, nous avons expliqué la

méthode de seuil, qui génère chaque valeur limite du calendrier

méthode caculate, qui calcule le nombre de jours et le style du calendrier

draw, dessine des tableaux et des paramètres tr et td dans le tableau

Dans cette section, nous les encapsulons dans une classe Calendar, puis nous la référen?ons sur la page frontale. Vous pouvez appeler cette classe lorsque vous réalisez d'autres projets similaires. à l'avenir.

Ce fichier de classe est créé avec le nom calendrier.php.

<?php 
class Calendar {
   /*
    * @deprecated 生成日歷的各個(gè)邊界值
    * @param string $year
    * @param string $month
    * @return array
    */
   function threshold($year, $month) {
      $firstDay = mktime(0, 0, 0, $month, 1, $year);  //mktime() 函數(shù)返回日期的 UNIX 時(shí)間戳。
      $lastDay = strtotime('+1 month -1 day', $firstDay);
      //取得天數(shù)  
      $days = date("t", $firstDay);
      //取得第一天是星期幾
      $firstDayOfWeek = date("N", $firstDay);
      //獲得最后一天是星期幾
      $lastDayOfWeek = date('N', $lastDay);
      
      //上一個(gè)月最后一天
      $lastMonthDate = strtotime('-1 day', $firstDay); //strtotime() 函數(shù)將任何英文文本的日期或時(shí)間描述解析為 Unix 時(shí)間戳
      $lastMonthOfLastDay = date('d', $lastMonthDate);
      //下一個(gè)月第一天
      $nextMonthDate = strtotime('+1 day', $lastDay);
      $nextMonthOfFirstDay = strtotime('+1 day', $lastDay);
      
      //日歷的第一個(gè)日期
      if($firstDayOfWeek == 7) {
         $firstDate = $firstDay;
      }else {
         $firstDate = strtotime('-' . $firstDayOfWeek . ' day', $firstDay);
      }
      //日歷的最后一個(gè)日期
      if($lastDayOfWeek == 6) {
         $lastDate = $lastDay;
      }elseif($lastDayOfWeek == 7) {
         $lastDate = strtotime('+6 day', $lastDay);
      }else {
         $lastDate = strtotime('+' . (6 - $lastDayOfWeek) . ' day', $lastDay);
      }
      return array(
            'days' => $days, 
            'firstDayOfWeek' => $firstDayOfWeek, 
            'lastDayOfWeek' => $lastDayOfWeek,
            'lastMonthOfLastDay' => $lastMonthOfLastDay,
            'firstDate' => $firstDate,
            'lastDate' => $lastDate,
            'year' => $year,
            'month' => $month
      );
   }
   /*
    * @author Pwstrick
    * @param array $calendar 通過threshold方法計(jì)算后的數(shù)據(jù)
    * @deprecated 計(jì)算日歷的天數(shù)與樣式
    */
   function caculate($calendar) {
      $days = $calendar['days'];
      $firstDayOfWeek = $calendar['firstDayOfWeek'];//本月第一天的星期
      $lastDayOfWeek = $calendar['lastDayOfWeek'];//本月最后一天的星期
      $lastMonthOfLastDay = $calendar['lastMonthOfLastDay'];//上個(gè)月的最后一天
      $year = $calendar['year'];
      $month = $calendar['month'];
      
      $dates = array();
      if($firstDayOfWeek != 7) {
         $lastDays = array();
         $current = $lastMonthOfLastDay;//上個(gè)月的最后一天
         for ($i = 0; $i < $firstDayOfWeek; $i++) {
            array_push($lastDays, $current);//添加上一個(gè)月的日期天數(shù)
            $current--;
         }
         $lastDays = array_reverse($lastDays);//反序
         foreach ($lastDays as $index => $day) {
            array_push($dates, array('day' => $day, 'tdclass' => ($index ==0 ?'rest':''), 'pclass' => 'outter'));
         }
      }
      
      //本月日歷信息
      for ($i = 1; $i <= $days; $i++) {
         $isRest = $this->_checkIsRest($year, $month, $i);
         //判斷是否是休息天
         array_push($dates, array('day' => $i, 'tdclass' => ($isRest ?'rest':''), 'pclass' => ''));
      }
      
      //下月日歷信息
      if($lastDayOfWeek == 7) {//最后一天是星期日
         $length = 6;
      }
      elseif($lastDayOfWeek == 6) {//最后一天是星期六
         $length = 0;
      }else {
         $length = 6 - $lastDayOfWeek;
      }
      for ($i = 1; $i <= $length; $i++) {
         array_push($dates, array('day' => $i, 'tdclass' => ($i==$length ?'rest':''), 'pclass' => 'outter'));
      }
      
      return $dates;
   }
   
   /*
    * @author Pwstrick
    * @deprecated 判斷是否是休息天
    */
   private function _checkIsRest($year, $month, $day) {
      $date = mktime(0, 0, 0, $month, $day, $year);
      $week = date("N", $date);
      return $week == 7 || $week == 6;
   }
   
   /*
    * @author Pwstrick
    * @param array $caculate 通過caculate方法計(jì)算后的數(shù)據(jù)
    * @deprecated 畫表格,設(shè)置table中的tr與td
    */
   function draw($caculate) {
      $tr = array();
      $length = count($caculate);
      $result = array();
      foreach ($caculate as $index => $date) {
         if($index % 7 == 0) {//第一列
            $tr = array($date);
         }elseif($index % 7 == 6 || $index == ($length-1)) {
            array_push($tr, $date);
            array_push($result, $tr);//添加到返回的數(shù)據(jù)中
            $tr = array();//清空數(shù)組列表
         }else {
            array_push($tr, $date);
         }
      }
      return $result;
   }
}
?>


Formation continue
||
<?php class Calendar { /* * @deprecated 生成日歷的各個(gè)邊界值 * @param string $year * @param string $month * @return array */ function threshold($year, $month) { $firstDay = mktime(0, 0, 0, $month, 1, $year); //mktime() 函數(shù)返回日期的 UNIX 時(shí)間戳。 $lastDay = strtotime('+1 month -1 day', $firstDay); //取得天數(shù) $days = date("t", $firstDay); //取得第一天是星期幾 $firstDayOfWeek = date("N", $firstDay); //獲得最后一天是星期幾 $lastDayOfWeek = date('N', $lastDay); //上一個(gè)月最后一天 $lastMonthDate = strtotime('-1 day', $firstDay); //strtotime() 函數(shù)將任何英文文本的日期或時(shí)間描述解析為 Unix 時(shí)間戳 $lastMonthOfLastDay = date('d', $lastMonthDate); //下一個(gè)月第一天 $nextMonthDate = strtotime('+1 day', $lastDay); $nextMonthOfFirstDay = strtotime('+1 day', $lastDay); //日歷的第一個(gè)日期 if($firstDayOfWeek == 7) { $firstDate = $firstDay; }else { $firstDate = strtotime('-' . $firstDayOfWeek . ' day', $firstDay); } //日歷的最后一個(gè)日期 if($lastDayOfWeek == 6) { $lastDate = $lastDay; }elseif($lastDayOfWeek == 7) { $lastDate = strtotime('+6 day', $lastDay); }else { $lastDate = strtotime('+' . (6 - $lastDayOfWeek) . ' day', $lastDay); } return array( 'days' => $days, 'firstDayOfWeek' => $firstDayOfWeek, 'lastDayOfWeek' => $lastDayOfWeek, 'lastMonthOfLastDay' => $lastMonthOfLastDay, 'firstDate' => $firstDate, 'lastDate' => $lastDate, 'year' => $year, 'month' => $month ); } /* * @author Pwstrick * @param array $calendar 通過threshold方法計(jì)算后的數(shù)據(jù) * @deprecated 計(jì)算日歷的天數(shù)與樣式 */ function caculate($calendar) { $days = $calendar['days']; $firstDayOfWeek = $calendar['firstDayOfWeek'];//本月第一天的星期 $lastDayOfWeek = $calendar['lastDayOfWeek'];//本月最后一天的星期 $lastMonthOfLastDay = $calendar['lastMonthOfLastDay'];//上個(gè)月的最后一天 $year = $calendar['year']; $month = $calendar['month']; $dates = array(); if($firstDayOfWeek != 7) { $lastDays = array(); $current = $lastMonthOfLastDay;//上個(gè)月的最后一天 for ($i = 0; $i < $firstDayOfWeek; $i++) { array_push($lastDays, $current);//添加上一個(gè)月的日期天數(shù) $current--; } $lastDays = array_reverse($lastDays);//反序 foreach ($lastDays as $index => $day) { array_push($dates, array('day' => $day, 'tdclass' => ($index ==0 ?'rest':''), 'pclass' => 'outter')); } } //本月日歷信息 for ($i = 1; $i <= $days; $i++) { $isRest = $this->_checkIsRest($year, $month, $i); //判斷是否是休息天 array_push($dates, array('day' => $i, 'tdclass' => ($isRest ?'rest':''), 'pclass' => '')); } //下月日歷信息 if($lastDayOfWeek == 7) {//最后一天是星期日 $length = 6; } elseif($lastDayOfWeek == 6) {//最后一天是星期六 $length = 0; }else { $length = 6 - $lastDayOfWeek; } for ($i = 1; $i <= $length; $i++) { array_push($dates, array('day' => $i, 'tdclass' => ($i==$length ?'rest':''), 'pclass' => 'outter')); } return $dates; } /* * @author Pwstrick * @deprecated 判斷是否是休息天 */ private function _checkIsRest($year, $month, $day) { $date = mktime(0, 0, 0, $month, $day, $year); $week = date("N", $date); return $week == 7 || $week == 6; } /* * @author Pwstrick * @param array $caculate 通過caculate方法計(jì)算后的數(shù)據(jù) * @deprecated 畫表格,設(shè)置table中的tr與td */ function draw($caculate) { $tr = array(); $length = count($caculate); $result = array(); foreach ($caculate as $index => $date) { if($index % 7 == 0) {//第一列 $tr = array($date); }elseif($index % 7 == 6 || $index == ($length-1)) { array_push($tr, $date); array_push($result, $tr);//添加到返回的數(shù)據(jù)中 $tr = array();//清空數(shù)組列表 }else { array_push($tr, $date); } } return $result; } } ?>
soumettreRéinitialiser le code