Planning::constructEventsArray PHP Method

constructEventsArray() static public method

Call populatePlanning functions for all $CFG_GLPI['planning_types'] types
Since: 9.1
static public constructEventsArray ( array $options = [] ) : array
$options array with this keys: - begin: mandatory, planning start. (should be an ISO_8601 date, but could be anything wo can be parsed by strtotime) - end: mandatory, planning end. (should be an ISO_8601 date, but could be anything wo can be parsed by strtotime) - display_done_events: default true, show also events tagged as done
return array $events : array with events in fullcalendar.io format
    static function constructEventsArray($options = array())
    {
        global $CFG_GLPI;
        $param['start'] = '';
        $param['end'] = '';
        $param['display_done_events'] = true;
        if (is_array($options) && count($options)) {
            foreach ($options as $key => $val) {
                $param[$key] = $val;
            }
        }
        $param['begin'] = date("Y-m-d H:i:s", strtotime($param['start']));
        $param['end'] = date("Y-m-d H:i:s", strtotime($param['end']));
        $raw_events = array();
        foreach ($CFG_GLPI['planning_types'] as $planning_type) {
            if (!$planning_type::canView()) {
                continue;
            }
            if ($_SESSION['glpi_plannings']['filters'][$planning_type]['display']) {
                $event_type_color = $_SESSION['glpi_plannings']['filters'][$planning_type]['color'];
                foreach ($_SESSION['glpi_plannings']['plannings'] as $actor => $actor_params) {
                    $actor_params['event_type_color'] = $event_type_color;
                    $actor_params['planning_type'] = $planning_type;
                    self::constructEventsArraySingleLine($actor, array_merge($param, $actor_params), $raw_events);
                }
            }
        }
        // construct events (in fullcalendar format)
        $events = array();
        foreach ($raw_events as $event) {
            $users_id = isset($event['users_id_tech']) && !empty($event['users_id_tech']) ? $event['users_id_tech'] : $event['users_id'];
            $content = Planning::displayPlanningItem($event, $users_id, 'in', false);
            $tooltip = Planning::displayPlanningItem($event, $users_id, 'in', true);
            $begin = date('c', strtotime($event['begin']));
            $end = date('c', strtotime($event['end']));
            // retreive all day events
            if (strpos($event['begin'], "00:00:00") != false && (strtotime($event['end']) - strtotime($event['begin'])) % DAY_TIMESTAMP == 0) {
                $begin = date('Y-m-d', strtotime($event['begin']));
                $end = date('Y-m-d', strtotime($event['end']));
            }
            $index_color = array_search("user_{$users_id}", array_keys($_SESSION['glpi_plannings']));
            $events[] = array('title' => $event['name'], 'content' => $content, 'tooltip' => $tooltip, 'start' => $begin, 'end' => $end, 'editable' => isset($event['editable']) ? $event['editable'] : false, 'color' => empty($event['color']) ? Planning::$palette_bg[$index_color] : $event['color'], 'borderColor' => empty($event['event_type_color']) ? self::getPaletteColor('ev', $event['itemtype']) : $event['event_type_color'], 'textColor' => Planning::$palette_fg[$index_color], 'typeColor' => empty($event['event_type_color']) ? self::getPaletteColor('ev', $event['itemtype']) : $event['event_type_color'], 'url' => isset($event['url']) ? $event['url'] : "", 'ajaxurl' => isset($event['ajaxurl']) ? $event['ajaxurl'] : "", 'itemtype' => $event['itemtype'], 'parentitemtype' => isset($event['parentitemtype']) ? $event['parentitemtype'] : "", 'items_id' => $event['id'], 'priority' => isset($event['priority']) ? $event['priority'] : "", 'state' => isset($event['state']) ? $event['state'] : "");
        }
        return $events;
    }

Usage Example

Ejemplo n.º 1
0
You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkCentralAccess();
if (!isset($_REQUEST["action"])) {
    exit;
}
if ($_REQUEST["action"] == "get_events") {
    header("Content-Type: application/json; charset=UTF-8");
    echo json_encode(Planning::constructEventsArray($_REQUEST));
    exit;
}
if ($_REQUEST["action"] == "update_event_times") {
    echo Planning::updateEventTimes($_REQUEST);
    exit;
}
Html::header_nocache();
header("Content-Type: text/html; charset=UTF-8");
if ($_REQUEST["action"] == "add_event_fromselect") {
    Planning::showAddEventForm($_REQUEST);
}
if ($_REQUEST["action"] == "add_event_sub_form") {
    Planning::showAddEventSubForm($_REQUEST);
}
if ($_REQUEST["action"] == "add_planning_form") {