Toolbox::getDaysOfWeekArray PHP Méthode

getDaysOfWeekArray() static public méthode

static public getDaysOfWeekArray ( )
    static function getDaysOfWeekArray()
    {
        $tab[0] = __("Sunday");
        $tab[1] = __("Monday");
        $tab[2] = __("Tuesday");
        $tab[3] = __("Wednesday");
        $tab[4] = __("Thursday");
        $tab[5] = __("Friday");
        $tab[6] = __("Saturday");
        return $tab;
    }

Usage Example

 /**
  * Show the planning
  *
  * Function name change since version 0.84 show() => showPlanning
  *
  * @param $who             ID of the user (0 = undefined)
  * @param $who_group       ID of the group of users (0 = undefined)
  * @param $when            Date of the planning to display
  * @param $type            type of planning to display (day, week, month)
  * @param $limititemtype   itemtype limit display to this itemtype (default '')
  *
  * @return Nothing (display function)
  **/
 static function showPlanning($who, $who_group, $when, $type, $limititemtype = '')
 {
     global $CFG_GLPI, $DB;
     if (!Session::haveRight("show_planning", "1") && !Session::haveRight("show_all_planning", "1")) {
         return false;
     }
     // Define some constants
     $date = explode("-", $when);
     $time = mktime(0, 0, 0, $date[1], $date[2], $date[0]);
     $daysinweek = Toolbox::getDaysOfWeekArray();
     // Check bisextile years
     list($current_year, $current_month, $current_day) = explode("-", $when);
     if ($current_year % 4 == 0) {
         $feb = 29;
     } else {
         $feb = 28;
     }
     $nb_days = array(31, $feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
     // Begin of the month
     $begin_month_day = strftime("%w", mktime(0, 0, 0, $current_month, 1, $current_year));
     if ($begin_month_day == 0) {
         $begin_month_day = 7;
     }
     $end_month_day = strftime("%w", mktime(0, 0, 0, $current_month, $nb_days[$current_month - 1], $current_year));
     // Day of the week
     $dayofweek = date("w", $time);
     // Cas du dimanche
     if ($dayofweek == 0) {
         $dayofweek = 7;
     }
     // Get begin and duration
     $begin = 0;
     $end = 0;
     switch ($type) {
         case "month":
             $begin = strtotime($current_year . "-" . $current_month . "-01 00:00:00");
             $end = $begin + DAY_TIMESTAMP * $nb_days[$current_month - 1];
             break;
         case "week":
             $tbegin = $begin = $time + mktime(0, 0, 0, 0, 1, 0) - mktime(0, 0, 0, 0, $dayofweek, 0);
             $end = $begin + WEEK_TIMESTAMP;
             break;
         case "day":
             $add = "";
             $begin = $time;
             $end = $begin + DAY_TIMESTAMP;
             break;
     }
     $begin = date("Y-m-d H:i:s", $begin);
     $end = date("Y-m-d H:i:s", $end);
     // Print Headers
     echo "<div class='center'><table class='tab_cadre_fixe'>";
     // Print Headers
     echo "<tr class='tab_bg_1'>";
     switch ($type) {
         case "month":
             for ($i = 1; $i <= 7; $i++) {
                 echo "<th width='12%'>" . $daysinweek[$i % 7] . "</th>";
             }
             break;
         case "week":
             for ($i = 1; $i <= 7; $i++, $tbegin += DAY_TIMESTAMP) {
                 echo "<th width='12%'>" . $daysinweek[$i % 7] . " " . date('d', $tbegin) . "</th>";
             }
             break;
         case "day":
             echo "<th width='12%'>" . $daysinweek[$dayofweek % 7] . "</th>";
             break;
     }
     echo "</tr>\n";
     $params = array('who' => $who, 'who_group' => $who_group, 'begin' => $begin, 'end' => $end);
     $interv = array();
     if (empty($limititemtype)) {
         foreach ($CFG_GLPI['planning_types'] as $itemtype) {
             $interv = array_merge($interv, $itemtype::populatePlanning($params));
         }
     } else {
         $interv = $limititemtype::populatePlanning($params);
     }
     // Display Items
     $tmp = explode(":", $CFG_GLPI["planning_begin"]);
     $hour_begin = $tmp[0];
     $tmp = explode(":", $CFG_GLPI["planning_end"]);
     $hour_end = $tmp[0];
     if ($tmp[1] > 0) {
         $hour_end++;
     }
     switch ($type) {
         case "week":
             for ($hour = $hour_begin; $hour <= $hour_end; $hour++) {
                 echo "<tr>";
                 for ($i = 1; $i <= 7; $i++) {
                     echo "<td class='tab_bg_3 top' width='12%'>";
                     echo "<span class='b'>" . self::displayUsingTwoDigits($hour) . ":00</span><br>";
                     // From midnight
                     if ($hour == $hour_begin) {
                         $begin_time = date("Y-m-d H:i:s", strtotime($when) + ($i - $dayofweek) * DAY_TIMESTAMP);
                     } else {
                         $begin_time = date("Y-m-d H:i:s", strtotime($when) + ($i - $dayofweek) * DAY_TIMESTAMP + $hour * HOUR_TIMESTAMP);
                     }
                     // To midnight
                     if ($hour == $hour_end) {
                         $end_time = date("Y-m-d H:i:s", strtotime($when) + ($i - $dayofweek) * DAY_TIMESTAMP + 24 * HOUR_TIMESTAMP);
                     } else {
                         $end_time = date("Y-m-d H:i:s", strtotime($when) + ($i - $dayofweek) * DAY_TIMESTAMP + ($hour + 1) * HOUR_TIMESTAMP);
                     }
                     reset($interv);
                     while ($data = current($interv)) {
                         $type = "";
                         if ($data["begin"] >= $begin_time && $data["end"] <= $end_time) {
                             $type = "in";
                         } else {
                             if ($data["begin"] < $begin_time && $data["end"] > $end_time) {
                                 $type = "through";
                             } else {
                                 if ($data["begin"] >= $begin_time && $data["begin"] < $end_time) {
                                     $type = "begin";
                                 } else {
                                     if ($data["end"] > $begin_time && $data["end"] <= $end_time) {
                                         $type = "end";
                                     }
                                 }
                             }
                         }
                         if (empty($type)) {
                             next($interv);
                         } else {
                             self::displayPlanningItem($data, $who, $type);
                             if ($type == "in") {
                                 unset($interv[key($interv)]);
                             } else {
                                 next($interv);
                             }
                         }
                     }
                     echo "</td>";
                 }
                 echo "</tr>\n";
             }
             break;
         case "day":
             for ($hour = $hour_begin; $hour <= $hour_end; $hour++) {
                 echo "<tr>";
                 $begin_time = date("Y-m-d H:i:s", strtotime($when) + $hour * HOUR_TIMESTAMP);
                 $end_time = date("Y-m-d H:i:s", strtotime($when) + ($hour + 1) * HOUR_TIMESTAMP);
                 echo "<td class='tab_bg_3 top' width='12%'>";
                 echo "<span class='b'>" . self::displayUsingTwoDigits($hour) . ":00</span><br>";
                 reset($interv);
                 while ($data = current($interv)) {
                     $type = "";
                     if ($data["begin"] >= $begin_time && $data["end"] <= $end_time) {
                         $type = "in";
                     } else {
                         if ($data["begin"] < $begin_time && $data["end"] > $end_time) {
                             $type = "through";
                         } else {
                             if ($data["begin"] >= $begin_time && $data["begin"] < $end_time) {
                                 $type = "begin";
                             } else {
                                 if ($data["end"] > $begin_time && $data["end"] <= $end_time) {
                                     $type = "end";
                                 }
                             }
                         }
                     }
                     if (empty($type)) {
                         next($interv);
                     } else {
                         self::displayPlanningItem($data, $who, $type, 1);
                         if ($type == "in") {
                             unset($interv[key($interv)]);
                         } else {
                             next($interv);
                         }
                     }
                 }
                 echo "</td></tr>";
             }
             break;
         case "month":
             echo "<tr class='tab_bg_3'>";
             // Display first day out of the month
             for ($i = 1; $i < $begin_month_day; $i++) {
                 echo "<td style='background-color:#ffffff'>&nbsp;</td>";
             }
             // Print real days
             if ($current_month < 10 && strlen($current_month) == 1) {
                 $current_month = "0" . $current_month;
             }
             $begin_time = strtotime($begin);
             $end_time = strtotime($end);
             for ($time = $begin_time; $time < $end_time; $time += DAY_TIMESTAMP) {
                 // Add 6 hours for midnight problem
                 $day = date("d", $time + 6 * HOUR_TIMESTAMP);
                 echo "<td height='100' class='tab_bg_3 top'>";
                 echo "<table class='center'><tr><td class='center'>";
                 echo "<span style='font-family: arial,helvetica,sans-serif; font-size: 14px; color: black'>" . $day . "</span></td></tr>";
                 echo "<tr class='tab_bg_3'>";
                 echo "<td class='tab_bg_3 top' width='12%'>";
                 $begin_day = date("Y-m-d H:i:s", $time);
                 $end_day = date("Y-m-d H:i:s", $time + DAY_TIMESTAMP);
                 reset($interv);
                 while ($data = current($interv)) {
                     $type = "";
                     if ($data["begin"] >= $begin_day && $data["end"] <= $end_day) {
                         $type = "in";
                     } else {
                         if ($data["begin"] < $begin_day && $data["end"] > $end_day) {
                             $type = "through";
                         } else {
                             if ($data["begin"] >= $begin_day && $data["begin"] < $end_day) {
                                 $type = "begin";
                             } else {
                                 if ($data["end"] > $begin_day && $data["end"] <= $end_day) {
                                     $type = "end";
                                 }
                             }
                         }
                     }
                     if (empty($type)) {
                         next($interv);
                     } else {
                         self::displayPlanningItem($data, $who, $type);
                         if ($type == "in") {
                             unset($interv[key($interv)]);
                         } else {
                             next($interv);
                         }
                     }
                 }
                 echo "</td></tr></table>";
                 echo "</td>";
                 // Add break line
                 if (($day + $begin_month_day) % 7 == 1) {
                     echo "</tr>\n";
                     if ($day != $nb_days[$current_month - 1]) {
                         echo "<tr>";
                     }
                 }
             }
             if ($end_month_day != 0) {
                 for ($i = 0; $i < 7 - $end_month_day; $i++) {
                     echo "<td style='background-color:#ffffff'>&nbsp;</td>";
                 }
             }
             echo "</tr>";
             break;
     }
     echo "</table></div>";
 }
All Usage Examples Of Toolbox::getDaysOfWeekArray