From b5cdfd519080dfc81e304595dae328f82e061893 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 Jan 2024 15:23:46 +0100 Subject: [PATCH] Rename class file for pdf generation to match Dolibarr standard --- htdocs/comm/action/rapport/index.php | 7 +- .../core/class/commondocgenerator.class.php | 8 +- .../pdf_standard_actions.class.php} | 9 +- htdocs/core/modules/action/modules_action.php | 92 ------------------- 4 files changed, 13 insertions(+), 103 deletions(-) rename htdocs/core/modules/action/{rapport.class.php => doc/pdf_standard_actions.class.php} (98%) diff --git a/htdocs/comm/action/rapport/index.php b/htdocs/comm/action/rapport/index.php index 1571061e32c..5e5974dc4f0 100644 --- a/htdocs/comm/action/rapport/index.php +++ b/htdocs/comm/action/rapport/index.php @@ -30,7 +30,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/modules/action/rapport.class.php'; // Load translation files required by the page $langs->loadLangs(array("agenda", "commercial")); @@ -68,8 +67,10 @@ if (!$user->hasRight("agenda", "allactions", "read")) { */ if ($action == 'builddoc') { - $cat = new CommActionRapport($db, $month, $year); - $result = $cat->write_file(GETPOST('id', 'int')); + require_once DOL_DOCUMENT_ROOT.'/core/modules/action/doc/pdf_standard_actions.class.php'; + + $cat = new pdf_standard_actions($db, $month, $year); + $result = $cat->write_file(0, $langs); if ($result < 0) { setEventMessages($cat->error, $cat->errors, 'errors'); } diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 81683c81d18..a33f3fc1b2d 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -509,7 +509,7 @@ abstract class CommonDocGenerator public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object') { // phpcs:enable - global $conf, $extrafields; + global $extrafields; $sumpayed = $sumdeposit = $sumcreditnote = ''; $already_payed_all = 0; @@ -831,8 +831,10 @@ abstract class CommonDocGenerator public function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object') { // phpcs:enable - global $conf, $extrafields; - dol_include_once('/core/lib/product.lib.php'); + global $extrafields; + + include_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; + $object->list_delivery_methods($object->shipping_method_id); $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth); diff --git a/htdocs/core/modules/action/rapport.class.php b/htdocs/core/modules/action/doc/pdf_standard_actions.class.php similarity index 98% rename from htdocs/core/modules/action/rapport.class.php rename to htdocs/core/modules/action/doc/pdf_standard_actions.class.php index 8b343f794b9..ba3baaa4e51 100644 --- a/htdocs/core/modules/action/rapport.class.php +++ b/htdocs/core/modules/action/doc/pdf_standard_actions.class.php @@ -19,7 +19,7 @@ */ /** - * \file htdocs/core/modules/action/rapport.class.php + * \file htdocs/core/modules/action/doc/pdf_standard_actions.class.php * \ingroup commercial * \brief File to build PDF with events */ @@ -33,7 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; /** * Class to generate event report */ -class CommActionRapport +class pdf_standard_actions { /** * @var DoliDB Database handler. @@ -89,7 +89,7 @@ class CommActionRapport */ public function __construct($db, $month, $year) { - global $conf, $langs; + global $langs; // Load translation files required by the page $langs->loadLangs(array("commercial", "projects")); @@ -120,11 +120,10 @@ class CommActionRapport * Write the object to document file to disk * * @param int $socid Thirdparty id - * @param int $catid Cat id * @param Translate $outputlangs Lang object for output language * @return int 1=OK, 0=KO */ - public function write_file($socid = 0, $catid = 0, $outputlangs = '') + public function write_file($socid, $outputlangs) { // phpcs:enable global $user, $conf, $langs, $hookmanager; diff --git a/htdocs/core/modules/action/modules_action.php b/htdocs/core/modules/action/modules_action.php index 2f88e233d7d..1069baa5714 100644 --- a/htdocs/core/modules/action/modules_action.php +++ b/htdocs/core/modules/action/modules_action.php @@ -53,95 +53,3 @@ abstract class ModeleAction extends CommonDocGenerator return $list; } } - -// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps -/** - * Create a product document on disk using template defined into PRODUCT_ADDON_PDF - * - * @param DoliDB $db data base object - * @param Object $object Object fichinter - * @param string $modele forces the model to use ('' by default) - * @param Translate $outputlangs lang object to use for translation - * @param int $hidedetails Hide details of lines - * @param int $hidedesc Hide description - * @param int $hideref Hide ref - * @return int 0 if KO, 1 if OK - */ -function action_create($db, $object, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0) -{ - // phpcs:enable - global $conf, $langs, $user; - $langs->load("action"); - - $error = 0; - - $srctemplatepath = ''; - - // Position modele on the name of fichinter model to use - if (!dol_strlen($modele)) { - if (getDolGlobalString('ACTION_EVENT_ADDON_PDF')) { - $modele = $conf->global->ACTION_EVENT_ADDON_PDF; - } else { - $modele = 'soleil'; - } - } - - // If selected modele is a filename template (then $modele="modelname:filename") - $tmp = explode(':', $modele, 2); - if (!empty($tmp[1])) { - $modele = $tmp[0]; - $srctemplatepath = $tmp[1]; - } - - // Search template files - $file = ''; - $classname = ''; - $filefound = 0; - $dirmodels = array('/'); - if (is_array($conf->modules_parts['models'])) { - $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']); - } - foreach ($dirmodels as $reldir) { - foreach (array('doc', 'pdf') as $prefix) { - $file = $prefix."_".$modele.".modules.php"; - - // On verifie l'emplacement du modele - $file = dol_buildpath($reldir."core/modules/action/doc/".$file, 0); - if (file_exists($file)) { - $filefound = 1; - $classname = $prefix.'_'.$modele; - break; - } - } - if ($filefound) { - break; - } - } - - // Charge le modele - if ($filefound) { - require_once $file; - - $obj = new $classname($db); - - // We save charset_output to restore it because write_file can change it if needed for - // output format that does not support UTF8. - $sav_charset_output = $outputlangs->charset_output; - if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) { - $outputlangs->charset_output = $sav_charset_output; - - // We delete old preview - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - dol_delete_preview($object); - - return 1; - } else { - $outputlangs->charset_output = $sav_charset_output; - dol_print_error($db, "action_pdf_create Error: ".$obj->error); - return 0; - } - } else { - print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file); - return 0; - } -}