Skip to content

Commit

Permalink
Merge pull request #1739 from Evarisk/9.2.0
Browse files Browse the repository at this point in the history
9.2.0
  • Loading branch information
nicolas-eoxia authored Apr 25, 2022
2 parents f3f906b + 7357be1 commit 2967218
Show file tree
Hide file tree
Showing 1,909 changed files with 2,394 additions and 312,903 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ npm-debug.log
vendor
.editorconfig
.gitattributes
digirisk-workflow
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## Informations

Version du module: 9.1.1
Version du module: 9.2.0

Dernière mise à jour: 14/03/2022
Dernière mise à jour: 25/04/2022

Prérequis:
* Dolibarr min version 13.0.0
Expand Down
51 changes: 37 additions & 14 deletions admin/config/riskassessmentdocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,11 @@
print $langs->trans('RiskDescriptionDescription');
print '</td>';


print '<td class="center">';
print ajax_constantonoff('DIGIRISKDOLIBARR_RISK_DESCRIPTION');
print '</td>';
print '</tr>';


print '<tr class="oddeven"><td>';
print $langs->trans('RiskCategoryEdit');
print "</td><td>";
Expand All @@ -227,17 +225,6 @@
print '</td>';
print '</tr>';

print '<tr class="oddeven"><td>';
print $langs->trans('ShowParentRisks');
print "</td><td>";
print $langs->trans('ShowParentRisksDescription');
print '</td>';

print '<td class="center">';
print ajax_constantonoff('DIGIRISKDOLIBARR_SHOW_PARENT_RISKS');
print '</td>';
print '</tr>';

print '<tr class="oddeven"><td>';
print $langs->trans('MoveRisks');
print "</td><td>";
Expand Down Expand Up @@ -266,12 +253,48 @@
print $langs->trans('RiskDescriptionPrefillDescription');
print '</td>';


print '<td class="center">';
print ajax_constantonoff('DIGIRISKDOLIBARR_RISK_DESCRIPTION_PREFILL');
print '</td>';
print '</tr>';

print '<tr class="oddeven"><td>';
print $langs->trans('ShowRisks');
print "</td><td>";
print $langs->trans('ShowRisksDescription');
print '</td>';

print '<td class="center">';
print ajax_constantonoff('DIGIRISKDOLIBARR_SHOW_RISKS');
print '</td>';
print '</tr>';

print '<tr class="oddeven"><td>';
print $langs->trans('ShowInheritedRisks');
print "</td><td>";
print $langs->trans('ShowInheritedRisksDescription');
print '</td>';

print '<td class="center">';
print ajax_constantonoff('DIGIRISKDOLIBARR_SHOW_INHERITED_RISKS');
print '</td>';
print '</tr>';

$result = !empty($conf->mc->entities['risk']) ? strpos($conf->mc->entities['risk'], $conf->entity) : 0;

if ($conf->multicompany->enabled && !empty($conf->mc->sharings['risk']) && $result > 0) {
print '<tr class="oddeven"><td>';
print $langs->trans('ShowSharedRisks');
print "</td><td>";
print $langs->trans('ShowSharedRisksDescription');
print '</td>';

print '<td class="center">';
print ajax_constantonoff('DIGIRISKDOLIBARR_SHOW_SHARED_RISKS');
print '</td>';
print '</tr>';
}

print '</table>';
print '<hr>';

Expand Down
4 changes: 2 additions & 2 deletions class/digiriskdocuments/firepermitdocument.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public function FirePermitDocumentFillJSON()
$firepermit->fetch($id);
}

$firepermitlines = $firepermitline->fetchAll(GETPOST('id'));
$preventionplanlines = $preventionplanline->fetchAll($firepermit->fk_preventionplan);
$firepermitlines = $firepermitline->fetchAll('', '', 0, 0, array(), 'AND', GETPOST('id'));
$preventionplanlines = $preventionplanline->fetchAll('', '', 0, 0, array(), 'AND', $firepermit->fk_preventionplan);
$digirisk_resources = $resources->digirisk_dolibarr_fetch_resources();

$extsociety = $resources->fetchResourcesFromObject('FP_EXT_SOCIETY', $firepermit);
Expand Down
2 changes: 1 addition & 1 deletion class/digiriskdocuments/preventionplandocument.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function PreventionPlanDocumentFillJSON()
$preventionplan->fetch($id);
}

