2
0
forked from Wavyzz/dolibarr

NEW Code for extrafields uses the new array $extrafields->attributes

This commit is contained in:
Laurent Destailleur
2019-10-06 14:41:52 +02:00
parent 76dad97cb1
commit 2b66282b61
156 changed files with 622 additions and 649 deletions

View File

@@ -3918,13 +3918,16 @@ abstract class CommonObject
*/
public function formAddObjectLine($dateSelector, $seller, $buyer, $defaulttpldir = '/core/tpl')
{
global $conf,$user,$langs,$object,$hookmanager;
global $conf,$user,$langs,$object,$hookmanager,$extrafields;
global $form,$bcnd,$var;
// Line extrafield
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafieldsline = new ExtraFields($this->db);
$extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line);
if (! is_object($extrafields))
{
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db);
}
$extrafields->fetch_name_optionals_label($this->table_element_line);
// Output template part (modules that overwrite templates must declare this into descriptor)
// Use global variables + $dateSelector + $seller and $buyer
@@ -3970,7 +3973,7 @@ abstract class CommonObject
*/
public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0, $defaulttpldir = '/core/tpl')
{
global $conf, $hookmanager, $langs, $user, $object, $form;
global $conf, $hookmanager, $langs, $user, $object, $form, $extrafields;
// TODO We should not use global var for this
global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax;
@@ -3981,11 +3984,14 @@ abstract class CommonObject
$num = count($this->lines);
// Line extrafield
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafieldsline = new ExtraFields($this->db);
$extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line);
if (! is_object($extrafields))
{
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db);
}
$extrafields->fetch_name_optionals_label($this->table_element_line);
$parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
$parameters = array('num'=>$num, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'table_element_line'=>$this->table_element_line);
$reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
{
@@ -4025,18 +4031,18 @@ abstract class CommonObject
{
if (empty($line->fk_parent_line))
{
$parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
$parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'table_element_line'=>$line->table_element);
$reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
}
else
{
$parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline, 'fk_parent_line'=>$line->fk_parent_line);
$parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'table_element_line'=>$line->table_element, 'fk_parent_line'=>$line->fk_parent_line);
$reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
}
}
if (empty($reshook))
{
$this->printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafieldsline, $defaulttpldir);
$this->printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir);
}
$i++;
@@ -4057,11 +4063,11 @@ abstract class CommonObject
* @param string $seller Object of seller third party
* @param string $buyer Object of buyer third party
* @param int $selected Object line selected
* @param int $extrafieldsline Object of extrafield line attribute
* @param Extrafields $extrafields Object of extrafields
* @param string $defaulttpldir Directory where to find the template
* @return void
*/
public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafieldsline = 0, $defaulttpldir = '/core/tpl')
public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafields = null, $defaulttpldir = '/core/tpl')
{
global $conf,$langs,$user,$object,$hookmanager;
global $form,$bc,$bcdd;
@@ -4897,6 +4903,8 @@ abstract class CommonObject
public function fetch_optionals($rowid = null, $optionsArray = null)
{
// phpcs:enable
global $extrafields;
if (empty($rowid)) $rowid=$this->id;
// To avoid SQL errors. Probably not the better solution though
@@ -4909,7 +4917,6 @@ abstract class CommonObject
if (! is_array($optionsArray))
{
// If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page.
global $extrafields;
if (! isset($extrafields) || ! is_object($extrafields))
{
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
@@ -6591,8 +6598,8 @@ abstract class CommonObject
//$out .= "titlefield";
//if (GETPOST('action', 'none') == 'create') $out.='create';
// BUG #11554 : For public page, use red dot for required fields, instead of bold label
$context = isset($params["context"]) ? $params["context"] : "none";
if ($context=="public") { // Public page : red dot instead of bold ble characters
$tpl_context = isset($params["tpl_context"]) ? $params["tpl_context"] : "none";
if ($tpl_context=="public") { // Public page : red dot instead of fieldrequired characters
$out .= '">';
if (! empty($extrafields->attributes[$this->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$this->table_element]['help'][$key]);
else $out .= $labeltoshow;