diff --git a/inc/autocriteria.class.php b/inc/autocriteria.class.php index c38f775..513aa9a 100644 --- a/inc/autocriteria.class.php +++ b/inc/autocriteria.class.php @@ -42,7 +42,7 @@ abstract class PluginReportsAutoCriteria { private $criterias_labels = []; //Parameters are stored as name => value - private $parameters = []; + protected $parameters = []; //Field in the SQL request (can be table.field) private $sql_field = ""; diff --git a/inc/autoreport.class.php b/inc/autoreport.class.php index be4fca3..aea7049 100644 --- a/inc/autoreport.class.php +++ b/inc/autoreport.class.php @@ -37,6 +37,7 @@ * - query executing using with criterias restriction * - result display & export (HTML, PDF, CSV, SLK) **/ +#[\AllowDynamicProperties] class PluginReportsAutoReport { private $criterias = []; diff --git a/inc/dropdowncriteria.class.php b/inc/dropdowncriteria.class.php index 8672ff4..0a32ace 100644 --- a/inc/dropdowncriteria.class.php +++ b/inc/dropdowncriteria.class.php @@ -53,21 +53,24 @@ class PluginReportsDropdownCriteria extends PluginReportsAutoCriteria { // For special condition private $condition = ''; + private $multiple = false; - /** - * @param $report - * @param $name - * @param $tableortype (default '') - * @param $label (default '') - * @param $condition (default '') - **/ - function __construct($report, $name, $tableortype='', $label='', $condition='') { - parent::__construct($report, $name, $name, $label); + /** + * @param $report + * @param $name + * @param $tableortype (default '') + * @param $label (default '') + * @param $condition (default '') + * @param $multiple (default false) + **/ + function __construct($report, $name, $tableortype='', $label='', $condition='', $multiple = false) { + parent::__construct($report, $name, $name, $label); $dbu = new DbUtils(); $this->condition = $condition; + $this->multiple = $multiple; if (empty($tableortype)) { $this->table = $dbu->getTableNameForForeignKeyField($name); @@ -123,15 +126,19 @@ public function setSearchZero() { } - /** - * Set default criteria value to 0 and entity restriction to current entity only - **/ - public function setDefaultValues() { + /** + * Set default criteria value to 0 and entity restriction to current entity only + **/ + public function setDefaultValues() { + if (!$this->multiple) { + $this->addParameter($this->getName(), 0); + } else { + $this->addParameter($this->getName(), []); + } - $this->addParameter($this->getName(), 0); - $this->setEntityRestriction($_SESSION["glpiactive_entity"]); - $this->setDisplayComments(); - } + $this->setEntityRestriction($_SESSION["glpiactive_entity"]); + $this->setDisplayComments(); + } /** @@ -219,10 +226,18 @@ public function getEntityRestrict() { **/ public function getSubName() { - $value = $this->getParameterValue(); - if ($value) { - return $this->getCriteriaLabel()." : ".Dropdown::getDropdownName($this->getTable(), $value); - } + $value = $this->getParameterValue(); + if ($value) { + if ($this->multiple) { + $name = $this->getCriteriaLabel()." : "; + $names = []; + foreach($value as $v) { + $names[] = Dropdown::getDropdownName($this->getTable(), $v); + } + return $name . implode(', ', $names); + } + return $this->getCriteriaLabel()." : ".Dropdown::getDropdownName($this->getTable(), $value); + } if ($this->searchzero) { // zero @@ -259,11 +274,40 @@ public function displayDropdownCriteria() { 'comments' => $this->getDisplayComments(), 'entity' => $this->getEntityRestrict()]; - if ($this->condition) { - $options['condition'] = [$this->condition]; - } - Dropdown::show($this->getItemType(), $options); - } + if ($this->condition) { + $options['condition'] = [$this->condition]; + } + + if ($this->multiple) { + $options['multiple'] = true; + $value = $this->getParameterValue() === 0 || $this->getParameterValue() === '0' ? [] : $this->getParameterValue(); + $values = is_array($value) ? $value : [$value]; + $options['used'] = $values; + $options['value'] = $values; + $options['name'] .= '[]'; + $options['width'] = '100%'; + } + + Dropdown::show($this->getItemType(), $options); + } + + public function getBookmarkUrl() { + if ($this->multiple) { + $url = ""; + foreach ($this->parameters as $parameter => $value) { + if (is_array($value)) { + foreach($value as $i => $v) { + $url .= '&' . $parameter . "[$i]=" . $v; + } + } else { + $url .= '&' . $parameter . '=' . $value; + } + } + return $url; + } else { + return parent::getBookmarkUrl(); + } + } /** @@ -275,19 +319,22 @@ public function getSqlCriteriasRestriction($link='AND') { $dbu = new DbUtils(); - if ($this->getParameterValue() || $this->searchzero) { - if (!$this->childrens) { - return $link . " " . $this->getSqlField() . "='" . $this->getParameterValue() . "' "; - } - if ($this->getParameterValue()) { - return $link . " " . $this->getSqlField() . - " IN (" . implode(',', $dbu->getSonsOf($this->getTable(), - $this->getParameterValue())) . ") "; - } - // 0 + its child means ALL - } - // Zero => means ALL => no criteria - return ''; - } + if ($this->getParameterValue() || $this->searchzero) { + if ($this->multiple && $this->getParameterValue()) { + return $link . " " . $this->getSqlField() . " IN (" . implode(',', $this->getParameterValue()) . ") "; + } + if (!$this->childrens) { + return $link . " " . $this->getSqlField() . "='" . $this->getParameterValue() . "' "; + } + if ($this->getParameterValue()) { + return $link . " " . $this->getSqlField() . + " IN (" . implode(',', $dbu->getSonsOf($this->getTable(), + $this->getParameterValue())) . ") "; + } + // 0 + its child means ALL + } + // Zero => means ALL => no criteria + return ''; + } } diff --git a/inc/groupcriteria.class.php b/inc/groupcriteria.class.php index b4efbb6..676af67 100644 --- a/inc/groupcriteria.class.php +++ b/inc/groupcriteria.class.php @@ -45,11 +45,11 @@ class PluginReportsGroupCriteria extends PluginReportsDropdownCriteria { * @param $name (default 'groups_id') * @param $label (default '') * @param $condition (default '') - **/ - function __construct($report, $name='groups_id', $label='', $condition='') { - - parent::__construct($report, $name, 'glpi_groups', ($label ? $label : __('Group')), - $condition); + * @param $multiple (default false) + **/ + function __construct($report, $name='groups_id', $label='', $condition='', $multiple = false) { + parent::__construct($report, $name, 'glpi_groups', ($label ? $label : __('Group')), + $condition, $multiple); } }