Skip to content

Commit

Permalink
add: evaluation ref
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-theo committed Feb 19, 2021
1 parent 5a47a03 commit 67f0778
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 35 deletions.
2 changes: 2 additions & 0 deletions class/digiriskevaluation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class DigiriskEvaluation extends CommonObject
'occurrence' => array('type'=>'integer', 'label'=>'Occurrence', 'enabled'=>'1', 'position'=>1220, 'notnull'=>0, 'visible'=>-1,),
'formation' => array('type'=>'integer', 'label'=>'Formation', 'enabled'=>'1', 'position'=>1230, 'notnull'=>0, 'visible'=>-1,),
'exposition' => array('type'=>'integer', 'label'=>'Exposition', 'enabled'=>'1', 'position'=>1210, 'notnull'=>0, 'visible'=>-1,),
'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>'1', 'position'=>40, 'notnull'=>0, 'visible'=>-1,),
);
public $rowid;
public $ref;
Expand All @@ -129,6 +130,7 @@ class DigiriskEvaluation extends CommonObject
public $occurrence;
public $formation;
public $exposition;
public $entity;
// END MODULEBUILDER PROPERTIES


Expand Down
10 changes: 6 additions & 4 deletions class/digiriskevaluation.class.php.back
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ class DigiriskEvaluation extends CommonObject
'fk_risk' => array('type'=>'integer', 'label'=>'ParentRisk', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>-1,),
'gravite' => array('type'=>'integer', 'label'=>'Gravity', 'enabled'=>'1', 'position'=>1200, 'notnull'=>0, 'visible'=>-1,),
'protection' => array('type'=>'integer', 'label'=>'Protection', 'enabled'=>'1', 'position'=>1240, 'notnull'=>0, 'visible'=>-1,),
'occurence' => array('type'=>'integer', 'label'=>'Occurence', 'enabled'=>'1', 'position'=>1220, 'notnull'=>0, 'visible'=>-1,),
'occurrence' => array('type'=>'integer', 'label'=>'Occurrence', 'enabled'=>'1', 'position'=>1220, 'notnull'=>0, 'visible'=>-1,),
'formation' => array('type'=>'integer', 'label'=>'Formation', 'enabled'=>'1', 'position'=>1230, 'notnull'=>0, 'visible'=>-1,),
'exposition' => array('type'=>'integer', 'label'=>'Exposition', 'enabled'=>'1', 'position'=>1210, 'notnull'=>0, 'visible'=>-1,),
);
public $rowid;
public $ref;
Expand All @@ -125,8 +126,9 @@ class DigiriskEvaluation extends CommonObject
public $fk_risk;
public $gravite;
public $protection;
public $occurence;
public $occurrence;
public $formation;
public $exposition;
// END MODULEBUILDER PROPERTIES


