Qual: Simplify canvas code
This commit is contained in:
parent
a918f3bf11
commit
3d7752ca76
@ -72,42 +72,33 @@ class Canvas
|
||||
|
||||
|
||||
/**
|
||||
* Initialize properties like ->control, ->control->object, ->template_dir
|
||||
* @param module Name of target module (thirdparty, ...)
|
||||
* @param card Type of card (ex: card, info, ...)
|
||||
* @param canvas Name of canvas (ex: mycanvas@mymodule)
|
||||
* Initialize properties: ->targetmodule, ->card, ->canvas
|
||||
* and MVC properties: ->control (Controller), ->control->object (Model), ->template_dir (View)
|
||||
* @param module Name of target module (thirdparty, contact, ...)
|
||||
* @param card Type of card (ex: card, info, contactcard, ...)
|
||||
* @param canvas Name of canvas (ex: mycanvas, default, or mycanvas@myexternalmodule)
|
||||
*/
|
||||
function getCanvas($module,$card,$canvas)
|
||||
function getCanvas($module, $card, $canvas)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
$error='';
|
||||
$this->card = $card;
|
||||
|
||||
// Define this->canvas, this->targetmodule, this->aliasmodule, targetmodule, childmodule
|
||||
// Set properties with value specific to dolibarr core: this->targetmodule, this->card, this->canvas
|
||||
$this->targetmodule = $module;
|
||||
$this->card = $card;
|
||||
$this->canvas = $canvas;
|
||||
$this->targetmodule = $this->aliasmodule = $module;
|
||||
$dirmodule = $module;
|
||||
// Correct values if canvas is into an external module
|
||||
if (preg_match('/^([^@]+)@([^@]+)$/i',$canvas,$regs))
|
||||
{
|
||||
$this->canvas = $regs[1];
|
||||
$this->aliasmodule = $regs[2];
|
||||
$dirmodule = $regs[2];
|
||||
}
|
||||
$targetmodule = $this->targetmodule;
|
||||
$childmodule = $this->aliasmodule;
|
||||
// For compatibility
|
||||
if ($targetmodule == 'thirdparty') { $targetmodule = 'societe'; }
|
||||
if ($childmodule == 'thirdparty') { $childmodule = 'societe'; $this->aliasmodule = 'societe'; }
|
||||
if ($targetmodule == 'contact') { $targetmodule = 'societe'; }
|
||||
if ($childmodule == 'contact') { $childmodule = 'societe'; }
|
||||
if ($dirmodule == 'thirdparty') { $dirmodule = 'societe'; }
|
||||
|
||||
/*print 'canvas='.$this->canvas.'<br>';
|
||||
print 'childmodule='.$childmodule.' targetmodule='.$targetmodule.'<br>';
|
||||
print 'this->aliasmodule='.$this->aliasmodule.' this->targetmodule='.$this->targetmodule.'<br>';
|
||||
print 'childmodule='.$conf->$childmodule->enabled.' targetmodule='.$conf->$targetmodule->enabled.'<br>';*/
|
||||
|
||||
if (! $conf->$childmodule->enabled || ! $conf->$targetmodule->enabled) accessforbidden();
|
||||
|
||||
$controlclassfile = dol_buildpath('/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/actions_'.$this->card.'_'.$this->canvas.'.class.php');
|
||||
$controlclassfile = dol_buildpath('/'.$dirmodule.'/canvas/'.$this->canvas.'/actions_'.$this->card.'_'.$this->canvas.'.class.php');
|
||||
if (file_exists($controlclassfile))
|
||||
{
|
||||
// Include actions class (controller)
|
||||
@ -119,7 +110,7 @@ class Canvas
|
||||
}
|
||||
|
||||
// TODO Dao should be declared and used by controller or templates when required only
|
||||
$modelclassfile = dol_buildpath('/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/dao_'.$this->targetmodule.'_'.$this->canvas.'.class.php');
|
||||
$modelclassfile = dol_buildpath('/'.$dirmodule.'/canvas/'.$this->canvas.'/dao_'.$this->targetmodule.'_'.$this->canvas.'.class.php');
|
||||
if (file_exists($modelclassfile))
|
||||
{
|
||||
// Include dataservice class (model)
|
||||
@ -132,16 +123,16 @@ class Canvas
|
||||
|
||||
// Include specific library
|
||||
// TODO Specific libraries must be included by files that need them only, so by actions and/or dao files.
|
||||
$libfile = dol_buildpath('/'.$this->aliasmodule.'/lib/'.$this->aliasmodule.'.lib.php');
|
||||
$libfile = dol_buildpath('/'.$dirmodule.'/lib/'.$dirmodule.'.lib.php');
|
||||
if (file_exists($libfile)) require_once($libfile);
|
||||
|
||||
// Template dir
|
||||
$this->template_dir = dol_buildpath('/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/tpl/');
|
||||
$this->template_dir = dol_buildpath('/'.$dirmodule.'/canvas/'.$this->canvas.'/tpl/');
|
||||
if (! is_dir($this->template_dir))
|
||||
{
|
||||
$this->template_dir='';
|
||||
}
|
||||
//print '/'.$this->aliasmodule.'/canvas/'.$this->canvas.'/tpl/';
|
||||
//print '/'.$dirmodule.'/canvas/'.$this->canvas.'/tpl/';
|
||||
//print 'template_dir='.$this->template_dir.'<br>';
|
||||
|
||||
return 1;
|
||||
|
||||
@ -173,9 +173,12 @@ class Societe extends CommonObject
|
||||
global $langs,$conf;
|
||||
|
||||
// Clean parameters
|
||||
if (empty($this->status)) $this->status=0;
|
||||
$this->name=$this->name?trim($this->name):trim($this->nom);
|
||||
if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name);
|
||||
$this->nom=$this->name; // For backward compatibility
|
||||
$this->nom=$this->name; // For backward compatibility
|
||||
if (empty($this->client)) $this->client=0;
|
||||
if (empty($this->fournisseur)) $this->fournisseur=0;
|
||||
|
||||
dol_syslog("Societe::create ".$this->name);
|
||||
|
||||
@ -186,8 +189,8 @@ class Societe extends CommonObject
|
||||
$this->error = $langs->trans("ErrorBadEMail",$this->email);
|
||||
return -1;
|
||||
}
|
||||
if (empty($this->client)) $this->client=0;
|
||||
if (empty($this->fournisseur)) $this->fournisseur=0;
|
||||
|
||||
$now=dol_now();
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
@ -195,8 +198,6 @@ class Societe extends CommonObject
|
||||
if ($this->code_client == -1) $this->get_codeclient($this->prefix_comm,0);
|
||||
if ($this->code_fournisseur == -1) $this->get_codefournisseur($this->prefix_comm,1);
|
||||
|
||||
$now=dol_now();
|
||||
|
||||
// Check more parameters
|
||||
$result = $this->verify();
|
||||
|
||||
|
||||
@ -56,6 +56,8 @@ $soc = new Societe($db);
|
||||
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
|
||||
if (!empty($socid)) $soc->getCanvas($socid);
|
||||
$canvas = (!empty($soc->canvas)?$soc->canvas:GETPOST("canvas"));
|
||||
|
||||
|
||||
if (! empty($canvas))
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/class/canvas.class.php");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user