Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 129 : New function _getSubcategories, and use it in sql_itilcat #132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion inc/helpdeskplus.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ function __construct($config = array()) {

if (isset($mr_values['itilcategories_id'])
&& $mr_values['itilcategories_id'] > 0) {
$this->sql_itilcat = "glpi_tickets.itilcategories_id = ".$mr_values['itilcategories_id'];
//TODO : add a beautifull checkBox in interface
if (true) {
$subCat=$this->_getSubcategories($mr_values['itilcategories_id']);
$this->sql_itilcat = "glpi_tickets.itilcategories_id IN (".$subCat." )";
} else {
$this->sql_itilcat = "glpi_tickets.itilcategories_id = ".$mr_values['itilcategories_id'];
}
}
}

Expand Down Expand Up @@ -1064,4 +1070,34 @@ private function _getPeriod() {
$this->_period_label = '%b %Y';
}
}

/**
* Get a list of Subcategories of glpi_itilcategories from one glpi_itilcategories.id
*
* @param $parentID The Id of the glpi_itilcategories
* @return String in format "id,itilcategories_id,itilcategories_id,itilcategories_id,itilcategories_id,..."
*/
private function _getSubcategories($parentID) {
global $DB, $LANG;

//Query With Parent included
//See https://stackoverflow.com/questions/20215744/how-to-create-a-mysql-hierarchical-recursive-query
$query = "select GROUP_CONCAT(concat (id )SEPARATOR ',') as LISTID from
(select id,
name,
itilcategories_id
from (select * from glpi_itilcategories
order by itilcategories_id, id) products_sorted,
(select @pv := '".$parentID."') initialisation
where
(find_in_set(itilcategories_id, @pv) > 0
and @pv := concat(@pv, ',', id)
) OR (id = ".$parentID.")
) as subCatID";

$result = $DB->query($query);
$data = $DB->fetch_assoc($result);

return $data['LISTID'];
}
}