Reminder::populatePlanning PHP Method

populatePlanning() static public method

Populate the planning with planned reminder
static public populatePlanning ( $options = [] ) : array
$options array of possible options: - who ID of the user (0 = undefined) - who_group ID of the group of users (0 = undefined) - begin Date - end Date - color - event_type_color - check_planned (boolean) - display_done_events (boolean)
return array of planning item
    static function populatePlanning($options = array())
    {
        global $DB, $CFG_GLPI;
        $default_options = array('genical' => false, 'color' => '', 'event_type_color' => '', 'check_planned' => false, 'display_done_events' => true);
        $options = array_merge($default_options, $options);
        $interv = array();
        $reminder = new self();
        if (!isset($options['begin']) || $options['begin'] == 'NULL' || !isset($options['end']) || $options['end'] == 'NULL') {
            return $interv;
        }
        $who = $options['who'];
        $who_group = $options['who_group'];
        $begin = $options['begin'];
        $end = $options['end'];
        $readpub = $readpriv = "";
        $joinstoadd = self::addVisibilityJoins(true);
        // See public reminder ?
        if (!$options['genical'] && $who === Session::getLoginUserID() && self::canView()) {
            $readpub = self::addVisibilityRestrict();
        }
        // See my private reminder ?
        if ($who_group === "mine" || $who === Session::getLoginUserID()) {
            $readpriv = "(`glpi_reminders`.`users_id` = '" . Session::getLoginUserID() . "')";
        } else {
            if ($who > 0) {
                $readpriv = "`glpi_reminders`.`users_id` = '{$who}'";
            }
            if ($who_group > 0) {
                if (!empty($readpriv)) {
                    $readpriv .= " OR ";
                }
                $readpriv .= " `glpi_groups_reminders`.`groups_id` = '{$who_group}'";
            }
            if (!empty($readpriv)) {
                $readpriv = '(' . $readpriv . ')';
            }
        }
        $ASSIGN = '';
        if (!empty($readpub) && !empty($readpriv)) {
            $ASSIGN = "({$readpub} OR {$readpriv})";
        } else {
            if ($readpub) {
                $ASSIGN = $readpub;
            } else {
                $ASSIGN = $readpriv;
            }
        }
        $PLANNED = '';
        if ($options['check_planned']) {
            $PLANNED = "AND state != " . Planning::INFO;
        }
        $DONE_EVENTS = '';
        if (!$options['display_done_events']) {
            $DONE_EVENTS = "AND state != " . Planning::DONE;
        }
        if ($ASSIGN) {
            $query2 = "SELECT DISTINCT `glpi_reminders`.*\n                    FROM `glpi_reminders`\n                    {$joinstoadd}\n                    WHERE `glpi_reminders`.`is_planned` = '1'\n                          AND {$ASSIGN}\n                          {$PLANNED}\n                          {$DONE_EVENTS}\n                          AND `begin` < '{$end}'\n                          AND `end` > '{$begin}'\n                    ORDER BY `begin`";
            $result2 = $DB->query($query2);
            if ($DB->numrows($result2) > 0) {
                for ($i = 0; $data = $DB->fetch_assoc($result2); $i++) {
                    if ($reminder->getFromDB($data["id"]) && $reminder->canViewItem()) {
                        $key = $data["begin"] . "\$\$" . "Reminder" . "\$\$" . $data["id"];
                        $interv[$key]['color'] = $options['color'];
                        $interv[$key]['event_type_color'] = $options['event_type_color'];
                        $interv[$key]["itemtype"] = 'Reminder';
                        $interv[$key]["reminders_id"] = $data["id"];
                        $interv[$key]["id"] = $data["id"];
                        if (strcmp($begin, $data["begin"]) > 0) {
                            $interv[$key]["begin"] = $begin;
                        } else {
                            $interv[$key]["begin"] = $data["begin"];
                        }
                        if (strcmp($end, $data["end"]) < 0) {
                            $interv[$key]["end"] = $end;
                        } else {
                            $interv[$key]["end"] = $data["end"];
                        }
                        $interv[$key]["name"] = Html::resume_text($data["name"], $CFG_GLPI["cut"]);
                        $interv[$key]["text"] = Html::resume_text(Html::clean(Toolbox::unclean_cross_side_scripting_deep($data["text"])), $CFG_GLPI["cut"]);
                        $interv[$key]["users_id"] = $data["users_id"];
                        $interv[$key]["state"] = $data["state"];
                        $interv[$key]["state"] = $data["state"];
                        $interv[$key]["url"] = $CFG_GLPI["root_doc"] . "/front/reminder.form.php?id=" . $data['id'];
                        $interv[$key]["ajaxurl"] = $CFG_GLPI["root_doc"] . "/ajax/planning.php" . "?action=edit_event_form" . "&itemtype=Reminder" . "&id=" . $data['id'] . "&url=" . $interv[$key]["url"];
                        $interv[$key]["editable"] = $reminder->canUpdateItem();
                    }
                }
            }
        }
        return $interv;
    }