Expand Down Expand Up @@ -346,7 +348,7 @@ class DigiriskEvaluation extends CommonObject
*/
public function fetchFromParent($parent_id, $active = 0)
{
$filter = array('fk_risk' => $parent_id);
$filter = array('customsql' => 'fk_risk=' . $this->db->escape($parent_id));
if ($active) $filter['status'] = 1;

$result = $this->fetchAll('', '', 0, 0, $filter, 'AND');
Expand Down Expand Up @@ -940,7 +942,7 @@ class DigiriskEvaluation extends CommonObject
$langs->load("digiriskdolibarr@digiriskdolibarr");

if (empty($conf->global->DIGIRISKDOLIBARR_DIGIRISKEVALUATION_ADDON)) {
$conf->global->DIGIRISKDOLIBARR_DIGIRISKEVALUATION_ADDON = 'mod_digiriskevaluation_standard';
$conf->global->DIGIRISKDOLIBARR_DIGIRISKEVALUATION_ADDON = 'mod_evaluation_standard';
}

if (!empty($conf->global->DIGIRISKDOLIBARR_DIGIRISKEVALUATION_ADDON))
Expand Down
24 changes: 12 additions & 12 deletions core/modules/digiriskdolibarr/mod_evaluation_standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
*/

/**
* \file htdocs/custom/digiriskdolibarr/core/modules/digiriskdolibarr/mod_risk_standard.php
* \ingroup digiriskdolibarr risk
* \file htdocs/custom/digiriskdolibarr/core/modules/digiriskdolibarr/mod_evaluation_standard.php
* \ingroup digiriskdolibarr evaluation
* \brief File containing class for numbering module Standard
*/
require_once DOL_DOCUMENT_ROOT.'/custom/digiriskdolibarr/core/modules/digiriskdolibarr/modules_digiriskevaluation.php';
/**
* Class to manage risk numbering rules Standard
* Class to manage evaluation numbering rules Standard
*/
class mod_evaluation_standard extends ModeleNumRefDigiriskEvaluation
{
Expand All @@ -35,15 +35,13 @@ class mod_evaluation_standard extends ModeleNumRefDigiriskEvaluation
*/
public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'

public $prefixevaluation = 'evaluation';
public $prefixevaluation = '';

/**
* @var string Error code (or message)
*/
public $error = '';



/**
* Returns the description of the numbering model
*
Expand All @@ -63,7 +61,7 @@ public function info()
*/
public function getExample()
{
return $this->prefixevaluation."0001";
return $this->prefixevaluation."1";
}
/**
* Return next value not used or last value used
Expand All @@ -76,7 +74,7 @@ public function getNextValue($object)
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';

// On defini critere recherche compteur
$mask = $conf->global->RISK_STANDARD_MASK;
$mask = $conf->global->EVALUATION_STANDARD_MASK;

if (!$mask)
{
Expand All @@ -85,11 +83,13 @@ public function getNextValue($object)
}

// Get entities
$entity = getEntity('evaluation', 1, $object);
$entity = $conf->entity;

$date = dol_now();

$numFinal = get_next_value($db, $mask, 'digiriskdolibarr_evaluation', 'ref','', $object, $date, 'next', false, null, $entity);
$numFinal = get_next_value($db, $mask, 'digiriskdolibarr_digiriskevaluation', 'ref','', $object, $date, 'next', false, null, $entity);


$this->prefixevaluation = $numFinal;
return $numFinal;
}
Expand All @@ -102,8 +102,8 @@ public function getNextValue($object)
* @param string $mode 'next' for next value or 'last' for last value
* @return string Next free value
*/
public function getNumRef($objsoc, $objforref, $mode = 'next')
public function getNumRef($objforref, $mode = 'next')
{
return $this->getNextValue($objsoc, $objforref, $mode);
return $this->getNextValue($objforref, $mode);
}
}
5 changes: 4 additions & 1 deletion core/modules/modDigiriskDolibarr.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ public function __construct($db)
42 => array('DIGIRISKDOLIBARR_RISK_ADDON','chaine', 'mod_risk_standard' ,'', 1),
43 => array('DIGIRISKDOLIBARR_RISK_DEFAULT_MODEL','chaine', 'risk_A4_odt' ,'', 1),
44 => array('MAIN_AGENDA_ACTIONAUTO_RISK_CREATE','chaine',1,'', 1),
45 => array('RISK_STANDARD_MASK','chaine','R{0000}','', 1)
45 => array('RISK_STANDARD_MASK','chaine','R{0000}','', 1),
46 => array('EVALUATION_STANDARD_MASK','chaine','E{0000}','', 1),
47 => array('DIGIRISKDOLIBARR_EVALUATION_ADDON','chaine', 'mod_evaluation_standard' ,'', 1)



);
Expand Down
40 changes: 26 additions & 14 deletions risk_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
dol_include_once('/digiriskdolibarr/class/digiriskevaluation.class.php');
dol_include_once('/digiriskdolibarr/class/digiriskelement.class.php');
dol_include_once('/digiriskdolibarr/core/modules/digiriskdolibarr/mod_risk_standard.php');
dol_include_once('/digiriskdolibarr/core/modules/digiriskdolibarr/mod_evaluation_standard.php');
dol_include_once('/digiriskdolibarr/lib/digiriskdolibarr_digiriskelement.lib.php');

// Load translation files required by the page
Expand Down Expand Up @@ -142,9 +143,9 @@

$risk->description = $riskComment ? $riskComment : '';
$risk->fk_element = $fk_element ? $fk_element : 0;

