CommonITILTask::genericPopulatePlanning PHP Метод

genericPopulatePlanning() статический публичный Метод

Populate the planning with planned tasks
static public genericPopulatePlanning ( $itemtype, $options = [] ) : array
$itemtype itemtype
$options array of options must contains : - 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 - display_done_events (boolean)
Результат array of planning item
    static function genericPopulatePlanning($itemtype, $options = array())
    {
        global $DB, $CFG_GLPI;
        $interv = array();
        if (!isset($options['begin']) || $options['begin'] == 'NULL' || !isset($options['end']) || $options['end'] == 'NULL') {
            return $interv;
        }
        if (!($item = getItemForItemtype($itemtype))) {
            return;
        }
        $parentitemtype = $item->getItilObjectItemType();
        if (!($parentitem = getItemForItemtype($parentitemtype))) {
            return;
        }
        $default_options = array('genical' => false, 'color' => '', 'event_type_color' => '', 'display_done_events' => true);
        $options = array_merge($default_options, $options);
        $who = $options['who'];
        $who_group = $options['who_group'];
        $whogroup = $options['whogroup'];
        $begin = $options['begin'];
        $end = $options['end'];
        // Get items to print
        $ASSIGN = "";
        if ($who_group === "mine") {
            if (!$options['genical'] && count($_SESSION["glpigroups"])) {
                $groups = implode("','", $_SESSION['glpigroups']);
                $ASSIGN = "`" . $item->getTable() . "`.`users_id_tech`\n                           IN (SELECT DISTINCT `users_id`\n                               FROM `glpi_groups_users`\n                               INNER JOIN `glpi_groups`\n                                  ON (`glpi_groups_users`.`groups_id` = `glpi_groups`.`id`)\n                               WHERE `glpi_groups_users`.`groups_id` IN ('{$groups}')\n                                     AND `glpi_groups`.`is_assign`)\n                                     AND ";
            } else {
                // Only personal ones
                $ASSIGN = "`" . $item->getTable() . "`.`users_id_tech` = '{$who}'\n                       AND ";
            }
        } else {
            if ($who > 0) {
                $ASSIGN = "`" . $item->getTable() . "`.`users_id_tech` = '{$who}'\n                       AND ";
            }
            if ($who_group > 0) {
                $ASSIGN = "`" . $item->getTable() . "`.`users_id_tech` IN (SELECT `users_id`\n                                                                   FROM `glpi_groups_users`\n                                                                   WHERE `groups_id` = '{$who_group}')\n                                                                         AND ";
            }
            if ($whogroup > 0) {
                $ASSIGN = "`" . $item->getTable() . "`.`groups_id_tech` = '{$whogroup}'\n                       AND ";
            }
        }
        if (empty($ASSIGN)) {
            $ASSIGN = "`" . $item->getTable() . "`.`users_id_tech`\n                        IN (SELECT DISTINCT `glpi_profiles_users`.`users_id`\n                            FROM `glpi_profiles`\n                            LEFT JOIN `glpi_profiles_users`\n                                 ON (`glpi_profiles`.`id` = `glpi_profiles_users`.`profiles_id`)\n                            WHERE `glpi_profiles`.`interface` = 'central' " . getEntitiesRestrictRequest("AND", "glpi_profiles_users", '', $_SESSION["glpiactive_entity"], 1) . ")\n                     AND ";
        }
        $DONE_EVENTS = '';
        if (!$options['display_done_events']) {
            $DONE_EVENTS = "`" . $item->getTable() . "`.`state` != " . Planning::DONE . " AND";
        }
        $addrestrict = '';
        if ($parentitem->maybeDeleted()) {
            $addrestrict = 'AND NOT `' . $parentitem->getTable() . '`.`is_deleted`';
        }
        $query = "SELECT `" . $item->getTable() . "`.*\n                FROM `" . $item->getTable() . "`\n                INNER JOIN `" . $parentitem->getTable() . "`\n                  ON (`" . $parentitem->getTable() . "`.`id` = `" . $item->getTable() . "`.`" . $parentitem->getForeignKeyField() . "`)\n                WHERE {$ASSIGN}\n                      {$DONE_EVENTS}\n                      '{$begin}' < `" . $item->getTable() . "`.`end`\n                      AND '{$end}' > `" . $item->getTable() . "`.`begin`\n                      {$addrestrict}\n                ORDER BY `" . $item->getTable() . "`.`begin`";
        $result = $DB->query($query);
        $interv = array();
        if ($DB->numrows($result) > 0) {
            for ($i = 0; $data = $DB->fetch_assoc($result); $i++) {
                if ($item->getFromDB($data["id"]) && $item->canViewItem()) {
                    if ($parentitem->getFromDBwithData($item->fields[$parentitem->getForeignKeyField()], 0)) {
                        $key = $data["begin"] . "\$\$\$" . $itemtype . "\$\$\$" . $data["id"];
                        $interv[$key]['color'] = $options['color'];
                        $interv[$key]['event_type_color'] = $options['event_type_color'];
                        $interv[$key]['itemtype'] = $itemtype;
                        $interv[$key]["url"] = $parentitemtype::getFormURL() . "?id=" . $item->fields[$parentitem->getForeignKeyField()];
                        $interv[$key]["ajaxurl"] = $CFG_GLPI["root_doc"] . "/ajax/planning.php" . "?action=edit_event_form" . "&itemtype=" . $itemtype . "&parentitemtype=" . $parentitemtype . "&parentid=" . $item->fields[$parentitem->getForeignKeyField()] . "&id=" . $data['id'] . "&url=" . $interv[$key]["url"];
                        $interv[$key][$item->getForeignKeyField()] = $data["id"];
                        $interv[$key]["id"] = $data["id"];
                        if (isset($data["state"])) {
                            $interv[$key]["state"] = $data["state"];
                        }
                        $interv[$key][$parentitem->getForeignKeyField()] = $item->fields[$parentitem->getForeignKeyField()];
                        $interv[$key]["users_id"] = $data["users_id"];
                        $interv[$key]["users_id_tech"] = $data["users_id_tech"];
                        $interv[$key]["groups_id_tech"] = $data["groups_id_tech"];
                        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"] = $parentitem->fields["name"];
                        $interv[$key]["content"] = Html::resume_text($item->fields["content"], $CFG_GLPI["cut"]);
                        $interv[$key]["status"] = $parentitem->fields["status"];
                        $interv[$key]["priority"] = $parentitem->fields["priority"];
                        $interv[$key]["editable"] = $item->canUpdateITILItem();
                        /// Specific for tickets
                        $interv[$key]["device"] = '';
                        if (isset($parentitem->hardwaredatas) && !empty($parentitem->hardwaredatas)) {
                            foreach ($parentitem->hardwaredatas as $hardwaredata) {
                                $interv[$key]["device"][$hardwaredata->fields['id']] = $hardwaredata ? $hardwaredata->getName() : '';
                            }
                            $interv[$key]["device"] = implode("<br>", $interv[$key]["device"]);
                        }
                    }
                }
            }
        }
        return $interv;
    }

Usage Example

 /**
  * Populate the planning with planned ticket tasks
  *
  * @param $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
  *
  * @return array of planning item
  **/
 static function populatePlanning($options = array())
 {
     return parent::genericPopulatePlanning('TicketTask', $options);
 }
All Usage Examples Of CommonITILTask::genericPopulatePlanning