mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Debug modulebuilder
This commit is contained in:
parent
cbde99b419
commit
ceeb9d7f1b
|
|
@ -38,3 +38,5 @@ PathToModulePackage=Path to zip of module/application package
|
|||
PathToModuleDocumentation=Path to file of module/application documentation
|
||||
SpaceOrSpecialCharAreNotAllowed=Spaces or special characters are not allowed.
|
||||
FileNotYetGenerated=File not yet generated
|
||||
SpecificationFile=File with business rules
|
||||
ConfirmDeleteProperty=Are you sure you want to delete the property <strong>%s</strong> ? This will change code in PHP class but also remove column from table definition of object.
|
||||
|
|
@ -37,9 +37,10 @@ $cancel=GETPOST('cancel','alpha');
|
|||
$module=GETPOST('module','alpha');
|
||||
$tab=GETPOST('tab','aZ09');
|
||||
$tabobj=GETPOST('tabobj','alpha');
|
||||
$propertykey=GETPOST('propertykey','alpha');
|
||||
if (empty($module)) $module='initmodule';
|
||||
if (empty($tab)) $tab='description';
|
||||
if (empty($tabobj)) $tabobj='newobject';
|
||||
if (empty($tabobj)) $tabobj='newobjectifnoobj';
|
||||
$file=GETPOST('file','alpha');
|
||||
|
||||
$modulename=dol_sanitizeFileName(GETPOST('modulename','alpha'));
|
||||
|
|
@ -58,6 +59,7 @@ $FILEFLAG='modulebuilder.txt';
|
|||
|
||||
$now=dol_now();
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
|
@ -320,6 +322,29 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname)
|
|||
$tabobj = 'deleteobject';
|
||||
}
|
||||
|
||||
if ($dirins && $action == 'confirm_deleteproperty' && $propertykey)
|
||||
{
|
||||
if (! $error)
|
||||
{
|
||||
$modulelowercase=strtolower($module);
|
||||
$objectlowercase=strtolower($objectname);
|
||||
|
||||
// File of class
|
||||
$fileforclass = $dirins.'/'.$modulelowercase.'/class/'.$objectlowercase.'.class.php';
|
||||
|
||||
// TODO
|
||||
|
||||
// File of sql
|
||||
$fileforsql = $dirins.'/'.$modulelowercase.'/sql/'.$objectlowercase.'.sql';
|
||||
$fileforsqlkey = $dirins.'/'.$modulelowercase.'/sql/'.$objectlowercase.'.key.sql';
|
||||
|
||||
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($dirins && $action == 'generatepackage')
|
||||
{
|
||||
$modulelowercase=strtolower($module);
|
||||
|
|
@ -838,9 +863,11 @@ elseif (! empty($module))
|
|||
$h++;
|
||||
|
||||
$listofobject = dol_dir_list($dir, 'files', 0, '\.txt$');
|
||||
$firstobjectname='';
|
||||
foreach($listofobject as $fileobj)
|
||||
{
|
||||
$objectname = preg_replace('/\.txt$/', '', $fileobj['name']);
|
||||
if (empty($firstobjectname)) $firstobjectname = $objectname;
|
||||
|
||||
$head3[$h][0] = $_SERVER["PHP_SELF"].'?tab=objects&module='.$module.'&tabobj='.$objectname;
|
||||
$head3[$h][1] = $objectname;
|
||||
|
|
@ -853,6 +880,12 @@ elseif (! empty($module))
|
|||
$head3[$h][2] = 'deleteobject';
|
||||
$h++;
|
||||
|
||||
// If tabobj was not defined, then we check if there is one obj. If yes, we force on it, if no, we will show tab to create new objects.
|
||||
if ($tabobj == 'newobjectifnoobj')
|
||||
{
|
||||
if ($firstobjectname) $tabobj=$firstobjectname;
|
||||
else $tabobj = 'newobject';
|
||||
}
|
||||
|
||||
dol_fiche_head($head3, $tabobj, '', -1, '');
|
||||
|
||||
|
|
@ -888,92 +921,168 @@ elseif (! empty($module))
|
|||
}
|
||||
else
|
||||
{
|
||||
try {
|
||||
$pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php';
|
||||
$pathtoapi = strtolower($module).'/class/api_'.strtolower($tabobj).'.class.php';
|
||||
$pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.class.php';
|
||||
$pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.class.php';
|
||||
print '<span class="fa fa-file"></span> '.$langs->trans("ClassFile").' : <strong>'.$pathtoclass.'</strong><br>';
|
||||
print '<span class="fa fa-file"></span> '.$langs->trans("ApiClassFile").' : <strong>'.$pathtoapi.'</strong><br>';
|
||||
print '<span class="fa fa-file"></span> '.$langs->trans("PageForList").' : <strong>'.$pathtolist.'</strong><br>';
|
||||
print '<span class="fa fa-file"></span> '.$langs->trans("PageForCreateEditView").' : <strong>'.$pathtocard.'</strong><br>';
|
||||
if ($action == 'deleteproperty')
|
||||
{
|
||||
$formconfirm = $form->formconfirm(
|
||||
$_SERVER["PHP_SELF"].'?propertykey='.urlencode(GETPOST('propertykey','alpha')).'&objectname='.urlencode($objectname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj),
|
||||
$langs->trans('Delete'), $langs->trans('ConfirmDeleteProperty', GETPOST('propertykey','alpha')), 'confirm_deleteproperty', '', 0, 1
|
||||
);
|
||||
|
||||
$result = dol_include_once($pathtoclass);
|
||||
$tmpobjet = new $tabobj($db);
|
||||
// Print form confirm
|
||||
print $formconfirm;
|
||||
}
|
||||
|
||||
$reflector = new ReflectionClass($tabobj);
|
||||
$properties = $reflector->getProperties(); // Can also use get_object_vars
|
||||
$propdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars
|
||||
//$propstat = $reflector->getStaticProperties();
|
||||
if ($action != 'editfile' || empty($file))
|
||||
{
|
||||
try {
|
||||
$pathtoclass = strtolower($module).'/class/'.strtolower($tabobj).'.class.php';
|
||||
$pathtoapi = strtolower($module).'/class/api_'.strtolower($tabobj).'.class.php';
|
||||
$pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php';
|
||||
$pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php';
|
||||
print '<span class="fa fa-file"></span> '.$langs->trans("ClassFile").' : <strong>'.$pathtoclass.'</strong>';
|
||||
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&file='.urlencode($pathtoclass).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
|
||||
print '<br>';
|
||||
print '<span class="fa fa-file"></span> '.$langs->trans("ApiClassFile").' : <strong>'.$pathtoapi.'</strong>';
|
||||
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&file='.urlencode($pathtoapi).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
|
||||
print '<br>';
|
||||
print '<span class="fa fa-file"></span> '.$langs->trans("PageForList").' : <strong>'.$pathtolist.'</strong>';
|
||||
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&file='.urlencode($pathtolist).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
|
||||
print '<br>';
|
||||
print '<span class="fa fa-file"></span> '.$langs->trans("PageForCreateEditView").' : <strong>'.$pathtocard.'</strong>';
|
||||
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&file='.urlencode($pathtocard).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
|
||||
print '<br>';
|
||||
|
||||
print load_fiche_titre($langs->trans("Properties"), '', '');
|
||||
$result = dol_include_once($pathtoclass);
|
||||
$tmpobjet = new $tabobj($db);
|
||||
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="initobject">';
|
||||
print '<input type="hidden" name="tab" value="objects">';
|
||||
print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
|
||||
print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
|
||||
$reflector = new ReflectionClass($tabobj);
|
||||
$properties = $reflector->getProperties(); // Can also use get_object_vars
|
||||
$propdefault = $reflector->getDefaultProperties(); // Can also use get_object_vars
|
||||
//$propstat = $reflector->getStaticProperties();
|
||||
|
||||
print '<table class="noborder">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Property");
|
||||
print ' (<a href="https://wiki.dolibarr.org/index.php/Language_and_development_rules#Table_and_fields_structures" target="_blank">'.$langs->trans("Example").'</a>)';
|
||||
print '</td>';
|
||||
print '<td>'.$langs->trans("Comment").'</td>';
|
||||
print '<td>'.$langs->trans("Type").'</td>';
|
||||
print '<td>'.$langs->trans("DefaultValue").'</td>';
|
||||
print '<td></td>';
|
||||
print '</tr>';
|
||||
print '<tr>';
|
||||
print '<td><input class="text" name="propname" value=""></td>';
|
||||
print '<td><input class="text" name="propname" value=""></td>';
|
||||
print '<td><input class="text" name="propname" value=""></td>';
|
||||
print '<td><input class="text" name="propname" value=""></td>';
|
||||
print '<td align="center">';
|
||||
print '<input class="button" type="submit" name="add" value="'.$langs->trans("Add").'">';
|
||||
print '</td></tr>';
|
||||
foreach($properties as $propkey => $propval)
|
||||
{
|
||||
if ($propval->class == $tabobj)
|
||||
print load_fiche_titre($langs->trans("Properties"), '', '');
|
||||
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="initobject">';
|
||||
print '<input type="hidden" name="tab" value="objects">';
|
||||
print '<input type="hidden" name="module" value="'.dol_escape_htmltag($module).'">';
|
||||
print '<input type="hidden" name="tabobj" value="'.dol_escape_htmltag($tabobj).'">';
|
||||
|
||||
print '<table class="noborder">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Property");
|
||||
print ' (<a href="https://wiki.dolibarr.org/index.php/Language_and_development_rules#Table_and_fields_structures" target="_blank">'.$langs->trans("Example").'</a>)';
|
||||
print '</td>';
|
||||
print '<td>'.$langs->trans("Label").'</td>';
|
||||
print '<td>'.$langs->trans("Type").'</td>';
|
||||
print '<td>'.$langs->trans("Position").'</td>';
|
||||
print '<td>'.$langs->trans("DefaultValue").'</td>';
|
||||
print '<td>'.$langs->trans("Index").'</td>';
|
||||
print '<td>'.$langs->trans("Comment").'</td>';
|
||||
print '<td></td>';
|
||||
print '</tr>';
|
||||
print '<tr>';
|
||||
print '<td><input class="text" name="propname" value=""></td>';
|
||||
print '<td><input class="text" name="proplabel" value=""></td>';
|
||||
print '<td><input class="text" name="proptype" value=""></td>';
|
||||
print '<td><input class="text" name="propposition" value=""></td>';
|
||||
print '<td><input class="text" name="propdefault" value=""></td>';
|
||||
print '<td><input class="text" name="propindex" value=""></td>';
|
||||
print '<td><input class="text" name="propcomment" value=""></td>';
|
||||
print '<td align="center">';
|
||||
print '<input class="button" type="submit" name="add" value="'.$langs->trans("Add").'">';
|
||||
print '</td></tr>';
|
||||
|
||||
$properties = $tmpobjet->fields;
|
||||
|
||||
foreach($properties as $propkey => $propval)
|
||||
{
|
||||
$propname=$propval->getName();
|
||||
/* If from Reflection
|
||||
if ($propval->class == $tabobj)
|
||||
{
|
||||
$propname=$propval->getName();
|
||||
$comment=$propval->getDocComment();
|
||||
$type=gettype($tmpobjet->$propname);
|
||||
$default=$propdefault[$propname];
|
||||
// Discard generic properties
|
||||
if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'isnolinkedbythird', 'ismultientitymanaged'))) continue;
|
||||
|
||||
// Discard generic properties
|
||||
if (in_array($propname, array('element', 'childtables', 'table_element', 'table_element_line', 'class_element_line', 'isnolinkedbythird', 'ismultientitymanaged'))) continue;
|
||||
// Keep or not lines
|
||||
if (in_array($propname, array('fk_element', 'lines'))) continue;
|
||||
}*/
|
||||
|
||||
// Keep or not lines
|
||||
if (in_array($propname, array('fk_element', 'lines'))) continue;
|
||||
$propname=$propkey;
|
||||
$proplabel=$propval['label'];
|
||||
$proptype=$propval['type'];
|
||||
$propposition=$propval['position'];
|
||||
$propdefault=$propval['default'];
|
||||
$propindex=$propval['index'];
|
||||
$propcomment=$propval['comment'];
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
print '<tr class="oddeven"><td>';
|
||||
print '<td>';
|
||||
print $propname;
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print $propval->getDocComment();
|
||||
print $proplabel;
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print gettype($tmpobjet->$propname);
|
||||
print $proptype;
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
print $propdefault[$propname];
|
||||
print $propposition;
|
||||
print '</td>';
|
||||
|
||||
print '<td>';
|
||||
|
||||
print $propdefault;
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print yn($propindex);
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print $propcomment;
|
||||
print '</td>';
|
||||
print '<td class="center">';
|
||||
print '<a href="'.$_SERVER["PHP_SELF"].'?action=deleteproperty&propertykey='.urlencode($propname).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj).'">'.img_delete().'</a>';
|
||||
print '</td>';
|
||||
|
||||
print '</tr>';
|
||||
}
|
||||
print '</table>';
|
||||
|
||||
print '</form>';
|
||||
}
|
||||
print '</table>';
|
||||
catch(Exception $e)
|
||||
{
|
||||
print $e->getMessage();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$fullpathoffile=dol_buildpath($file, 0);
|
||||
|
||||
$content = file_get_contents($fullpathoffile);
|
||||
|
||||
// New module
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="action" value="savefile">';
|
||||
print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'">';
|
||||
print '<input type="hidden" name="tab" value="'.$tab.'">';
|
||||
print '<input type="hidden" name="module" value="'.$module.'">';
|
||||
|
||||
$doleditor=new DolEditor('editfilecontent', $content, '', '600', 'Full', 'In', true, false, false, 0, '99%');
|
||||
print $doleditor->Create(1, '', false);
|
||||
print '<br>';
|
||||
print '<center>';
|
||||
print '<input type="submit" class="button" name="savefile" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
|
||||
print ' ';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
|
||||
print '</center>';
|
||||
|
||||
print '</form>';
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
print $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,22 +52,24 @@ class MyObject extends CommonObject
|
|||
* @var array Does myobject support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
|
||||
*/
|
||||
protected $ismultientitymanaged = 1;
|
||||
|
||||
|
||||
/**
|
||||
* @var string String with name of icon for myobject
|
||||
*/
|
||||
* @var string String with name of icon for myobject
|
||||
*/
|
||||
public $picto = 'myobject';
|
||||
|
||||
/**
|
||||
* @var int Entity Id
|
||||
*/
|
||||
public $entity;
|
||||
|
||||
/* BEGIN PROPERTY FIELDS - Do not remove this comment */
|
||||
/**
|
||||
* @var array Array with all fields and their property
|
||||
*/
|
||||
public $fields;
|
||||
public $fields=array(
|
||||
'ref'=>array('type'=>'string','label'=>'Ref','position'=>10,'index'=>true,'comment'=>'Reference of object'),
|
||||
'entity'=>array('type'=>'integer','label'=>'Entity','index'=>true),
|
||||
'status'=>array('type'=>'integer','label'=>'Status','index'=>true),
|
||||
'date'=>array('type'=>'date','label'=>'Date','default'=>'__NOW__'),
|
||||
'title'=>array('type'=>'string','label'=>'Title'),
|
||||
);
|
||||
/* END PROPERTY FIELDS - Do not remove this comment */
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -68,13 +68,7 @@ $toselect = GETPOST('toselect', 'array');
|
|||
|
||||
$id = GETPOST('id','int');
|
||||
$backtopage = GETPOST('backtopage');
|
||||
$myparam = GETPOST('myparam','alpha');
|
||||
|
||||
$search_all=trim(GETPOST("sall"));
|
||||
$search_field1=GETPOST("search_field1");
|
||||
$search_field2=GETPOST("search_field2");
|
||||
$search_myfield=GETPOST('search_myfield');
|
||||
$optioncss = GETPOST('optioncss','alpha');
|
||||
$optioncss = GETPOST('optioncss','alpha');
|
||||
|
||||
// Load variable for pagination
|
||||
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
|
||||
|
|
@ -85,6 +79,7 @@ if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined,
|
|||
$offset = $limit * $page;
|
||||
$pageprev = $page - 1;
|
||||
$pagenext = $page + 1;
|
||||
|
||||
if (! $sortfield) $sortfield="t.rowid"; // Set here default search field
|
||||
if (! $sortorder) $sortorder="ASC";
|
||||
|
||||
|
|
@ -96,6 +91,19 @@ if ($user->societe_id > 0)
|
|||
//accessforbidden();
|
||||
}
|
||||
|
||||
// Initialize array of search criterias
|
||||
$object=new MyModule($db);
|
||||
$search_all=trim(GETPOST("search_all"));
|
||||
$search=array();
|
||||
foreach($object->fields as $key)
|
||||
{
|
||||
if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha');
|
||||
}
|
||||
/*$search_field1=GETPOST("search_field1");
|
||||
$search_field2=GETPOST("search_field2");
|
||||
$search_myfield=GETPOST('search_myfield');
|
||||
*/
|
||||
|
||||
// Initialize technical object to manage context to save list fields
|
||||
$contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'myobjectlist';
|
||||
|
||||
|
|
@ -133,8 +141,6 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
|
|||
}
|
||||
|
||||
|
||||
$object=new Skeleton_Class($db);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user