Skip to content

Commit

Permalink
feat(targetticket,targetchange): add tag for notification
Browse files Browse the repository at this point in the history
new tag provides a way to enumerate generated items in the notification

Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Nov 4, 2020
1 parent 3b5e95c commit 9da6fb5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
9 changes: 4 additions & 5 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ public function generateTarget() {
$generatedTarget = $targetObject->save($this);
if ($generatedTarget === null) {
$success = false;
break;
continue;
}
$this->targetList[] = $generatedTarget;
// Map [itemtype of the target] [item ID of the target] = ID of the generated target
Expand Down Expand Up @@ -1159,7 +1159,6 @@ public function post_addItem() {
]);
}
}
$this->sendNotification();
if ($this->input['status'] == self::STATUS_ACCEPTED) {
if (!$this->generateTarget()) {
Session::addMessageAfterRedirect(__('Cannot generate targets!', 'formcreator'), true, ERROR);
Expand All @@ -1173,11 +1172,11 @@ public function post_addItem() {
}
}
$this->createIssue();
$this->sendNotification();
Session::addMessageAfterRedirect(__('The form has been successfully saved!', 'formcreator'), true, INFO);
}

public function post_updateItem($history = 1) {
$this->sendNotification();
if ($this->input['status'] == self::STATUS_ACCEPTED) {
if (!$this->generateTarget()) {
Session::addMessageAfterRedirect(__('Cannot generate targets!', 'formcreator'), true, ERROR);
Expand All @@ -1191,6 +1190,7 @@ public function post_updateItem($history = 1) {
}
}
$this->updateIssue();
$this->sendNotification();
Session::addMessageAfterRedirect(__('The form has been successfully saved!', 'formcreator'), true, INFO);
}

Expand Down Expand Up @@ -1342,8 +1342,7 @@ private function sendNotification() {
break;
case self::STATUS_ACCEPTED :
// Notify the requester
$form = new PluginFormcreatorForm();
$form->getFromDB($this->fields['plugin_formcreator_forms_id']);
$form = $this->getForm();
if ($form->fields['validation_required'] != PluginFormcreatorForm::VALIDATION_NONE) {
NotificationEvent::raiseEvent('plugin_formcreator_accepted', $this);
} else {
Expand Down
25 changes: 24 additions & 1 deletion inc/notificationtargetformanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ public function addDataForTemplate($event, $options = []) {
$this->data['##formcreator.validation_comment##'] = $this->obj->fields['comment'];
$this->data['##formcreator.validation_link##'] = $link;
$this->data['##formcreator.request_id##'] = $this->obj->fields['id'];

$targetList = [];
foreach ($this->obj->targetList as $target) {
/** @var CommonDBTM $target */
$typeName = $target->getTypeName(1);
$typeId = $target->getID();
$targetList[] = "$typeName $typeId";
}
$this->data['##formcreator.targets##'] = implode(', ', $targetList);

$this->data['##lang.formcreator.form_id##'] = __('Form #', 'formcreator');
$this->data['##lang.formcreator.form_name##'] = __('Form name', 'formcreator');
$this->data['##lang.formcreator.form_requester##'] = __('Requester', 'formcreator');
$this->data['##lang.formcreator.form_validator##'] = __('Validator', 'formcreator');
$this->data['##lang.formcreator.form_creation_date##'] = __('Creation date');
$this->data['##lang.formcreator.form_full_answers##'] = __('Full form answers', 'formcreator');
$this->data['##lang.formcreator.validation_comment##'] = __('Refused comment', 'formcreator');
$this->data['##lang.formcreator.validation_link##'] = __('Validation link', 'formcreator');
$this->data['##lang.formcreator.request_id##'] = __('Request #', 'formcreator');
$this->data['##lang.formcreator.targets##'] = __('List of generated targets', 'formcreator');

}

public function getTags() {
Expand All @@ -84,13 +105,15 @@ public function getTags() {
'formcreator.validation_comment' => __('Refused comment', 'formcreator'),
'formcreator.validation_link' => __('Validation link', 'formcreator'),
'formcreator.request_id' => __('Request #', 'formcreator'),
'formcreator.targets' => __('List of generated targets', 'formcreator'),
];

foreach ($tags as $tag => $label) {
$this->addTagToList(['tag' => $tag,
'label' => $label,
'value' => true,
'events' => NotificationTarget::TAG_FOR_ALL_EVENTS]);
'events' => NotificationTarget::TAG_FOR_ALL_EVENTS]
);
}
}

Expand Down

0 comments on commit 9da6fb5

Please sign in to comment.