Move resource module functions into commonobject :
- new method to get an array with object properties - new method to fetch an object only with id and element_type
This commit is contained in:
parent
d9c567ca3d
commit
71c44d82ab
@ -3277,6 +3277,85 @@ abstract class CommonObject
|
|||||||
print '</table>';
|
print '</table>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an array with properties of an element
|
||||||
|
*
|
||||||
|
* @param string $element_type Element type. ex : project_task or object@modulext or object_under@module
|
||||||
|
* @return array (module, classpath, element, subelement, classfile, classname)
|
||||||
|
*/
|
||||||
|
function getElementProperties($element_type)
|
||||||
|
{
|
||||||
|
// Parse element/subelement (ex: project_task)
|
||||||
|
$module = $element = $subelement = $element_type;
|
||||||
|
|
||||||
|
// If we ask an resource form external module (instead of default path)
|
||||||
|
if (preg_match('/^([^@]+)@([^@]+)$/i',$element_type,$regs))
|
||||||
|
{
|
||||||
|
$element = $subelement = $regs[1];
|
||||||
|
$module = $regs[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
//print '<br />1. element : '.$element.' - module : '.$module .'<br />';
|
||||||
|
if ( preg_match('/^([^_]+)_([^_]+)/i',$element,$regs))
|
||||||
|
{
|
||||||
|
$module = $element = $regs[1];
|
||||||
|
$subelement = $regs[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
$classfile = strtolower($subelement);
|
||||||
|
$classname = ucfirst($subelement);
|
||||||
|
$classpath = $module.'/class';
|
||||||
|
|
||||||
|
// For compat
|
||||||
|
if($element_type == "action") {
|
||||||
|
$classpath = 'comm/action/class';
|
||||||
|
$subelement = 'Actioncomm';
|
||||||
|
$classfile = strtolower($subelement);
|
||||||
|
$classname = ucfirst($subelement);
|
||||||
|
$module = 'agenda';
|
||||||
|
}
|
||||||
|
// TODO : add other elements
|
||||||
|
|
||||||
|
$element_properties = array(
|
||||||
|
'module' => $module,
|
||||||
|
'classpath' => $classpath,
|
||||||
|
'element' => $element,
|
||||||
|
'subelement' => $subelement,
|
||||||
|
'classfile' => $classfile,
|
||||||
|
'classname' => $classname
|
||||||
|
);
|
||||||
|
return $element_properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch an object with element_type and its id
|
||||||
|
* Inclusion classes is automatic
|
||||||
|
*
|
||||||
|
* @param int $element_id
|
||||||
|
* @param string $element_type
|
||||||
|
* @return object || 0 || -1 if error
|
||||||
|
*/
|
||||||
|
function fetchObjectByElement($element_id,$element_type) {
|
||||||
|
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
$element_prop = $this->getElementProperties($element_type);
|
||||||
|
if (is_array($element_prop) && $conf->$element_prop['module']->enabled)
|
||||||
|
{
|
||||||
|
dol_include_once('/'.$element_prop['classpath'].'/'.$element_prop['classfile'].'.class.php');
|
||||||
|
|
||||||
|
$objectstat = new $element_prop['classname']($this->db);
|
||||||
|
$ret = $objectstat->fetch($element_id);
|
||||||
|
if ($ret >= 0)
|
||||||
|
{
|
||||||
|
return $objectstat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrite magic function to solve problem of cloning object that are kept as references
|
* Overwrite magic function to solve problem of cloning object that are kept as references
|
||||||
*
|
*
|
||||||
|
|||||||
@ -16,8 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file place/class/resource.class.php
|
* \file resource/class/resource.class.php
|
||||||
* \ingroup place
|
* \ingroup resource
|
||||||
* \brief Class file for resource object
|
* \brief Class file for resource object
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@ -49,8 +49,6 @@ class Resource extends CommonObject
|
|||||||
var $tms='';
|
var $tms='';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -375,84 +373,6 @@ class Resource extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param string $element_type Element type project_task
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
function getElementProperties($element_type)
|
|
||||||
{
|
|
||||||
// Parse element/subelement (ex: project_task)
|
|
||||||
$module = $element = $subelement = $element_type;
|
|
||||||
|
|
||||||
// If we ask an resource form external module (instead of default path)
|
|
||||||
if (preg_match('/^([^@]+)@([^@]+)$/i',$element_type,$regs))
|
|
||||||
{
|
|
||||||
$element = $subelement = $regs[1];
|
|
||||||
$module = $regs[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
//print '<br />1. element : '.$element.' - module : '.$module .'<br />';
|
|
||||||
|
|
||||||
if ( preg_match('/^([^_]+)_([^_]+)/i',$element,$regs))
|
|
||||||
{
|
|
||||||
$module = $element = $regs[1];
|
|
||||||
$subelement = $regs[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
$classfile = strtolower($subelement);
|
|
||||||
$classname = ucfirst($subelement);
|
|
||||||
$classpath = $module.'/class';
|
|
||||||
|
|
||||||
|
|
||||||
// For compat
|
|
||||||
if($element_type == "action") {
|
|
||||||
$classpath = 'comm/action/class';
|
|
||||||
$subelement = 'Actioncomm';
|
|
||||||
$classfile = strtolower($subelement);
|
|
||||||
$classname = ucfirst($subelement);
|
|
||||||
$module = 'agenda';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$element_properties = array(
|
|
||||||
'module' => $module,
|
|
||||||
'classpath' => $classpath,
|
|
||||||
'element' => $element,
|
|
||||||
'subelement' => $subelement,
|
|
||||||
'classfile' => $classfile,
|
|
||||||
'classname' => $classname
|
|
||||||
);
|
|
||||||
return $element_properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch an object with element_type and his id
|
|
||||||
* Inclusion classes is automatic
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function fetchObjectByElement($element_id,$element_type) {
|
|
||||||
|
|
||||||
global $conf;
|
|
||||||
|
|
||||||
$element_prop = $this->getElementProperties($element_type);
|
|
||||||
|
|
||||||
if (is_array($element_prop) && $conf->$element_prop['module']->enabled)
|
|
||||||
{
|
|
||||||
dol_include_once('/'.$element_prop['classpath'].'/'.$element_prop['classfile'].'.class.php');
|
|
||||||
|
|
||||||
$objectstat = new $element_prop['classname']($this->db);
|
|
||||||
$ret = $objectstat->fetch($element_id);
|
|
||||||
if ($ret >= 0)
|
|
||||||
{
|
|
||||||
return $objectstat;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add resources to the actioncom object
|
* Add resources to the actioncom object
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user