2
0
forked from Wavyzz/dolibarr

Standardize code

This commit is contained in:
Laurent Destailleur
2025-04-24 00:51:47 +02:00
parent 1435c02986
commit e034b4b0ef
5 changed files with 38 additions and 14 deletions

View File

@@ -432,7 +432,6 @@ class BOM extends CommonObject
* Load object lines in memory from the database by type of product * Load object lines in memory from the database by type of product
* *
* @param int<0,1> $typeproduct 0 type product, 1 type service * @param int<0,1> $typeproduct 0 type product, 1 type service
*
* @return int<-1,1> Return integer <0 if KO, 0 if not found, >0 if OK * @return int<-1,1> Return integer <0 if KO, 0 if not found, >0 if OK
*/ */
public function fetchLinesbytypeproduct($typeproduct = 0) public function fetchLinesbytypeproduct($typeproduct = 0)
@@ -469,6 +468,11 @@ class BOM extends CommonObject
'@phan-var-force BOMLine $newline'; '@phan-var-force BOMLine $newline';
$newline->setVarsFromFetchObj($obj); $newline->setVarsFromFetchObj($obj);
// Load also extrafields for the line
//if (empty($noextrafields)) {
$newline->fetch_optionals();
//}
$this->lines[] = $newline; $this->lines[] = $newline;
} }
$i++; $i++;

View File

@@ -32,6 +32,11 @@ function bomAdminPrepareHead()
{ {
global $langs, $conf; global $langs, $conf;
global $db;
$extrafields = new ExtraFields($db);
$extrafields->fetch_name_optionals_label('bom_bom');
$extrafields->fetch_name_optionals_label('bom_bomline');
$langs->load("mrp"); $langs->load("mrp");
$h = 0; $h = 0;
@@ -44,11 +49,19 @@ function bomAdminPrepareHead()
$head[$h][0] = DOL_URL_ROOT."/admin/bom_extrafields.php"; $head[$h][0] = DOL_URL_ROOT."/admin/bom_extrafields.php";
$head[$h][1] = $langs->trans("ExtraFields"); $head[$h][1] = $langs->trans("ExtraFields");
$nbExtrafields = is_countable($extrafields->attributes['bom_bom']['label']) ? count($extrafields->attributes['bom_bom']['label']) : 0;
if ($nbExtrafields > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>';
}
$head[$h][2] = 'bom_extrafields'; $head[$h][2] = 'bom_extrafields';
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT."/admin/bomline_extrafields.php"; $head[$h][0] = DOL_URL_ROOT."/admin/bomline_extrafields.php";
$head[$h][1] = $langs->trans("ExtraFieldsLines"); $head[$h][1] = $langs->trans("ExtraFieldsLines");
$nbExtrafields = is_countable($extrafields->attributes['bom_bomline']['label']) ? count($extrafields->attributes['bom_bomline']['label']) : 0;
if ($nbExtrafields > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>';
}
$head[$h][2] = 'bomline_extrafields'; $head[$h][2] = 'bomline_extrafields';
$h++; $h++;

View File

@@ -5354,8 +5354,8 @@ abstract class CommonObject
print "<!-- begin printObjectLines() -->\n"; print "<!-- begin printObjectLines() -->\n";
foreach ($this->lines as $line) { foreach ($this->lines as $line) {
//Line extrafield // Line extrafield. TODO Remove this. extrafields should be already loaded.
$line->fetch_optionals(); //$line->fetch_optionals();
if (is_object($hookmanager)) { if (is_object($hookmanager)) {
if (empty($line->fk_parent_line)) { if (empty($line->fk_parent_line)) {
@@ -5366,7 +5366,7 @@ abstract class CommonObject
$reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
} }
} }
if (empty($reshook) && $buyer !== null) { if (empty($reshook)) {
$this->printObjectLine($action, $line, '', $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir); $this->printObjectLine($action, $line, '', $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir);
} }
@@ -5387,7 +5387,7 @@ abstract class CommonObject
* @param int $i I * @param int $i I
* @param int $dateSelector 1=Show also date range input fields * @param int $dateSelector 1=Show also date range input fields
* @param Societe $seller Object of seller third party * @param Societe $seller Object of seller third party
* @param Societe $buyer Object of buyer third party * @param ?Societe $buyer Object of buyer third party
* @param int $selected ID line selected * @param int $selected ID line selected
* @param ?ExtraFields $extrafields Object of extrafields * @param ?ExtraFields $extrafields Object of extrafields
* @param string $defaulttpldir Directory where to find the template (deprecated) * @param string $defaulttpldir Directory where to find the template (deprecated)
@@ -6348,7 +6348,6 @@ abstract class CommonObject
$sql .= " WHERE type_object = '".$this->db->escape($element)."'"; $sql .= " WHERE type_object = '".$this->db->escape($element)."'";
$sql .= " AND fk_object = ".((int) $this->id); $sql .= " AND fk_object = ".((int) $this->id);
//dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
$numrows = $this->db->num_rows($resql); $numrows = $this->db->num_rows($resql);
@@ -10716,11 +10715,10 @@ abstract class CommonObject
'@phan-var-force CommonObjectLine $newline'; '@phan-var-force CommonObjectLine $newline';
$newline->setVarsFromFetchObj($obj); $newline->setVarsFromFetchObj($obj);
// Note: extrafields load of line not yet supported // Load also extrafields for the line
/* if (empty($noextrafields)) {
if (empty($noextrafields)) { $newline->fetch_optionals();
// Load extrafields of line }
}*/
$this->lines[] = $newline; $this->lines[] = $newline;
} }

View File

@@ -1,8 +1,8 @@
<?php <?php
/* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr> * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com> * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr> * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View File

@@ -49,10 +49,19 @@ function mymoduleAdminPrepareHead()
$head[$h][1] = $langs->trans("ExtraFields"); $head[$h][1] = $langs->trans("ExtraFields");
$nbExtrafields = is_countable($extrafields->attributes['myobject']['label']) ? count($extrafields->attributes['myobject']['label']) : 0; $nbExtrafields = is_countable($extrafields->attributes['myobject']['label']) ? count($extrafields->attributes['myobject']['label']) : 0;
if ($nbExtrafields > 0) { if ($nbExtrafields > 0) {
$head[$h][1] .= ' <span class="badge">' . $nbExtrafields . '</span>'; $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>';
} }
$head[$h][2] = 'myobject_extrafields'; $head[$h][2] = 'myobject_extrafields';
$h++; $h++;
$head[$h][0] = dol_buildpath("/mymodule/admin/myobjectline_extrafields.php", 1);
$head[$h][1] = $langs->trans("ExtraFieldsLines");
$nbExtrafields = is_countable($extrafields->attributes['myobjectline']['label']) ? count($extrafields->attributes['myobject']['label']) : 0;
if ($nbExtrafields > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>';
}
$head[$h][2] = 'myobject_extrafieldsline';
$h++;
*/ */
$head[$h][0] = dol_buildpath("/mymodule/admin/about.php", 1); $head[$h][0] = dol_buildpath("/mymodule/admin/about.php", 1);