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 Aug 22, 2019
1 parent d987243 commit eca75f2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions inc/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,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 @@ -350,7 +350,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 @@ -103,6 +103,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
16 changes: 13 additions & 3 deletions inc/targetbase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,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 Expand Up @@ -1843,15 +1843,25 @@ protected function saveTags(PluginFormcreatorFormanswer $formanswer, $targetId)
$formAnswerFk = PluginFormcreatorFormAnswer::getForeignKeyField();
$questionFk = PluginFormcreatorQuestion::getForeignKeyField();
$result = $DB->request([
'SELECT' => ['answer'],
'SELECT' => ['plugin_formcreator_questions_id', 'answer'],
'FROM' => PluginFormcreatorAnswer::getTable(),
'WHERE' => [
$formAnswerFk => [(int) $formanswer->fields['id']],
$questionFk => $this->fields['tag_questions']
],
]);
foreach ($result as $line) {
$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
2 changes: 1 addition & 1 deletion inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,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

0 comments on commit eca75f2

Please sign in to comment.