Usage Example

 /**
  *  Generate ical file content
  *
  * @param $who user ID
  * @param $who_group group ID
  *
  * @return icalendar string
  **/
 static function generateIcal($who, $who_group)
 {
     global $CFG_GLPI, $LANG;
     if ($who == 0 && $who_group == 0) {
         return false;
     }
     include_once GLPI_ROOT . "/lib/icalcreator/iCalcreator.class.php";
     $v = new vcalendar();
     if (!empty($CFG_GLPI["version"])) {
         $v->setConfig('unique_id', "GLPI-Planning-" . trim($CFG_GLPI["version"]));
     } else {
         $v->setConfig('unique_id', "GLPI-Planning-UnknownVersion");
     }
     $v->setConfig('filename', "glpi.ics");
     $v->setProperty("method", "PUBLISH");
     $v->setProperty("version", "2.0");
     $v->setProperty("x-wr-calname", "GLPI-" . $who . "-" . $who_group);
     $v->setProperty("calscale", "GREGORIAN");
     $interv = array();
     $begin = time() - MONTH_TIMESTAMP * 12;
     $end = time() + MONTH_TIMESTAMP * 12;
     $begin = date("Y-m-d H:i:s", $begin);
     $end = date("Y-m-d H:i:s", $end);
     // ---------------Tracking
     $interv = TicketPlanning::populatePlanning(array('who' => $who, 'who_group' => $who_group, 'begin' => $begin, 'end' => $end));
     // ---------------Reminder
     $data = Reminder::populatePlanning(array('who' => $who, 'who_group' => $who_group, 'begin' => $begin, 'end' => $end));
     $interv = array_merge($interv, $data);
     // ---------------Plugin
     $data = doHookFunction("planning_populate", array("begin" => $begin, "end" => $end, "who" => $who, "who_group" => $who_group));
     if (isset($data["items"]) && count($data["items"])) {
         $interv = array_merge($data["items"], $interv);
     }
     if (count($interv) > 0) {
         foreach ($interv as $key => $val) {
             $vevent = new vevent();
             //initiate EVENT
             if (isset($val["tickettasks_id"])) {
                 $vevent->setProperty("uid", "Job#" . $val["tickettasks_id"]);
             } else {
                 if (isset($val["reminders_id"])) {
                     $vevent->setProperty("uid", "Event#" . $val["reminders_id"]);
                 } else {
                     if (isset($val['planningID'])) {
                         // Specify the ID (for plugins)
                         $vevent->setProperty("uid", "Plugin#" . $val['planningID']);
                     } else {
                         $vevent->setProperty("uid", "Plugin#" . $key);
                     }
                 }
             }
             $vevent->setProperty("dstamp", $val["begin"]);
             $vevent->setProperty("dtstart", $val["begin"]);
             $vevent->setProperty("dtend", $val["end"]);
             if (isset($val["tickets_id"])) {
                 $vevent->setProperty("summary", $LANG['planning'][8] . " # " . $val["tickets_id"] . " " . $LANG['document'][14] . " # " . $val["device"]);
             } else {
                 if (isset($val["name"])) {
                     $vevent->setProperty("summary", $val["name"]);
                 }
             }
             if (isset($val["content"])) {
                 $vevent->setProperty("description", html_clean($val["content"]));
             } else {
                 if (isset($val["name"])) {
                     $vevent->setProperty("description", $val["name"]);
                 }
             }
             if (isset($val["tickets_id"])) {
                 $vevent->setProperty("url", $CFG_GLPI["url_base"] . "/index.php?redirect=tracking_" . $val["tickets_id"]);
             }
             $v->setComponent($vevent);
         }
     }
     $v->sort();
     //$v->parse();
     return $v->returnCalendar();
 }
All Usage Examples Of Reminder::populatePlanning