$preventionplanlines = $preventionplanline->fetchAll(GETPOST('id'));
$preventionplanlines = $preventionplanline->fetchAll('', '', 0, 0, array(), 'AND', GETPOST('id'));
$digirisk_resources = $resources->digirisk_dolibarr_fetch_resources();

$extsociety = $resources->fetchResourcesFromObject('PP_EXT_SOCIETY', $preventionplan);
Expand Down
23 changes: 14 additions & 9 deletions class/digiriskelement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class DigiriskElement extends CommonObject
'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => '1', 'position' => 120, 'notnull' => -1, 'visible' => -2,),
'fk_parent' => array('type' => 'integer', 'label' => 'ParentElement', 'enabled' => '1', 'position' => 130, 'notnull' => 1, 'visible' => 1, 'default' => 0,),
'fk_standard' => array('type' => 'integer', 'label' => 'Standard', 'enabled' => '1', 'position' => 140, 'notnull' => 1, 'visible' => 0, 'default' => 1,),
'rank' => array('type' => 'integer', 'label' => 'Order', 'enabled' => '1', 'position' => 150, 'notnull' => 1, 'visible' => 0),
'ranks' => array('type' => 'integer', 'label' => 'Order', 'enabled' => '1', 'position' => 150, 'notnull' => 1, 'visible' => 0),
);

public $rowid;
Expand All @@ -117,7 +117,7 @@ class DigiriskElement extends CommonObject
public $fk_user_modif;
public $fk_parent;
public $fk_standard;
public $rank;
public $ranks;

