/**
  * constructor
  *
  * @param string $date        current date in the planning
  * @param null   $date_min    min date of the planning
  * @param null   $date_max    max
  * @param bool   $selectable  is the planning selectable
  * @param string $height      [optional] height of the planning, default : auto
  * @param bool   $large       [optional] is the planning a large one
  * @param bool   $adapt_range [optional] can the planning adapt the range
  */
 function __construct($date, $date_min = null, $date_max = null, $selectable = false, $height = "auto", $large = false, $adapt_range = false)
 {
     parent::__construct($date);
     $this->today = CMbDT::date();
     $this->type = "month";
     $this->selectable = $selectable;
     $this->height = $height ? $height : "auto";
     $this->large = $large;
     $this->adapt_range = $adapt_range;
     $this->no_dates = true;
     if (is_int($date) || is_int($date_min) || is_int($date_max)) {
         $this->no_dates = true;
         $this->date_min = $this->date_min_active = $this->_date_min_planning = $date_min;
         $this->date_max = $this->date_max_active = $this->_date_max_planning = $date_max;
         $this->nb_days = CMbDT::transform(null, $this->date_max, "%d") - CMbDT::transform(null, $this->date_min, "%d");
         for ($i = 0; $i < $this->nb_days; $i++) {
             $this->days[$i] = array();
             $this->load_data[$i] = array();
         }
     } else {
         $this->date_min = $this->date_min_active = $this->_date_min_planning = CMbDT::date("first day of this month", $date);
         $this->date_max = $this->date_max_active = $this->_date_max_planning = CMbDT::date("last day of this month", $this->date_min);
         // add the last days of previous month
         $min_day_number = CMbDT::format($this->date_min, "%w");
         $this->first_day_of_first_week = $first_day = CMbDT::date("this week", $min_day_number == 0 ? CMbDT::date("-1 DAY", $this->date_min) : $this->date_min);
         while ($first_day != $this->date_min) {
             $this->days[$first_day] = array();
             $first_day = CMbDT::date("+1 DAY", $first_day);
         }
         $this->nb_days = CMbDT::transform(null, $this->date_max, "%d");
         for ($i = 0; $i < $this->nb_days; $i++) {
             $_day = CMbDT::date("+{$i} day", $this->date_min);
             $this->days[$_day] = array();
             $this->load_data[$_day] = array();
         }
         //fill the rest of the last week
         $max_day_number = CMbDT::format($this->date_max, "%w");
         if ($max_day_number != 0) {
             $last_day_of_week = CMbDT::date("this week +6 days", $this->date_max);
             $last_day_of_month = $this->date_max;
             while ($last_day_of_month <= $last_day_of_week) {
                 $this->days[$last_day_of_month] = array();
                 $last_day_of_month = CMbDT::date("+1 DAY", $last_day_of_month);
             }
         }
         $this->classes_for_days = $this->days;
     }
     $this->previous_month = CMbDT::date("-1 DAY", $this->date_min);
     $this->next_month = CMbDT::date("+1 DAY", $this->date_max);
     $this->_date_min_planning = reset(array_keys($this->days));
     $this->_date_max_planning = end(array_keys($this->days));
     $this->_hours = array();
 }
Example #2
0
 /**
  * add an event to the present planning
  *
  * @param CPlanningEvent $event an event
  *
  * @return null
  */
 function addEvent(CPlanningEvent $event)
 {
     //start plage out of borne
     $date_start = CMbDT::date($event->start);
     if ($date_start != $this->date) {
         $event->day = $this->date;
         $event->start = $this->date . " 00:00:00";
         $event->hour = "00";
         $event->minutes = "00";
         $event->length = CMbDT::minutesRelative($event->start, $event->end);
     }
     //end of plage is out of borne
     $date_end = CMbDT::date($event->end);
     if ($date_end != $this->date) {
         $event->length = CMbDT::minutesRelative($event->start, $this->date . " 23:59:59");
     }
     parent::addEvent($event);
 }
 /**
  * constructor
  *
  * @param string $date        current date in the planning
  * @param null   $date_min    min date of the planning
  * @param null   $date_max    max
  * @param int    $nb_days     nb of day in the planning
  * @param bool   $selectable  is the planning selectable
  * @param string $height      [optional] height of the planning, default : auto
  * @param bool   $large       [optional] is the planning a large one
  * @param bool   $adapt_range [optional] can the planning adapt the range
  */
 function __construct($date, $date_min = null, $date_max = null, $nb_days = 7, $selectable = false, $height = "auto", $large = false, $adapt_range = false)
 {
     parent::__construct($date);
     $this->type = "week";
     $this->selectable = $selectable;
     $this->height = $height ? $height : "auto";
     $this->large = $large;
     $this->nb_days = $nb_days;
     $this->adapt_range = $adapt_range;
     $this->maximum_load = 6;
     if (is_int($date) || is_int($date_min) || is_int($date_max)) {
         $this->no_dates = true;
         $this->date_min = $this->date_min_active = $this->_date_min_planning = $date_min;
         $this->date_max = $this->date_max_active = $this->_date_max_planning = $date_max;
         for ($i = 0; $i < $this->nb_days; $i++) {
             $this->days[$i] = array();
             $this->load_data[$i] = array();
         }
     } else {
         $days = array("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday");
         $last_day = $days[$this->nb_days - 1];
         $monday = CMbDT::date("last monday", CMbDT::date("+1 day", $this->date));
         $sunday = CMbDT::date("next {$last_day}", CMbDT::date("-1 DAY", $this->date));
         if (CMbDT::daysRelative($monday, $sunday) > 7) {
             $sunday = CMbDT::date("-7 DAYS", $sunday);
         }
         $this->date_min_active = $date_min ? max($monday, CMbDT::date($date_min)) : $monday;
         $this->date_max_active = $date_max ? min($sunday, CMbDT::date($date_max)) : $sunday;
         $this->date_min = $monday;
         $this->date_max = $sunday;
         // Days period
         for ($i = 0; $i < $this->nb_days; $i++) {
             $_day = CMbDT::date("+{$i} day", $monday);
             $this->days[$_day] = array();
             $this->load_data[$_day] = array();
         }
         $this->_date_min_planning = reset(array_keys($this->days));
         $this->_date_max_planning = end(array_keys($this->days));
     }
     $this->_hours = array("00", "04", "08", "12", "16", "20");
 }