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
*
* @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
*/
public function fetchLinesbytypeproduct($typeproduct = 0)
@@ -469,6 +468,11 @@ class BOM extends CommonObject
'@phan-var-force BOMLine $newline';
$newline->setVarsFromFetchObj($obj);
// Load also extrafields for the line
//if (empty($noextrafields)) {
$newline->fetch_optionals();
//}
$this->lines[] = $newline;
}
$i++;

View File

@@ -32,6 +32,11 @@ function bomAdminPrepareHead()
{
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");
$h = 0;
@@ -44,11 +49,19 @@ function bomAdminPrepareHead()
$head[$h][0] = DOL_URL_ROOT."/admin/bom_extrafields.php";
$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';
$h++;
$head[$h][0] = DOL_URL_ROOT."/admin/bomline_extrafields.php";
$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';
$h++;

View File

@@ -5354,8 +5354,8 @@ abstract class CommonObject
print "<!-- begin printObjectLines() -->\n";
foreach ($this->lines as $line) {
//Line extrafield
$line->fetch_optionals();
// Line extrafield. TODO Remove this. extrafields should be already loaded.
//$line->fetch_optionals();
if (is_object($hookmanager)) {
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
}
}
if (empty($reshook) && $buyer !== null) {
if (empty($reshook)) {
$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 $dateSelector 1=Show also date range input fields
* @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 ?ExtraFields $extrafields Object of extrafields
* @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 .= " 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);
if ($resql) {
$numrows = $this->db->num_rows($resql);
@@ -10716,11 +10715,10 @@ abstract class CommonObject
'@phan-var-force CommonObjectLine $newline';
$newline->setVarsFromFetchObj($obj);
// Note: extrafields load of line not yet supported
/*
// Load also extrafields for the line
if (empty($noextrafields)) {
// Load extrafields of line
}*/
$newline->fetch_optionals();
}
$this->lines[] = $newline;
}

View File

@@ -49,10 +49,19 @@ function mymoduleAdminPrepareHead()
$head[$h][1] = $langs->trans("ExtraFields");
$nbExtrafields = is_countable($extrafields->attributes['myobject']['label']) ? count($extrafields->attributes['myobject']['label']) : 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';
$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);