/**
* Constructor
Expand Down Expand Up @@ -417,7 +417,7 @@ public function getRiskAssessmentCategoriesNumber()
* @return string HTML string with
* @throws Exception
*/
public function select_digiriskelement_list($selected = '', $htmlname = 'fk_element', $filter = '', $showempty = '1', $forcecombo = 0, $events = array(), $outputmode = 0, $limit = 0, $morecss = 'minwidth100', $moreparam = 0, $multiple = false, $noroot = 0)
public function select_digiriskelement_list($selected = '', $htmlname = 'fk_element', $filter = '', $showempty = '1', $forcecombo = 0, $events = array(), $outputmode = 0, $limit = 0, $morecss = 'minwidth100', $moreparam = 0, $multiple = false, $noroot = 0, $contextpage = '', $multientitymanagedoff = true)
{
global $conf, $langs;

Expand All @@ -436,8 +436,11 @@ public function select_digiriskelement_list($selected = '', $htmlname = 'fk_elem
$sql = "SELECT *";
$sql .= " FROM " . MAIN_DB_PREFIX . "digiriskdolibarr_digiriskelement as s";

$sql .= " WHERE s.entity IN (" . getEntity($this->table_element) . ")";
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1 && $multientitymanagedoff == false) $sql .= ' WHERE s.entity IN (' . getEntity($this->element) . ')';
else $sql .= ' WHERE s.entity = ' . $conf->entity;

if ($filter) $sql .= " AND (" . $filter . ")";

if ($moreparam > 0 ) {
$children = $this->fetchDigiriskElementFlat($moreparam);
if ( ! empty($children) && $children > 0) {
Expand Down Expand Up @@ -482,7 +485,7 @@ public function select_digiriskelement_list($selected = '', $htmlname = 'fk_elem
if ($num) {
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$label = $obj->ref . ' - ' . $obj->label;
$label = !empty(!empty($conf->global->DIGIRISKDOLIBARR_SHOW_SHARED_RISKS) && $contextpage == 'sharedrisk') ? 'S'. $obj->entity . ' - ' . $obj->ref . ' - ' . $obj->label : $obj->ref . ' - ' . $obj->label;


if (empty($outputmode)) {
Expand Down Expand Up @@ -598,9 +601,11 @@ public function getNomUrl($withpicto = 0, $option = '', $addlabel = 0, $moreinpo
$linkclose .= ' class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"';
} else $linkclose = ($morecss ? ' class="' . $morecss . '"' : '');

$linkstart = '<a href="' . $url . '"';
$linkstart .= $linkclose . '>';
$linkend = '</a>';
if ($option != 'nolink') {
$linkstart = '<a href="' . $url . '"';
$linkstart .= $linkclose . '>';
$linkend = '</a>';
}

$result .= $linkstart;
if ($withpicto) $result .= '<i class="fas fa-info-circle"></i>' . ' ';
Expand All @@ -626,7 +631,7 @@ public function getNomUrl($withpicto = 0, $option = '', $addlabel = 0, $moreinpo
*/
public function getTrashList()
{
$objects = $this->fetchAll('', 'rank');
$objects = $this->fetchAll('', 'ranks');
if (is_array($objects)) {
$recurse_tree = recurse_tree($this->id, 0, $objects);
$ids = [];
Expand Down
11 changes: 8 additions & 3 deletions class/firepermit.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,13 +766,18 @@ public function fetch($rowid)
}

/**
* Load firepermit line line from database
* Load firepermit line line from database
*
* @param string $sortorder Sort Order
* @param string $sortfield Sort field
* @param int $limit offset limit
* @param int $offset offset limit
* @param array $filter filter array
* @param string $filtermode filter mode (AND or OR)
* @param int $parent_id
* @param int $limit
* @return array|int
*/
public function fetchAll($parent_id = 0, $limit = 0)
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND', $parent_id = 0)
{
global $db;
$sql = 'SELECT t.rowid, t.ref, t.date_creation, t.description, t.category, t.use_equipment, t.fk_element';
Expand Down
11 changes: 8 additions & 3 deletions class/preventionplan.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,13 +866,18 @@ public function fetch($rowid)
}

/**
* Load preventionplan line line from database
* Load preventionplan line line from database
*
* @param string $sortorder Sort Order
* @param string $sortfield Sort field
* @param int $limit offset limit
* @param int $offset offset limit
* @param array $filter filter array
* @param string $filtermode filter mode (AND or OR)
* @param int $parent_id
* @param int $limit
* @return array|int
*/
public function fetchAll($parent_id = 0, $limit = 0)
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND', $parent_id = 0)
{
global $db;
$sql = 'SELECT t.rowid, t.ref, t.date_creation, t.description, t.category, t.prevention_method, t.fk_element';
Expand Down
107 changes: 104 additions & 3 deletions class/riskanalysis/risk.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Risk extends CommonObject
'fk_element' => array('type' => 'integer', 'label' => 'ParentElement', 'enabled' => '1', 'position' => 9, 'notnull' => 1, 'visible' => 1,),
'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => '1', 'position' => 20, 'notnull' => 1, 'visible' => 4, 'noteditable' => '1', 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'showoncombobox' => '1', 'comment' => "Reference of object"),
'ref_ext' => array('type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => '1', 'position' => 30, 'notnull' => 0, 'visible' => 0,),
'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => '1', 'position' => 40, 'notnull' => 1, 'visible' => 0,),
'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => '1', 'position' => 8, 'notnull' => 1, 'visible' => 0,),
'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => '1', 'position' => 50, 'notnull' => 1, 'visible' => 0,),
'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => '1', 'position' => 60, 'notnull' => 0, 'visible' => 0,),
'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => '1', 'position' => 70, 'notnull' => -1, 'visible' => 0,),
Expand Down Expand Up @@ -180,12 +180,14 @@ public function fetchFromParent($parent_id)
* @return array|int <0 if KO, 0 if not found, >0 if OK
* @throws Exception
*/
public function fetchRisksOrderedByCotation($parent_id, $get_children_data = false, $get_parents_data = false)
public function fetchRisksOrderedByCotation($parent_id, $get_children_data = false, $get_parents_data = false, $get_shared_data = false)
{
global $conf;
$object = new DigiriskElement($this->db);
$objects = $object->fetchAll('', '', 0, 0, array('customsql' => 'status > 0' ));
$risk = new Risk($this->db);
$result = $risk->fetchFromParent($parent_id);
$filter = '';

// RISKS de l'élément parent.
if ($result > 0 && ! empty($result)) {
Expand Down Expand Up @@ -261,6 +263,37 @@ public function fetchRisksOrderedByCotation($parent_id, $get_children_data = fal
}
}

if ( $get_shared_data ) {
$digiriskelementtmp = new DigiriskElement($this->db);

// $AllSharingsRisks = $conf->mc->sharings['risk'];
//
// foreach ($AllSharingsRisks as $Allsharingsrisk) {
// $filter .= $Allsharingsrisk . ',';
// }
//
// $filter = rtrim($filter, ',');

$allrisks = $risk->fetchAll('', '', 0, 0, array('customsql' => 'status > 0 AND entity NOT IN (' . $conf->entity . ')'), 'AND', 0);

foreach ($allrisks as $key => $allrisk) {
$digiriskelementtmp->fetch($allrisk->fk_element);
$digiriskelementtmp->element = 'digiriskdolibarr';
$digiriskelementtmp->fetchObjectLinked($allrisk->id, 'digiriskdolibarr_risk', $object->id, 'digiriskdolibarr_digiriskelement', 'AND', 1, 'sourcetype', 0);
$alreadyImported = !empty($digiriskelementtmp->linkedObjectsIds) ? 1 : 0;
if ($alreadyImported > 0) {
$evaluation = new RiskAssessment($this->db);
$lastEvaluation = $evaluation->fetchFromParent($allrisk->id, 1);
if ( $lastEvaluation > 0 && ! empty($lastEvaluation) && is_array($lastEvaluation)) {
$lastEvaluation = array_shift($lastEvaluation);
$allrisk->lastEvaluation = $lastEvaluation->cotation;
}

$risks[$allrisk->id] = $allrisk;
}
}
}

if ( ! empty($risks) ) {
usort($risks, function ($first, $second) {
return $first->lastEvaluation < $second->lastEvaluation;
Expand Down Expand Up @@ -292,7 +325,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset =
$sql = 'SELECT ';
$sql .= $this->getFieldList();
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN (' . getEntity($this->table_element) . ')';
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN (' . getEntity($this->element) . ')';
else $sql .= ' WHERE 1 = 1';

// Manage filter
Expand Down Expand Up @@ -554,4 +587,72 @@ public function get_related_tasks($risk)
return -1;
}
}

/**
* Return clickable name (with picto eventually)
*
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
* @param string $option Variant where the link point to ('', 'nolink')
* @param int $addlabel 0=Default, 1=Add label into string, >1=Add first chars into string
* @param string $moreinpopup Text to add into popup
* @param string $sep Separator between ref and label if option addlabel is set
* @param int $notooltip 1=Disable tooltip
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
* @param string $morecss More css on a link
* @return string String with URL
*/
public function getNomUrl($withpicto = 0, $option = '', $addlabel = 0, $moreinpopup = '', $sep = ' - ', $notooltip = 0, $save_lastsearch_value = -1, $morecss = '')
{
global $conf, $langs, $user, $hookmanager;

if ( ! empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips

$result = '';

$label = '';
if ($option != 'nolink') $label = '<i class="fas fa-exclamation-triangle"></i> <u class="paddingrightonly">' . $langs->trans('Risk') . '</u>';
$label .= ($label ? '<br>' : '') . '<b>' . $langs->trans('Ref') . ': </b>' . $this->ref; // The space must be after the : to not being explode when showing the title in img_picto
if ($moreinpopup) $label .= '<br>' . $moreinpopup;

$url = dol_buildpath('/digiriskdolibarr/view/digiriskelement/digiriskelement_risk.php', 1) . '?id=' . $this->fk_element;

if ($option != 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
}

$linkclose = '';
if ($option == 'blank') {
$linkclose .= ' target=_blank';
}

if (empty($notooltip) && $user->rights->digiriskdolibarr->risk->read) {
if ( ! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("ShowRisk");
$linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"';
}
$linkclose .= ' title="' . dol_escape_htmltag($label, 1) . '"';
$linkclose .= ' class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"';
} else $linkclose = ($morecss ? ' class="' . $morecss . '"' : '');

$linkstart = '<a href="' . $url . '"';
$linkstart .= $linkclose . '>';
$linkend = '</a>';

$result .= $linkstart;
if ($withpicto) $result .= '<i class="fas fa-exclamation-triangle"></i>' . ' ';
if ($withpicto != 2) $result .= $this->ref;
$result .= $linkend;

global $action;
$hookmanager->initHooks(array('riskdao'));
$parameters = array('id' => $this->id, 'getnomurl' => $result);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $this may have been modified by some hooks
if ($reshook > 0) $result = $hookmanager->resPrint;
else $result .= $hookmanager->resPrint;

return $result;
}
}
2 changes: 1 addition & 1 deletion class/riskanalysis/riskassessment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class RiskAssessment extends CommonObject
* @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 $ismultientitymanaged = 1;
public $ismultientitymanaged = 0;

/**
* @var int Does object support extrafields ? 0=No, 1=Yes
Expand Down
Loading

0 comments on commit 2967218

Please sign in to comment.