Skip to content

Commit

Permalink
Qual: Add abstract write_file to ModelePDFStock & ModelePDFStockTransfer
Browse files Browse the repository at this point in the history
And update phpdoc for derived classes
  • Loading branch information
mdeweerd committed Aug 16, 2024
1 parent 57966d3 commit 0754d2c
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 40 deletions.
2 changes: 1 addition & 1 deletion htdocs/admin/stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
require_once $file;

$module = new $classname($db);
'@phan-var-force CommonDocGenerator $module';
'@phan-var-force ModelePDFStock $module';

if ($module->write_file($object, $langs) > 0) {
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=stock&file=SPECIMEN.pdf");
Expand Down
2 changes: 1 addition & 1 deletion htdocs/admin/stocktransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
require_once $file;

$module = new $classname($db);
'@phan-var-force CommonDocGenerator $module';
'@phan-var-force ModelePDFStockTransfer $module';

if ($module->write_file($tmpobject, $langs) > 0) {
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
Expand Down
24 changes: 12 additions & 12 deletions htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ public function info($langs)
* Function to build a document on disk using the generic odt module.
*
* @param Entrepot $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
* @return int 1 if OK, <=0 if KO
* @param Translate $outputlangs Lang output object
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param int<0,1> $hidedetails Do not show line details
* @param int<0,1> $hidedesc Do not show desc
* @param int<0,1> $hideref Do not show ref
* @return int<-1,1> 1 if OK, <=0 if KO
*/
public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
// phpcs:enable
global $stock, $langs, $conf, $mysoc, $hookmanager, $user;
Expand Down Expand Up @@ -321,7 +321,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails
);
complete_substitutions_array($substitutionarray, $langs, $object);
// Call the ODTSubstitution hook
$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray);
$parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$substitutionarray);
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks

// Line of free text
Expand Down Expand Up @@ -379,7 +379,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails
complete_substitutions_array($tmparray, $outputlangs, $object);

// Call the ODTSubstitution hook
$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray);
$parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks

foreach ($tmparray as $key => $value) {
Expand Down Expand Up @@ -411,7 +411,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails
$array_lines = $this->get_substitutionarray_each_var_object($supplierprice, $outputlangs);
complete_substitutions_array($array_lines, $outputlangs, $object, $supplierprice, "completesubstitutionarray_lines");
// Call the ODTSubstitutionLine hook
$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$array_lines, 'line'=>$supplierprice);
$parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$array_lines, 'line' => $supplierprice);
$reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
foreach ($array_lines as $key => $val) {
try {
Expand Down Expand Up @@ -442,7 +442,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails
}

// Call the beforeODTSave hook
$parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
$parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
$reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks

// Write new file
Expand Down Expand Up @@ -470,7 +470,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails

$odfHandler = null; // Destroy object

$this->result = array('fullpath'=>$file);
$this->result = array('fullpath' => $file);

return 1; // Success
} else {
Expand Down
14 changes: 7 additions & 7 deletions htdocs/core/modules/stock/doc/pdf_standard_stock.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ public function __construct($db)

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build a document on disk using the generic odt module.
* Function to build a pdf on disk
*
* @param Entrepot $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
* @return int 1 if OK, <=0 if KO
* @param Translate $outputlangs Lang output object
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param int<0,1> $hidedetails Do not show line details
* @param int<0,1> $hidedesc Do not show desc
* @param int<0,1> $hideref Do not show ref
* @return int<-1,1> 1 if OK, <=0 if KO
*/
public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
Expand Down
22 changes: 19 additions & 3 deletions htdocs/core/modules/stock/modules_stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ abstract class ModelePDFStock extends CommonDocGenerator
/**
* Return list of active generation modules
*
* @param DoliDB $db Database handler
* @param integer $maxfilenamelength Max length of value to show
* @return array List of templates
* @param DoliDB $db Database handler
* @param int<0,max> $maxfilenamelength Max length of value to show
* @return string[]|int<-1,0> List of templates
*/
public static function liste_modeles($db, $maxfilenamelength = 0)
{
Expand All @@ -68,4 +68,20 @@ public static function liste_modeles($db, $maxfilenamelength = 0)

return $list;
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build a document
*
* @param Entrepot $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<0,1> $hidedetails Do not show line details
* @param int<0,1> $hidedesc Do not show desc
* @param int<0,1> $hideref Do not show ref
* @return int<-1,1> 1 if OK, <=0 if KO
*/
abstract public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0);
// phpcs:enable
}
11 changes: 6 additions & 5 deletions htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,18 @@ public function __construct(DoliDB $db)
}*/
}


// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build pdf onto disk
*
* @param StockTransfer $object Object StockTransfer to generate (or id if old method)
* @param Translate $outputlangs Lang output object
* @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
* @return int 1=OK, 0=KO
* @param int<0,1> $hidedetails Do not show line details
* @param int<0,1> $hidedesc Do not show desc
* @param int<0,1> $hideref Do not show ref
* @return int<-1,1> 1 if OK, <=0 if KO
*/
public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ public function __construct($db)

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build pdf onto disk
* Function to build pdf onto disk
*
* @param Object $object Object to generate
* @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
* @return int 1=OK, 0=KO
* @param StockTransfer $object Object StockTransfer to generate (or id if old method)
* @param Translate $outputlangs Lang output object
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param int<0,1> $hidedetails Do not show line details
* @param int<0,1> $hidedesc Do not show desc
* @param int<0,1> $hideref Do not show ref
* @return int<-1,1> 1 if OK, <=0 if KO
*/
public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
Expand Down
20 changes: 17 additions & 3 deletions htdocs/core/modules/stocktransfer/modules_stocktransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ abstract class ModelePDFStockTransfer extends CommonDocGenerator
/**
* Return list of active generation modules
*
* @param DoliDB $db Database handler
* @param integer $maxfilenamelength Max length of value to show
* @return array List of templates
* @param DoliDB $db Database handler
* @param int<0,max> $maxfilenamelength Max length of value to show
* @return string[]|int<-1,0> List of templates
*/
public static function liste_modeles($db, $maxfilenamelength = 0)
{
Expand All @@ -58,6 +58,20 @@ public static function liste_modeles($db, $maxfilenamelength = 0)

return $list;
}

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Function to build document onto disk
*
* @param StockTransfer $object Object StockTransfer to generate (or id if old method)
* @param Translate $outputlangs Lang output object
* @param string $srctemplatepath Full path of source filename for generator using a template file
* @param int<0,1> $hidedetails Do not show line details
* @param int<0,1> $hidedesc Do not show desc
* @param int<0,1> $hideref Do not show ref
* @return int<-1,1> 1 if OK, <=0 if KO
*/
abstract public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0);
}


Expand Down

0 comments on commit 0754d2c

Please sign in to comment.