Skip to content

Commit

Permalink
feat(targetticket,targetchange): set a group from an object from a qu…
Browse files Browse the repository at this point in the history
…estion

Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Jan 29, 2020
1 parent e6cbff3 commit 8d7af9f
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 8 deletions.
4 changes: 4 additions & 0 deletions inc/target_actor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ abstract class PluginFormcreatorTarget_Actor extends CommonDBChild implements Pl
const ACTOR_TYPE_SUPPLIER = 7;
const ACTOR_TYPE_QUESTION_SUPPLIER = 8;
const ACTOR_TYPE_QUESTION_ACTORS = 9;
const ACTOR_TYPE_GROUP_FROM_OBJECT = 10;

const ACTOR_ROLE_REQUESTER = 1;
const ACTOR_ROLE_OBSERVER = 2;
Expand All @@ -60,6 +61,7 @@ static function getEnumActorType() {
self::ACTOR_TYPE_QUESTION_PERSON => __('Person from the question', 'formcreator'),
self::ACTOR_TYPE_GROUP => __('Specific group', 'formcreator'),
self::ACTOR_TYPE_QUESTION_GROUP => __('Group from the question', 'formcreator'),
self::ACTOR_TYPE_GROUP_FROM_OBJECT => __('Group from an object', 'formcreator'),
self::ACTOR_TYPE_SUPPLIER => __('Specific supplier', 'formcreator'),
self::ACTOR_TYPE_QUESTION_SUPPLIER => __('Supplier from the question', 'formcreator'),
self::ACTOR_TYPE_QUESTION_ACTORS => __('Actors from the question', 'formcreator'),
Expand Down Expand Up @@ -109,6 +111,7 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
case self::ACTOR_TYPE_QUESTION_PERSON :
case self::ACTOR_TYPE_QUESTION_GROUP :
case self::ACTOR_TYPE_QUESTION_SUPPLIER :
case self::ACTOR_TYPE_GROUP_FROM_OBJECT :
$question = $linker->getObject($input['actor_value'], PluginFormcreatorQuestion::class);
if ($question === false) {
$linker->postpone($input[$idKey], $item->getType(), $input, $containerId);
Expand Down Expand Up @@ -192,6 +195,7 @@ public function export($remove_uuid = false) {
case self::ACTOR_TYPE_QUESTION_GROUP:
case self::ACTOR_TYPE_SUPPLIER:
case self::ACTOR_TYPE_QUESTION_ACTORS:
case self::ACTOR_TYPE_GROUP_FROM_OBJECT:
$question = new PluginFormcreatorQuestion;
if ($question->getFromDB($target_actor['actor_value'])) {
$target_actor['actor_value'] = $question->fields['uuid'];
Expand Down
114 changes: 106 additions & 8 deletions inc/targetbase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,17 +445,14 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
switch ($actor['actor_type']) {
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR :
$userIds = [$formanswer->fields['requester_id']];
$notify = $actor['use_notification'];
break;
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR :
$userIds = [$_SESSION['glpiID']];
$notify = $actor['use_notification'];
break;
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_PERSON :
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP :
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_SUPPLIER :
$userIds = [$actor['actor_value']];
$notify = $actor['use_notification'];
break;
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_PERSON :
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_GROUP :
Expand All @@ -465,7 +462,7 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
$formanswerId = $formanswer->getID();
$answer->getFromDBByCrit([
'AND' => [
'plugin_formcreator_questions_id' => $actorValue,
'plugin_formcreator_questions_id' => $actorValue,
'plugin_formcreator_formanswers_id' => $formanswerId
]
]);
Expand All @@ -475,15 +472,14 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
} else {
$userIds = [$answer->fields['answer']];
}
$notify = $actor['use_notification'];
break;
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS:
$answer = new PluginFormcreatorAnswer();
$actorValue = $actor['actor_value'];
$formanswerId = $formanswer->getID();
$answer->getFromDBByCrit([
'AND' => [
'plugin_formcreator_questions_id' => $actorValue,
'plugin_formcreator_questions_id' => $actorValue,
'plugin_formcreator_formanswers_id' => $formanswerId
]
]);
Expand All @@ -493,9 +489,53 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
} else {
$userIds = json_decode($answer->fields['answer'], JSON_OBJECT_AS_ARRAY);
}
$notify = $actor['use_notification'];
break;
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT:
// Get the object from the question
$answer = new PluginFormcreatorAnswer();
$actorValue = $actor['actor_value'];
$formanswerId = $formanswer->getID();
$answer->getFromDBByCrit([
'AND' => [
'plugin_formcreator_questions_id' => $actorValue,
'plugin_formcreator_formanswers_id' => $formanswerId
]
]);
if ($answer->isNewItem()) {
continue 2;
}
// Get the itemtype of the object
$question = new PluginFormcreatorQuestion();
$question->getFromDB($answer->fields[PluginFormcreatorQuestion::getForeignKeyField()]);
if ($question->isNewItem()) {
continue 2;
}
$itemtype = $question->fields['values'];
if (!is_subclass_of($itemtype, CommonDBTM::class)) {
continue 2;
}

// Check the object has a group FK
$groupFk = Group::getForeignKeyField();
$object = new $itemtype();
if (!$DB->fieldExists($object->getTable(), $groupFk)) {
continue 2;
}

// get the group
if (!$object->getFromDB($answer->fields['answer'])) {
continue 2;
}

// ignore invalid ID
if (Group::isNewId($object->fields[$groupFk])) {
continue 2;
}

$userIds = [$object->fields[$groupFk]];
break;
}
$notify = $actor['use_notification'];

switch ($actor['actor_type']) {
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR :
Expand All @@ -509,7 +549,8 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF
break;
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP :
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_GROUP :
foreach ($userIds as $groupId) {
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT:
foreach ($userIds as $groupId) {
$this->addGroupActor($actor['actor_role'], $groupId);
}
break;
Expand Down Expand Up @@ -1107,6 +1148,19 @@ protected function showActorsSettings() {
);
echo '</div>';

echo '<div id="block_requester_group_from_object" style="display:none">';
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['glpiselect'],
],
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT,
[
'value' => 0
]
);
echo '</div>';

echo '<div id="block_requester_question_actors" style="display:none">';
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
Expand Down Expand Up @@ -1167,6 +1221,12 @@ protected function showActorsSettings() {
echo $img_group . ' <b>' . __('Group from the question', 'formcreator')
. '</b> "' . $question->getName() . '"';
break;
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT:
$question = new PluginFormcreatorQuestion();
$question->getFromDB($values['actor_value']);
echo $img_group . ' <b>' . __('Group from the object', 'formcreator')
. '</b> "' . $question->getName() . '"';
break;
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS:
$question = new PluginFormcreatorQuestion();
$question->getFromDB($values['actor_value']);
Expand Down Expand Up @@ -1244,6 +1304,19 @@ protected function showActorsSettings() {
);
echo '</div>';

echo '<div id="block_watcher_group_from_object" style="display:none">';
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['glpiselect'],
],
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT,
[
'value' => 0
]
);
echo '</div>';

echo '<div id="block_watcher_question_actors" style="display:none">';
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
Expand Down Expand Up @@ -1304,6 +1377,12 @@ protected function showActorsSettings() {
echo $img_group . ' <b>' . __('Group from the question', 'formcreator')
. '</b> "' . $question->getName() . '"';
break;
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT:
$question = new PluginFormcreatorQuestion();
$question->getFromDB($values['actor_value']);
echo $img_group . ' <b>' . __('Group from the object', 'formcreator')
. '</b> "' . $question->getName() . '"';
break;
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS :
$question = new PluginFormcreatorQuestion();
$question->getFromDB($values['actor_value']);
Expand Down Expand Up @@ -1388,6 +1467,19 @@ protected function showActorsSettings() {
);
echo '</div>';

echo '<div id="block_assigned_group_from_object" style="display:none">';
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['glpiselect'],
],
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT,
[
'value' => 0
]
);
echo '</div>';

