Skip to content

Commit

Permalink
feat(target): remove target itemtype
Browse files Browse the repository at this point in the history
this type is useless and only is intermediate in relation between form and target change or target ticket

Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Aug 22, 2019
1 parent 93597c0 commit 41bc125
Show file tree
Hide file tree
Showing 23 changed files with 1,024 additions and 2,721 deletions.
36 changes: 0 additions & 36 deletions ajax/target.php

This file was deleted.

43 changes: 26 additions & 17 deletions front/form.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,46 @@

$form = new PluginFormcreatorForm();

if (isset($_POST["add"])) {
if (isset($_POST['add'])) {
// Add a new Form
Session::checkRight("entity", UPDATE);
Session::checkRight('entity', UPDATE);
$newID = $form->add($_POST);
Html::redirect($CFG_GLPI['root_doc'] . '/plugins/formcreator/front/form.form.php?id=' . $newID);

Html::redirect($CFG_GLPI["root_doc"] . '/plugins/formcreator/front/form.form.php?id=' . $newID);

} else if (isset($_POST["update"])) {
} else if (isset($_POST['update'])) {
// Edit an existing form
Session::checkRight("entity", UPDATE);
Session::checkRight('entity', UPDATE);
$form->update($_POST);
Html::back();

} else if (isset($_POST["delete"])) {
} else if (isset($_POST['delete'])) {
// Delete a form (is_deleted = true)
Session::checkRight("entity", UPDATE);
Session::checkRight('entity', UPDATE);
$form->delete($_POST);
$form->redirectToList();

} else if (isset($_POST["restore"])) {
} else if (isset($_POST['restore'])) {
// Restore a deleteted form (is_deleted = false)
Session::checkRight("entity", UPDATE);
Session::checkRight('entity', UPDATE);
$form->restore($_POST);
$form->redirectToList();

} else if (isset($_POST["purge"])) {
} else if (isset($_POST['purge'])) {
// Delete defenitively a form from DB and all its datas
Session::checkRight("entity", UPDATE);
Session::checkRight('entity', UPDATE);
$form->delete($_POST, 1);
$form->redirectToList();

} else if (isset($_POST['add_target'])) {
Session::checkRight('entity', UPDATE);
$form->addTarget($_POST);
Html::back();

} else if (isset($_POST['delete_target'])) {
Session::checkRight('entity', UPDATE);
$form->deleteTarget($_POST);
Html::redirect($CFG_GLPI['root_doc'] . '/plugins/formcreator/front/form.form.php?id=' . $_POST['plugin_formcreator_forms_id']);

} else if (isset($_POST['filetype_create'])) {
$documentType = new DocumentType();
$canAddType = $documentType->canCreate();
Expand All @@ -86,9 +95,9 @@
}
Html::back();

} else if (isset($_GET["import_form"])) {
} else if (isset($_GET['import_form'])) {
// Import form
Session::checkRight("entity", UPDATE);
Session::checkRight('entity', UPDATE);
Html::header(
PluginFormcreatorForm::getTypeName(2),
$_SERVER['PHP_SELF'],
Expand All @@ -102,9 +111,9 @@
$form->showImportForm();
Html::footer();

} else if (isset($_POST["import_send"])) {
} else if (isset($_POST['import_send'])) {
// Import form
Session::checkRight("entity", UPDATE);
Session::checkRight('entity', UPDATE);
$form->importJson($_REQUEST);
Html::back();

Expand Down Expand Up @@ -142,7 +151,7 @@

} else {
// Show forms form
Session::checkRight("entity", UPDATE);
Session::checkRight('entity', UPDATE);

Html::header(
PluginFormcreatorForm::getTypeName(2),
Expand Down
61 changes: 0 additions & 61 deletions front/target.form.php

This file was deleted.

37 changes: 14 additions & 23 deletions front/targetchange.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,33 @@
$use_notification = ($_POST['use_notification'] == 0) ? 0 : 1;
$targetChange_actor = new PluginFormcreatorTargetChange_Actor();
$targetChange_actor->add([
'plugin_formcreator_targetchanges_id' => $id,
'actor_role' => $_POST['actor_role'],
'actor_type' => $_POST['actor_type'],
'actor_value' => $actor_value,
'use_notification' => $use_notification
'plugin_formcreator_targetchanges_id' => $id,
'actor_role' => $_POST['actor_role'],
'actor_type' => $_POST['actor_type'],
'actor_value' => $actor_value,
'use_notification' => $use_notification
]);
Html::back();

} else if (isset($_GET['delete_actor'])) {
$targetChange_actor = new PluginFormcreatorTargetChange_Actor();
$targetChange_actor->delete([
'id' => (int) $_GET['delete_actor']
'id' => (int) $_GET['delete_actor']
]);
Html::back();

// Show target ticket form
} else {
Html::header(
__('Form Creator', 'formcreator'),
$_SERVER['PHP_SELF'],
'admin',
'PluginFormcreatorForm'
);
__('Form Creator', 'formcreator'),
$_SERVER['PHP_SELF'],
'admin',
'PluginFormcreatorForm'
);

$itemtype = "PluginFormcreatorTargetChange";
$iterator = $DB->request([
'SELECT' => ['plugin_formcreator_forms_id'],
'FROM' => PluginFormcreatorTarget::getTable(),
'WHERE' => [
'itemtype' => $itemtype,
'items_id' => (int) $_REQUEST['id'],
]
]);
$first = $iterator->next();
$form = new PluginFormcreatorForm;
$form->getFromDB($first['plugin_formcreator_forms_id']);
$itemtype = PluginFormcreatorTargetChange::class;
$targetchange->getFromDB((int) $_REQUEST['id']);
$form = $targetchange->getForm();

$_SESSION['glpilisttitle'][$itemtype] = sprintf(__('%1$s = %2$s'),
$form->getTypeName(1), $form->getName());
Expand Down
15 changes: 3 additions & 12 deletions front/targetticket.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,9 @@
'PluginFormcreatorForm'
);

$itemtype = "PluginFormcreatorTargetTicket";
$iterator = $DB->request([
'SELECT' => ['plugin_formcreator_forms_id'],
'FROM' => PluginFormcreatorTarget::getTable(),
'WHERE' => [
'itemtype' => $itemtype,
'items_id' => (int) $_REQUEST['id'],
]
]);
$first = $iterator->next();
$form = new PluginFormcreatorForm;
$form->getFromDB($first['plugin_formcreator_forms_id']);
$itemtype = PluginFormcreatorTargetTicket::class;
$targetticket->getFromDB((int) $_REQUEST['id']);
$form = $targetticket->getForm();

$_SESSION['glpilisttitle'][$itemtype] = sprintf(__('%1$s = %2$s'),
$form->getTypeName(1), $form->getName());
Expand Down
8 changes: 8 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,14 @@ function plugin_formcreator_hook_purge_ticket(CommonDBTM $item) {
}
}

function plugin_formcreator_hook_pre_purge_targetTicket(CommonDBTM $item) {
$item->pre_purgeItem();
}

function plugin_formcreator_hook_pre_purge_targetChange(CommonDBTM $item) {
$item->pre_purgeItem();
}

function plugin_formcreator_dynamicReport($params) {
switch ($params['item_type']) {
case PluginFormcreatorFormAnswer::class;
Expand Down
Loading

0 comments on commit 41bc125

Please sign in to comment.