Clean code: fight against global vars

This commit is contained in:
Laurent Destailleur 2024-08-27 06:20:04 +02:00
parent 53c8851f2c
commit dcfaae3bd5
7 changed files with 10 additions and 49 deletions

View file

@ -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>',

View file

@ -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 '</td>';
if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines') {
if ($this->status == 0 && $user->hasRight('bom', 'write') && $action != 'selectlines') {
print '<td class="linecoledit center">';
$coldisplay++;
if (($line->info_bits & 2) == 2 || !empty($disableedit)) {

View file

@ -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 = '';

View file

@ -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

View file

@ -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
</td>
<?php
if ($this->statut == 0 && !empty($object_rights->creer) && $action != 'selectlines') {
print '<td class="linecoledit center">';
$coldisplay++;
if (($line->info_bits & 2) == 2 || !empty($disableedit)) {
} else { ?>
<a class="editfielda reposition" href="<?php print $_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=editline&amp;lineid='.$line->id.'#line_'.$line->id; ?>">
<?php print img_edit().'</a>';
}
print '</td>';
/*
if ($num > 1 && $conf->browser->layout != 'phone' && ($this->situation_counter == 1 || !$this->situation_cycle_ref) && empty($disablemove)) {
print '<td class="linecolmove tdlineupdown center">';
$coldisplay++;
if ($i > 0) { ?>
<a class="lineupdown" href="<?php print $_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=up&amp;rowid='.$line->id; ?>">
<?php print img_up('default', 0, 'imgupforline'); ?>
</a>
<?php }
if ($i < $num - 1) { ?>
<a class="lineupdown" href="<?php print $_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=down&amp;rowid='.$line->id; ?>">
<?php print img_down('default', 0, 'imgdownforline'); ?>
</a>
<?php }
print '</td>';
} else {
print '<td '.(($conf->browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'></td>';
$coldisplay++;
}*/
} else {
//print '<td colspan="3"></td>';
$coldisplay += 3;
}
$coldisplay += 3;
if ($action == 'selectlines') { ?>
<td class="linecolcheck center"><input type="checkbox" class="linecheckbox" name="line_checkbox[<?php print $i + 1; ?>]" value="<?php print $line->id; ?>" ></td>

View file

@ -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) {

View file

@ -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;
<td class="linecolvalue nowrap"><?php $coldisplay++;
print $line->value ?></td>
<?php
if (!empty($object_rights->write) && $action != 'selectlines') {
if ($user->hasRight('variants', 'write') && $action != 'selectlines') {
print '<td class="linecoledit center width25">';
$coldisplay++;
if (empty($disableedit)) { ?>