echo '<div id="block_assigned_question_actors" style="display:none">';
PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
Expand Down Expand Up @@ -1462,6 +1554,12 @@ protected function showActorsSettings() {
echo $img_group . ' <b>' . __('Group from the question', 'formcreator')
. '</b> "' . $question->getName() . '"';
break;
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT:
$question = new PluginFormcreatorQuestion();
$question->getFromDB($values['actor_value']);
echo $img_group . ' <b>' . __('Group from the object', 'formcreator')
. '</b> "' . $question->getName() . '"';
break;
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS :
$question = new PluginFormcreatorQuestion();
$question->getFromDB($values['actor_value']);
Expand Down
6 changes: 6 additions & 0 deletions js/scripts.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ function plugin_formcreator_ChangeActorRequester(value) {
$('#block_requester_question_user').hide();
$('#block_requester_group').hide();
$('#block_requester_question_group').hide();
$('#block_requester_group_from_object').hide();
$('#block_requester_question_actors').hide();
$('#block_requester_supplier').hide();
$('#block_requester_question_supplier').hide();
Expand All @@ -1024,6 +1025,7 @@ function plugin_formcreator_ChangeActorRequester(value) {
case '4' : $('#block_requester_question_user').show(); break;
case '5' : $('#block_requester_group').show(); break;
case '6' : $('#block_requester_question_group').show(); break;
case '10': $('#block_requester_group_from_object').show(); break;
case '9' : $('#block_requester_question_actors').show(); break;
case '7' : $('#block_requester_supplier').show(); break;
case '8' : $('#block_requester_question_supplier').show(); break;
Expand All @@ -1035,6 +1037,7 @@ function plugin_formcreator_ChangeActorWatcher(value) {
$('#block_watcher_question_user').hide();
$('#block_watcher_group').hide();
$('#block_watcher_question_group').hide();
$('#block_watcher_group_from_object').hide();
$('#block_watcher_question_actors').hide();
$('#block_watcher_supplier').hide();
$('#block_watcher_question_supplier').hide();
Expand All @@ -1045,6 +1048,7 @@ function plugin_formcreator_ChangeActorWatcher(value) {
case '5' : $('#block_watcher_group').show(); break;
case '6' : $('#block_watcher_question_group').show(); break;
case '9' : $('#block_watcher_question_actors').show(); break;
case '10': $('#block_watcher_group_from_object').show(); break;
case '7' : $('#block_watcher_supplier').show(); break;
case '8' : $('#block_watcher_question_supplier').show(); break;
}
Expand All @@ -1055,6 +1059,7 @@ function plugin_formcreator_ChangeActorAssigned(value) {
$('#block_assigned_question_user').hide();
$('#block_assigned_group').hide();
$('#block_assigned_question_group').hide();
$('#block_assigned_group_from_object').hide();
$('#block_assigned_question_actors').hide();
$('#block_assigned_supplier').hide();
$('#block_assigned_question_supplier').hide();
Expand All @@ -1066,6 +1071,7 @@ function plugin_formcreator_ChangeActorAssigned(value) {
case '5' : $('#block_assigned_group').show(); break;
case '6' : $('#block_assigned_question_group').show(); break;
case '9' : $('#block_assigned_question_actors').show(); break;
case '10': $('#block_assigned_group_from_object').show(); break;
case '7' : $('#block_assigned_supplier').show(); break;
case '8' : $('#block_assigned_question_supplier').show(); break;
}
Expand Down

0 comments on commit 8d7af9f

Please sign in to comment.