From dcfaae3bd5e447c13271a2b0f30dd5a66a6986b7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Aug 2024 06:20:04 +0200 Subject: [PATCH] Clean code: fight against global vars --- dev/tools/phan/config.php | 2 -- htdocs/bom/tpl/objectline_view.tpl.php | 3 +- htdocs/core/class/commonobject.class.php | 4 +-- htdocs/core/tpl/objectline_view.tpl.php | 7 ++-- htdocs/hrm/core/tpl/objectline_view.tpl.php | 36 +------------------ .../variants/class/ProductAttribute.class.php | 4 +-- .../productattributevalueline_view.tpl.php | 3 +- 7 files changed, 10 insertions(+), 49 deletions(-) diff --git a/dev/tools/phan/config.php b/dev/tools/phan/config.php index febfb91167a..840065e5fd7 100644 --- a/dev/tools/phan/config.php +++ b/dev/tools/phan/config.php @@ -268,8 +268,6 @@ return [ 'menumanager' => '\MenuManager', 'mysoc' => '\Societe', 'nblines' => '\int', - // 'obj' => '\CommonObject', // Deprecated - 'object_rights' => 'int|stdClass', 'objectoffield' => '\CommonObject', 'objsoc' => '\Societe', 'senderissupplier' => 'int<0,2>', diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index 9e52fb9c187..e9dcd4678a6 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -29,7 +29,6 @@ * $element (used to test $user->hasRight($element, 'creer')) * $permtoedit (used to replace test $user->hasRight($element, 'creer')) * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax) - * $object_rights->creer initialized from = $object->getRights() * $disableedit, $disablemove, $disableremove * * $type, $text, $description, $line @@ -207,7 +206,7 @@ if (!empty($line->fk_bom_child)) { } print ''; -if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines') { +if ($this->status == 0 && $user->hasRight('bom', 'write') && $action != 'selectlines') { print ''; $coldisplay++; if (($line->info_bits & 2) == 2 || !empty($disableedit)) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 2b86a378e0b..7127d0fe0ca 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5274,9 +5274,7 @@ abstract class CommonObject { global $conf, $langs, $user, $object, $hookmanager; global $form; - global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! - - $object_rights = $this->getRights(); + global $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! // var used into tpl $text = ''; diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 79de54f92c7..5d197a7e921 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -35,7 +35,6 @@ * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax) * $outputalsopricetotalwithtax * $usemargins (0 to disable all margins columns, 1 to show according to margin setup) - * $object_rights->creer initialized from = $object->getRights() * $disableedit, $disablemove, $disableremove * * $text, $description, $line @@ -446,7 +445,11 @@ if ($outputalsopricetotalwithtax) { $coldisplay++; } -if ($this->status == 0 && !empty($object_rights->creer) && $action != 'selectlines') { +// TODO Replace this with $permissiontoedit ? +$objectRights = $this->getRights(); +$tmppermtoedit = $objectRights->creer; + +if ($this->status == 0 && $tmppermtoedit && $action != 'selectlines') { $situationinvoicelinewithparent = 0; if (isset($line->fk_prev_id) && in_array($object->element, array('facture', 'facturedet'))) { // @phan-suppress-next-line PhanUndeclaredConstantOfClass diff --git a/htdocs/hrm/core/tpl/objectline_view.tpl.php b/htdocs/hrm/core/tpl/objectline_view.tpl.php index 3c68d6fd011..3aa7da00fea 100644 --- a/htdocs/hrm/core/tpl/objectline_view.tpl.php +++ b/htdocs/hrm/core/tpl/objectline_view.tpl.php @@ -37,7 +37,6 @@ * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax) * $outputalsopricetotalwithtax * $usemargins (0 to disable all margins columns, 1 to show according to margin setup) - * $object_rights->creer initialized from = $object->getRights() * $disableedit, $disablemove, $disableremove * * $text, $description, $line @@ -107,40 +106,7 @@ print displayRankInfos($line->rankorder, $line->fk_skill, 'TNote', ($this->statu statut == 0 && !empty($object_rights->creer) && $action != 'selectlines') { - print ''; - $coldisplay++; - if (($line->info_bits & 2) == 2 || !empty($disableedit)) { - } else { ?> - id.'#line_'.$line->id; ?>"> - '; - } - print ''; - - /* - if ($num > 1 && $conf->browser->layout != 'phone' && ($this->situation_counter == 1 || !$this->situation_cycle_ref) && empty($disablemove)) { - print ''; - $coldisplay++; - if ($i > 0) { ?> - id; ?>"> - - - - id; ?>"> - - - '; - } else { - print 'browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'>'; - $coldisplay++; - }*/ -} else { - //print ''; - $coldisplay += 3; -} +$coldisplay += 3; if ($action == 'selectlines') { ?> diff --git a/htdocs/variants/class/ProductAttribute.class.php b/htdocs/variants/class/ProductAttribute.class.php index b6371710f57..1a2ea4baf8a 100644 --- a/htdocs/variants/class/ProductAttribute.class.php +++ b/htdocs/variants/class/ProductAttribute.class.php @@ -1407,9 +1407,7 @@ class ProductAttribute extends CommonObject { global $conf, $langs, $user, $object, $hookmanager; global $form; - global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! - - $object_rights = $user->rights->variants; + global $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! // Line in view mode if ($action != 'editline' || $selected != $line->id) { diff --git a/htdocs/variants/tpl/productattributevalueline_view.tpl.php b/htdocs/variants/tpl/productattributevalueline_view.tpl.php index b96c5032b0d..650379055d0 100644 --- a/htdocs/variants/tpl/productattributevalueline_view.tpl.php +++ b/htdocs/variants/tpl/productattributevalueline_view.tpl.php @@ -28,7 +28,6 @@ * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax) * $outputalsopricetotalwithtax * $usemargins (0 to disable all margins columns, 1 to show according to margin setup) - * $object_rights->creer initialized from = $object->getRights() * $disableedit, $disablemove, $disableremove * * $text, $description, $line @@ -62,7 +61,7 @@ $coldisplay = 0; value ?> write) && $action != 'selectlines') { +if ($user->hasRight('variants', 'write') && $action != 'selectlines') { print ''; $coldisplay++; if (empty($disableedit)) { ?>