Skip to content

Commit

Permalink
Debug modulebuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 11, 2017
1 parent cbde99b commit ceeb9d7
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 85 deletions.
2 changes: 2 additions & 0 deletions htdocs/langs/en_US/modulebuilder.lang
Expand Up @@ -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.
243 changes: 176 additions & 67 deletions htdocs/modulebuilder/index.php
Expand Up @@ -37,9 +37,10 @@
$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'));
Expand All @@ -58,6 +59,7 @@

$now=dol_now();


/*
* Actions
*/
Expand Down Expand Up @@ -320,6 +322,29 @@
$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);
Expand Down Expand Up @@ -838,9 +863,11 @@
$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;
Expand All @@ -853,6 +880,12 @@
$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, '');

Expand Down Expand Up @@ -888,91 +921,167 @@
}
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>';

$result = dol_include_once($pathtoclass);
$tmpobjet = new $tabobj($db);

$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 == '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
);

print load_fiche_titre($langs->trans("Properties"), '', '');
// Print form confirm
print $formconfirm;
}

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("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)
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>';

$result = dol_include_once($pathtoclass);
$tmpobjet = new $tabobj($db);

$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 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();

// 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;

/* 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;
// 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 '</table>';

print '</form>';
print '</form>';
}
catch(Exception $e)
{
print $e->getMessage();
}
}
catch(Exception $e)
else
{
print $e->getMessage();
$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 ' &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
print '</center>';

print '</form>';
}
}
}
Expand Down
20 changes: 11 additions & 9 deletions htdocs/modulebuilder/template/class/myobject.class.php
Expand Up @@ -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 */



Expand Down

0 comments on commit ceeb9d7

Please sign in to comment.