本文整理汇总了PHP中Search::getMetaItemtypeAvailable方法的典型用法代码示例。如果您正苦于以下问题:PHP Search::getMetaItemtypeAvailable方法的具体用法?PHP Search::getMetaItemtypeAvailable怎么用?PHP Search::getMetaItemtypeAvailable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Search
的用法示例。
在下文中一共展示了Search::getMetaItemtypeAvailable方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showGenericSearch
/**
* Print generic search form
*
*@param $itemtype type to display the form
*@param $params parameters array may include field, contains, sort, is_deleted, link, link2, contains2, field2, type2
*
*@return nothing (displays)
*
**/
function showGenericSearch($params)
{
global $CFG_GLPI;
$itemtype = "PluginResourcesDirectory";
$itemtable = $this->table;
// Default values of parameters
$p['link'] = array();
//
$p['field'] = array();
$p['contains'] = array();
$p['searchtype'] = array();
$p['sort'] = '';
$p['is_deleted'] = 0;
$p['link2'] = '';
//
$p['contains2'] = '';
$p['field2'] = '';
$p['itemtype2'] = '';
$p['searchtype2'] = '';
foreach ($params as $key => $val) {
$p[$key] = $val;
}
$options = Search::getCleanedOptions("PluginResourcesDirectory");
$target = $CFG_GLPI["root_doc"] . "/plugins/resources/front/directory.php";
// Instanciate an object to access method
$item = NULL;
if (class_exists($itemtype)) {
$item = new $itemtype();
}
$linked = Search::getMetaItemtypeAvailable($itemtype);
echo "<form name='searchform{$itemtype}' method='get' action=\"{$target}\">";
echo "<table class='tab_cadre_fixe' >";
echo "<tr class='tab_bg_1'>";
echo "<td>";
echo "<table>";
// Display normal search parameters
for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) {
echo "<tr><td class='left' width='50%'>";
// First line display add / delete images for normal and meta search items
if ($i == 0) {
echo "<input type='hidden' disabled id='add_search_count' name='add_search_count' value='1'>";
echo "<a href='#' onClick = \"document.getElementById('add_search_count').disabled=false;document.forms['searchform{$itemtype}'].submit();\">";
echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/plus.png\" alt='+' title='" . __s('Add a search criterion') . "'></a> ";
if ($_SESSION["glpisearchcount"][$itemtype] > 1) {
echo "<input type='hidden' disabled id='delete_search_count' name='delete_search_count' value='1'>";
echo "<a href='#' onClick = \"document.getElementById('delete_search_count').disabled=false;document.forms['searchform{$itemtype}'].submit();\">";
echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/moins.png\" alt='-' title='" . __s('Delete a search criterion') . "'></a> ";
}
if (is_array($linked) && count($linked) > 0) {
echo "<input type='hidden' disabled id='add_search_count2' name='add_search_count2' value='1'>";
echo "<a href='#' onClick = \"document.getElementById('add_search_count2').disabled=false;document.forms['searchform{$itemtype}'].submit();\">";
echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_plus.png\" alt='+' title='" . __s('Add a global search criterion') . "'></a> ";
if ($_SESSION["glpisearchcount2"][$itemtype] > 0) {
echo "<input type='hidden' disabled id='delete_search_count2' name='delete_search_count2' value='1'>";
echo "<a href='#' onClick = \"document.getElementById('delete_search_count2').disabled=false;document.forms['searchform{$itemtype}'].submit();\">";
echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_moins.png\" alt='-' title='" . __s('Delete a global search criterion') . "'></a> ";
}
}
$itemtable = getTableForItemType($itemtype);
}
// Display link item
if ($i > 0) {
echo "<select name='link[{$i}]'>";
echo "<option value='AND' ";
if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "AND") {
echo "selected";
}
echo ">AND</option>\n";
echo "<option value='OR' ";
if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR") {
echo "selected";
}
echo ">OR</option>\n";
echo "<option value='AND NOT' ";
if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "AND NOT") {
echo "selected";
}
echo ">AND NOT</option>\n";
echo "<option value='OR NOT' ";
if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR NOT") {
echo "selected";
}
echo ">OR NOT</option>";
echo "</select> ";
}
// display select box to define serach item
echo "<select id='Search{$itemtype}{$i}' name=\"field[{$i}]\" size='1'>";
echo "<option value='view' ";
if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "view") {
echo "selected";
}
//.........这里部分代码省略.........
示例2: showGenericSearch
function showGenericSearch($itemtype, $params)
{
global $CFG_GLPI;
// Default values of parameters
$p = array();
$p['link'] = array();
//
$p['field'] = array();
$p['contains'] = array();
$p['searchtype'] = array();
$p['sort'] = '';
$p['is_deleted'] = 0;
$p['link2'] = '';
//
$p['contains2'] = '';
$p['field2'] = '';
$p['itemtype2'] = '';
$p['searchtype2'] = '';
foreach ($params as $key => $val) {
$p[$key] = $val;
}
$options = Search::getCleanedOptions($itemtype);
// $target = Toolbox::getItemTypeSearchURL($itemtype);
// Instanciate an object to access method
$item = NULL;
if ($itemtype != 'States' && class_exists($itemtype)) {
$item = new $itemtype();
}
$linked = Search::getMetaItemtypeAvailable($itemtype);
if (!isset($_GET['id']) || strstr($_SERVER['REQUEST_URI'], 'displayview_rule.form.php')) {
$item->getEmpty();
} else {
$item->getFromDB($_GET['id']);
}
if (strstr($_SERVER['REQUEST_URI'], 'displayview_rule.form.php')) {
echo "<form name='searchform{$itemtype}' method='get' action=\"" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/displayview_rule.form.php\">";
} else {
echo "<form name='searchform{$itemtype}' method='get' action=\"" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/componentscatalog_rule.form.php\">";
}
$item->showFormHeader();
// echo "<form name='searchform$itemtype' method='get' action=\"".
// $CFG_GLPI['root_doc']."/plugins/monitoring/front/componentscatalog_rule.form.php\">";
// echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_1'>";
echo "<td>";
echo __('Name') . " :";
echo "</td>";
echo "<td>";
echo "<input type='text' name='name' value='" . $_GET['name'] . "'/>";
echo "</td>";
echo "<td>";
echo __('Status') . " :";
echo "</td>";
echo "<td>";
echo $_GET['itemtype'];
echo "</td>";
echo "</tr>";
if (isset($_GET['itemtype'])) {
echo "<tr class='tab_bg_1'>";
echo "<td colspan='3'>";
echo "<table>";
// Display normal search parameters
for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) {
echo "<tr><td class='left' width='50%'>";
// First line display add / delete images for normal and meta search items
if ($i == 0) {
echo "<input type='hidden' disabled id='add_search_count' name='add_search_count'\n value='1'>";
echo "<a href='#' onClick = \"document.getElementById('add_search_count').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">";
echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/plus.png\" alt='+' title=\"" . __s('Add a search criterion') . "\"></a> ";
if ($_SESSION["glpisearchcount"][$itemtype] > 1) {
echo "<input type='hidden' disabled id='delete_search_count'\n name='delete_search_count' value='1'>";
echo "<a href='#' onClick = \"document.getElementById('delete_search_count').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">";
echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/moins.png\" alt='-' title=\"" . __s('Delete a search criterion') . "\"></a> ";
}
if (is_array($linked) && count($linked) > 0) {
echo "<input type='hidden' disabled id='add_search_count2' name='add_search_count2'\n value='1'>";
echo "<a href='#' onClick=\"document.getElementById('add_search_count2').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">";
echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_plus.png\" alt='+' title=\"" . __s('Add a global search criterion') . "\"></a> ";
if ($_SESSION["glpisearchcount2"][$itemtype] > 0) {
echo "<input type='hidden' disabled id='delete_search_count2'\n name='delete_search_count2' value='1'>";
echo "<a href='#' onClick=\"document.getElementById('delete_search_count2').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">";
echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_moins.png\" alt='-' title=\"" . __s('Delete a global search criterion') . "\"></a> ";
}
}
// $itemtable = getTableForItemType($itemtype);
// if ($item && $item->maybeDeleted()) {
// echo "<input type='hidden' id='is_deleted' name='is_deleted' value='".
// $p['is_deleted']."'>";
// echo "<a href='#' onClick = \"toogle('is_deleted','','','');
// document.forms['searchform$itemtype'].submit();\">
// <img src=\"".$CFG_GLPI["root_doc"]."/pics/showdeleted".
// (!$p['is_deleted']?'_no':'').".png\" name='img_deleted' alt=\"".
// (!$p['is_deleted']?$LANG['common'][3]:$LANG['common'][81])."\" title=\"".
// (!$p['is_deleted']?$LANG['common'][3]:$LANG['common'][81])."\" ></a>";
// // Dropdown::showYesNo("is_deleted",$p['is_deleted']);
// echo ' ';
// }
}
// Display link item
if ($i > 0) {
//.........这里部分代码省略.........
示例3: array
// Non define case
if (isset($_POST["itemtype"]) && isset($_POST["num"])) {
$metacriteria = array();
if (isset($_SESSION['glpisearch'][$_POST["itemtype"]]['metacriteria'][$_POST["num"]]) && is_array($_SESSION['glpisearch'][$_POST["itemtype"]]['metacriteria'][$_POST["num"]])) {
$metacriteria = $_SESSION['glpisearch'][$_POST["itemtype"]]['metacriteria'][$_POST["num"]];
} else {
// Set default field
$options = Search::getCleanedOptions($_POST["itemtype"]);
foreach ($options as $key => $val) {
if (is_array($val)) {
$metacriteria['field'] = $key;
break;
}
}
}
$linked = Search::getMetaItemtypeAvailable($_POST["itemtype"]);
$rand = mt_rand();
$rowid = 'metasearchrow' . $_POST['itemtype'] . $rand;
echo "<tr class='metacriteria' id='{$rowid}'><td class='left' colspan='2'>";
echo "<table class='tab_format'><tr class='left'>";
echo "<td width='30%'>";
echo "<img class='pointer' src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_moins.png\" alt='-' title=\"" . __s('Delete a global search criterion') . "\" onclick=\"" . Html::jsGetElementbyID($rowid) . ".remove();\">";
echo " ";
// Display link item (not for the first item)
$value = '';
if (isset($metacriteria["link"])) {
$value = $metacriteria["link"];
}
Dropdown::showFromArray("metacriteria[" . $_POST["num"] . "][link]", Search::getLogicalOperators(), array('value' => $value, 'width' => '40%'));
// Display select of the linked item type available
foreach ($linked as $key) {
示例4: prepareQueryToUse
/**
* Prepare query to use depending of the type
*
* @param $type bookmark type
* @param $query_tab parameters array
*
* @return prepared query array
**/
function prepareQueryToUse($type, $query_tab)
{
switch ($type) {
case self::SEARCH:
// Check if all datas are valid
$opt = Search::getCleanedOptions($this->fields['itemtype']);
$query_tab_save = $query_tab;
$partial_load = false;
// Standard search
if (isset($query_tab_save['criteria']) && count($query_tab_save['criteria'])) {
unset($query_tab['criteria']);
$new_key = 0;
foreach ($query_tab_save['criteria'] as $key => $val) {
if ($val['field'] != 'view' && $val['field'] != 'all' && (!isset($opt[$val['field']]) || isset($opt[$val['field']]['nosearch']) && $opt[$val['field']]['nosearch'])) {
$partial_load = true;
} else {
$query_tab['criteria'][$new_key] = $val;
$new_key++;
}
}
}
// Meta search
if (isset($query_tab_save['metacriteria']) && count($query_tab_save['metacriteria'])) {
$meta_ok = Search::getMetaItemtypeAvailable($query_tab['itemtype']);
unset($query_tab['metacriteria']);
$new_key = 0;
foreach ($query_tab_save['metacriteria'] as $key => $val) {
$opt = Search::getCleanedOptions($val['itemtype']);
// Use if meta type is valid and option available
if (!in_array($val['itemtype'], $meta_ok) || !isset($opt[$val['field']])) {
$partial_load = true;
} else {
$query_tab['metacriteria'][$new_key] = $val;
$new_key++;
}
}
}
// Display message
if ($partial_load) {
Session::addMessageAfterRedirect(__('Partial load of the bookmark.'), false, ERROR);
}
// add reset value
$query_tab['reset'] = 'reset';
break;
}
return $query_tab;
}
示例5: test_search_all_meta
/**
* Test search with all meta to not have SQL errors
*/
public function test_search_all_meta()
{
$itemtypeslist = array('Computer', 'Problem', 'Ticket', 'Printer', 'Monitor', 'Peripheral', 'Software', 'Phone');
foreach ($itemtypeslist as $itemtype) {
// do a search query
$search_params = array('is_deleted' => 0, 'start' => 0, 'criteria' => array(0 => array('field' => 'view', 'searchtype' => 'contains', 'value' => '')), 'metacriteria' => array());
$metacriteria = array();
$metaList = Search::getMetaItemtypeAvailable($itemtype);
foreach ($metaList as $metaitemtype) {
$item = getItemForItemtype($metaitemtype);
foreach ($item->getSearchOptions() as $key => $data) {
if (is_int($key)) {
if (isset($data['datatype']) && $data['datatype'] == 'bool') {
$metacriteria[] = array('link' => 'AND', 'field' => $key, 'searchtype' => 'equals', 'value' => 0);
} else {
$metacriteria[] = array('link' => 'AND', 'field' => $key, 'searchtype' => 'contains', 'value' => 'f');
}
}
}
}
$search_params['metacriteria'] = $metacriteria;
$data = $this->doSearch($itemtype, $search_params);
// check for sql error (data key missing or empty)
$this->assertArrayHasKey('data', $data, $data['last_errors']);
$this->assertNotCount(0, $data['data'], $data['last_errors']);
}
}
示例6: showCriteria
/**
* Displays tab content
* This function adapted from Search::showGenericSearch with controls removed
* @param bool $formcontrol : display form buttons
* @return nothing, displays a seach form
*/
static function showCriteria(PluginFusioninventoryDeployGroup $item, $formcontrol = true, $p)
{
global $CFG_GLPI, $DB;
$is_dynamic = $item->isDynamicGroup();
$itemtype = "PluginFusioninventoryComputer";
$can_update = $item->canEdit($item->getID());
if ($can_update) {
//show generic search form (duplicated from Search class)
echo "<form name='group_search_form' method='POST'>";
echo "<input type='hidden' name='plugin_fusioninventory_deploygroups_id' value='" . $item->getID() . "'>";
echo "<input type='hidden' name='id' value='" . $item->getID() . "'>";
// add tow hidden fields to permit delete of (meta)criteria
echo "<input type='hidden' name='criteria' value=''>";
echo "<input type='hidden' name='metacriteria' value=''>";
}
echo "<div class='tabs_criteria'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr><th>" . _n('Criterion', 'Criteria', 2) . "</th></tr>";
echo "<tr><td>";
echo "<div id='searchcriteria'>";
$nb_criteria = count($p['criteria']);
if ($nb_criteria == 0) {
$nb_criteria++;
}
$nb_meta_criteria = isset($p['metacriteria']) ? count($p['metacriteria']) : 0;
$nbsearchcountvar = 'nbcriteria' . strtolower($itemtype) . mt_rand();
$nbmetasearchcountvar = 'nbmetacriteria' . strtolower($itemtype) . mt_rand();
$searchcriteriatableid = 'criteriatable' . strtolower($itemtype) . mt_rand();
// init criteria count
$js = "var {$nbsearchcountvar}=" . $nb_criteria . ";";
$js .= "var {$nbmetasearchcountvar}=" . $nb_meta_criteria . ";";
echo Html::scriptBlock($js);
echo "<table class='tab_format' id='{$searchcriteriatableid}'>";
// Displays normal search parameters
for ($i = 0; $i < $nb_criteria; $i++) {
$_POST['itemtype'] = $itemtype;
$_POST['num'] = $i;
include GLPI_ROOT . '/ajax/searchrow.php';
}
$metanames = array();
$linked = Search::getMetaItemtypeAvailable('Computer');
if (is_array($linked) && count($linked) > 0) {
for ($i = 0; $i < $nb_meta_criteria; $i++) {
$_POST['itemtype'] = $itemtype;
$_POST['num'] = $i;
include GLPI_ROOT . '/ajax/searchmetarow.php';
}
}
echo "</table>\n";
echo "</td>";
echo "</tr>";
echo "</table>\n";
// For dropdown
echo "<input type='hidden' name='itemtype' value='{$itemtype}'>";
if ($can_update) {
// add new button to search form (to store and preview)
echo "<div class='center'>";
if ($is_dynamic) {
echo "<input type='submit' value=\" " . _sx('button', 'Save') . " \" class='submit' name='save'>";
} else {
echo "<input type='submit' value=\" " . __('Preview') . " \" class='submit' name='preview'>";
}
echo "</div>";
}
echo "</td></tr></table>";
echo "</div>";
//restore search session variables
//$_SESSION['glpisearch'] = $glpisearch_session;
// Reset to start when submit new search
echo "<input type='hidden' name='start' value='0'>";
Html::closeForm();
//clean with javascript search control
/*
$clean_script = "jQuery( document ).ready(function( $ ) {
$('#parent_criteria img').remove();
$('.tabs_criteria img[name=img_deleted').remove();
});";
echo Html::scriptBlock($clean_script);*/
}
示例7: prepareQueryToUse
/**
* Prepare query to use depending of the type
*
* @param $type bookmark type
* @param $query_tab parameters array
*
* @return prepared query array
**/
function prepareQueryToUse($type, $query_tab)
{
global $LANG;
switch ($type) {
case BOOKMARK_SEARCH:
// Check if all datas are valid
$opt = Search::getCleanedOptions($this->fields['itemtype']);
$query_tab_save = $query_tab;
$partial_load = false;
// Standard search
if (isset($query_tab_save['field']) && count($query_tab_save['field'])) {
unset($query_tab['field']);
unset($query_tab['searchtype']);
unset($query_tab['contains']);
unset($query_tab['link']);
$new_key = 0;
foreach ($query_tab_save['field'] as $key => $val) {
if ($val != 'view' && $val != 'all' && !isset($opt[$val])) {
$query_tab['glpisearchcount']--;
$partial_load = true;
} else {
$query_tab['field'][$new_key] = $val;
if (isset($query_tab_save['searchtype']) && isset($query_tab_save['searchtype'][$key])) {
$query_tab['searchtype'][$new_key] = $query_tab_save['searchtype'][$key];
}
$query_tab['contains'][$new_key] = $query_tab_save['contains'][$key];
if (isset($query_tab_save['link'][$key])) {
$query_tab['link'][$new_key] = $query_tab_save['link'][$key];
}
$new_key++;
}
}
}
if ($query_tab['glpisearchcount'] == 0) {
$query_tab['glpisearchcount'] = 1;
}
// Meta search
if (isset($query_tab_save['itemtype2']) && count($query_tab_save['itemtype2'])) {
$meta_ok = Search::getMetaItemtypeAvailable($query_tab['itemtype']);
unset($query_tab['field2']);
unset($query_tab['searchtype2']);
unset($query_tab['contains2']);
unset($query_tab['link2']);
unset($query_tab['itemtype2']);
$new_key = 0;
foreach ($query_tab_save['field2'] as $key => $val) {
$opt = Search::getCleanedOptions($query_tab_save['itemtype2'][$key]);
// Use if meta type is valid and option available
if (!in_array($query_tab_save['itemtype2'][$key], $meta_ok) || !isset($opt[$val])) {
$query_tab['glpisearchcount2']--;
$partial_load = true;
} else {
$query_tab['field2'][$new_key] = $val;
if (isset($query_tab_save['searchtype2']) && isset($query_tab_save['searchtype2'][$key])) {
$query_tab['searchtype2'][$new_key] = $query_tab_save['searchtype2'][$key];
}
$query_tab['contains2'][$new_key] = $query_tab_save['contains2'][$key];
$query_tab['link2'][$new_key] = $query_tab_save['link2'][$key];
$query_tab['itemtype2'][$new_key] = $query_tab_save['itemtype2'][$key];
$new_key++;
}
}
}
// Display message
if ($partial_load) {
addMessageAfterRedirect($LANG['bookmark'][2], false, ERROR);
}
// add reset value
$query_tab['reset'] = 'reset';
break;
}
return $query_tab;
}