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]]
]
];
......
......@@ -1631,7 +1631,7 @@ class Profile extends CommonDBTM {
'rightname' => 'computer',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'computer'"
'condition' => ['NEWTABLE.name' => 'computer']
]
];
......@@ -1645,7 +1645,7 @@ class Profile extends CommonDBTM {
'rightname' => 'monitor',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'monitor'"
'condition' => ['NEWTABLE.name' => 'monitor']
]
];
......@@ -1659,7 +1659,7 @@ class Profile extends CommonDBTM {
'rightname' => 'software',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'software'"
'condition' => ['NEWTABLE.name' => 'software']
]
];
......@@ -1673,7 +1673,7 @@ class Profile extends CommonDBTM {
'rightname' => 'networking',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'networking'"
'condition' => ['NEWTABLE.name' => 'networking']
]
];
......@@ -1687,7 +1687,7 @@ class Profile extends CommonDBTM {
'rightname' => 'printer',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'printer'"
'condition' => ['NEWTABLE.name' => 'printer']
]
];
......@@ -1701,7 +1701,7 @@ class Profile extends CommonDBTM {
'rightname' => 'peripheral',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'peripheral'"
'condition' => ['NEWTABLE.name' => 'peripheral']
]
];
......@@ -1715,7 +1715,7 @@ class Profile extends CommonDBTM {
'rightname' => 'cartridge',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'cartridge'"
'condition' => ['NEWTABLE.name' => 'cartridge']
]
];
......@@ -1729,7 +1729,7 @@ class Profile extends CommonDBTM {
'rightname' => 'consumable',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'consumable'"
'condition' => ['NEWTABLE.name' => 'consumable']
]
];
......@@ -1743,7 +1743,7 @@ class Profile extends CommonDBTM {
'rightname' => 'phone',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'phone'"
'condition' => ['NEWTABLE.name' => 'phone']
]
];
......@@ -1757,7 +1757,7 @@ class Profile extends CommonDBTM {
'rightname' => 'internet',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'internet'"
'condition' => ['NEWTABLE.name' => 'internet']
]
];
......@@ -1776,7 +1776,7 @@ class Profile extends CommonDBTM {
'rightname' => 'contact_entreprise',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'contact_enterprise'"
'condition' => ['NEWTABLE.name' => 'contact_enterprise']
]
];
......@@ -1790,7 +1790,7 @@ class Profile extends CommonDBTM {
'rightname' => 'document',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'document'"
'condition' => ['NEWTABLE.name' => 'document']
]
];
......@@ -1804,7 +1804,7 @@ class Profile extends CommonDBTM {
'rightname' => 'contract',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'contract'"
'condition' => ['NEWTABLE.name' => 'contract']
]
];
......@@ -1818,7 +1818,7 @@ class Profile extends CommonDBTM {
'rightname' => 'infocom',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'infocom'"
'condition' => ['NEWTABLE.name' => 'infocom']
]
];
......@@ -1832,7 +1832,7 @@ class Profile extends CommonDBTM {
'rightname' => 'budget',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'budget'"
'condition' => ['NEWTABLE.name' => 'budget']
]
];
......@@ -1851,7 +1851,7 @@ class Profile extends CommonDBTM {
'rightname' => 'knowbase',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'knowbase'"
'condition' => ['NEWTABLE.name' => 'knowbase']
]
];
......@@ -1865,7 +1865,7 @@ class Profile extends CommonDBTM {
'rightname' => 'reservation',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'reservation'"
'condition' => ['NEWTABLE.name' => 'reservation']
]
];
......@@ -1880,7 +1880,7 @@ class Profile extends CommonDBTM {
'nowrite' => true,
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'reports'"
'condition' => ['NEWTABLE.name' => 'reports']
]
];
......@@ -1899,7 +1899,7 @@ class Profile extends CommonDBTM {
'rightname' => 'dropdown',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'dropdown'"
'condition' => ['NEWTABLE.name' => 'dropdown']
]
];
......@@ -1914,7 +1914,7 @@ class Profile extends CommonDBTM {
'noread' => true,
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'device'"
'condition' => ['NEWTABLE.name' => 'device']
]
];
......@@ -1928,7 +1928,7 @@ class Profile extends CommonDBTM {
'rightname' => 'notification',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'notification'"
'condition' => ['NEWTABLE.name' => 'notification']
]
];
......@@ -1942,7 +1942,7 @@ class Profile extends CommonDBTM {
'rightname' => 'typedoc',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'typedoc'"
'condition' => ['NEWTABLE.name' => 'typedoc']
]
];
......@@ -1956,7 +1956,7 @@ class Profile extends CommonDBTM {
'rightname' => 'link',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'link'"
'condition' => ['NEWTABLE.name' => 'link']
]
];
......@@ -1971,7 +1971,7 @@ class Profile extends CommonDBTM {
'noread' => true,
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'config'"
'condition' => ['NEWTABLE.name' => 'config']
]
];
......@@ -1986,7 +1986,7 @@ class Profile extends CommonDBTM {
'noread' => true,
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'personalization'"
'condition' => ['NEWTABLE.name' => 'personalization']
]
];
......@@ -2001,7 +2001,7 @@ class Profile extends CommonDBTM {
'noread' => true,
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'search_config'"
'condition' => ['NEWTABLE.name' => 'search_config']
]
];
......@@ -2015,7 +2015,7 @@ class Profile extends CommonDBTM {
'rightname' => 'calendar',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'calendar'"
'condition' => ['NEWTABLE.name' => 'calendar']
]
];
......@@ -2035,7 +2035,7 @@ class Profile extends CommonDBTM {
'nowrite' => true,
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'rule_ticket'"
'condition' => ['NEWTABLE.name' => 'rule_ticket']
]
];
......@@ -2049,7 +2049,7 @@ class Profile extends CommonDBTM {
'rightname' => 'rule_mailcollector',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'rule_mailcollector'"
'condition' => ['NEWTABLE.name' => 'rule_mailcollector']
]
];
......@@ -2063,7 +2063,7 @@ class Profile extends CommonDBTM {
'rightname' => 'rule_import',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'rule_import'"
'condition' => ['NEWTABLE.name' => 'rule_import']
]
];
......@@ -2077,7 +2077,7 @@ class Profile extends CommonDBTM {
'rightname' => 'rule_ldap',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'rule_ldap'"
'condition' => ['NEWTABLE.name' => 'rule_ldap']
]
];
......@@ -2091,7 +2091,7 @@ class Profile extends CommonDBTM {
'rightname' => 'rule_softwarecategories',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'rule_softwarecategories'"
'condition' => ['NEWTABLE.name' => 'rule_softwarecategories']
]
];
......@@ -2105,7 +2105,7 @@ class Profile extends CommonDBTM {
'rightname' => 'rule_dictionnary_software',
'joinparams' => [
'jointype' => 'child',
'condition' => "AND `NEWTABLE`.`name`= 'rule_dictionnary_software'"
'condition' => ['NEWTABLE.name' => 'rule_dictionnary_software']