Commit 28e42d41 authored by Johan Cwiklinski's avatar Johan Cwiklinski Committed by Johan Cwiklinski

Convert to iterator

Use iterator for search join conditions and replace hardcoded conditions
parent d45be5cf
......@@ -1154,6 +1154,11 @@ abstract class API extends CommonGLPI {
//specific case for restriction
$already_linked_table = [];
$join = $search->addDefaultJoin($itemtype, $table, $already_linked_table);
$join = $DB->mergeStatementWithParams(
$join,
$search->getQueryParams()
);
$where = $search->addDefaultWhere($itemtype);
if ($where == '') {
$where = "1=1 ";
......
......@@ -323,8 +323,8 @@ class CartridgeItem extends CommonDBTM {
'massiveaction' => false,
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`date_use` IS NOT NULL
AND NEWTABLE.`date_out` IS NULL'
'condition' => ['NOT' => ['NEWTABLE.date_use' >= null],
'NEWTABLE.date_out' => null]
]
];
......@@ -339,7 +339,7 @@ class CartridgeItem extends CommonDBTM {
'massiveaction' => false,
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`date_out` IS NOT NULL'
'condition' => ['NOT' => ['NEWTABLE.date_out' => null]]
]
];
......@@ -354,8 +354,8 @@ class CartridgeItem extends CommonDBTM {
'massiveaction' => false,
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`date_use` IS NULL
AND NEWTABLE.`date_out` IS NULL'
'condition' => ['NEWTABLE.date_use' => null,
'NEWTABLE.date_out' => null]
]
];
......
......@@ -2978,7 +2978,7 @@ abstract class CommonITILObject extends CommonDBTM {
if (!Session::isCron() // no filter for cron
&& Session::getCurrentInterface() == 'helpdesk') {
$newtab['condition'] = "`is_helpdeskvisible`";
$newtab['condition'] = ['is_helpdeskvisible' => 1];
}
$tab[] = $newtab;
......@@ -3031,6 +3031,7 @@ abstract class CommonITILObject extends CommonDBTM {
* @since 0.85
**/
function getSearchOptionsSolution() {
global $DB;
$tab = [];
......@@ -3098,14 +3099,18 @@ abstract class CommonITILObject extends CommonDBTM {
'joinparams' => [
'jointype' => 'itemtype_item',
// Get only last created solution
'condition' => '
AND NEWTABLE.`id` = (
SELECT `id` FROM `' . ITILSolution::getTable() . '`
WHERE `' . ITILSolution::getTable() . '`.`items_id` = REFTABLE.`id`
AND `' . ITILSolution::getTable() . '`.`itemtype` = \'' . static::getType() . '\'
ORDER BY `' . ITILSolution::getTable() . '`.`id` DESC
LIMIT 1
)'
'condition' => [
'NEWTABLE.id' => ['=', new QuerySubQuery([
'SELECT' => 'id',
'FROM' => ITILSolution::getTable(),
'WHERE' => [
ITILSolution::getTable() . '.items_id' => new QueryExpression($DB->quoteName('REFTABLE.id')),
ITILSolution::getTable() . '.itemtype' => static::getType()
],
'ORDER' => ITILSolution::getTable() . '.id DESC',
'LIMIT' => 1
])]
]
]
];
......@@ -3177,7 +3182,7 @@ abstract class CommonITILObject extends CommonDBTM {
'table' => getTableForItemType($this->userlinkclass),
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`type` = '.CommonITILActor::REQUESTER
'condition' => ['NEWTABLE.type' => CommonITILActor::REQUESTER]
]
]
]
......@@ -3197,13 +3202,13 @@ abstract class CommonITILObject extends CommonDBTM {
'name' => __('Requester group'),
'forcegroupby' => true,
'massiveaction' => false,
'condition' => 'is_requester',
'condition' => ['is_requester' => 1],
'joinparams' => [
'beforejoin' => [
'table' => getTableForItemType($this->grouplinkclass),
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`type` = '.CommonITILActor::REQUESTER
'condition' => ['NEWTABLE.type' => CommonITILActor::REQUESTER]
]
]
]
......@@ -3211,7 +3216,7 @@ abstract class CommonITILObject extends CommonDBTM {
if (!Session::isCron() // no filter for cron
&& Session::getCurrentInterface() == 'helpdesk') {
$newtab['condition'] .= " AND `id` IN (".implode(",", $_SESSION['glpigroups']).")";
$newtab['condition']['id'] = $_SESSION['glpigroups'];
}
$tab[] = $newtab;
......@@ -3250,7 +3255,7 @@ abstract class CommonITILObject extends CommonDBTM {
'table' => getTableForItemType($this->userlinkclass),
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`type` = '.CommonITILActor::OBSERVER
'condition' => ['NEWTABLE.type' => CommonITILActor::OBSERVER]
]
]
]
......@@ -3264,13 +3269,13 @@ abstract class CommonITILObject extends CommonDBTM {
'name' => __('Watcher group'),
'forcegroupby' => true,
'massiveaction' => false,
'condition' => 'is_requester',
'condition' => ['is_requester' => 1],
'joinparams' => [
'beforejoin' => [
'table' => getTableForItemType($this->grouplinkclass),
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`type` = '.CommonITILActor::OBSERVER
'condition' => ['NEWTABLE.type' => CommonITILActor::OBSERVER]
]
]
]
......@@ -3295,7 +3300,7 @@ abstract class CommonITILObject extends CommonDBTM {
'table' => getTableForItemType($this->userlinkclass),
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`type` = '.CommonITILActor::ASSIGN
'condition' => ['NEWTABLE.type' => CommonITILActor::ASSIGN]
]
]
]
......@@ -3314,7 +3319,7 @@ abstract class CommonITILObject extends CommonDBTM {
'table' => getTableForItemType($this->supplierlinkclass),
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`type` = '.CommonITILActor::ASSIGN
'condition' => ['NEWTABLE.type' => CommonITILActor::ASSIGN]
]
]
]
......@@ -3328,13 +3333,13 @@ abstract class CommonITILObject extends CommonDBTM {
'name' => __('Technician group'),
'forcegroupby' => true,
'massiveaction' => false,
'condition' => 'is_assign',
'condition' => ['is_assign' => 1],
'joinparams' => [
'beforejoin' => [
'table' => getTableForItemType($this->grouplinkclass),
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`type` = '.CommonITILActor::ASSIGN
'condition' => ['NEWTABLE.type' => CommonITILActor::ASSIGN]
]
]
]
......@@ -3354,7 +3359,7 @@ abstract class CommonITILObject extends CommonDBTM {
'massiveaction' => false,
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`type` = '.CommonITILActor::REQUESTER
'condition' => ['NEWTABLE.type' => CommonITILActor::REQUESTER]
]
];
......@@ -3367,7 +3372,7 @@ abstract class CommonITILObject extends CommonDBTM {
'massiveaction' => false,
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`type` = '.CommonITILActor::REQUESTER
'condition' => ['NEWTABLE.type' => CommonITILActor::REQUESTER]
]
];
......
......@@ -636,7 +636,7 @@ abstract class CommonITILTask extends CommonDBTM {
'field' => 'completename',
'name' => __('Group in charge of the task'),
'datatype' => 'dropdown',
'condition' => 'is_task'
'condition' => ['is_task' => 1]
];
return $tab;
......@@ -654,8 +654,12 @@ abstract class CommonITILTask extends CommonDBTM {
$task_condition = '';
if (!Session::haveRight("task", CommonITILTask::SEEPRIVATE)) {
$task_condition = "AND (`NEWTABLE`.`is_private` = 0
OR `NEWTABLE`.`users_id` = '".Session::getLoginUserID()."')";
$task_condition = [
'OR' => [
'NEWTABLE.is_private' => 0,
'NEWTABLE.users_id' => Session::getLoginUserID()
]
];
}
$tab[] = [
......@@ -780,7 +784,7 @@ abstract class CommonITILTask extends CommonDBTM {
'linkfield' => 'groups_id_tech',
'name' => __('Group in charge'),
'datatype' => 'itemlink',
'condition' => 'is_task',
'condition' => ['is_task' => 1],
'forcegroupby' => true,
'massiveaction' => false,
'joinparams' => [
......
......@@ -704,7 +704,7 @@ abstract class CommonTreeDropdown extends CommonDropdown {
'datatype' => 'dropdown',
'massiveaction' => false,
// Add virtual condition to relink table
'joinparams' => ['condition' => "AND 1=1"]
'joinparams' => ['condition' => [new QueryExpression("1=1")]]
];
$tab[] = [
......
......@@ -295,7 +295,7 @@ class ConsumableItem extends CommonDBTM {
'massiveaction' => false,
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`date_out` IS NOT NULL'
'condition' => ['NOT' => ['NEWTABLE.date_out' => null]]
]
];
......@@ -310,7 +310,7 @@ class ConsumableItem extends CommonDBTM {
'massiveaction' => false,
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`date_out` IS NULL'
'condition' => ['NEWTABLE.date_out' => null]
]
];
......
......@@ -507,7 +507,7 @@ class Group extends CommonTreeDropdown {
'table' => 'glpi_groups_users',
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`is_manager` = 1'
'condition' => ['NEWTABLE.is_manager' => 1]
]
]
]
......@@ -527,7 +527,7 @@ class Group extends CommonTreeDropdown {
'table' => 'glpi_groups_users',
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`is_userdelegate` = 1'
'condition' => ['NEWTABLE.is_userdelegate' => 1]
]
]
]
......
......@@ -542,8 +542,12 @@ class ITILFollowup extends CommonDBChild {
$followup_condition = '';
if (!Session::haveRight('followup', self::SEEPRIVATE)) {
$followup_condition = "AND (`NEWTABLE`.`is_private` = 0
OR `NEWTABLE`.`users_id` = '".Session::getLoginUserID()."')";
$followup_condition = [
'OR' => [
'NEWTABLE.is_private' => 0,
'NEWTABLE.users_id' => Session::getLoginUserID()
]
];
}
$tab[] = [
......
This diff is collapsed.
......@@ -675,7 +675,7 @@ class Link extends CommonDBTM {
if (!Session::isCron()
&& !isCommandLine() && isset($_SESSION['glpiactiveentities_string'])) {
$newtab['joinparams']['condition'] = getEntitiesRestrictRequest('AND', 'NEWTABLE');
$newtab['joinparams']['condition'] = getEntitiesRestrictCriteria('NEWTABLE');
}
$tab[] = $newtab;
......
......@@ -220,7 +220,7 @@ class NetworkName extends FQDNLabel {
'massiveaction' => false,
'joinparams' => [
'jointype' => 'mainitemtype_mainitem',
'condition' => 'AND NEWTABLE.`is_deleted` = 0'
'condition' => ['NEWTABLE.is_deleted' => 0]
]
];
......
......@@ -946,7 +946,7 @@ class NetworkPort extends CommonDBChild {
$networkNameJoin = ['jointype' => 'itemtype_item',
'specific_itemtype' => 'NetworkPort',
'condition' => 'AND NEWTABLE.`is_deleted` = 0',
'condition' => ['NEWTABLE.is_deleted' => 0],
'beforejoin' => ['table' => 'glpi_networkports',
'joinparams' => $joinparams]];
NetworkName::rawSearchOptionsToAdd($tab, $networkNameJoin, $itemtype);
......
......@@ -720,8 +720,8 @@ class Printer extends CommonDBTM {
'massiveaction' => false,
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`date_use` IS NOT NULL
AND NEWTABLE.`date_out` IS NULL'
'condition' => ['NOT' => ['NEWTABLE.date_use' => null],
'NEWTABLE.date_out' => null]
]
];
......@@ -736,7 +736,7 @@ class Printer extends CommonDBTM {
'massiveaction' => false,
'joinparams' => [
'jointype' => 'child',
'condition' => 'AND NEWTABLE.`date_out` IS NOT NULL'
'condition' => ['NOT' => ['NEWTABLE.date_out' => null]]
]
];
......
This diff is collapsed.
......@@ -444,6 +444,8 @@ class Project extends CommonDBTM {
function rawSearchOptions() {
global $DB;
$tab = [];
$tab[] = [
......@@ -487,7 +489,7 @@ class Project extends CommonDBTM {
'datatype' => 'itemlink',
'massiveaction' => false,
'joinparams' => [
'condition' => 'AND 1=1'
'condition' => [new QueryExpression('1=1')]
]
];
......@@ -683,7 +685,7 @@ class Project extends CommonDBTM {
'joinparams' => [
'jointype' => 'child',
'specific_itemtype' => 'ProjectCost',
'condition' => 'AND NEWTABLE.`projects_id` = REFTABLE.`id`',
'condition' => ['NEWTABLE.projects_id' => new QueryExpression($DB->quoteName('REFTABLE.id'))],
'beforejoin' => [
'table' => $this->getTable(),
'joinparams' => [
......@@ -793,7 +795,7 @@ class Project extends CommonDBTM {
'massiveaction' => false,
'joinparams' => [
'jointype' => 'child',
'condition' => "AND NEWTABLE.`itemtype` = '$itil_type'"
'condition' => ['NEWTABLE.itemtype' => $itil_type]
]
];
$index++;
......
......@@ -159,7 +159,7 @@ class RuleAsset extends Rule {
$actions['groups_id']['name'] = __('Group');
$actions['groups_id']['type'] = 'dropdown';
$actions['groups_id']['table'] = 'glpi_groups';
$actions['groups_id']['condition'] = 'is_itemgroup';
$actions['groups_id']['condition'] = ['is_itemgroup' => 1];
$actions['users_id_tech']['table'] = 'glpi_users';
$actions['users_id_tech']['type'] = 'dropdown';
......@@ -168,7 +168,7 @@ class RuleAsset extends Rule {
$actions['groups_id_tech']['name'] = __('Group in charge of the hardware');
$actions['groups_id_tech']['type'] = 'dropdown';
$actions['groups_id_tech']['table'] = 'glpi_groups';
$actions['groups_id_tech']['condition'] = 'is_assign';
$actions['groups_id_tech']['condition'] = ['is_assign' => 1];
$actions['comment']['table'] = '';
$actions['comment']['field'] = 'comment';
......
......@@ -339,7 +339,7 @@ class RuleRight extends Rule {
$actions['groups_id']['name'] = __('Default group');
$actions['groups_id']['linkfield'] = 'groups_id';
$actions['groups_id']['type'] = 'dropdown';
$actions['groups_id']['condition'] = "`is_usergroup`='1'";
$actions['groups_id']['condition'] = ['is_usergroup' => 1];
$actions['_profiles_id_default']['table'] = 'glpi_profiles';
$actions['_profiles_id_default']['field'] = 'name';
......
......@@ -409,7 +409,7 @@ class RuleTicket extends Rule {
$criterias['_groups_id_assign']['name'] = __('Technician group');
$criterias['_groups_id_assign']['linkfield'] = '_groups_id_assign';
$criterias['_groups_id_assign']['type'] = 'dropdown';
$criterias['_groups_id_assign']['condition'] = '`is_assign`';
$criterias['_groups_id_assign']['condition'] = ['is_assign' => 1];
$criterias['_suppliers_id_assign']['table'] = 'glpi_suppliers';
$criterias['_suppliers_id_assign']['field'] = 'name';
......@@ -478,7 +478,7 @@ class RuleTicket extends Rule {
__('Time to resolve'));
$criterias['slas_id_ttr']['linkfield'] = 'slas_id_ttr';
$criterias['slas_id_ttr']['type'] = 'dropdown';
$criterias['slas_id_ttr']['condition'] = "`glpi_slas`.`type` = '".SLM::TTR."'";
$criterias['slas_id_ttr']['condition'] = ['glpi_slas.type' => SLM::TTR];
$criterias['slas_id_tto']['table'] = 'glpi_slas';
$criterias['slas_id_tto']['field'] = 'name';
......@@ -486,7 +486,7 @@ class RuleTicket extends Rule {
__('Time to own'));
$criterias['slas_id_tto']['linkfield'] = 'slas_id_tto';
$criterias['slas_id_tto']['type'] = 'dropdown';
$criterias['slas_id_tto']['condition'] = "`glpi_slas`.`type` = '".SLM::TTO."'";
$criterias['slas_id_tto']['condition'] = ['glpi_slas.type' => SLM::TTO];
$criterias['olas_id_ttr']['table'] = 'glpi_olas';
$criterias['olas_id_ttr']['field'] = 'name';
......@@ -494,7 +494,7 @@ class RuleTicket extends Rule {
__('Time to resolve'));
$criterias['olas_id_ttr']['linkfield'] = 'olas_id_ttr';
$criterias['olas_id_ttr']['type'] = 'dropdown';
$criterias['olas_id_ttr']['condition'] = "`glpi_olas`.`type` = '".SLM::TTR."'";
$criterias['olas_id_ttr']['condition'] = ['glpi_olas.type' => SLM::TTR];
$criterias['olas_id_tto']['table'] = 'glpi_olas';
$criterias['olas_id_tto']['field'] = 'name';
......@@ -502,7 +502,7 @@ class RuleTicket extends Rule {
__('Time to own'));
$criterias['olas_id_tto']['linkfield'] = 'olas_id_tto';
$criterias['olas_id_tto']['type'] = 'dropdown';
$criterias['olas_id_tto']['condition'] = "`glpi_olas`.`type` = '".SLM::TTO."'";
$criterias['olas_id_tto']['condition'] = ['glpi_olas.type' => SLM::TTO];
$criterias['_date_creation_calendars_id'] = [
'name' => __("Creation date is a working hour in calendar"),
......@@ -539,7 +539,7 @@ class RuleTicket extends Rule {
$actions['_groups_id_requester']['name'] = __('Requester group');
$actions['_groups_id_requester']['type'] = 'dropdown';
$actions['_groups_id_requester']['table'] = 'glpi_groups';
$actions['_groups_id_requester']['condition'] = '`is_requester`';
$actions['_groups_id_requester']['condition'] = ['is_requester' => 1];
$actions['_groups_id_requester']['force_actions'] = ['assign', 'append', 'fromitem'];
$actions['_groups_id_requester']['permitseveral'] = ['append'];
$actions['_groups_id_requester']['appendto'] = '_additional_groups_requesters';
......@@ -555,7 +555,7 @@ class RuleTicket extends Rule {
$actions['_groups_id_assign']['table'] = 'glpi_groups';
$actions['_groups_id_assign']['name'] = __('Technician group');
$actions['_groups_id_assign']['type'] = 'dropdown';
$actions['_groups_id_assign']['condition'] = '`is_assign`';
$actions['_groups_id_assign']['condition'] = ['is_assign' => 1];
$actions['_groups_id_assign']['force_actions'] = ['assign', 'append'];
$actions['_groups_id_assign']['permitseveral'] = ['append'];
$actions['_groups_id_assign']['appendto'] = '_additional_groups_assigns';
......@@ -580,7 +580,7 @@ class RuleTicket extends Rule {
$actions['_groups_id_observer']['table'] = 'glpi_groups';
$actions['_groups_id_observer']['name'] = __('Watcher group');
$actions['_groups_id_observer']['type'] = 'dropdown';
$actions['_groups_id_observer']['condition'] = '`is_requester`';
$actions['_groups_id_observer']['condition'] = ['is_requester' => 1];
$actions['_groups_id_observer']['force_actions'] = ['assign', 'append'];
$actions['_groups_id_observer']['permitseveral'] = ['append'];
$actions['_groups_id_observer']['appendto'] = '_additional_groups_observers';
......@@ -609,7 +609,7 @@ class RuleTicket extends Rule {
__('Time to resolve'));
$actions['slas_id_ttr']['linkfield'] = 'slas_id_ttr';
$actions['slas_id_ttr']['type'] = 'dropdown';
$actions['slas_id_ttr']['condition'] = "`glpi_slas`.`type` = '".SLM::TTR."'";
$actions['slas_id_ttr']['condition'] = ['glpi_slas.type' => SLM::TTR];
$actions['slas_id_tto']['table'] = 'glpi_slas';
$actions['slas_id_tto']['field'] = 'name';
......@@ -617,7 +617,7 @@ class RuleTicket extends Rule {
__('Time to own'));
$actions['slas_id_tto']['linkfield'] = 'slas_id_tto';
$actions['slas_id_tto']['type'] = 'dropdown';
$actions['slas_id_tto']['condition'] = "`glpi_slas`.`type` = '".SLM::TTO."'";
$actions['slas_id_tto']['condition'] = ['glpi_slas.type' => SLM::TTO];
$actions['olas_id_ttr']['table'] = 'glpi_olas';
$actions['olas_id_ttr']['field'] = 'name';
......@@ -625,7 +625,7 @@ class RuleTicket extends Rule {
__('Time to resolve'));
$actions['olas_id_ttr']['linkfield'] = 'olas_id_ttr';
$actions['olas_id_ttr']['type'] = 'dropdown';
$actions['olas_id_ttr']['condition'] = "`glpi_olas`.`type` = '".SLM::TTR."'";
$actions['olas_id_ttr']['condition'] = ['glpi_olas.type' => SLM::TTR];
$actions['olas_id_tto']['table'] = 'glpi_olas';
$actions['olas_id_tto']['field'] = 'name';
......@@ -633,7 +633,7 @@ class RuleTicket extends Rule {
__('Time to own'));
$actions['olas_id_tto']['linkfield'] = 'olas_id_tto';
$actions['olas_id_tto']['type'] = 'dropdown';
$actions['olas_id_tto']['condition'] = "`glpi_olas`.`type` = '".SLM::TTO."'";
$actions['olas_id_tto']['condition'] = ['glpi_olas.type' => SLM::TTO];
$actions['users_id_validate']['name'] = sprintf(__('%1$s - %2$s'),
__('Send an approval request'),
......
......@@ -679,7 +679,7 @@ class Search {
* @since 10.0.0 Method is no longer static
**/
public function constructSQL(array &$data, $sub_item = false) {
global $CFG_GLPI, $DB;
global $CFG_GLPI;
if (!isset($data['itemtype'])) {
return false;
......@@ -723,7 +723,7 @@ class Search {
//// 2 - FROM AND LEFT JOIN
// Set reference table
$FROM = " FROM " . $DB->quoteName($itemtable);
$FROM = " FROM " . $this->db->quoteName($itemtable);
// Init already linked tables array in order not to link a table several times
$already_link_tables = [];
......@@ -791,7 +791,7 @@ class Search {
$LINK = " ";
$first = false;
}
$COMMONWHERE .= $LINK. $DB->quoteName("$itemtable.is_deleted") . " = " . (int)$data['search']['is_deleted'] . " ";
$COMMONWHERE .= $LINK. $this->db->quoteName("$itemtable.is_deleted") . " = " . (int)$data['search']['is_deleted'] . " ";
}
// Remove template items
......@@ -801,7 +801,7 @@ class Search {
$LINK = " ";
$first = false;
}
$COMMONWHERE .= $LINK . $DB->quoteName("$itemtable.is_template") . " = 0 ";
$COMMONWHERE .= $LINK . $this->db->quoteName("$itemtable.is_template") . " = 0 ";
}
// Add Restrict to current entities
......@@ -1052,8 +1052,8 @@ class Search {
// Replace 'AllAssets' by itemtype
// Use quoted value to prevent replacement of AllAssets in column identifiers
$tmpquery = str_replace(
$DB->quoteValue('AllAssets'),
$DB->quoteValue($ctype),
$this->db->quoteValue('AllAssets'),
$this->db->quoteValue($ctype),
$tmpquery
);
} else {// Ref table case
......@@ -5069,7 +5069,7 @@ JAVASCRIPT;
$condition = $joinparams['condition'];
if (is_array($condition)) {
$it = new DBmysqlIterator($this->db);
$condition = $it->analyseCrit($condition);
$condition = ' AND ' . $it->analyseCrit($condition);
$this->addQueryParams($it->getParameters());
}
$from = [
......@@ -5519,7 +5519,7 @@ JAVASCRIPT;
**/
public function giveItem($itemtype, $ID, array $data, $meta = 0,
array $addobjectparams = [], $orig_itemtype = null) {
global $CFG_GLPI, $DB;
global $CFG_GLPI;
$searchopt = &self::getOptions($itemtype);
if ($itemtype == 'AllAssets' || isset($CFG_GLPI["union_search_type"][$itemtype])
......@@ -7693,7 +7693,18 @@ JAVASCRIPT;
$complexjoin = '';
if (isset($joinparams['condition'])) {
$complexjoin .= $joinparams['condition'];
if (!is_array($joinparams['condition'])) {
$complexjoin .= $joinparams['condition'];
} else {
global $DB;
$dbi = new DBMysqlIterator($DB);
$sql_clause = $dbi->analyseCrit($joinparams['condition']);
$sql_expr = $DB->mergeStatementWithParams(
$sql_clause,
$dbi->getParameters()
);
$complexjoin .= ' AND ' . $sql_expr; //TODO: and should came from conf
}
}
// For jointype == child
......@@ -7711,7 +7722,18 @@ JAVASCRIPT;
$complexjoin .= $tab['table'];
}
if (isset($tab['joinparams']) && isset($tab['joinparams']['condition'])) {
$complexjoin .= $tab['joinparams']['condition'];
if (!is_array($tab['joinparams']['condition'])) {
$complexjoin .= $tab['joinparams']['condition'];
} else {
global $DB;
$dbi = new DBMysqlIterator($DB);
$sql_clause = $dbi->analyseCrit($tab['joinparams']['condition']);
$sql_expr = $DB->mergeStatementWithParams(
$sql_clause,
$dbi->getParameters()
);
$complexjoin .= ' AND ' . $sql_expr; //TODO: and should came from conf
}
}
}
}
......
......@@ -586,15 +586,18 @@ class Software extends CommonDBTM {
'beforejoin' => [
'table' => 'glpi_softwareversions',
'joinparams' => ['jointype' => 'child'],
'condition' => "AND NEWTABLE.`is_deleted_computer` = 0
AND NEWTABLE.`is_deleted` = 0
AND NEWTABLE.`is_template_computer` = 0"
'condition' => ['NEWTABLE.is_deleted_computer' => 0,
'NEWTABLE.is_deleted' => 0,
'NEWTABLE.is_template_computer' => 0]
],
]
];
if (Session::getLoginUserID()) {
$newtab['joinparams']['beforejoin']['condition'] .= getEntitiesRestrictRequest(' AND', 'NEWTABLE');
$newtab['joinparams']['beforejoin']['condition'] = array_merge(
$newtab['joinparams']['beforejoin']['condition'],
getEntitiesRestrictCriteria('NEWTABLE')