This commit is contained in:
Laurent Destailleur 2020-04-03 17:53:17 +02:00
parent 372d719693
commit d46417c8bd
4 changed files with 45 additions and 15 deletions

View File

@ -888,17 +888,31 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
// Edit the class 'class/'.strtolower($objectname).'.class.php'
if (GETPOST('includerefgeneration', 'aZ09')) {
// Replace 'visible'=>1, 'noteditable'=>0, 'default'=>''
$arrayreplacement = array('/\'visible\'=>1,\s*\'noteditable\'=>0,\s*\'default\'=>\'\'/' => "'visible'=>4, 'noteditable'=>1, 'default'=>'(PROV)'");
$arrayreplacement = array(
'/\'visible\'=>1,\s*\'noteditable\'=>0,\s*\'default\'=>\'\'/' => "'visible'=>4, 'noteditable'=>1, 'default'=>'(PROV)'"
);
//var_dump($arrayreplacement);exit;
//var_dump($destdir.'/class/'.strtolower($objectname).'.class.php');exit;
dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1);
$arrayreplacement = array(
'/\'models\' => 0,/' => '\'models\' => 1,'
);
dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1);
}
// Edit the setup file and the card page
if (GETPOST('includedocgeneration', 'aZ09')) {
// Replace '$includedocgeneration = 0;' into '$includedocgeneration = 1;' into files
$arrayreplacement = array('/\$includedocgeneration = 0;/' => '$includedocgeneration = 1;');
// Replace some var init into some files
$arrayreplacement = array(
'/\$includedocgeneration = 0;/' => '$includedocgeneration = 1;'
);
dolReplaceInFile($destdir.'/class/'.strtolower($objectname).'.class.php', $arrayreplacement, '', 0, 0, 1);
$arrayreplacement = array(
'/\'models\' => 0,/' => '\'models\' => 1,'
);
dolReplaceInFile($destdir.'/core/modules/mod'.$module.'.class.php', $arrayreplacement, '', 0, 0, 1);
}
// Scan for object class files

View File

@ -922,7 +922,7 @@ class MyObject extends CommonObject
$langs->load("mymodule@myobject");
if (empty($conf->global->MYMODULE_MYOBJECT_ADDON)) {
$conf->global->MYMODULE_MYOBJECT_ADDON = 'mod_mymobject_standard';
$conf->global->MYMODULE_MYOBJECT_ADDON = 'mod_myobject_standard';
}
if (!empty($conf->global->MYMODULE_MYOBJECT_ADDON))
@ -952,7 +952,7 @@ class MyObject extends CommonObject
$obj = new $classname();
$numref = $obj->getNextValue($this);
if ($numref != "")
if ($numref != '' && $numref != '-1')
{
return $numref;
}
@ -963,7 +963,7 @@ class MyObject extends CommonObject
return "";
}
} else {
print $langs->trans("Error")." ".$langs->trans("ClassNotFound");
print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
return "";
}
}

View File

@ -100,13 +100,18 @@ class mod_myobject_advanced extends ModeleNumRefMyObject
{
global $conf,$langs,$mysoc;
$old_code_client=$mysoc->code_client;
$object = new MyObject($this->db);
$object->initAsSpecimen();
/*$old_code_client=$mysoc->code_client;
$old_code_type=$mysoc->typent_code;
$mysoc->code_client='CCCCCCCCCC';
$mysoc->typent_code='TTTTTTTTTT';
$numExample = $this->getNextValue($mysoc, '');
$mysoc->code_client=$old_code_client;
$mysoc->typent_code=$old_code_type;
$mysoc->typent_code='TTTTTTTTTT';*/
$numExample = $this->getNextValue($object, '');
/*$mysoc->code_client=$old_code_client;
$mysoc->typent_code=$old_code_type;*/
if (! $numExample)
{

View File

@ -76,9 +76,10 @@ class mod_myobject_standard extends ModeleNumRefMyObject
* Checks if the numbers already in force in the data base do not
* cause conflicts that would prevent this numbering from working.
*
* @return boolean false if conflict, true if ok
* @param Object $object Object we need next value for
* @return boolean false if conflict, true if ok
*/
public function canBeActivated()
public function canBeActivated($object)
{
global $conf,$langs,$db;
@ -88,7 +89,12 @@ class mod_myobject_standard extends ModeleNumRefMyObject
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."mymodule_myobject";
$sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
$sql.= " AND entity = ".$conf->entity;
if ($object->ismultientitymanaged == 1) {
$sql.= " AND entity = ".$conf->entity;
}
elseif ($object->ismultientitymanaged == 2) {
// TODO
}
$resql=$db->query($sql);
if ($resql)
@ -121,7 +127,12 @@ class mod_myobject_standard extends ModeleNumRefMyObject
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."mymodule_myobject";
$sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
$sql.= " AND entity = ".$conf->entity;
if ($object->ismultientitymanaged == 1) {
$sql.= " AND entity = ".$conf->entity;
}
elseif ($object->ismultientitymanaged == 2) {
// TODO
}
$resql=$db->query($sql);
if ($resql)