Skip to content

Commit

Permalink
fix(targetticket,targetchange): avoid adding same actor several times
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Aug 31, 2021
1 parent 87789ad commit 1f82f3b
Showing 1 changed file with 133 additions and 7 deletions.
140 changes: 133 additions & 7 deletions inc/abstracttarget.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,8 @@ protected function showActorSettingsHeader($type) {
* @return void
*/
protected function showActorSettingsForType($actorType, array $actors) {
global $DB;

$itemActor = new PluginFormcreatorTarget_Actor();
$dropdownItems = ['' => Dropdown::EMPTY_VALUE] + $itemActor::getEnumActorType();

Expand Down Expand Up @@ -1929,6 +1931,21 @@ protected function showActorSettingsForType($actorType, array $actors) {
echo '</div>';

echo '<div id="block_' . $type . '_question_user" style="display:none">';
// find already used items
$request = $DB->request([
'FROM' => PluginFormcreatorTarget_Actor::getTable(),
'WHERE' => [
'itemtype' => $this->getType(),
'items_id' => $this->getID(),
'actor_role' => $actorRole,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_PERSON,
]
]);
$used = [];
foreach ($request as $row) {
$used[$row['actor_value']] = $row['actor_value'];
}

PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
Expand All @@ -1943,71 +1960,180 @@ protected function showActorSettingsForType($actorType, array $actors) {
],
],
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_PERSON,
0
0,
[
'used' => $used,
]
);
echo '</div>';

echo '<div id="block_' . $type . '_question_group" style="display:none">';
// find already used items
$request = $DB->request([
'FROM' => PluginFormcreatorTarget_Actor::getTable(),
'WHERE' => [
'itemtype' => $this->getType(),
'items_id' => $this->getID(),
'actor_role' => $actorRole,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_GROUP,
]
]);
$used = [];
foreach ($request as $row) {
$used[$row['actor_value']] = $row['actor_value'];
}

PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['glpiselect'],
'values' => ['LIKE', '%"itemtype":"' . Group::class . '"%'],
],
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_GROUP,
0
0,
[
'used' => $used,
]
);
echo '</div>';

echo '<div id="block_' . $type . '_group_from_object" style="display:none">';
// find already used items
$request = $DB->request([
'FROM' => PluginFormcreatorTarget_Actor::getTable(),
'WHERE' => [
'itemtype' => $this->getType(),
'items_id' => $this->getID(),
'actor_role' => $actorRole,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_GROUP,
]
]);
$used = [];
foreach ($request as $row) {
$used[$row['actor_value']] = $row['actor_value'];
}

PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['glpiselect'],
],
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_GROUP_FROM_OBJECT,
0
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_GROUP,
0,
[
'used' => $used,
]
);
echo '</div>';

echo '<div id="block_' . $type . '_tech_group_from_object" style="display:none">';
// find already used items
$request = $DB->request([
'FROM' => PluginFormcreatorTarget_Actor::getTable(),
'WHERE' => [
'itemtype' => $this->getType(),
'items_id' => $this->getID(),
'actor_role' => $actorRole,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_TECH_GROUP_FROM_OBJECT,
]
]);
$used = [];
foreach ($request as $row) {
$used[$row['actor_value']] = $row['actor_value'];
}

PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['glpiselect'],
],
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_TECH_GROUP_FROM_OBJECT,
0
0,
[
'used' => $used,
]
);
echo '</div>';

echo '<div id="block_' . $type . '_question_actors" style="display:none">';
// find already used items
$request = $DB->request([
'FROM' => PluginFormcreatorTarget_Actor::getTable(),
'WHERE' => [
'itemtype' => $this->getType(),
'items_id' => $this->getID(),
'actor_role' => $actorRole,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS,
]
]);
$used = [];
foreach ($request as $row) {
$used[$row['actor_value']] = $row['actor_value'];
}

PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['actor'],
],
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_ACTORS,
0
0,
[
'used' => $used,
]
);
echo '</div>';

if ($actorType == CommonITILActor::ASSIGN) {
echo '<div id="block_' . $type . '_supplier" style="display:none">';
// find already used items
$request = $DB->request([
'FROM' => PluginFormcreatorTarget_Actor::getTable(),
'WHERE' => [
'itemtype' => $this->getType(),
'items_id' => $this->getID(),
'actor_role' => $actorRole,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_SUPPLIER,
]
]);
$used = [];
foreach ($request as $row) {
$used[$row['actor_value']] = $row['actor_value'];
}

Supplier::dropdown([
'name' => 'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_SUPPLIER,
'used' => $used,
]);
echo '</div>';

echo '<div id="block_' . $type . '_question_supplier" style="display:none">';
// find already used items
$request = $DB->request([
'FROM' => PluginFormcreatorTarget_Actor::getTable(),
'WHERE' => [
'itemtype' => $this->getType(),
'items_id' => $this->getID(),
'actor_role' => $actorRole,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_SUPPLIER,
]
]);
$used = [];
foreach ($request as $row) {
$used[$row['actor_value']] = $row['actor_value'];
}

PluginFormcreatorQuestion::dropdownForForm(
$this->getForm()->getID(),
[
'fieldtype' => ['glpiselect'],
'values' => ['LIKE', '%"itemtype":"' . Supplier::class . '"%'],
],
'actor_value_' . PluginFormcreatorTarget_Actor::ACTOR_TYPE_QUESTION_SUPPLIER,
0
0,
[
'used' => $used,
]
);
echo '</div>';
}
Expand Down

0 comments on commit 1f82f3b

Please sign in to comment.