Skip to content

Commit

Permalink
Evarisk#4012 [DigiriskElement] fix: gp and wu odt documents
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-micka committed Jun 26, 2024
1 parent fec6012 commit 978a94e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
require_once __DIR__ . '/../../../../../class/riskanalysis/risk.class.php';
require_once __DIR__ . '/../../../../../class/evaluator.class.php';
require_once __DIR__ . '/../../../../../class/accident.class.php';
require_once __DIR__ . '/../../../../../class/digiriskresources.class.php';

// Load saturne libraries
// Load Saturne libraries
require_once __DIR__ . '/../../../../../../saturne/core/modules/saturne/modules_saturne.php';

/**
Expand Down Expand Up @@ -306,6 +307,32 @@ public function write_file(SaturneDocuments $objectDocument, Translate $outputLa
$tmpArray['photo'] = DOL_DOCUMENT_ROOT . $noPhoto;
}

$resources = new DigiriskResources($this->db);
$userTmp = new User($this->db);

// Get QRCode to public interface
if (isModEnabled('multicompany')) {
$qrCodePath = DOL_DATA_ROOT . '/digiriskdolibarr/multicompany/ticketqrcode/';
} else {
$qrCodePath = $conf->digiriskdolibarr->multidir_output[$conf->entity ?: 1] . '/ticketqrcode/';
}
$QRCodeList = dol_dir_list($qrCodePath);
if (is_array($QRCodeList) && !empty($QRCodeList)) {
$QRCode = array_shift($QRCodeList);
$QRCodeImagePath = $QRCode['fullname'];
} else {
$QRCodeImagePath = DOL_DOCUMENT_ROOT . '/public/theme/common/nophoto.png';
}

$allLinks = $resources->fetchDigiriskResources();
$responsibleResources = $allLinks['Responsible'];
$userTmp->fetch($responsibleResources->id[0]);

// @todo The keyword "signature" is needed because we want the image to be cropped to fit in the table
$tmpArray['helpUrl'] = DOL_MAIN_URL_ROOT . '/custom/digiriskdolibarr/public/ticket/create_ticket.php';
$tmpArray['signatureQRCodeTicket'] = $QRCodeImagePath;
$tmpArray['securityResponsible'] = (!empty($userTmp) ? dol_strtoupper($userTmp->lastname) . ' ' . ucfirst($userTmp->firstname) : '');

if (isset($moreParam['tmparray']) && is_array($moreParam['tmparray'])) {
$moreParam['tmparray'] = array_merge($moreParam['tmparray'], $tmpArray);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

// Load DigiriskDolibarr libraries
require_once __DIR__ . '/../digiriskelementdocument/modules_digiriskelementdocument.php';
require_once __DIR__ . '/../../../../../class/digiriskresources.class.php';

/**
* Class to build documents using ODF templates generator
Expand Down Expand Up @@ -65,52 +64,4 @@ public function info(Translate $langs): string
{
return parent::info($langs);
}

/**
* Function to build a document on disk
*
* @param SaturneDocuments $objectDocument Object source to build document
* @param Translate $outputLangs Lang object to use for output
* @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 array $moreParam More param (Object/user/etc)
* @return int 1 if OK, <=0 if KO
* @throws Exception
*/
public function write_file(SaturneDocuments $objectDocument, Translate $outputLangs, string $srcTemplatePath, int $hideDetails = 0, int $hideDesc = 0, int $hideRef = 0, array $moreParam): int
{
global $conf;

$resources = new DigiriskResources($this->db);
$userTmp = new User($this->db);

// Get QRCode to public interface
if (isModEnabled('multicompany')) {
$qrCodePath = DOL_DATA_ROOT . '/digiriskdolibarr/multicompany/ticketqrcode/';
} else {
$qrCodePath = $conf->digiriskdolibarr->multidir_output[$conf->entity ?: 1] . '/ticketqrcode/';
}
$QRCodeList = dol_dir_list($qrCodePath);
if (is_array($QRCodeList) && !empty($QRCodeList)) {
$QRCode = array_shift($QRCodeList);
$QRCodeImagePath = $QRCode['fullname'];
} else {
$QRCodeImagePath = DOL_DOCUMENT_ROOT . '/public/theme/common/nophoto.png';
}

$allLinks = $resources->fetchDigiriskResources();
$responsibleResources = $allLinks['Responsible'];
$userTmp->fetch($responsibleResources->id[0]);

// @todo The keyword "signature" is needed because we want the image to be cropped to fit in the table
$tmpArray['helpUrl'] = DOL_MAIN_URL_ROOT . '/custom/digiriskdolibarr/public/ticket/create_ticket.php';
$tmpArray['signatureQRCodeTicket'] = $QRCodeImagePath;
$tmpArray['securityResponsible'] = (!empty($userTmp) ? dol_strtoupper($userTmp->lastname) . ' ' . ucfirst($userTmp->firstname) : '');

$moreParam['tmparray'] = $tmpArray;

return parent::write_file($objectDocument, $outputLangs, $srcTemplatePath, $hideDetails, $hideDesc, $hideRef, $moreParam);
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 978a94e

Please sign in to comment.