Skip to content

Commit 93597c0

Browse files
committed
fix(targetticket,targetchange): fix display of actors
Signed-off-by: Thierry Bugier <[email protected]>
1 parent 66a0337 commit 93597c0

File tree

4 files changed

+56
-16
lines changed

4 files changed

+56
-16
lines changed

inc/target.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ public function prepareInputForAdd($input) {
172172
$targetTicket_actor = new PluginFormcreatorTargetTicket_Actor();
173173
$targetTicket_actor->add([
174174
'plugin_formcreator_targettickets_id' => $id_targetticket,
175-
'actor_role' => 'requester',
176-
'actor_type' => 'creator',
175+
'actor_role' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER,
176+
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR,
177177
'use_notification' => '1'
178178
]);
179179
$targetTicket_actor = new PluginFormcreatorTargetTicket_Actor();
180180
$targetTicket_actor->add([
181181
'plugin_formcreator_targettickets_id' => $id_targetticket,
182-
'actor_role' => 'observer',
183-
'actor_type' => 'validator',
182+
'actor_role' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER,
183+
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR,
184184
'use_notification' => '1'
185185
]);
186186
}

inc/targetbase.class.php

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ abstract class PluginFormcreatorTargetBase extends CommonDBTM implements PluginF
5454

5555
protected $form = null;
5656

57+
/** @var boolean $skipCreateActors Flag to disable creation of actors after creation of the item */
58+
protected $skipCreateActors = false;
59+
5760
abstract public function export($remove_uuid = false);
5861

5962
abstract public function save(PluginFormcreatorFormAnswer $formanswer);
@@ -1134,7 +1137,11 @@ protected function showActorsSettings() {
11341137
$itemActor = $this->getItem_Actor();
11351138
$itemActorTable = $itemActor::getTable();
11361139
$fk = self::getForeignKeyField();
1137-
$actors = ['requester' => [], 'observer' => [], 'assigned' => []];
1140+
$actors = [
1141+
PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER => [],
1142+
PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER => [],
1143+
PluginFormcreatorTarget_Actor::ACTOR_ROLE_ASSIGNED => [],
1144+
];
11381145
$result = $DB->request([
11391146
'SELECT' => ['id', 'actor_role', 'actor_type', 'actor_value', 'use_notification'],
11401147
'FROM' => $itemActorTable,
@@ -1195,7 +1202,7 @@ protected function showActorsSettings() {
11951202

11961203
// => Add requester form
11971204
echo '<form name="form_target" id="form_add_requester" method="post" style="display:none" action="'
1198-
. $CFG_GLPI['root_doc'] . '/plugins/formcreator/front/targetchange.form.php">';
1205+
. static::getFormURL() . '">';
11991206

12001207
$dropdownItems = ['' => Dropdown::EMPTY_VALUE] + $itemActor::getEnumActorType();
12011208
unset($dropdownItems['supplier']);
@@ -1287,7 +1294,7 @@ protected function showActorsSettings() {
12871294
Html::closeForm();
12881295

12891296
// => List of saved requesters
1290-
foreach ($actors['requester'] as $id => $values) {
1297+
foreach ($actors[PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER] as $id => $values) {
12911298
echo '<div>';
12921299
switch ($values['actor_type']) {
12931300
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR :
@@ -1337,7 +1344,7 @@ protected function showActorsSettings() {
13371344

13381345
// => Add observer form
13391346
echo '<form name="form_target" id="form_add_watcher" method="post" style="display:none" action="'
1340-
. $CFG_GLPI['root_doc'] . '/plugins/formcreator/front/targetchange.form.php">';
1347+
. static::getFormURL() . '">';
13411348

13421349
$dropdownItems = ['' => Dropdown::EMPTY_VALUE] + $itemActor::getEnumActorType();
13431350
unset($dropdownItems['supplier']);
@@ -1426,7 +1433,7 @@ protected function showActorsSettings() {
14261433
Html::closeForm();
14271434

14281435
// => List of saved observers
1429-
foreach ($actors['observer'] as $id => $values) {
1436+
foreach ($actors[PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER] as $id => $values) {
14301437
echo '<div>';
14311438
switch ($values['actor_type']) {
14321439
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR :
@@ -1476,7 +1483,7 @@ protected function showActorsSettings() {
14761483

14771484
// => Add assigned to form
14781485
echo '<form name="form_target" id="form_add_assigned" method="post" style="display:none" action="'
1479-
. $CFG_GLPI['root_doc'] . '/plugins/formcreator/front/targetchange.form.php">';
1486+
. static::getFormURL() . '">';
14801487

14811488
$dropdownItems = ['' => Dropdown::EMPTY_VALUE] + $itemActor::getEnumActorType();
14821489
Dropdown::showFromArray(
@@ -1589,7 +1596,7 @@ protected function showActorsSettings() {
15891596
Html::closeForm();
15901597

15911598
// => List of saved assigned to
1592-
foreach ($actors['assigned'] as $id => $values) {
1599+
foreach ($actors[PluginFormcreatorTarget_Actor::ACTOR_ROLE_ASSIGNED] as $id => $values) {
15931600
echo '<div>';
15941601
switch ($values['actor_type']) {
15951602
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR :
@@ -1811,6 +1818,17 @@ protected function setTargetDueDate($data, PluginFormcreatorFormAnswer $formansw
18111818
return $data;
18121819
}
18131820

1821+
public function prepareInputForAdd($input) {
1822+
if (isset($input['_skip_create_actors']) && $input['_skip_create_actors']) {
1823+
$this->skipCreateActors = true;
1824+
}
1825+
// generate a unique id
1826+
if (!isset($input['uuid'])
1827+
|| empty($input['uuid'])) {
1828+
$input['uuid'] = plugin_formcreator_getUuid();
1829+
}
1830+
}
1831+
18141832
public function prepareInputForUpdate($input) {
18151833
global $DB;
18161834

@@ -1842,6 +1860,26 @@ public function prepareInputForUpdate($input) {
18421860
return $input;
18431861
}
18441862

1863+
public function post_addItem() {
1864+
if (!$this->skipCreateActors) {
1865+
$target_actor = $this->getItem_Actor();
1866+
$myFk = self::getForeignKeyField();
1867+
$target_actor->add([
1868+
$myFk => $this->getID(),
1869+
'actor_role' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER,
1870+
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR,
1871+
'use_notification' => '1',
1872+
]);
1873+
$target_actor = $this->getItem_Actor();
1874+
$target_actor->add([
1875+
$myFk => $this->getID(),
1876+
'actor_role' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER,
1877+
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR,
1878+
'use_notification' => '1',
1879+
]);
1880+
}
1881+
}
1882+
18451883
protected static function getDeleteImage($id) {
18461884
global $CFG_GLPI;
18471885

inc/targetchange.class.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,12 @@ public function showForm($options = []) {
367367
echo '</div>';
368368
}
369369

370+
public function prepareInputForAdd($input) {
371+
$input = parent::prepareInputForAdd($input);
372+
373+
return $input;
374+
}
375+
370376
/**
371377
* Prepare input data for updating the target ticket
372378
*

inc/targetticket.class.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,7 @@ function updateCompositePeerType() {
360360
}
361361

362362
public function prepareInputForAdd($input) {
363-
// generate a unique id
364-
if (!isset($input['uuid'])
365-
|| empty($input['uuid'])) {
366-
$input['uuid'] = plugin_formcreator_getUuid();
367-
}
363+
$input = parent::prepareInputForAdd($input);
368364

369365
return $input;
370366
}

0 commit comments

Comments
 (0)