Move generic function from commonobject.class to functions2.lib.php (work on resource module)
This commit is contained in:
parent
e76ce87547
commit
fdb50ab116
@ -3277,84 +3277,6 @@ 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add resources to the current object
|
* Add resources to the current object
|
||||||
|
|||||||
@ -1656,3 +1656,124 @@ function cleanCorruptedTree($db, $tabletocleantree, $fieldfkparent)
|
|||||||
return $totalnb;
|
return $totalnb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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';
|
||||||
|
$module = 'agenda';
|
||||||
|
}
|
||||||
|
|
||||||
|
// To work with non standard path
|
||||||
|
if ($element_type == 'facture' || $element_type == 'invoice') {
|
||||||
|
$classpath = 'compta/facture/class';
|
||||||
|
$module='facture';
|
||||||
|
$subelement='facture';
|
||||||
|
}
|
||||||
|
if ($element_type == 'commande' || $element_type == 'order') {
|
||||||
|
$classpath = 'commande/class';
|
||||||
|
$module='commande';
|
||||||
|
$subelement='commande';
|
||||||
|
}
|
||||||
|
if ($element_type == 'propal') {
|
||||||
|
$classpath = 'comm/propal/class';
|
||||||
|
}
|
||||||
|
if ($element_type == 'shipping') {
|
||||||
|
$classpath = 'expedition/class';
|
||||||
|
$subelement = 'expedition';
|
||||||
|
$module = 'expedition_bon';
|
||||||
|
}
|
||||||
|
if ($element_type == 'delivery') {
|
||||||
|
$classpath = 'livraison/class';
|
||||||
|
$subelement = 'livraison';
|
||||||
|
$module = 'livraison_bon';
|
||||||
|
}
|
||||||
|
if ($element_type == 'contract') {
|
||||||
|
$classpath = 'contrat/class';
|
||||||
|
$module='contrat';
|
||||||
|
$subelement='contrat';
|
||||||
|
}
|
||||||
|
if ($element_type == 'member') {
|
||||||
|
$classpath = 'adherents/class';
|
||||||
|
$module='adherent';
|
||||||
|
$subelement='adherent';
|
||||||
|
}
|
||||||
|
if ($element_type == 'cabinetmed_cons') {
|
||||||
|
$classpath = 'cabinetmed/class';
|
||||||
|
$module='cabinetmed';
|
||||||
|
$subelement='cabinetmedcons';
|
||||||
|
}
|
||||||
|
if ($element_type == 'fichinter') {
|
||||||
|
$classpath = 'fichinter/class';
|
||||||
|
$module='ficheinter';
|
||||||
|
$subelement='fichinter';
|
||||||
|
}
|
||||||
|
$classfile = strtolower($subelement);
|
||||||
|
$classname = ucfirst($subelement);
|
||||||
|
|
||||||
|
$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 = 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;
|
||||||
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ $sortfield = GETPOST('sortfield','alpha');
|
|||||||
$page = GETPOST('page','int');
|
$page = GETPOST('page','int');
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( ! $user->rights->place->read)
|
if( ! $user->rights->resource->read)
|
||||||
accessforbidden();
|
accessforbidden();
|
||||||
|
|
||||||
$object=new Resource($db);
|
$object=new Resource($db);
|
||||||
@ -100,7 +100,7 @@ else
|
|||||||
{
|
{
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
|
||||||
|
|
||||||
$act = $object->fetchObjectByElement($element_id,$element);
|
$act = fetchObjectByElement($element_id,$element);
|
||||||
if(is_object($act)) {
|
if(is_object($act)) {
|
||||||
|
|
||||||
$head=actions_prepare_head($act);
|
$head=actions_prepare_head($act);
|
||||||
@ -135,7 +135,7 @@ else
|
|||||||
*/
|
*/
|
||||||
if($element_id && $element == 'societe')
|
if($element_id && $element == 'societe')
|
||||||
{
|
{
|
||||||
$socstatic = $object->fetchObjectByElement($element_id,$element);
|
$socstatic = fetchObjectByElement($element_id,$element);
|
||||||
if(is_object($socstatic)) {
|
if(is_object($socstatic)) {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||||
$head = societe_prepare_head($socstatic);
|
$head = societe_prepare_head($socstatic);
|
||||||
@ -148,11 +148,11 @@ else
|
|||||||
//$linkback = '<a href="'.DOL_URL_ROOT.'/comm/action/listactions.php">'.$langs->trans("BackToList").'</a>';
|
//$linkback = '<a href="'.DOL_URL_ROOT.'/comm/action/listactions.php">'.$langs->trans("BackToList").'</a>';
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
print '<tr><td width="25%">'.$langs->trans('ThirdPartyName').'</td>';
|
print '<tr><td width="25%">'.$langs->trans('ThirdPartyName').'</td>';
|
||||||
print '<td colspan="3">';
|
print '<td colspan="3">';
|
||||||
print $form->showrefnav($socstatic, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom');
|
print $form->showrefnav($socstatic, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom');
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
print '</table>';
|
print '</table>';
|
||||||
|
|
||||||
print '</div>';
|
print '</div>';
|
||||||
@ -173,7 +173,7 @@ else
|
|||||||
$resources=(array) $resources; // To be sure $resources is an array
|
$resources=(array) $resources; // To be sure $resources is an array
|
||||||
foreach($resources as $resource_obj)
|
foreach($resources as $resource_obj)
|
||||||
{
|
{
|
||||||
$element_prop = $object->getElementProperties($resource_obj);
|
$element_prop = getElementProperties($resource_obj);
|
||||||
//var_dump($element_prop);
|
//var_dump($element_prop);
|
||||||
|
|
||||||
print_titre($langs->trans(ucfirst($element_prop['element']).'Singular'));
|
print_titre($langs->trans(ucfirst($element_prop['element']).'Singular'));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user