Advertisement
Guest User

php class

a guest
May 12th, 2017
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.70 KB | None | 0 0
  1. <?php
  2. setlocale(LC_ALL, array('Dutch_Netherlands', 'Dutch', 'nl_NL', 'nl', 'nl_NL.ISO8859-1', 'nld_NLD'));
  3. error_reporting(E_ALL);
  4. ini_set("display_errors", 1);
  5.  
  6.  
  7. class Calendar
  8. {
  9.  
  10.  
  11.     public function getInfo($m, $y)
  12.     {
  13.         $days = date('t', mktime(0, 0, 0, $m, 1, $y));
  14.         $firstday = date('N', strtotime('first day of ' . $y . '-' . $m));
  15.         $info['days'] = $days;
  16.         $info['firstday'] = $firstday;
  17.         return $info;
  18.     }
  19.  
  20.     public function makeMonth($m, $y)
  21.     {
  22.  
  23.         $maand = array();
  24.         // Get info for this year
  25.         $info = $this->getInfo($m, $y);
  26.  
  27.         // Get array with dates
  28.         $amount = $info['days'];
  29.         for ($i = 1; $i <= $amount; $i++) {
  30.             $maand[$i] = str_pad($i, 2, '0', STR_PAD_LEFT) . "-" . $m . "-" . $y;
  31.         }
  32.  
  33.         // place the array content correctly
  34.         $needed = 42;
  35.         $begin = $info['firstday'] - 1;
  36.  
  37.         #begin van array
  38.        for ($i = 0; $i < $begin; $i++) {
  39.             array_unshift($maand, "Before Month Start");
  40.         }
  41.  
  42.         #eind van array
  43.        $nognodig = $needed - ($begin + $amount);
  44.         for ($i = 0; $i < $nognodig; $i++) {
  45.             array_push($maand, "After month");
  46.         }
  47.  
  48.         return $maand;
  49.     }
  50.  
  51.     public function buildArray()
  52.     {
  53.  
  54.          //Build multidimensional array
  55.         $calendar['calendar'] = array(
  56.             $info = $this->getInfo(date("m", strtotime("-2 Months")), date("Y", strtotime("-2 Months"))),
  57.             $maand = $this->makeMonth(date("m", strtotime("-2 Months")), date("Y", strtotime("-2 Months"))),
  58.             $info = $this->getInfo(date("m", strtotime("-1 Months")), date("Y", strtotime("-1 Months"))),
  59.             $maand = $this->makeMonth(date("m", strtotime("-1 Months")), date("Y", strtotime("-1 Months"))),
  60.             $info = $this->getInfo(strftime('%m'), strftime('%Y')),
  61.             $maand = $this->makeMonth(strftime('%m'), strftime('%Y')),
  62.             $info = $this->getInfo(date("m", strtotime("+1 Months")), date("Y", strtotime("+1 Months"))),
  63.             $maand = $this->makeMonth(date("m", strtotime("+1 Months")), date("Y", strtotime("+1 Months"))),
  64.             $info = $this->getInfo(date("m", strtotime("+2 Months")), date("Y", strtotime("+2 Months"))),
  65.             $maand = $this->makeMonth(date("m", strtotime("+2 Months")), date("Y", strtotime("+2 Months"))),
  66.             $info = $this->getInfo(date("m", strtotime("+3 Months")), date("Y", strtotime("+3 Months"))),
  67.             $maand = $this->makeMonth(date("m", strtotime("+3 Months")), date("Y", strtotime("+3 Months")))
  68.         );
  69.  
  70.  
  71.         echo '<pre>';
  72.         print_r($calendar);
  73.         echo '</pre>';
  74.  
  75.     }
  76. }
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement