Skip to content

Commit

Permalink
fix(targetticket,targetchange): fix display of actors
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Aug 22, 2019
1 parent 66a0337 commit 93597c0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
8 changes: 4 additions & 4 deletions inc/target.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ public function prepareInputForAdd($input) {
$targetTicket_actor = new PluginFormcreatorTargetTicket_Actor();
$targetTicket_actor->add([
'plugin_formcreator_targettickets_id' => $id_targetticket,
'actor_role' => 'requester',
'actor_type' => 'creator',
'actor_role' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR,
'use_notification' => '1'
]);
$targetTicket_actor = new PluginFormcreatorTargetTicket_Actor();
$targetTicket_actor->add([
'plugin_formcreator_targettickets_id' => $id_targetticket,
'actor_role' => 'observer',
'actor_type' => 'validator',
'actor_role' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR,
'use_notification' => '1'
]);
}
Expand Down
52 changes: 45 additions & 7 deletions inc/targetbase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ abstract class PluginFormcreatorTargetBase extends CommonDBTM implements PluginF

protected $form = null;

/** @var boolean $skipCreateActors Flag to disable creation of actors after creation of the item */
protected $skipCreateActors = false;

abstract public function export($remove_uuid = false);

abstract public function save(PluginFormcreatorFormAnswer $formanswer);
Expand Down Expand Up @@ -1134,7 +1137,11 @@ protected function showActorsSettings() {
$itemActor = $this->getItem_Actor();
$itemActorTable = $itemActor::getTable();
$fk = self::getForeignKeyField();
$actors = ['requester' => [], 'observer' => [], 'assigned' => []];
$actors = [
PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER => [],
PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER => [],
PluginFormcreatorTarget_Actor::ACTOR_ROLE_ASSIGNED => [],
];
$result = $DB->request([
'SELECT' => ['id', 'actor_role', 'actor_type', 'actor_value', 'use_notification'],
'FROM' => $itemActorTable,
Expand Down Expand Up @@ -1195,7 +1202,7 @@ protected function showActorsSettings() {

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

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

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

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

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

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

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

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

// => List of saved assigned to
foreach ($actors['assigned'] as $id => $values) {
foreach ($actors[PluginFormcreatorTarget_Actor::ACTOR_ROLE_ASSIGNED] as $id => $values) {
echo '<div>';
switch ($values['actor_type']) {
case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR :
Expand Down Expand Up @@ -1811,6 +1818,17 @@ protected function setTargetDueDate($data, PluginFormcreatorFormAnswer $formansw
return $data;
}

public function prepareInputForAdd($input) {
if (isset($input['_skip_create_actors']) && $input['_skip_create_actors']) {
$this->skipCreateActors = true;
}
// generate a unique id
if (!isset($input['uuid'])
|| empty($input['uuid'])) {
$input['uuid'] = plugin_formcreator_getUuid();
}
}

public function prepareInputForUpdate($input) {
global $DB;

Expand Down Expand Up @@ -1842,6 +1860,26 @@ public function prepareInputForUpdate($input) {
return $input;
}

public function post_addItem() {
if (!$this->skipCreateActors) {
$target_actor = $this->getItem_Actor();
$myFk = self::getForeignKeyField();
$target_actor->add([
$myFk => $this->getID(),
'actor_role' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR,
'use_notification' => '1',
]);
$target_actor = $this->getItem_Actor();
$target_actor->add([
$myFk => $this->getID(),
'actor_role' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER,
'actor_type' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR,
'use_notification' => '1',
]);
}
}

protected static function getDeleteImage($id) {
global $CFG_GLPI;

Expand Down
6 changes: 6 additions & 0 deletions inc/targetchange.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ public function showForm($options = []) {
echo '</div>';
}

public function prepareInputForAdd($input) {
$input = parent::prepareInputForAdd($input);

return $input;
}

/**
* Prepare input data for updating the target ticket
*
Expand Down
6 changes: 1 addition & 5 deletions inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,7 @@ function updateCompositePeerType() {
}

public function prepareInputForAdd($input) {
// generate a unique id
if (!isset($input['uuid'])
|| empty($input['uuid'])) {
$input['uuid'] = plugin_formcreator_getUuid();
}
$input = parent::prepareInputForAdd($input);

return $input;
}
Expand Down

0 comments on commit 93597c0

Please sign in to comment.