Skip to content

Commit f41dafc

Browse files
committed
fix(glpiselectfield,dropdownfield): comparisons methods for conditions
1 parent aaae034 commit f41dafc

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

inc/field/dropdownfield.class.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,7 @@ private function getMyGroups($userID) {
591591

592592
public function equals($value): bool {
593593
$value = html_entity_decode($value);
594-
$itemtype = json_decode($this->question->fields['values'], true);
595-
$itemtype = $itemtype['itemtype'];
594+
$itemtype = $this->question->fields['itemtype'];
596595
$dropdown = new $itemtype();
597596
if ($dropdown->isNewId($this->value)) {
598597
return ($value === '');
@@ -614,7 +613,7 @@ public function notEquals($value): bool {
614613

615614
public function greaterThan($value): bool {
616615
$value = html_entity_decode($value);
617-
$itemtype = $this->question->fields['values'];
616+
$itemtype = $this->question->fields['itemtype'];
618617
$dropdown = new $itemtype();
619618
if (!$dropdown->getFromDB($this->value)) {
620619
throw new ComparisonException('Item not found for comparison');
@@ -633,7 +632,7 @@ public function lessThan($value): bool {
633632

634633
public function regex($value): bool {
635634
$value = html_entity_decode($value);
636-
$itemtype = $this->getSubItemtype($this->question->fields['values']);
635+
$itemtype = $this->question->fields['itemtype'];
637636
$dropdown = new $itemtype();
638637
if (!$dropdown->getFromDB($this->value)) {
639638
throw new ComparisonException('Item not found for comparison');

tests/3-unit/GlpiPlugin/Formcreator/Field/DropdownField.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,15 @@ public function providerEquals() {
278278
return [
279279
[
280280
'fields' => $this->getQuestion([
281-
'values' => json_encode(['itemtype' => \Location::class])
281+
'itemtype' => \Location::class,
282282
]),
283283
'value' => $location1->fields['completename'],
284284
'answer' => (string) $location1Id,
285285
'expected' => true,
286286
],
287287
[
288288
'fields' => $this->getQuestion([
289-
'values' => json_encode(['itemtype' => \Location::class])
289+
'itemtype' => \Location::class,
290290
]),
291291
'value' => $location2->fields['completename'],
292292
'answer' => (string) $location1Id,
@@ -317,15 +317,15 @@ public function providerNotEquals() {
317317
return [
318318
[
319319
'fields' => $this->getQuestion([
320-
'values' => json_encode(['itemtype' => \Location::class])
320+
'itemtype' => \Location::class,
321321
]),
322322
'value' => $location1->fields['completename'],
323323
'answer' => (string) $location1Id,
324324
'expected' => false,
325325
],
326326
[
327327
'fields' => $this->getQuestion([
328-
'values' => json_encode(['itemtype' => \Location::class])
328+
'itemtype' => \Location::class,
329329
]),
330330
'value' => $location2->fields['completename'],
331331
'answer' => (string) $location1Id,

0 commit comments

Comments
 (0)