forked from Evarisk/Digirisk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Evarisk#3191 [Accident] add: perms, class, lib, and document template
- Loading branch information
1 parent
838d702
commit 3770eb8
Showing
7 changed files
with
426 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
<?php | ||
/* Copyright (C) 2021-2023 EVARISK <[email protected]> | ||
* | ||
* 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/>. | ||
*/ | ||
|
||
/** | ||
* \file class/accident_investigation.class.php | ||
* \ingroup digiriskdolibarr | ||
* \brief This file is a class file for Accident Investigation | ||
*/ | ||
|
||
require_once __DIR__ . '/../lib/digiriskdolibarr_function.lib.php'; | ||
require_once __DIR__ . '/../../saturne/class/saturneobject.class.php'; | ||
|
||
/** | ||
* Class to manage accident investigations. | ||
* Saved into database table llx_digiriskdolibarr_accident_investigation | ||
*/ | ||
class AccidentInvestigation extends SaturneObject | ||
{ | ||
/** | ||
* @var string Module name. | ||
*/ | ||
public $module = 'digiriskdolibarr'; | ||
|
||
/** | ||
* @var string Element type of object. | ||
*/ | ||
public $element = 'accident_investigation'; | ||
|
||
/** | ||
* @var string Name of table without prefix where object is stored. This is also the key used for extrafields management. | ||
*/ | ||
public $table_element = 'digiriskdolibarr_accident_investigation'; | ||
|
||
/** | ||
* @var int Does this object support multicompany module ? | ||
* 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table | ||
*/ | ||
public int $ismultientitymanaged = 1; | ||
|
||
/** | ||
* @var int Does object support extrafields ? 0=No, 1=Yes | ||
*/ | ||
public int $isextrafieldmanaged = 1; | ||
|
||
/** | ||
* @var string String with name of icon for digiriskelement. Must be the part after the 'object_' into object_digiriskelement.png | ||
*/ | ||
public string $picto = 'fontawesome_fa-tasks_fas_#d35968'; | ||
|
||
public const STATUS_DELETED = -1; | ||
public const STATUS_DRAFT = 0; | ||
public const STATUS_VALIDATED = 1; | ||
public const STATUS_LOCKED = 2; | ||
public const STATUS_ARCHIVED = 3; | ||
|
||
/** | ||
* 'type' field format: | ||
* 'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]', | ||
* 'select' (list of values are in 'options'), | ||
* 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter[:Sortfield]]]]', | ||
* 'chkbxlst:...', | ||
* 'varchar(x)', | ||
* 'text', 'text:none', 'html', | ||
* 'double(24,8)', 'real', 'price', | ||
* 'date', 'datetime', 'timestamp', 'duration', | ||
* 'boolean', 'checkbox', 'radio', 'array', | ||
* 'mail', 'phone', 'url', 'password', 'ip' | ||
* Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" | ||
* 'label' the translation key. | ||
* 'picto' is code of a picto to show before value in forms | ||
* 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM' or '!empty($conf->multicurrency->enabled)' ...) | ||
* 'position' is the sort order of field. | ||
* 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty '' or 0. | ||
* 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing) | ||
* 'noteditable' says if field is not editable (1 or 0) | ||
* 'default' is a default value for creation (can still be overwroted by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created. | ||
* 'index' if we want an index in database. | ||
* 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). | ||
* 'searchall' is 1 if we want to search in this field when making a search from the quick search button. | ||
* 'isameasure' must be set to 1 or 2 if field can be used for measure. Field type must be summable like integer or double(24,8). Use 1 in most cases, or 2 if you don't want to see the column total into list (for example for percentage) | ||
* 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200' | ||
* 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click. | ||
* 'showoncombobox' if value of the field must be visible into the label of the combobox that list record | ||
* 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code. | ||
* 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar' | ||
* 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1. | ||
* 'comment' is not used. You can store here any text of your choice. It is not used by application. | ||
* 'validate' is 1 if you need to validate with $this->validateField() | ||
* 'copytoclipboard' is 1 or 2 to allow to add a picto to copy value into clipboard (1=picto after label, 2=picto after value) | ||
* 'size' limit the length of a fields | ||
* | ||
* Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor. | ||
*/ | ||
|
||
/** | ||
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. | ||
*/ | ||
public $fields = [ | ||
'rowid' => ['type' => 'integer', 'label' => 'TechnicalID', 'enabled' => '1', 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => '1', 'index' => 1, 'comment' => "Id"], | ||
'ref' => ['type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => '1', 'position' => 10, 'notnull' => 1, 'visible' => 4, 'noteditable' => '1', 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'showoncombobox' => '1', 'comment' => "Reference of object"], | ||
'ref_ext' => ['type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => '1', 'position' => 20, 'notnull' => 0, 'visible' => 0,], | ||
'entity' => ['type' => 'integer', 'label' => 'Entity', 'enabled' => '1', 'position' => 10, 'notnull' => 1, 'visible' => 0,], | ||
'date_creation' => ['type' => 'datetime', 'label' => 'DateCreation', 'enabled' => '1', 'position' => 20, 'notnull' => 1, 'visible' => 0,], | ||
'tms' => ['type' => 'timestamp', 'label' => 'DateModification', 'enabled' => '1', 'position' => 30, 'notnull' => 0, 'visible' => 0,], | ||
'status' => ['type' => 'smallint', 'label' => 'Status', 'enabled' => '1', 'position' => 40, 'notnull' => 0, 'visible' => 0, 'index' => 0,], | ||
'seniority_at_post' => ['type' => 'varchar(255)', 'label' => 'SeniorityAtPost', 'enabled' => '1', 'position' => 60, 'notnull' => 0, 'visible' => 4,], | ||
'fk_usual_task' => ['type' => 'integer', 'label' => 'FkTask', 'enabled' => '1', 'position' => 70, 'notnull' => 0, 'visible' => 4,], | ||
'accident_on_job' => ['type' => 'boolean', 'label' => 'AccidentOnJob', 'enabled' => '1', 'position' => 80, 'notnull' => 0, 'visible' => 4,], | ||
'near_miss_on_job' => ['type' => 'boolean', 'label' => 'NearMissOnJob', 'enabled' => '1', 'position' => 90, 'notnull' => 0, 'visible' => 4,], | ||
'circumstances' => ['type' => 'text', 'label' => 'Circumstances', 'enabled' => '1', 'position' => 130, 'notnull' => 0, 'visible' => 4,], | ||
// 'consequences' => ['type' => 'text', 'label' => 'Consequences', 'enabled' => '1', 'position' => 140, 'notnull' => 0, 'visible' => 1,], | ||
'special_note' => ['type' => 'text', 'label' => 'SpecialNote', 'enabled' => '1', 'position' => 150, 'notnull' => 0, 'visible' => 4,], | ||
'emergency_called' => ['type' => 'boolean', 'label' => 'EmergencyCalled', 'enabled' => '1', 'position' => 160, 'notnull' => 0, 'visible' => 4,], | ||
'fk_emergency' => ['type' => 'integer', 'label' => 'EmergencyType', 'enabled' => '1', 'position' => 170, 'notnull' => 0, 'visible' => 4,], | ||
'fk_who_called_emergency' => ['type' => 'integer', 'label' => 'WhoCalledEmergency', 'enabled' => '1', 'position' => 180, 'notnull' => 0, 'visible' => 4,], | ||
'when_were_emergency_called' => ['type' => 'timestamp', 'label' => 'WhenWereEmergencyCalled', 'enabled' => '1', 'position' => 190, 'notnull' => 0, 'visible' => 4,], | ||
'fk_accident' => ['type' => 'integer:Accident:custom/digiriskdolibarr/class/accident/accident.class.php', 'label' => 'FkAccident', 'enabled' => '1', 'position' => 200, 'notnull' => 1, 'visible' => 1,], | ||
'fk_user_creat' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'picto' => 'user', 'enabled' => 1, 'position' => 210, 'notnull' => 1, 'visible' => 0, 'foreignkey' => 'user.rowid'], | ||
'fk_user_modif' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'picto' => 'user', 'enabled' => 1, 'position' => 220, 'notnull' => 0, 'visible' => 0, 'foreignkey' => 'user.rowid'], | ||
]; | ||
|
||
public $rowid; | ||
public $ref; | ||
public $ref_ext; | ||
public $entity; | ||
public $date_creation; | ||
public $tms; | ||
public $status; | ||
public $seniority_at_post; | ||
public $fk_usual_task; | ||
public $accident_on_job; | ||
public $near_miss_on_job; | ||
public $circumstances; | ||
//public $consequences; | ||
public $special_note; | ||
public $emergency_called; | ||
public $fk_emergency; | ||
public $fk_who_called_emergency; | ||
public $when_were_emergency_called; | ||
public $fk_accident; | ||
public $fk_user_creat; | ||
public $fk_user_modif; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param DoliDb $db Database handler | ||
*/ | ||
public function __construct(DoliDB $db) | ||
{ | ||
parent::__construct($db, $this->module, $this->element); | ||
} | ||
|
||
/** | ||
* Create object into database. | ||
* | ||
* @param User $user User that creates. | ||
* @param bool $notrigger false = launch triggers after, true = disable triggers. | ||
* @return int 0 < if KO, ID of created object if OK. | ||
*/ | ||
public function create(User $user, bool $notrigger = false): int | ||
{ | ||
$this->ref = $this->getNextNumRef(); | ||
$this->status = $this->status ?: self::STATUS_DRAFT; | ||
|
||
return parent::create($user, $notrigger); | ||
} | ||
|
||
/** | ||
* Return the label of the status | ||
* | ||
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto | ||
* @return string Label of status | ||
*/ | ||
public function getLibStatut(int $mode = 0): string | ||
{ | ||
return $this->LibStatut($this->status, $mode); | ||
} | ||
|
||
/** | ||
* Return the status. | ||
* | ||
* @param int $status ID status. | ||
* @param int $mode 0 = long label, 1 = short label, 2 = Picto + short label, 3 = Picto, 4 = Picto + long label, 5 = Short label + Picto, 6 = Long label + Picto. | ||
* @return string Label of status. | ||
*/ | ||
public function LibStatut(int $status, int $mode = 0): string | ||
{ | ||
if (empty($this->labelStatus) || empty($this->labelStatusShort)) { | ||
global $langs; | ||
|
||
$this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('StatusDraft'); | ||
$this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated'); | ||
$this->labelStatus[self::STATUS_LOCKED] = $langs->transnoentitiesnoconv('Locked'); | ||
$this->labelStatus[self::STATUS_ARCHIVED] = $langs->transnoentitiesnoconv('Archived'); | ||
$this->labelStatus[self::STATUS_DELETED] = $langs->transnoentitiesnoconv('Deleted'); | ||
|
||
$this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('StatusDraft'); | ||
$this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated'); | ||
$this->labelStatusShort[self::STATUS_LOCKED] = $langs->transnoentitiesnoconv('Locked'); | ||
$this->labelStatusShort[self::STATUS_ARCHIVED] = $langs->transnoentitiesnoconv('Archived'); | ||
$this->labelStatusShort[self::STATUS_DELETED] = $langs->transnoentitiesnoconv('Deleted'); | ||
} | ||
|
||
$statusType = 'status' . $status; | ||
if ($status == self::STATUS_VALIDATED) { | ||
$statusType = 'status4'; | ||
} | ||
if ($status == self::STATUS_LOCKED) { | ||
$statusType = 'status6'; | ||
} | ||
if ($status == self::STATUS_ARCHIVED) { | ||
$statusType = 'status8'; | ||
} | ||
if ($status == self::STATUS_DELETED) { | ||
$statusType = 'status9'; | ||
} | ||
|
||
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); | ||
} | ||
} | ||
|
2 changes: 2 additions & 0 deletions
2
core/modules/digiriskdolibarr/accidentinvestigation/index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
//Silence is golden |
42 changes: 42 additions & 0 deletions
42
core/modules/digiriskdolibarr/accidentinvestigation/mod_accident_investigation_standard.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/* Copyright (C) 2023 EVARISK <[email protected]> | ||
* | ||
* 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/>. | ||
* or see https://www.gnu.org/ | ||
*/ | ||
|
||
/** | ||
* \file core/modules/digiriskdolibarr/address/mod_accident_investigation_standard.php | ||
* \ingroup digiriskdolibarr | ||
* \brief File of class to manage address numbering rules standard. | ||
*/ | ||
|
||
// Load Saturne libraries. | ||
require_once __DIR__ . '/../../../../../saturne/core/modules/saturne/modules_saturne.php'; | ||
|
||
/** | ||
* Class to manage accident investigation numbering rules standard. | ||
*/ | ||
class mod_accident_investigation_standard extends ModeleNumRefSaturne | ||
{ | ||
/** | ||
* @var string Numbering module ref prefix. | ||
*/ | ||
public string $prefix = 'AI'; | ||
|
||
/** | ||
* @var string Name. | ||
*/ | ||
public string $name = 'Bebhionn'; | ||
} |
2 changes: 2 additions & 0 deletions
2
core/modules/digiriskdolibarr/digiriskdocuments/accidentinvestigationdocument/index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
//Silence is golden |
68 changes: 68 additions & 0 deletions
68
...digiriskdocuments/accidentinvestigationdocument/modules_accidentinvestigationdocument.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/* Copyright (C) 2021 EVARISK <[email protected]> | ||
* | ||
* 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/>. | ||
* or see https://www.gnu.org/ | ||
*/ | ||
|
||
/** | ||
* \file core/modules/digiriskdolibarr/modules_accidentinvestigationdocument.php | ||
* \ingroup digiriskdolibarr | ||
* \brief File that contains parent class for digiriskelementdocuments document models | ||
*/ | ||
|
||
require_once DOL_DOCUMENT_ROOT . '/core/class/commondocgenerator.class.php'; | ||
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'; | ||
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; | ||
|
||
/** | ||
* Parent class for documents models | ||
*/ | ||
abstract class ModeleODTAccidentInvestigationDocument extends CommonDocGenerator | ||
{ | ||
|
||
/** | ||
* Function to build a document on disk using the generic odt module. | ||
* | ||
* @param AccidentInvestigationDocument $object Object source to build document | ||
* @param Translate $outputlangs Lang output object | ||
* @param string $srctemplatepath Full path of source filename for generator using a template file | ||
* @param int $hidedetails Do not show line details | ||
* @param int $hidedesc Do not show desc | ||
* @param int $hideref Do not show ref | ||
* @param DigiriskElement $digiriskelement Object for get DigiriskElement info | ||
* @return int 1 if OK, <=0 if KO | ||
* @throws Exception | ||
*/ | ||
public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $digiriskelement) | ||
{ | ||
return 0; | ||
} | ||
|
||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps | ||
/** | ||
* Return list of active generation modules | ||
* | ||
* @param DoliDB $db Database handler | ||
* @param int $maxfilenamelength Max length of value to show | ||
* @return array List of templates | ||
*/ | ||
public static function liste_modeles($db, $maxfilenamelength = 0) | ||
{ | ||
$type = 'accidentinvestigationdocument'; | ||
|
||
require_once __DIR__ . '/../../../../../lib/digiriskdolibarr_function.lib.php'; | ||
return getListOfModelsDigirisk($db, $type, $maxfilenamelength); | ||
} | ||
} |
Oops, something went wrong.