本文整理汇总了PHP中Search::addDefaultJoin方法的典型用法代码示例。如果您正苦于以下问题:PHP Search::addDefaultJoin方法的具体用法?PHP Search::addDefaultJoin怎么用?PHP Search::addDefaultJoin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Search
的用法示例。
在下文中一共展示了Search::addDefaultJoin方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showMinimalList
//.........这里部分代码省略.........
foreach ($p['field'] as $key => $val) {
if (!in_array($val, $toview) && $val != 'all' && $val != 'view') {
array_push($toview, $val);
}
}
}
// Add order item
if (!in_array($p['sort'], $toview)) {
array_push($toview, $p['sort']);
}
// Clean toview array
$toview = array_unique($toview);
foreach ($toview as $key => $val) {
if (!isset($limitsearchopt[$val])) {
unset($toview[$key]);
}
}
$toview_count = count($toview);
//// 1 - SELECT
$query = "SELECT " . Search::addDefaultSelect($itemtype);
// Add select for all toview item
foreach ($toview as $key => $val) {
$query .= Search::addSelect($itemtype, $val, $key, 0);
}
$query .= "`" . $itemtable . "`.`id` AS id ";
//// 2 - FROM AND LEFT JOIN
// Set reference table
$query .= " FROM `" . $itemtable . "`";
// Init already linked tables array in order not to link a table several times
$already_link_tables = array();
// Put reference table
array_push($already_link_tables, $itemtable);
// Add default join
$COMMONLEFTJOIN = Search::addDefaultJoin($itemtype, $itemtable, $already_link_tables);
$query .= $COMMONLEFTJOIN;
$searchopt = array();
$searchopt[$itemtype] =& Search::getOptions($itemtype);
// Add all table for toview items
foreach ($toview as $key => $val) {
$query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"]);
}
// Search all case :
if (in_array("all", $p['field'])) {
foreach ($searchopt[$itemtype] as $key => $val) {
// Do not search on Group Name
if (is_array($val)) {
$query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"]);
}
}
}
//// 3 - WHERE
// default string
$COMMONWHERE = Search::addDefaultWhere($itemtype);
$first = empty($COMMONWHERE);
// Add deleted if item have it
if ($item && $item->maybeDeleted()) {
$LINK = " AND ";
if ($first) {
$LINK = " ";
$first = false;
}
$COMMONWHERE .= $LINK . "`{$itemtable}`.`is_deleted` = '" . $p['is_deleted'] . "' ";
}
// Remove template items
if ($item && $item->maybeTemplate()) {
$LINK = " AND ";
示例2: constructSQL
//.........这里部分代码省略.........
}
// Add order item
if (!in_array($p['sort'], $toview)) {
array_push($toview, $p['sort']);
}
// // Special case for Ticket : put ID in front
// if ($itemtype=='Ticket') {
// array_unshift($toview, 2);
// }
// Clean toview array
$toview = array_unique($toview);
foreach ($toview as $key => $val) {
if (!isset($limitsearchopt[$val])) {
unset($toview[$key]);
}
}
// $toview_count = count($toview);
// Construct the request
//// 1 - SELECT
// request currentuser for SQL supervision, not displayed
$SELECT = "SELECT " . Search::addDefaultSelect($itemtype);
// Add select for all toview item
foreach ($toview as $key => $val) {
$SELECT .= Search::addSelect($itemtype, $val, $key, 0);
}
//// 2 - FROM AND LEFT JOIN
// Set reference table
$FROM = " FROM `{$itemtable}`";
// Init already linked tables array in order not to link a table several times
$already_link_tables = array();
// Put reference table
array_push($already_link_tables, $itemtable);
// Add default join
$COMMONLEFTJOIN = Search::addDefaultJoin($itemtype, $itemtable, $already_link_tables);
$FROM .= $COMMONLEFTJOIN;
$searchopt = array();
$searchopt[$itemtype] =& Search::getOptions($itemtype);
// Add all table for toview items
foreach ($toview as $key => $val) {
$FROM .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$val]["joinparams"]);
}
// Search all case :
if (in_array("all", $p['field'])) {
foreach ($searchopt[$itemtype] as $key => $val) {
// Do not search on Group Name
if (is_array($val)) {
$FROM .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]);
}
}
}
//// 3 - WHERE
// default string
$COMMONWHERE = Search::addDefaultWhere($itemtype);
$first = empty($COMMONWHERE);
// Add deleted if item have it
if ($item && $item->maybeDeleted()) {
$LINK = " AND ";
if ($first) {
$LINK = " ";
$first = false;
}
$COMMONWHERE .= $LINK . "`{$itemtable}`.`is_deleted` = '" . $p['is_deleted'] . "' ";
}
// Remove template items
if ($item && $item->maybeTemplate()) {
$LINK = " AND ";
示例3: showMinimalList
//.........这里部分代码省略.........
foreach ($p['field'] as $key => $val) {
if (!in_array($val, $toview) && $val != 'all' && $val != 'view') {
array_push($toview, $val);
}
}
}
// Add order item
if (!in_array($p['sort'], $toview)) {
array_push($toview, $p['sort']);
}
// Clean toview array
$toview = array_unique($toview);
foreach ($toview as $key => $val) {
if (!isset($limitsearchopt[$val])) {
unset($toview[$key]);
}
}
$toview_count = count($toview);
//// 1 - SELECT
$query = "SELECT " . Search::addDefaultSelect($itemtype);
// Add select for all toview item
foreach ($toview as $key => $val) {
$query .= Search::addSelect($itemtype, $val, $key, 0);
}
$query .= "`" . $itemtable . "`.`id` AS id ";
//// 2 - FROM AND LEFT JOIN
// Set reference table
$query .= " FROM `" . $itemtable . "`";
// Init already linked tables array in order not to link a table several times
$already_link_tables = array();
// Put reference table
array_push($already_link_tables, $itemtable);
// Add default join
$COMMONLEFTJOIN = Search::addDefaultJoin($itemtype, $itemtable, $already_link_tables);
$query .= $COMMONLEFTJOIN;
$searchopt = array();
$searchopt[$itemtype] =& Search::getOptions($itemtype);
// Add all table for toview items
foreach ($toview as $key => $val) {
$query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$val]["joinparams"]);
}
// Search all case :
if (in_array("all", $p['field'])) {
foreach ($searchopt[$itemtype] as $key => $val) {
// Do not search on Group Name
if (is_array($val)) {
$query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]);
}
}
}
$query .= " WHERE `" . $itemtable . "`.`plugin_resources_resources_id` = '" . $p['id'] . "'";
$query .= " AND `" . $itemtable . "`.`is_deleted` = '" . $p['is_deleted'] . "' ";
//// 7 - Manage GROUP BY
$GROUPBY = "";
// Meta Search / Search All / Count tickets
if (in_array('all', $p['field'])) {
$GROUPBY = " GROUP BY `" . $itemtable . "`.`id`";
}
if (empty($GROUPBY)) {
foreach ($toview as $key2 => $val2) {
if (!empty($GROUPBY)) {
break;
}
if (isset($searchopt[$itemtype][$val2]["forcegroupby"])) {
$GROUPBY = " GROUP BY `" . $itemtable . "`.`id`";
}
示例4: showMinimalList
//.........这里部分代码省略.........
foreach ($p['field'] as $key => $val) {
if (!in_array($val, $toview) && $val != 'all' && $val != 'view') {
array_push($toview, $val);
}
}
}
// Add order item
if (!in_array($p['sort'], $toview)) {
array_push($toview, $p['sort']);
}
// Clean toview array
$toview = array_unique($toview);
foreach ($toview as $key => $val) {
if (!isset($limitsearchopt[$val])) {
unset($toview[$key]);
}
}
$toview_count = count($toview);
//// 1 - SELECT
$query = "SELECT " . Search::addDefaultSelect("User");
// Add select for all toview item
foreach ($toview as $key => $val) {
$query .= self::addSelect("PluginResourcesDirectory", $val, $key, 0);
}
$query .= "`glpi_plugin_resources_resources`.`id` AS id ";
//// 2 - FROM AND LEFT JOIN
// Set reference table
$query .= " FROM `" . $itemtable . "`";
// Init already linked tables array in order not to link a table several times
$already_link_tables = array();
// Put reference table
array_push($already_link_tables, $itemtable);
// Add default join
$COMMONLEFTJOIN = Search::addDefaultJoin("PluginResourcesDirectory", $itemtable, $already_link_tables);
$query .= $COMMONLEFTJOIN;
$searchopt = array();
$searchopt["PluginResourcesDirectory"] =& Search::getOptions("PluginResourcesDirectory");
// Add all table for toview items
foreach ($toview as $key => $val) {
$query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt["PluginResourcesDirectory"][$val]["table"], $searchopt["PluginResourcesDirectory"][$val]["linkfield"], 0, 0, $searchopt["PluginResourcesDirectory"][$val]["joinparams"]);
}
// Search all case :
if (in_array("all", $p['field'])) {
foreach ($searchopt[$itemtype] as $key => $val) {
// Do not search on Group Name
if (is_array($val)) {
$query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt["PluginResourcesDirectory"][$key]["table"], $searchopt["PluginResourcesDirectory"][$key]["linkfield"], 0, 0, $searchopt["PluginResourcesDirectory"][$key]["joinparams"]);
}
}
}
$ASSIGN = " `glpi_plugin_resources_resources`.`is_leaving` = 0 AND `glpi_users`.`is_active` = 1 AND ";
//// 3 - WHERE
// default string
$COMMONWHERE = Search::addDefaultWhere($itemtype);
$first = empty($COMMONWHERE);
// Add deleted if item have it
if ($PluginResourcesResource && $PluginResourcesResource->maybeDeleted()) {
$LINK = " AND ";
if ($first) {
$LINK = " ";
$first = false;
}
$COMMONWHERE .= $LINK . "`glpi_plugin_resources_resources`.`is_deleted` = '" . $p['is_deleted'] . "' ";
}
// Remove template items
if ($PluginResourcesResource && $PluginResourcesResource->maybeTemplate()) {
示例5: getItems
/**
* Return a collection of rows of the desired itemtype
*
* @param $itemtype string itemtype (class) of object
* @param $params array with theses options :
* - 'expand_dropdowns' (default: false): show dropdown's names instead of id. Optionnal
* - 'get_hateoas' (default: true): show relations of items in a links attribute. Optionnal
* - 'only_id' (default: false): keep only id in fields list. Optionnal
* - 'range' (default: 0-50): limit the list to start-end attributes
* - 'sort' (default: id): sort by the field.
* - 'order' (default: ASC): ASC(ending) or DESC(ending).
* - 'searchText' (default: NULL): array of filters to pass on the query (with key = field and value the search)
* @param $totalcount integer output parameter who receive the total count of the query resulat.
* As this function paginate results (with a mysql LIMIT),
* we can have the full range. (default 0)
*
* @return array collection of fields
**/
protected function getItems($itemtype, $params = array(), &$totalcount = 0)
{
global $DB;
$this->initEndpoint();
// default params
$default = array('expand_dropdowns' => false, 'get_hateoas' => true, 'only_id' => false, 'range' => "0-" . $_SESSION['glpilist_limit'], 'sort' => "id", 'order' => "ASC", 'searchText' => NULL);
$params = array_merge($default, $params);
if (!$itemtype::canView()) {
return $this->messageRightError();
}
$found = array();
$item = new $itemtype();
$item->getEmpty();
$table = getTableForItemType($itemtype);
// transform range parameter in start and limit variables
if (isset($params['range']) > 0) {
if (preg_match("/^[0-9]+-[0-9]+\$/", $params['range'])) {
$range = explode("-", $params['range']);
$params['start'] = $range[0];
$params['list_limit'] = $range[1] - $range[0] + 1;
$params['range'] = $range;
} else {
$this->returnError("range must be in format : [start-end] with integers");
}
} else {
$params['range'] = array(0, $_SESSION['glpilist_limit']);
}
// check parameters
if (isset($params['order']) && !in_array(strtoupper($params['order']), array('DESC', 'ASC'))) {
$this->returnError("order must be DESC or ASC");
}
if (!isset($item->fields[$params['sort']])) {
$this->returnError("sort param is not a field of {$table}");
}
//specific case for restriction
$already_linked_table = array();
$join = Search::addDefaultJoin($itemtype, $table, $already_linked_table);
$where = Search::addDefaultWhere($itemtype);
if ($where == '') {
$where = "1=1 ";
}
// add filter for a parent itemtype
if (isset($this->parameters['parent_itemtype']) && isset($this->parameters['parent_id'])) {
// check parent itemtype
if (!class_exists($this->parameters['parent_itemtype']) || !is_subclass_of($this->parameters['parent_itemtype'], 'CommonDBTM')) {
$this->returnError(__("parent itemtype not found or not an instance of CommonDBTM"), 400, "ERROR_ITEMTYPE_NOT_FOUND_NOR_COMMONDBTM");
}
$fk_parent = getForeignKeyFieldForItemType($this->parameters['parent_itemtype']);
$fk_child = getForeignKeyFieldForItemType($itemtype);
// check parent rights
$parent_item = new $this->parameters['parent_itemtype']();
if (!$parent_item->getFromDB($this->parameters['parent_id'])) {
return $this->messageNotfoundError();
}
if (!$parent_item->can($this->parameters['parent_id'], READ)) {
return $this->messageRightError();
}
// filter with parents fields
if (isset($item->fields[$fk_parent])) {
$where .= " AND `{$table}`.`{$fk_parent}` = " . $this->parameters['parent_id'];
} else {
if (isset($item->fields['itemtype']) && isset($item->fields['items_id'])) {
$where .= " AND `{$table}`.`itemtype` = '" . $this->parameters['parent_itemtype'] . "'\n AND `{$table}`.`items_id` = " . $this->parameters['parent_id'];
} else {
if (isset($parent_item->fields[$fk_child])) {
$parentTable = getTableForItemType($this->parameters['parent_itemtype']);
$join .= " LEFT JOIN `{$parentTable}` ON `{$parentTable}`.`{$fk_child}` = `{$table}`.`id` ";
$where .= " AND `{$parentTable}`.`id` = '" . $this->parameters['parent_id'] . "'";
} else {
if (isset($parent_item->fields['itemtype']) && isset($parent_item->fields['items_id'])) {
$parentTable = getTableForItemType($this->parameters['parent_itemtype']);
$join .= " LEFT JOIN `{$parentTable}` ON `itemtype`='{$itemtype}' AND `{$parentTable}`.`items_id` = `{$table}`.`id` ";
$where .= " AND `{$parentTable}`.`id` = '" . $this->parameters['parent_id'] . "'";
}
}
}
}
}
// filter by searchText parameter
if (is_array($params['searchText'])) {
if (array_keys($params['searchText']) == array('all')) {
$labelfield = "name";
//.........这里部分代码省略.........
示例6: showList
//.........这里部分代码省略.........
// Special case for Ticket : put ID in front
if ($itemtype == 'Ticket') {
array_unshift($toview, 2);
}
// Clean toview array
$toview = array_unique($toview);
foreach ($toview as $key => $val) {
if (!isset($limitsearchopt[$val])) {
unset($toview[$key]);
}
}
// delete entities display
//var_dump($toview);
if (array_search('80', $toview) !== false) {
unset($toview[array_search('80', $toview)]);
}
$toview_count = count($toview);
// Construct the request
//// 1 - SELECT
//$SELECT = "SELECT ".PluginMobileSearch::addDefaultSelect($itemtype);
$SELECT = "SELECT '" . $_SESSION['glpiname'] . "' AS currentuser, " . PluginMobileSearch::addDefaultSelect($itemtype);
// Add select for all toview item
foreach ($toview as $key => $val) {
$SELECT .= Search::addSelect($itemtype, $val, $key, 0);
}
//// 2 - FROM AND LEFT JOIN
// Set reference table
$FROM = " FROM `{$itemtable}`";
// Init already linked tables array in order not to link a table several times
$already_link_tables = array();
// Put reference table
array_push($already_link_tables, $itemtable);
// Add default join
$COMMONLEFTJOIN = Search::addDefaultJoin($itemtype, $itemtable, $already_link_tables);
$FROM .= $COMMONLEFTJOIN;
$searchopt = array();
$searchopt[$itemtype] =& Search::getOptions($itemtype);
// Add all table for toview items
//foreach ($toview as $key => $val) {
// $FROM .= Search::addLeftJoin($itemtype,$itemtable,$already_link_tables,
// $searchopt[$itemtype][$val]["table"],
// $searchopt[$itemtype][$val]["linkfield"]);
//}
foreach ($toview as $key => $val) {
$FROM .= self::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$val]["joinparams"]);
}
// Search all case :
//if (in_array("all",$p['field'])) {
// foreach ($searchopt[$itemtype] as $key => $val) {
// // Do not search on Group Name
// if (is_array($val)) {
// $FROM .= Search::addLeftJoin($itemtype,$itemtable,$already_link_tables,
// $searchopt[$itemtype][$key]["table"],
// $searchopt[$itemtype][$key]["linkfield"]);
// }
// }
//}
// Search all case :
if (in_array("all", $p['field'])) {
foreach ($searchopt[$itemtype] as $key => $val) {
// Do not search on Group Name
if (is_array($val)) {
$FROM .= self::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]);
}
}
}
示例7: getItems
/**
* Return a collection of rows of the desired itemtype
*
* @since version 9.1
*
* @param string $itemtype itemtype (class) of object
* @param array $params array with theses options :
* - 'expand_dropdowns' (default: false): show dropdown's names instead of id. Optionnal
* - 'get_hateoas' (default: true): show relations of items in a links attribute. Optionnal
* - 'only_id' (default: false): keep only id in fields list. Optionnal
* - 'range' (default: 0-50): limit the list to start-end attributes
*
* @return array collection of fields
*/
protected function getItems($itemtype, $params = array())
{
global $DB;
$this->initEndpoint();
// default params
$default = array('expand_dropdowns' => false, 'get_hateoas' => true, 'only_id' => false, 'range' => "0-50", 'sort' => "id", 'order' => "ASC");
$params = array_merge($default, $params);
if (!$itemtype::canView()) {
return $this->messageRightError();
}
$found = array();
$item = new $itemtype();
$item->getEmpty();
$table = getTableForItemType($itemtype);
// transform range parameter in start and limit variables
if (isset($params['range']) > 0) {
if (preg_match("/^[0-9]+-[0-9]+\$/", $params['range'])) {
$range = explode("-", $params['range']);
$params['start'] = $range[0];
$params['list_limit'] = $range[1] - $range[0];
} else {
$this->returnError("range must be in format : [start-end] with integers");
}
}
// check parameters
if (isset($params['order']) && !in_array(strtoupper($params['order']), array('DESC', 'ASC'))) {
$this->returnError("order must be DESC or ASC");
}
if (!isset($item->fields[$params['sort']])) {
$this->returnError("sort param is not a field of {$table}");
}
//specific case for restriction
$already_linked_table = array();
$where = "1=1 ";
$join = Search::addDefaultJoin($itemtype, $table, $already_linked_table);
$where .= Search::addDefaultWhere($itemtype);
// add filter for a parent itemtype
if (isset($this->parameters['parent_itemtype']) && isset($this->parameters['parent_id'])) {
// check parent itemtype
if (!class_exists($this->parameters['parent_itemtype']) || !is_subclass_of($this->parameters['parent_itemtype'], 'CommonDBTM')) {
$this->returnError(__("parent itemtype not found or not an instance of CommonDBTM"), 400, "ERROR_ITEMTYPE_NOT_FOUND_NOR_COMMONDBTM");
}
$fk_parent = getForeignKeyFieldForItemType($this->parameters['parent_itemtype']);
// check parent rights
$parent_item = new $this->parameters['parent_itemtype']();
if (!$parent_item->getFromDB($this->parameters['parent_id'])) {
return $this->messageNotfoundError();
}
if (!$parent_item->can($this->parameters['parent_id'], READ)) {
return $this->messageRightError();
}
// filter with parents fields
if (isset($item->fields[$fk_parent])) {
$where .= " AND `{$table}`.`{$fk_parent}` = " . $this->parameters['parent_id'];
} else {
if (isset($item->fields['itemtype']) && isset($item->fields['items_id'])) {
$where .= " AND `{$table}`.`itemtype` = '" . $this->parameters['parent_itemtype'] . "'\n AND `{$table}`.`items_id` = " . $this->parameters['parent_id'];
}
}
}
// filter with entity
if ($item->isEntityAssign()) {
$where .= getEntitiesRestrictRequest(" AND", $itemtype::getTable(), '', $_SESSION['glpiactiveentities']);
}
// build query
$query = "SELECT DISTINCT `{$table}`.id, `{$table}`.*\n FROM `{$table}`\n {$join}\n WHERE {$where}\n ORDER BY " . $params['sort'] . " " . $params['order'] . "\n LIMIT " . $params['start'] . ", " . $params['list_limit'];
if ($result = $DB->query($query)) {
while ($data = $DB->fetch_assoc($result)) {
$found[] = $data;
}
}
foreach ($found as $key => &$fields) {
// only keep id in field list
if ($params['only_id']) {
$fields = array('id' => $fields['id']);
}
// expand dropdown (retrieve name of dropdowns) and get hateoas
$fields = self::parseDropdowns($fields, $params);
// get hateoas from children
if ($params['get_hateoas']) {
$hclasses = self::getHatoasClasses($itemtype);
foreach ($hclasses as $hclass) {
$fields['links'][] = array('rel' => $hclass, 'href' => self::$api_url . "/{$itemtype}/" . $fields['id'] . "/{$hclass}/");
}
}
}
//.........这里部分代码省略.........