Skip to content

Commit 47db2d8

Browse files
committed
fix(targetticket): fix tags handling
1 parent 7e579d8 commit 47db2d8

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

inc/field.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public function prepareQuestionInputForSave($input) {
5959
return $input;
6060
}
6161

62-
public function getValueForTarget() {
63-
return Toolbox::addslashes_deep($this->value);
62+
public function getRawValue() {
63+
return $this->value;
6464
}
6565

6666
/**

inc/fields/dropdownfield.class.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ public function getValueForTargetText($richText) {
248248
return Toolbox::addslashes_deep($value);
249249
}
250250

251-
252251
public function getDocumentsForTarget() {
253252
return [];
254253
}

inc/fields/tagfield.class.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public function getValueForDesign() {
106106
return implode("\r\n", $this->value);
107107
}
108108

109+
public function getValueForTargetText($richText) {
110+
$value = Dropdown::getDropdownName(PluginTagTag::getTable(), $this->value);
111+
return Toolbox::addslashes_deep($value);
112+
}
113+
109114
public function isValid() {
110115
// If the field is required it can't be empty
111116
if ($this->isRequired() && $this->value == '') {

inc/targetbase.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ function change_tag_type() {
967967
echo '<div id="tag_specific_value" style="display: none">';
968968

969969
$result = $DB->request([
970-
'SELECT' => ['name'],
970+
'SELECT' => ['id', 'name'],
971971
'FROM' => PluginTagTag::getTable(),
972972
'WHERE' => [
973973
'AND' => [

inc/targetticket.class.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ public function prepareInputForUpdate($input) {
946946
}
947947

948948
$plugin = new Plugin();
949-
if ($plugin->isInstalled('tag') && $plugin->isActivated('tag')) {
949+
if ($plugin->isActivated('tag')) {
950950
$input['tag_questions'] = (!empty($input['_tag_questions']))
951951
? implode(',', $input['_tag_questions'])
952952
: '';
@@ -1214,7 +1214,6 @@ public function save(PluginFormcreatorFormAnswer $formanswer) {
12141214
// Add tag if presents
12151215
$plugin = new Plugin();
12161216
if ($plugin->isActivated('tag')) {
1217-
12181217
$tagObj = new PluginTagTagItem();
12191218
$tags = [];
12201219

@@ -1224,13 +1223,23 @@ public function save(PluginFormcreatorFormAnswer $formanswer) {
12241223
|| $this->fields['tag_type'] == 'questions_or_specific')
12251224
&& (!empty($this->fields['tag_questions']))) {
12261225

1227-
$query = "SELECT answer
1226+
$query = "SELECT plugin_formcreator_questions_id, answer
12281227
FROM `glpi_plugin_formcreator_answers`
12291228
WHERE `plugin_formcreator_formanswers_id` = " . $formanswer->fields['id'] . "
12301229
AND `plugin_formcreator_questions_id` IN (" . $this->fields['tag_questions'] . ")";
12311230
$result = $DB->query($query);
12321231
while ($line = $DB->fetch_array($result)) {
1233-
$tab = json_decode($line['answer']);
1232+
$question = new PluginFormcreatorQuestion();
1233+
$question->getFromDB($line['plugin_formcreator_questions_id']);
1234+
$field = PluginFormcreatorFields::getFieldInstance(
1235+
$question->fields['fieldtype'],
1236+
$question
1237+
);
1238+
$field->deserializeValue($line['answer']);
1239+
$tab = $field->getRawValue();
1240+
if (is_integer($tab)) {
1241+
$tab = [$tab];
1242+
}
12341243
if (is_array($tab)) {
12351244
$tags = array_merge($tags, $tab);
12361245
}

0 commit comments

Comments
 (0)