Skip to content

Commit

Permalink
fix(targetchange): time to resolve not populated when required
Browse files Browse the repository at this point in the history
Signed-off-by: btry <tbugier@teclib.com>
  • Loading branch information
btry committed Oct 28, 2018
1 parent 74a0d83 commit b1240d6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 71 deletions.
52 changes: 52 additions & 0 deletions inc/targetbase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -902,4 +902,56 @@ function change_location() {
echo '</td>';
echo '</tr>';
}

/**
* Sets the time to resolve of the target object
*
* @param array $data data of the target object
* @param PluginFormcreatorForm_Answer $formanswer Answers previously saved
* @return array updated data of the target object
*/
protected function setTargetDueDate($data, PluginFormcreatorForm_Answer $formanswer) {
global $DB;

$answer = new PluginFormcreatorAnswer();
if ($this->fields['due_date_question'] !== null) {
$request = [
'FROM' => $answer::getTable(),
'WHERE' => [
'AND' => [
$formanswer::getForeignKeyField() => $formanswer->fields['id'],
PluginFormcreatorQuestion::getForeignKeyField() => $this->fields['due_date_question'],
],
],
];
$iterator = $DB->request($request);
if ($iterator->count() > 0) {
$iterator->rewind();
$date = $iterator->current();
}
} else {
$date = null;
}
$str = "+" . $this->fields['due_date_value'] . " " . $this->fields['due_date_period'];

switch ($this->fields['due_date_rule']) {
case 'answer':
$due_date = $date['answer'];
break;
case 'ticket':
$due_date = date('Y-m-d H:i:s', strtotime($str));
break;
case 'calcul':
$due_date = date('Y-m-d H:i:s', strtotime($date['answer'] . " " . $str));
break;
default:
$due_date = null;
break;
}
if (!is_null($due_date)) {
$data['time_to_resolve'] = $due_date;
}

return $data;
}
}
40 changes: 1 addition & 39 deletions inc/targetchange.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1090,44 +1090,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
break;
}

// Define due date
if ($this->fields['due_date_question'] !== null) {
$request = [
'FROM' => $answer::getTable(),
'WHERE' => [
'AND' => [
$formanswer::getForeignKeyField() => $formanswer->fields['id'],
PluginFormcreatorQuestion::getForeignKeyField() => $this->fields['due_date_question'],
],
],
];
$iterator = $DB->request($request);
if ($iterator->count() > 0) {
$iterator->rewind();
$date = $iterator->current();
}
} else {
$date = null;
}
$str = "+" . $this->fields['due_date_value'] . " " . $this->fields['due_date_period'];

switch ($this->fields['due_date_rule']) {
case 'answer':
$due_date = $date['answer'];
break;
case 'ticket':
$due_date = date('Y-m-d H:i:s', strtotime($str));
break;
case 'calcul':
$due_date = date('Y-m-d H:i:s', strtotime($date['answer'] . " " . $str));
break;
default:
$due_date = null;
break;
}
if (!is_null($due_date)) {
$data['due_date'] = $due_date;
}
$data = $this->setTargetDueDate($data, $formanswer);

$data = $this->requesters + $this->observers + $this->assigned + $this->assignedSuppliers + $data;
$data = $this->requesterGroups + $this->observerGroups + $this->assignedGroups + $data;
Expand All @@ -1140,7 +1103,6 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
// Add tag if presents
$plugin = new Plugin();
if ($plugin->isActivated('tag')) {

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

Expand Down
32 changes: 0 additions & 32 deletions inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1370,38 +1370,6 @@ protected function setTargetCategory($data, $formanswer) {
return $data;
}

protected function setTargetDueDate($data, $formanswer) {
$answer = new PluginFormcreatorAnswer();
if ($this->fields['due_date_question'] !== null) {
$found = $answer->find('`plugin_formcreator_forms_answers_id` = '.$formanswer->fields['id'].
' AND `plugin_formcreator_questions_id` = '.$this->fields['due_date_question']);
$date = array_shift($found);
} else {
$date = null;
}
$str = "+" . $this->fields['due_date_value'] . " " . $this->fields['due_date_period'];

switch ($this->fields['due_date_rule']) {
case 'answer':
$due_date = $date['answer'];
break;
case 'ticket':
$due_date = date('Y-m-d H:i:s', strtotime($str));
break;
case 'calcul':
$due_date = date('Y-m-d H:i:s', strtotime($date['answer'] . " " . $str));
break;
default:
$due_date = null;
break;
}
if (!is_null($due_date)) {
$data['time_to_resolve'] = $due_date;
}

return $data;
}

protected function setTargetUrgency($data, $formanswer) {
switch ($this->fields['urgency_rule']) {
case 'answer':
Expand Down

0 comments on commit b1240d6

Please sign in to comment.