Skip to content

Commit

Permalink
fix(targetticket): fix tags handling
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jul 2, 2019
1 parent 7e579d8 commit 47db2d8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions inc/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public function prepareQuestionInputForSave($input) {
return $input;
}

public function getValueForTarget() {
return Toolbox::addslashes_deep($this->value);
public function getRawValue() {
return $this->value;
}

/**
Expand Down
1 change: 0 additions & 1 deletion inc/fields/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ public function getValueForTargetText($richText) {
return Toolbox::addslashes_deep($value);
}


public function getDocumentsForTarget() {
return [];
}
Expand Down
5 changes: 5 additions & 0 deletions inc/fields/tagfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public function getValueForDesign() {
return implode("\r\n", $this->value);
}

public function getValueForTargetText($richText) {
$value = Dropdown::getDropdownName(PluginTagTag::getTable(), $this->value);
return Toolbox::addslashes_deep($value);
}

public function isValid() {
// If the field is required it can't be empty
if ($this->isRequired() && $this->value == '') {
Expand Down
2 changes: 1 addition & 1 deletion inc/targetbase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ function change_tag_type() {
echo '<div id="tag_specific_value" style="display: none">';

$result = $DB->request([
'SELECT' => ['name'],
'SELECT' => ['id', 'name'],
'FROM' => PluginTagTag::getTable(),
'WHERE' => [
'AND' => [
Expand Down
17 changes: 13 additions & 4 deletions inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ public function prepareInputForUpdate($input) {
}

$plugin = new Plugin();
if ($plugin->isInstalled('tag') && $plugin->isActivated('tag')) {
if ($plugin->isActivated('tag')) {
$input['tag_questions'] = (!empty($input['_tag_questions']))
? implode(',', $input['_tag_questions'])
: '';
Expand Down Expand Up @@ -1214,7 +1214,6 @@ public function save(PluginFormcreatorFormAnswer $formanswer) {
// Add tag if presents
$plugin = new Plugin();
if ($plugin->isActivated('tag')) {

$tagObj = new PluginTagTagItem();
$tags = [];

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

$query = "SELECT answer
$query = "SELECT plugin_formcreator_questions_id, answer
FROM `glpi_plugin_formcreator_answers`
WHERE `plugin_formcreator_formanswers_id` = " . $formanswer->fields['id'] . "
AND `plugin_formcreator_questions_id` IN (" . $this->fields['tag_questions'] . ")";
$result = $DB->query($query);
while ($line = $DB->fetch_array($result)) {
$tab = json_decode($line['answer']);
$question = new PluginFormcreatorQuestion();
$question->getFromDB($line['plugin_formcreator_questions_id']);
$field = PluginFormcreatorFields::getFieldInstance(
$question->fields['fieldtype'],
$question
);
$field->deserializeValue($line['answer']);
$tab = $field->getRawValue();
if (is_integer($tab)) {
$tab = [$tab];
}
if (is_array($tab)) {
$tags = array_merge($tags, $tab);
}
Expand Down

0 comments on commit 47db2d8

Please sign in to comment.