Skip to content

Commit

Permalink
Evarisk#3518 [PreventionPlan] add: categories
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-micka committed Dec 6, 2023
1 parent 6232c43 commit 97c74f6
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 9 deletions.
10 changes: 8 additions & 2 deletions class/actions_digiriskdolibarr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public function constructCategory($parameters, &$object)
'obj_class' => 'Accident',
'obj_table' => 'digiriskdolibarr_accident',
],
'preventionplan' => [
'id' => 436302002,
'code' => 'preventionplan',
'obj_class' => 'PreventionPlan',
'obj_table' => 'digiriskdolibarr_preventionplan',
],
];
}

Expand Down Expand Up @@ -511,7 +517,7 @@ public function printCommonFooter($parameters)
} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
$offset = $limit * $page;

if ($type == 'accident') {
if ($type == 'accident' || $type == 'preventionplan') {
require_once __DIR__ . '/' . $type . '.class.php';

$classname = ucfirst($type);
Expand Down Expand Up @@ -702,7 +708,7 @@ public function doActions($parameters, $object, $action)
$id = GETPOST('id');
$elementId = GETPOST('element_id');
$type = GETPOST('type');
if ($id > 0 && $elementId > 0 && ($type == 'accident' && $user->rights->digiriskdolibarr->$type->write)) {
if ($id > 0 && $elementId > 0 && (($type == 'accident' || $type == 'preventionplan') && $user->rights->digiriskdolibarr->$type->write)) {

require_once __DIR__ . '/' . $type . '.class.php';
$classname = ucfirst($type);
Expand Down
12 changes: 12 additions & 0 deletions class/preventionplan.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,18 @@ public function createFromClone(User $user, int $fromID, array $options): int
}
}
}

if (!empty($options['categories'])) {
$cat = new Categorie($this->db);
$categories = $cat->containing($fromID, 'preventionplan');
if (is_array($categories) && !empty($categories)) {
$categoryIds = [];
foreach ($categories as $cat) {
$categoryIds[] = $cat->id;
}
$object->setCategories($categoryIds);
}
}
} else {
$this->error = $object->error;
$this->errors = $object->errors;
Expand Down
15 changes: 15 additions & 0 deletions core/modules/modDigiriskDolibarr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,21 @@ public function __construct($db)
'user' => 0, // 0=Menu for internal users, 1=external users, 2=both
];

$this->menu[$r++] = [
'fk_menu' => 'fk_mainmenu=digiriskdolibarr,fk_leftmenu=digiriskpreventionplan',
'type' => 'left',
'titre' => '<i class="fas fa-tags pictofixedwidth" style="padding-right: 4px;"></i>' . $langs->transnoentities('Categories'),
'mainmenu' => 'digiriskdolibarr',
'leftmenu' => 'digiriskdolibarr_preventionplantags',
'url' => '/categories/index.php?type=preventionplan',
'langs' => 'digiriskdolibarr@digiriskdolibarr',
'position' => 100 + $r,
'enabled' => '$conf->digiriskdolibarr->enabled && $conf->categorie->enabled && $user->rights->digiriskdolibarr->preventionplan->read',
'perms' => '$user->rights->digiriskdolibarr->preventionplan->read',
'target' => '',
'user' => 0,
];

