From b1646a78a770a3a8f2faa4b3504fd4186b9fd05a Mon Sep 17 00:00:00 2001 From: moyooo Date: Mon, 5 Jan 2009 21:45:47 +0000 Subject: [PATCH] addHaving for plugin example git-svn-id: https://forge.glpi-project.org/svn/example/trunk@58 349b9182-4a13-0410-896f-e5e9767dd1b3 --- hook.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hook.php b/hook.php index 7ae35d6..2a71d41 100644 --- a/hook.php +++ b/hook.php @@ -78,6 +78,7 @@ function plugin_example_getSearchOption(){ $sopt[PLUGIN_EXAMPLE_TYPE][3]['field']='serial'; $sopt[PLUGIN_EXAMPLE_TYPE][3]['linkfield']='serial'; $sopt[PLUGIN_EXAMPLE_TYPE][3]['name']='Serial'; + $sopt[PLUGIN_EXAMPLE_TYPE][3]['usehaving']=true; $sopt[PLUGIN_EXAMPLE_TYPE][30]['table']='glpi_plugin_example'; $sopt[PLUGIN_EXAMPLE_TYPE][30]['field']='ID'; @@ -148,6 +149,31 @@ function plugin_example_addWhere($link,$nott,$type,$ID,$val){ return ""; } +function plugin_example_addHaving($link,$nott,$type,$ID,$val,$num){ + global $SEARCH_OPTION; + + $table=$SEARCH_OPTION[$type][$ID]["table"]; + $field=$SEARCH_OPTION[$type][$ID]["field"]; + + $SEARCH=makeTextSearch($val,$nott); + + // Example of standard Having clause but use it ONLY for specific Having + // No need of the function if you do not have specific cases + switch ($table.".".$field){ + case "glpi_plugin_example.serial" : + $ADD=""; + if (($nott&&$val!="NULL")||$val=='^$') { + $ADD=" OR ITEM_$num IS NULL"; + } + + return " $LINK ( ITEM_".$num.$SEARCH." $ADD ) "; + break; + } + + + return ""; +} + function plugin_example_addSelect($type,$ID,$num){ global $SEARCH_OPTION;