mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-24 02:11:27 +01:00
Work on modulebuilder
This commit is contained in:
@@ -46,10 +46,20 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='
|
|||||||
// Check parameters
|
// Check parameters
|
||||||
if (count($addfieldentry) > 0)
|
if (count($addfieldentry) > 0)
|
||||||
{
|
{
|
||||||
|
if (empty($addfieldentry['name']))
|
||||||
|
{
|
||||||
|
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Name")), null, 'errors');
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
if (empty($addfieldentry['label']))
|
||||||
|
{
|
||||||
|
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Label")), null, 'errors');
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
if (! preg_match('/^(integer|date|timestamp|varchar|double)/', $addfieldentry['type']))
|
if (! preg_match('/^(integer|date|timestamp|varchar|double)/', $addfieldentry['type']))
|
||||||
{
|
{
|
||||||
setEventMessages($langs->trans('FilesForObjectUpdated', $objectname), null, 'errors');
|
setEventMessages($langs->trans('BadFormatForType', $objectname), null, 'errors');
|
||||||
return -1;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +69,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='
|
|||||||
{
|
{
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors');
|
setEventMessages($langs->trans("ErrorFileNotFound", $pathoffiletoeditsrc), null, 'errors');
|
||||||
return -1;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
//$pathoffiletoedittmp=$destdir.'/class/'.strtolower($objectname).'.class.php.tmp';
|
//$pathoffiletoedittmp=$destdir.'/class/'.strtolower($objectname).'.class.php.tmp';
|
||||||
@@ -69,7 +79,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='
|
|||||||
{
|
{
|
||||||
include_once $pathoffiletoeditsrc;
|
include_once $pathoffiletoeditsrc;
|
||||||
if (class_exists($objectname)) $object=new $objectname($db);
|
if (class_exists($objectname)) $object=new $objectname($db);
|
||||||
else return -1;
|
else return -4;
|
||||||
|
|
||||||
// Backup old file
|
// Backup old file
|
||||||
dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.'.back', $newmask, 1);
|
dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.'.back', $newmask, 1);
|
||||||
@@ -157,7 +167,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='
|
|||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
print $e->getMessage();
|
print $e->getMessage();
|
||||||
return -1;
|
return -5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,4 +63,6 @@ UseAsciiDocFormat=You can use Markdown format, but it is recommanded to use Asci
|
|||||||
IsAMeasure=Is a measure
|
IsAMeasure=Is a measure
|
||||||
DirScanned=Directory scanned
|
DirScanned=Directory scanned
|
||||||
NoTrigger=No trigger
|
NoTrigger=No trigger
|
||||||
NoWidget=No widget
|
NoWidget=No widget
|
||||||
|
EnabledDesc=Condition to have this field active (Examples: 1 or $conf->global->MYMODULE_MYOPTION)
|
||||||
|
VisibleDesc=Is field is visible in list (-1 means not shown by default but can be added into list to be viewed)
|
||||||
|
|||||||
@@ -362,7 +362,7 @@ if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj))
|
|||||||
dol_mkdir($destdir);
|
dol_mkdir($destdir);
|
||||||
|
|
||||||
$addfieldentry = array(
|
$addfieldentry = array(
|
||||||
'name'=>GETPOST('propname','aZ09'),'type'=>GETPOST('proptype','aZ09'),'label'=>GETPOST('proplabel','aZ09'),'visible'=>GETPOST('propvisible','int'),'enabled'=>GETPOST('propenabled','int'),
|
'name'=>GETPOST('propname','aZ09'),'type'=>GETPOST('proptype','alpha'),'label'=>GETPOST('proplabel','alpha'),'visible'=>GETPOST('propvisible','int'),'enabled'=>GETPOST('propenabled','int'),
|
||||||
'position'=>GETPOST('propposition','int'),'notnull'=>GETPOST('propnotnull','int'),'index'=>GETPOST('propindex','int'),'searchall'=>GETPOST('propsearchall','int'),
|
'position'=>GETPOST('propposition','int'),'notnull'=>GETPOST('propnotnull','int'),'index'=>GETPOST('propindex','int'),'searchall'=>GETPOST('propsearchall','int'),
|
||||||
'isameasure'=>GETPOST('propisameasure','int'), 'comment'=>GETPOST('propcomment','alpha'),'help'=>GETPOST('prophelp'));
|
'isameasure'=>GETPOST('propisameasure','int'), 'comment'=>GETPOST('propcomment','alpha'),'help'=>GETPOST('prophelp'));
|
||||||
|
|
||||||
@@ -370,14 +370,21 @@ if ($dirins && $action == 'addproperty' && !empty($module) && ! empty($tabobj))
|
|||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$result=rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, $addfieldentry);
|
$result=rebuildObjectClass($destdir, $module, $objectname, $newmask, $srcdir, $addfieldentry);
|
||||||
if ($result <= 0) $error++;
|
// var_dump($result);exit;
|
||||||
|
if ($result <= 0)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Edit sql with new properties
|
// Edit sql with new properties
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$result=rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir);
|
$result=rebuildObjectSql($destdir, $module, $objectname, $newmask, $srcdir);
|
||||||
if ($result <= 0) $error++;
|
if ($result <= 0)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
@@ -1423,6 +1430,7 @@ elseif (! empty($module))
|
|||||||
print load_fiche_titre($langs->trans("Properties"), '', '');
|
print load_fiche_titre($langs->trans("Properties"), '', '');
|
||||||
|
|
||||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
||||||
|
|
||||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||||
print '<input type="hidden" name="action" value="addproperty">';
|
print '<input type="hidden" name="action" value="addproperty">';
|
||||||
print '<input type="hidden" name="tab" value="objects">';
|
print '<input type="hidden" name="tab" value="objects">';
|
||||||
@@ -1443,31 +1451,33 @@ elseif (! empty($module))
|
|||||||
//print '<td>'.$langs->trans("DefaultValue").'</td>';
|
//print '<td>'.$langs->trans("DefaultValue").'</td>';
|
||||||
print '<td class="center">'.$langs->trans("DatabaseIndex").'</td>';
|
print '<td class="center">'.$langs->trans("DatabaseIndex").'</td>';
|
||||||
print '<td class="right">'.$langs->trans("Position").'</td>';
|
print '<td class="right">'.$langs->trans("Position").'</td>';
|
||||||
print '<td class="right">'.$langs->trans("Enabled").'</td>';
|
print '<td class="center">'.$form->textwithpicto($langs->trans("Enabled"), $langs->trans("EnabledDesc")).'</td>';
|
||||||
print '<td class="right">'.$langs->trans("Visible").'</td>';
|
print '<td class="center">'.$form->textwithpicto($langs->trans("Visible"), $langs->trans("VisibleDesc")).'</td>';
|
||||||
print '<td class="right">'.$langs->trans("IsAMeasure").'</td>';
|
print '<td class="center">'.$langs->trans("IsAMeasure").'</td>';
|
||||||
print '<td class="center">'.$langs->trans("SearchAll").'</td>';
|
print '<td class="center">'.$langs->trans("SearchAll").'</td>';
|
||||||
print '<td>'.$langs->trans("Comment").'</td>';
|
print '<td>'.$langs->trans("Comment").'</td>';
|
||||||
print '<td></td>';
|
print '<td></td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
|
// Line to add a property
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td><input class="text" name="propname" value=""></td>';
|
print '<td><input class="text" name="propname" value="'.GETPOST('propname','alpha').'"></td>';
|
||||||
print '<td><input class="text" name="proplabel" value=""></td>';
|
print '<td><input class="text" name="proplabel" value="'.GETPOST('proplabel','alpha').'"></td>';
|
||||||
print '<td><input class="text" name="proptype" value=""></td>';
|
print '<td><input class="text" name="proptype" value="'.GETPOST('proptype','alpha').'"></td>';
|
||||||
print '<td class="center"><input class="text" size="2" name="propnotnull" value=""></td>';
|
print '<td class="center"><input class="text" size="2" name="propnotnull" value="'.GETPOST('propnotnull','alpha').'"></td>';
|
||||||
//print '<td><input class="text" name="propdefault" value=""></td>';
|
//print '<td><input class="text" name="propdefault" value=""></td>';
|
||||||
print '<td class="center"><input class="text" size="2" name="propindex" value=""></td>';
|
print '<td class="center"><input class="text" size="2" name="propindex" value="'.GETPOST('propindex','alpha').'"></td>';
|
||||||
print '<td class="right"><input class="text right" size="2" name="propposition" value=""></td>';
|
print '<td class="right"><input class="text right" size="2" name="propposition" value="'.GETPOST('propposition','alpha').'"></td>';
|
||||||
print '<td class="center"><input class="text" size="2" name="propenabled" value=""></td>';
|
print '<td class="center"><input class="text" size="2" name="propenabled" value="'.GETPOST('propenabled','alpha').'"></td>';
|
||||||
print '<td class="center"><input class="text" size="2" name="propvisible" value=""></td>';
|
print '<td class="center"><input class="text" size="2" name="propvisible" value="'.GETPOST('propvisible','alpha').'"></td>';
|
||||||
print '<td class="center"><input class="text" size="2" name="propisameasure" value=""></td>';
|
print '<td class="center"><input class="text" size="2" name="propisameasure" value="'.GETPOST('propisameasure','alpha').'"></td>';
|
||||||
print '<td class="center"><input class="text" size="2" name="propsearchall" value=""></td>';
|
print '<td class="center"><input class="text" size="2" name="propsearchall" value="'.GETPOST('propsearchall','alpha').'"></td>';
|
||||||
print '<td><input class="text" name="propcomment" value=""></td>';
|
print '<td><input class="text" name="propcomment" value="'.GETPOST('propcomment','alpha').'"></td>';
|
||||||
print '<td align="center">';
|
print '<td align="center">';
|
||||||
print '<input class="button" type="submit" name="add" value="'.$langs->trans("Add").'">';
|
print '<input class="button" type="submit" name="add" value="'.$langs->trans("Add").'">';
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
$properties = $tmpobjet->fields;
|
$properties = dol_sort_array($tmpobjet->fields, 'position');
|
||||||
|
|
||||||
foreach($properties as $propkey => $propval)
|
foreach($properties as $propkey => $propval)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class MyObject extends CommonObject
|
|||||||
* 'type' if the field format.
|
* 'type' if the field format.
|
||||||
* 'label' the translation key.
|
* 'label' the translation key.
|
||||||
* 'enabled' is a condition when the filed must be managed.
|
* 'enabled' is a condition when the filed must be managed.
|
||||||
* 'visible' says if field is visible in list (-1 means not shown by default but can be aded into list to be viewed).
|
* 'visible' says if field is visible in list (-1 means not shown by default but can be added into list to be viewed).
|
||||||
* 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
|
* 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
|
||||||
* 'index' if we want an index in database.
|
* 'index' if we want an index in database.
|
||||||
* 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
|
* 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
|
||||||
|
|||||||
Reference in New Issue
Block a user