diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index c2fb6d6d08d..54028db20af 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -3277,6 +3277,85 @@ abstract class CommonObject
print '';
}
+
+ /**
+ * 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 '
1. element : '.$element.' - module : '.$module .'
';
+ 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
*
diff --git a/htdocs/resource/class/resource.class.php b/htdocs/resource/class/resource.class.php
index edbf4bc0ad6..f422749847e 100644
--- a/htdocs/resource/class/resource.class.php
+++ b/htdocs/resource/class/resource.class.php
@@ -16,8 +16,8 @@
*/
/**
- * \file place/class/resource.class.php
- * \ingroup place
+ * \file resource/class/resource.class.php
+ * \ingroup resource
* \brief Class file for resource object
*/
@@ -49,8 +49,6 @@ class Resource extends CommonObject
var $tms='';
-
-
/**
* 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 '
1. element : '.$element.' - module : '.$module .'
';
-
- 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
*