From 776bab44281818cf2b370c28d5215c2ab9de5e7c Mon Sep 17 00:00:00 2001 From: moyooo Date: Tue, 24 Jan 2012 12:05:59 +0000 Subject: [PATCH] drop display_planning hook. Use standard function git-svn-id: https://forge.glpi-project.org/svn/example/trunk@186 349b9182-4a13-0410-896f-e5e9767dd1b3 --- hook.php | 33 ---------------------------- inc/example.class.php | 50 +++++++++++++++++++++++++++++++++++++------ setup.php | 4 +++- 3 files changed, 47 insertions(+), 40 deletions(-) diff --git a/hook.php b/hook.php index 6d97b20..1245fdb 100644 --- a/hook.php +++ b/hook.php @@ -499,39 +499,6 @@ function plugin_item_transfer_example($parm) { return false; } -// Display the planning item -function plugin_display_planning_example($parm) { - - // $parm["type"] say begin end in or from type - // Add items in the items fields of the parm array - switch ($parm["type"]) { - case "in" : - //TRANS: %1$s is the start time of a planned item, %2$s is the end and %3$s is its name - printf(__('From %1$s to %2$s: %3$s'),date("H:i",strtotime($parm["begin"])), - date("H:i",strtotime($parm["end"])), - Html::resume_text($parm["name"],80)) ; - - break; - - case "through" : - echo Html::resume_text($parm["name"],80); - break; - - case "begin" : - //TRANS: %1$s is the start time of a planned item, %2$s is its name - printf(__('Start at %1$s: %2$s'),date("H:i",strtotime($parm["begin"])), - Html::resume_text($parm["name"],80)) ; - break; - - case "end" : - //TRANS: %1$s is the end time of a planned item and %2$s is its name - printf(__('End at %1$s: %2$s'),date("H:i",strtotime($parm["end"])), - Html::resume_text($parm["name"],80)) ; - break; - } -} - - // Do special actions for dynamic report function plugin_example_dynamicReport($parm) { diff --git a/inc/example.class.php b/inc/example.class.php index e249b0b..ae4beb2 100644 --- a/inc/example.class.php +++ b/inc/example.class.php @@ -250,17 +250,55 @@ class PluginExampleExample extends CommonDBTM { // needed to be correcly displayed $output = array(); $key = $parm["begin"]."$$$"."plugin_example1"; - $output[$key]["plugin"] = "example"; $output[$key]["begin"] = date("Y-m-d 17:00:00"); $output[$key]["end"] = date("Y-m-d 18:00:00"); $output[$key]["name"] = __("test planning example 1"); - // Set the ID using the ID of the item in the database to have unique ID - $ID = date("Ymd"); // Current date for example - $output[$key]["planningID"] = "plugin_example".$ID; // Specify the itemtype to be able to use specific display system $output[$key]["itemtype"] = "PluginExampleExample"; + // Set the ID using the ID of the item in the database to have unique ID + $output[$key][getForeignKeyFieldForItemType('PluginExampleExample')] = 1; return $output; } + + /** + * Display a Planning Item + * + * @param $val Array of the item to display + * @param $who ID of the user (0 if all) + * @param $type position of the item in the time block (in, through, begin or end) + * @param $complete complete display (more details) + * + * @return Nothing (display function) + **/ + static function displayPlanningItem(array $val, $who, $type="", $complete=0) { + + // $parm["type"] say begin end in or from type + // Add items in the items fields of the parm array + switch ($type) { + case "in" : + //TRANS: %1$s is the start time of a planned item, %2$s is the end and %3$s is its name + printf(__('From %1$s to %2$s: %3$s'),date("H:i",strtotime($val["begin"])), + date("H:i",strtotime($val["end"])), + Html::resume_text($val["name"],80)) ; + + break; + + case "through" : + echo Html::resume_text($val["name"],80); + break; + + case "begin" : + //TRANS: %1$s is the start time of a planned item, %2$s is its name + printf(__('Start at %1$s: %2$s'),date("H:i",strtotime($val["begin"])), + Html::resume_text($val["name"],80)) ; + break; + + case "end" : + //TRANS: %1$s is the end time of a planned item and %2$s is its name + printf(__('End at %1$s: %2$s'),date("H:i",strtotime($val["end"])), + Html::resume_text($val["name"],80)) ; + break; + } + } } - -?> +?> \ No newline at end of file diff --git a/setup.php b/setup.php index decfe7f..118cc52 100755 --- a/setup.php +++ b/setup.php @@ -135,7 +135,9 @@ function plugin_init_example() { $CFG_GLPI['planning_types'][] = 'PluginExampleExample'; //function to display planning items - $PLUGIN_HOOKS['display_planning']['example'] = 'plugin_display_planning_example'; + // No more used sinc GLPi 0.84 + // $PLUGIN_HOOKS['display_planning']['example'] = 'plugin_display_planning_example'; + // Use instead : displayPlanningItem of the specific itemtype // Massive Action definition $PLUGIN_HOOKS['use_massive_action']['example'] = 1;