Skip to content

Commit b9946ce

Browse files
authored
NEW #33506 Add a constant to apply a ratio to resize images in ODT templates (#33543)
* CLOSE #33506 add a constant holding the ratio to resize images in ODT templates A new Dolibarr constant MAIN_DOC_ODT_IMAGE_RATIO is taken in consideration for ODT templates. This constant holds a number that is multiplied when computing the size of images in ODT templates. All doc_generic_*_odt_modules.php files have been updated to call the setImage Method with a new parameter $ratio The method setImage in the file odt.php has been modified to have a new parameter $ratio and use it to compute the image size * FIX #33506 wrong branch some other files needed to be changed in the develop branch * FIX #33506 PR errors fixed * FIX #33506 codesniffer errors fixed * QUAL #33506 completed method comment
1 parent 73e54ae commit b9946ce

25 files changed

Lines changed: 201 additions & 33 deletions

htdocs/core/modules/asset/doc/doc_generic_asset_odt.modules.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,19 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
380380
$parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
381381
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
382382

383+
// retrieve the constant to apply a ratio for image size or set the ratio to 1
384+
if (getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO')) {
385+
$ratio = floatval(getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO'));
386+
} else {
387+
$ratio = 1;
388+
}
389+
383390
foreach ($tmparray as $key => $value) {
384391
try {
385392
if (preg_match('/logo$/', $key)) {
386393
// Image
387394
if (file_exists($value)) {
388-
$odfHandler->setImage($key, $value);
395+
$odfHandler->setImage($key, $value, $ratio);
389396
} else {
390397
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
391398
}

htdocs/core/modules/bom/doc/doc_generic_bom_odt.modules.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,18 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
378378
$parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
379379
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
380380

381+
// retrieve the constant to apply a ratio for image size or set the ratio to 1
382+
if (getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO')) {
383+
$ratio = floatval(getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO'));
384+
} else {
385+
$ratio = 1;
386+
}
387+
381388
foreach ($tmparray as $key => $value) {
382389
try {
383390
if (preg_match('/logo$/', $key)) { // Image
384391
if (file_exists($value)) {
385-
$odfHandler->setImage($key, $value);
392+
$odfHandler->setImage($key, $value, $ratio);
386393
} else {
387394
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
388395
}

htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,18 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
399399
$parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
400400
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
401401

402+
// retrieve the constant to apply a ratio for image size or set the ratio to 1
403+
if (getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO')) {
404+
$ratio = floatval(getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO'));
405+
} else {
406+
$ratio = 1;
407+
}
408+
402409
foreach ($tmparray as $key => $value) {
403410
try {
404411
if (preg_match('/logo$/', $key)) { // Image
405412
if (file_exists($value)) {
406-
$odfHandler->setImage($key, $value);
413+
$odfHandler->setImage($key, $value, $ratio);
407414
} else {
408415
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
409416
}

htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,19 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
389389
// Call the ODTSubstitution hook
390390
$parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
391391
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
392+
// retrieve the constant to apply a ratio for image size or set the ratio to 1
393+
if (getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO')) {
394+
$ratio = floatval(getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO'));
395+
} else {
396+
$ratio = 1;
397+
}
392398

393399
foreach ($tmparray as $key => $value) {
394400
try {
395401
if (preg_match('/logo$/', $key)) {
396402
// Image
397403
if (file_exists($value)) {
398-
$odfHandler->setImage($key, $value);
404+
$odfHandler->setImage($key, $value, $ratio);
399405
} else {
400406
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
401407
}

htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,21 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
372372
dol_syslog($e->getMessage(), LOG_INFO);
373373
}
374374

375+
// retrieve the constant to apply a ratio for image size or set the ratio to 1
376+
if (getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO')) {
377+
$ratio = floatval(getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO'));
378+
} else {
379+
$ratio = 1;
380+
}
381+
375382
// Make substitutions into odt of user info
376383
$tmparray = $this->get_substitutionarray_user($user, $outputlangs);
377384
foreach ($tmparray as $key => $value) {
378385
try {
379386
if (preg_match('/logo$/', $key)) { // Image
380387
//var_dump($value);exit;
381388
if (file_exists($value)) {
382-
$odfHandler->setImage($key, $value);
389+
$odfHandler->setImage($key, $value, $ratio);
383390
} else {
384391
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
385392
}
@@ -397,7 +404,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
397404
if (preg_match('/logo$/', $key)) { // Image
398405
//var_dump($value);exit;
399406
if (file_exists($value)) {
400-
$odfHandler->setImage($key, $value);
407+
$odfHandler->setImage($key, $value, $ratio);
401408
} else {
402409
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
403410
}
@@ -419,7 +426,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
419426
try {
420427
if (preg_match('/logo$/', $key)) { // Image
421428
if (file_exists($value)) {
422-
$odfHandler->setImage($key, $value);
429+
$odfHandler->setImage($key, $value, $ratio);
423430
} else {
424431
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
425432
}
@@ -437,7 +444,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
437444
try {
438445
if (preg_match('/logo$/', $key)) { // Image
439446
if (file_exists($value)) {
440-
$odfHandler->setImage($key, $value);
447+
$odfHandler->setImage($key, $value, $ratio);
441448
} else {
442449
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
443450
}
@@ -464,7 +471,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
464471
if (preg_match('/logo$/', $key)) {
465472
// Image
466473
if (file_exists($value)) {
467-
$odfHandler->setImage($key, $value);
474+
$odfHandler->setImage($key, $value, $ratio);
468475
} else {
469476
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
470477
}

htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,20 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
453453
$parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
454454
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
455455

456+
// retrieve the constant to apply a ratio for image size or set the ratio to 1
457+
if (getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO')) {
458+
$ratio = floatval(getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO'));
459+
} else {
460+
$ratio = 1;
461+
}
462+
463+
//var_dump($tmparray); exit;
456464
foreach ($tmparray as $key => $value) {
457465
try {
458466
if (preg_match('/logo$/', $key)) { // Image
459467
//var_dump($value);exit;
460468
if (file_exists($value)) {
461-
$odfHandler->setImage($key, $value);
469+
$odfHandler->setImage($key, $value, $ratio);
462470
} else {
463471
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
464472
}

htdocs/core/modules/member/doc/doc_generic_member_odt.class.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,20 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $mode =
351351
'substitutionarray' => &$tmparray
352352
);
353353
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
354+
355+
// retrieve the constant to apply a ratio for image size or set the ratio to 1
356+
if (getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO')) {
357+
$ratio = floatval(getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO'));
358+
} else {
359+
$ratio = 1;
360+
}
361+
354362
foreach ($tmparray as $key => $value) {
355363
try {
356364
if (preg_match('/logo$/', $key)) {
357365
// Image
358366
if (file_exists($value)) {
359-
$odfHandler->setImage($key, $value);
367+
$odfHandler->setImage($key, $value, $ratio);
360368
} else {
361369
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
362370
}

htdocs/core/modules/mrp/doc/doc_generic_mo_odt.modules.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,19 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
378378
$parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
379379
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
380380

381+
// retrieve the constant to apply a ratio for image size or set the ratio to 1
382+
if (getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO')) {
383+
$ratio = floatval(getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO'));
384+
} else {
385+
$ratio = 1;
386+
}
387+
381388
foreach ($tmparray as $key => $value) {
382389
try {
383390
if (preg_match('/logo$/', $key)) {
384391
// Image
385392
if (file_exists($value)) {
386-
$odfHandler->setImage($key, $value);
393+
$odfHandler->setImage($key, $value, $ratio);
387394
} else {
388395
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
389396
}

htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,18 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
390390
$parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
391391
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
392392

393+
// retrieve the constant to apply a ratio for image size or set the ratio to 1
394+
if (getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO')) {
395+
$ratio = floatval(getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO'));
396+
} else {
397+
$ratio = 1;
398+
}
399+
393400
foreach ($tmparray as $key => $value) {
394401
try {
395402
if (preg_match('/logo$/', $key)) { // Image
396403
if (file_exists($value)) {
397-
$odfHandler->setImage($key, $value);
404+
$odfHandler->setImage($key, $value, $ratio);
398405
} else {
399406
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
400407
}

htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,18 @@ public function write_file($object, $outputlangs, $srctemplatepath = '')
651651
$parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
652652
$reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
653653

654+
// retrieve the constant to apply a ratio for image size or set the ratio to 1
655+
if (getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO')) {
656+
$ratio = floatval(getDolGlobalString('MAIN_DOC_ODT_IMAGE_RATIO'));
657+
} else {
658+
$ratio = 1;
659+
}
660+
654661
foreach ($tmparray as $key => $value) {
655662
try {
656663
if (preg_match('/logo$/', $key)) { // Image
657664
if (file_exists($value)) {
658-
$odfHandler->setImage($key, $value);
665+
$odfHandler->setImage($key, $value, $ratio);
659666
} else {
660667
$odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
661668
}

0 commit comments

Comments
 (0)