mirror of
				https://github.com/pluginsGLPI/example.git
				synced 2025-11-04 05:24:52 +01:00 
			
		
		
		
	drop display_planning hook. Use standard function
git-svn-id: https://forge.glpi-project.org/svn/example/trunk@186 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
		
							
								
								
									
										33
									
								
								hook.php
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								hook.php
									
									
									
									
									
								
							@@ -499,39 +499,6 @@ function plugin_item_transfer_example($parm) {
 | 
				
			|||||||
   return false;
 | 
					   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
 | 
					// Do special actions for dynamic report
 | 
				
			||||||
function plugin_example_dynamicReport($parm) {
 | 
					function plugin_example_dynamicReport($parm) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -250,17 +250,55 @@ class PluginExampleExample extends CommonDBTM {
 | 
				
			|||||||
      // needed to be correcly displayed
 | 
					      // needed to be correcly displayed
 | 
				
			||||||
      $output = array();
 | 
					      $output = array();
 | 
				
			||||||
      $key = $parm["begin"]."$$$"."plugin_example1";
 | 
					      $key = $parm["begin"]."$$$"."plugin_example1";
 | 
				
			||||||
      $output[$key]["plugin"] = "example";
 | 
					 | 
				
			||||||
      $output[$key]["begin"]  = date("Y-m-d 17:00:00");
 | 
					      $output[$key]["begin"]  = date("Y-m-d 17:00:00");
 | 
				
			||||||
      $output[$key]["end"]    = date("Y-m-d 18:00:00");
 | 
					      $output[$key]["end"]    = date("Y-m-d 18:00:00");
 | 
				
			||||||
      $output[$key]["name"]   = __("test planning example 1");
 | 
					      $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
 | 
					      // Specify the itemtype to be able to use specific display system
 | 
				
			||||||
      $output[$key]["itemtype"] = "PluginExampleExample";
 | 
					      $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;
 | 
					      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;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					   }   
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					?>
 | 
				
			||||||
?>
 | 
					 | 
				
			||||||
@@ -135,7 +135,9 @@ function plugin_init_example() {
 | 
				
			|||||||
   $CFG_GLPI['planning_types'][] = 'PluginExampleExample';
 | 
					   $CFG_GLPI['planning_types'][] = 'PluginExampleExample';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   //function to display planning items
 | 
					   //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
 | 
					   // Massive Action definition
 | 
				
			||||||
   $PLUGIN_HOOKS['use_massive_action']['example'] = 1;
 | 
					   $PLUGIN_HOOKS['use_massive_action']['example'] = 1;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user