$this->menu[$r++] = [
'fk_menu' => 'fk_mainmenu=digiriskdolibarr', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type' => 'left', // This is a Left menu entry
Expand Down
2 changes: 2 additions & 0 deletions langs/fr_FR/digiriskdolibarr.lang
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ AccidentInvestigationRole = Les rôles de l'enquête accident
LesionsOrWorkStop = lésions ou arrêts de travail
AccidentsCategoriesArea = Espace des tags/catégories des accidents
AddAccidentIntoCategory = Assigner cette catégorie à l'accident
PreventionplansCategoriesArea = Espace des tags/catégories des plans de prévention
AddPreventionplanIntoCategory = Assigner cette catégorie au plan de prévention

# AccidentTooltip - Tooltip des accidents
VictimActivityTooltip = Précisez l’activité ou la tâche de la victime au moment de l’accident, c’est-à-dire ce que faisait la victime
Expand Down
20 changes: 20 additions & 0 deletions sql/preventionplan/llx_categorie_preventionplan.key.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Copyright (C) 2021-2023 EVARISK <technique@evarisk.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see https://www.gnu.org/licenses/.

ALTER TABLE llx_categorie_preventionplan ADD PRIMARY KEY pk_categorie_preventionplan (fk_categorie, fk_preventionplan);
ALTER TABLE llx_categorie_preventionplan ADD INDEX idx_categorie_preventionplan_fk_categorie (fk_categorie);
ALTER TABLE llx_categorie_preventionplan ADD INDEX idx_categorie_preventionplan_fk_preventionplan (fk_preventionplan);
ALTER TABLE llx_categorie_preventionplan ADD CONSTRAINT fk_categorie_preventionplan_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid);
ALTER TABLE llx_categorie_preventionplan ADD CONSTRAINT llx_categorie_preventionplan_digiriskdolibarr_preventionplan_rowid FOREIGN KEY (fk_preventionplan) REFERENCES llx_digiriskdolibarr_preventionplan (rowid);
20 changes: 20 additions & 0 deletions sql/preventionplan/llx_categorie_preventionplan.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Copyright (C) 2021-2023 EVARISK <technique@evarisk.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see https://www.gnu.org/licenses/.

CREATE TABLE llx_categorie_preventionplan(
fk_categorie integer NOT NULL,
fk_preventionplan integer NOT NULL,
import_key varchar(14)
) ENGINE=innodb;
61 changes: 54 additions & 7 deletions view/preventionplan/preventionplan_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
require_once DOL_DOCUMENT_ROOT .'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php';
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';