if ($ref) {
$risk->ref = $ref;
$refRisk = new $conf->global->DIGIRISKDOLIBARR_RISK_ADDON();
if ($refRisk) {
$risk->ref = $refRisk->getNextValue($risk);
}

if (!$error)
Expand All @@ -153,18 +154,20 @@

if ($result > 0)
{

$formation = GETPOST('formation');
$protection = GETPOST('protection');
$occurrence = GETPOST('occurrence');
$gravite = GETPOST('gravite');
$exposition = GETPOST('exposition');

$evaluation = new DigiriskEvaluation($db);
$refCot = new $conf->global->DIGIRISKDOLIBARR_EVALUATION_ADDON();
$evaluation->cotation = $cotation;
$evaluation->fk_risk = $risk->id;
$evaluation->status = 1;
$evaluation->method = $method;

$evaluation->ref = $refCot->getNumRef($evaluation);
$evaluation->formation = $formation ;
$evaluation->protection = $protection ;
$evaluation->occurrence = $occurrence ;
Expand Down Expand Up @@ -217,6 +220,9 @@
$evaluation->status = 1;
$evaluation->method = $method;

$refCot = new $conf->global->DIGIRISKDOLIBARR_EVALUATION_ADDON();
$evaluation->ref = $refCot->getNextValue($evaluation);

if ($method == 'digirisk') {
$evaluation->formation = $formation ;
$evaluation->protection = $protection ;
Expand Down Expand Up @@ -275,6 +281,7 @@
<div id="cardContent" value="">

<?php

// Example : Adding jquery code
//print '<script type="text/javascript" language="javascript">
//jQuery(document).ready(function() {
Expand All @@ -290,8 +297,8 @@
//});
//</script>';

// Part to show record
if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create')))
// VIEW
if ($object->id > 0)
{
$res = $object->fetch_optionals();

Expand Down Expand Up @@ -343,6 +350,9 @@
$risks = $risk->fetchFromParent($object->id);
if (!empty($risks)) {
foreach ($risks as $risk) {
$evaluation = new DigiriskEvaluation($db);
$lastCotation = $evaluation->fetchFromParent($risk->id,1);
$lastCotation = array_shift($lastCotation);
// action = edit
if ($action == 'editRisk' . $risk->id) {
?>
Expand All @@ -353,8 +363,10 @@
<?php
$riskRef = substr($risk->ref, 1);
$riskRef = ltrim($riskRef, '0');
$cotationRef = substr($lastCotation->ref, 1);
$cotationRef = ltrim($cotationRef, '0');
// au lieu de 'R' mettre l'accronyme des risques qui sera futurement configurable dans digirisk
echo 'R' . $riskRef; ?>
echo 'R' . $riskRef . ' - E' . $cotationRef; ?>
</strong>
</span>
</div>
Expand All @@ -364,15 +376,12 @@
<div class="table-cell table-50 cell-cotation" data-title="Cot.">
<div class="cotation-container grid wpeo-modal-event tooltip hover cotation-square" id="cotation_square<?php echo $risk->id ?>">
<?php
$evaluation = new DigiriskEvaluation($db);
$lastCotation = $evaluation->fetchFromParent($risk->id,1);
if (!empty($lastCotation)) {
//ici pas faire un foreach, accèder juste au premier élément
foreach ($lastCotation as $cot) {
$cot = $lastCotation;
if ($action == 'editRisk' . $risk->id) { ?>
<div data-title="Cot." class="table-cell table-50 cell-cotation">

<textarea style="display: none;" name="evaluation_variables"><?php echo ! empty( $risk->data['evaluation']->data ) ? $risk->data['evaluation']->data['variables'] : '{}'; ?></textarea>
<textarea style="display: none;" name="evaluation_variables"><?php echo ! empty( $risk->data['evaluation']->data ) ? $risk->data['evaluation']->data['variables'] : '{}'; ?></textarea>
<div class="wpeo-dropdown dropdown-grid dropdown-padding-0 cotation-container wpeo-tooltip-event"
aria-label="<?php echo 'Veuillez remplir la cotation'; ?>"
data-color="red"
Expand Down Expand Up @@ -478,7 +487,6 @@ class="dropdown-item cotation"><?php echo $request; ?></li>
</div>
<?php
}
}
}?>
</div>
</div>
Expand All @@ -502,6 +510,8 @@ class="dropdown-item cotation"><?php echo $request; ?></li>
</div>

<!-- action = view-->


<?php
} else {
?>
Expand All @@ -513,8 +523,10 @@ class="dropdown-item cotation"><?php echo $request; ?></li>
<?php
$riskRef = substr($risk->ref, 1);
$riskRef = ltrim($riskRef, '0');
$cotationRef = substr($lastCotation->ref, 1);
$cotationRef = ltrim($cotationRef, '0');
// au lieu de 'R' mettre l'accronyme des risques qui sera futurement configurable dans digirisk
echo 'R' . $riskRef; ?>
echo 'R' . $riskRef . ' - E' . $cotationRef; ?>
</strong>
</span>
</div>
Expand Down
5 changes: 3 additions & 2 deletions sql/llx_digiriskdolibarr_digiriskevaluation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ CREATE TABLE llx_digiriskdolibarr_digiriskevaluation(
fk_risk integer,
gravite integer,
protection integer,
occurrence integer,
occurrence integer,
formation integer,
exposition integer
exposition integer,
entity integer DEFAULT 1
-- END MODULEBUILDER FIELDS
) ENGINE=innodb;
5 changes: 3 additions & 2 deletions sql/llx_digiriskdolibarr_digiriskevaluation.sql.back
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ CREATE TABLE llx_digiriskdolibarr_digiriskevaluation(
fk_risk integer,
gravite integer,
protection integer,
occurence integer,
formation integer
occurrence integer,
formation integer,
exposition integer
-- END MODULEBUILDER FIELDS
) ENGINE=innodb;

0 comments on commit 67f0778

Please sign in to comment.