// Load Saturne libraries.
require_once __DIR__ . '/../../../saturne/class/saturnesignature.class.php';
Expand Down Expand Up @@ -232,6 +233,12 @@
if ( ! $error) {
$result = $object->create($user, true);
if ($result > 0) {
if (isModEnabled('categorie')) {
$categories = GETPOST('categories', 'array');
if (method_exists($object, 'setCategories')) {
$object->setCategories($categories);
}
}
$object->setInProgress($user, true);
$digiriskresources->setDigiriskResources($db, $user->id, 'ExtSociety', 'societe', array($extSocietyId), $conf->entity, 'preventionplan', $object->id, 1);
$digiriskresources->setDigiriskResources($db, $user->id, 'LabourInspector', 'societe', array($labourInspectorId), $conf->entity, 'preventionplan', $object->id, 1);
Expand Down Expand Up @@ -341,6 +348,12 @@
if ( ! $error) {
$result = $object->update($user, false);
if ($result > 0) {
if (isModEnabled('categorie')) {
$categories = GETPOST('categories', 'array');
if (method_exists($object, 'setCategories')) {
$object->setCategories($categories);
}
}
$digiriskresources->setDigiriskResources($db, $user->id, 'ExtSociety', 'societe', array($extSocietyId), $conf->entity, 'preventionplan', $object->id, 0);
$digiriskresources->setDigiriskResources($db, $user->id, 'LabourInspector', 'societe', array($labourInspectorId), $conf->entity, 'preventionplan', $object->id, 0);
$digiriskresources->setDigiriskResources($db, $user->id, 'LabourInspectorAssigned', 'socpeople', array($labourInspectorContactId), $conf->entity, 'preventionplan', $object->id, 0);
Expand Down Expand Up @@ -582,6 +595,7 @@
$options['preventionplan_risk'] = GETPOST('clone_preventionplan_risk');
$options['attendants'] = GETPOST('clone_attendants');
$options['schedule'] = GETPOST('clone_schedule');
$options['categories'] = GETPOST('clone_categories');

if (1 == 0 && ! GETPOST('clone_preventionplan_risk') && ! GETPOST('clone_attendants') && ! GETPOST('clone_schedule')) {
setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
Expand Down Expand Up @@ -743,6 +757,15 @@
print $form->selectcontacts((GETPOST('labour_inspector') ? GETPOST('labour_inspector') : ($allLinks['LabourInspectorSociety']->id[0] ?: -1)), $labourInspectorContactId, 'labour_inspector_contact', 1, '', '', 1, 'minwidth100imp widthcentpercentminusxx maxwidth400');
print '</td></tr>';

// Categories
if (!empty($conf->categorie->enabled)) {
print '<tr><td>'.$langs->trans("Categories").'</td><td>';
$categoryArborescence = $form->select_all_categories('preventionplan', '', 'parent', 64, 0, 1);
print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('categories', $categoryArborescence, GETPOST('categories', 'array'), '', 0, 'minwidth100imp widthcentpercentminusxx maxwidth400');
print '<a class="butActionNew" href="' . DOL_URL_ROOT . '/categories/index.php?type=preventionplan&backtopage=' . urlencode($_SERVER['PHP_SELF'] . '?action=create') . '" target="_blank"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans('AddCategories') . '"></span></a>';
print "</td></tr>";
}

// Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';

Expand Down Expand Up @@ -902,6 +925,23 @@
print $form->selectcontacts($labourInspectorSociety->id, dol_strlen($contact->email) ? $labourInspectorContact->id : -1, 'labour_inspector_contact', '', 0, '', 1, 'minwidth100imp widthcentpercentminusxx maxwidth400');
print '</td></tr>';

// Tags-Categories
if ($conf->categorie->enabled) {
print '<tr><td>'.$langs->trans("Categories").'</td><td>';
$categoryArborescence = $form->select_all_categories('preventionplan', '', 'parent', 64, 0, 1);
$c = new Categorie($db);
$cats = $c->containing($object->id, 'preventionplan');
$arrayselected = array();
if (is_array($cats)) {
foreach ($cats as $cat) {
$arrayselected[] = $cat->id;
}
}
print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('categories', $categoryArborescence, $arrayselected, '', 0, 'minwidth100imp widthcentpercentminusxx maxwidth400');
print '<a class="butActionNew" href="' . DOL_URL_ROOT . '/categories/index.php?type=preventionplan&backtopage=' . urlencode($_SERVER['PHP_SELF'] . '?action=create') . '" target="_blank"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans('AddCategories') . '"></span></a>';
print "</td></tr>";
}

// Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
print '</table>';
Expand Down Expand Up @@ -939,13 +979,13 @@
if (($action == 'clone' && (empty($conf->use_javascript_ajax) || ! empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js
|| ( ! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { // Always output when not jmobile nor js
// Define confirmation messages
$formquestionclone = array(
'text' => $langs->trans("ConfirmClone"),
array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("NewLabelForClonePreventionPlan"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf") . ' ' . $object->ref : $tmpcode, 'size' => 24),
array('type' => 'checkbox', 'name' => 'clone_preventionplan_risk', 'label' => $langs->trans("ClonePreventionPlanRisk"), 'value' => 1),
array('type' => 'checkbox', 'name' => 'clone_attendants', 'label' => $langs->trans("CloneAttendantsPreventionPlan"), 'value' => 1),
array('type' => 'checkbox', 'name' => 'clone_schedule', 'label' => $langs->trans("CloneSchedulePreventionPlan"), 'value' => 1),
);
$formquestionclone = ['text' => $langs->trans("ConfirmClone"),
['type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("NewLabelForClonePreventionPlan"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf") . ' ' . $object->ref : $tmpcode, 'size' => 24],
['type' => 'checkbox', 'name' => 'clone_preventionplan_risk', 'label' => $langs->trans("ClonePreventionPlanRisk"), 'value' => 1],
['type' => 'checkbox', 'name' => 'clone_attendants', 'label' => $langs->trans("CloneAttendantsPreventionPlan"), 'value' => 1],
['type' => 'checkbox', 'name' => 'clone_schedule', 'label' => $langs->trans("CloneSchedulePreventionPlan"), 'value' => 1],
['type' => 'checkbox', 'name' => 'clone_categories', 'label' => $langs->trans('CloneCategories'), 'value' => 1]
];

$formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ToClone'), $langs->trans('ConfirmClonePreventionPlan', $object->ref), 'confirm_clone', $formquestionclone, 'yes', 'actionButtonClone', 350, 600);
}
Expand Down Expand Up @@ -1047,6 +1087,13 @@
print '</td></tr>';
}

// Categories
if ($conf->categorie->enabled) {
print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
print $form->showCategories($object->id, 'preventionplan', 1);
print "</td></tr>";
}

print '</table>';
print '</div>';
print '<div class="fichehalfright">';
Expand Down

0 comments on commit 97c74f6

Please sign in to comment.