Debug modulebuilder for lines

This commit is contained in:
Laurent Destailleur 2019-05-19 16:21:11 +02:00
parent 2900f8828a
commit 2debffe170
4 changed files with 173 additions and 9 deletions

View File

@ -325,6 +325,62 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
dol_fiche_end();
/*
* Lines
*/
if (! empty($object->table_element_line))
{
// Show object lines
$result = $object->getLinesArray();
print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#addline' : '#line_' . GETPOST('lineid', 'int')) . '" method="POST">
<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
<input type="hidden" name="mode" value="">
<input type="hidden" name="id" value="' . $object->id . '">
';
if (! empty($conf->use_javascript_ajax) && $object->status == 0) {
include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
}
print '<div class="div-table-responsive-no-min">';
if (! empty($object->lines) && $object->status == 0 && $permissiontoadd && $action != 'selectlines' && $action != 'editline')
{
print '<table id="tablelines" class="noborder noshadow" width="100%">';
}
if (! empty($object->lines))
{
// $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
}
// Form to add new line
if ($object->status == 0 && $permissiontoadd && $action != 'selectlines')
{
if ($action != 'editline')
{
// Add products/services form
// $object->formAddObjectLine(1, $mysoc, $soc);
$parameters = array();
$reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
}
}
if (! empty($object->lines) && $object->status == 0 && $permissiontoadd && $action != 'selectlines' && $action != 'editline')
{
print '</table>';
}
print '</div>';
print "</form>\n";
}
// Buttons for actions
if ($action != 'presend' && $action != 'editline') {
print '<div class="tabsAction">'."\n";

View File

@ -850,6 +850,31 @@ class BOM extends CommonObject
}
}
/**
* Create an array of lines
*
* @return array|int array of lines if OK, <0 if KO
*/
public function getLinesArray()
{
$this->lines=array();
$objectline = new BOMLine($this->db);
$result = $objectline->fetchAll('', '', 0, 0, array('fk_bom'=>$this->id));
if (is_numeric($result))
{
$this->error = $this->error;
$this->errors = $this->errors;
return $result;
}
else
{
$this->lines = $result;
return $this->lines();
}
}
/**
* Initialise object with example values
* Id must be 0 if object instance is a specimen

View File

@ -163,7 +163,10 @@ if ($dirins && $action == 'initmodule' && $modulename)
dol_delete_file($destdir.'/myobject_agenda.php');
dol_delete_file($destdir.'/myobject_list.php');
dol_delete_file($destdir.'/lib/'.strtolower($modulename).'_myobject.lib.php');
dol_delete_file($destdir.'/test/phpunit/MyObjectFunctionnalTest.php');
dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
dol_delete_file($destdir.'/test/phpunit');
dol_delete_file($destdir.'/test');
dol_delete_file($destdir.'/sql/llx'.strtolower($modulename).'_myobject.sql');
dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject_extrafields.sql');
dol_delete_file($destdir.'/sql/llx_'.strtolower($modulename).'_myobject.key.sql');
@ -223,6 +226,9 @@ if ($dirins && $action == 'initmodule' && $modulename)
if ($dirins && $action == 'initapi' && !empty($module))
{
$modulename = ucfirst($module); // Force first letter in uppercase
$objectname = $tabobj;
dol_mkdir($dirins.'/'.strtolower($module).'/class');
$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
$srcfile = $srcdir.'/class/api_mymodule.class.php';
@ -232,9 +238,6 @@ if ($dirins && $action == 'initapi' && !empty($module))
if ($result > 0)
{
$modulename = ucfirst($module); // Force first letter in uppercase
$objectname = $tabobj;
//var_dump($phpfileval['fullname']);
$arrayreplacement=array(
'mymodule'=>strtolower($modulename),
@ -254,6 +257,46 @@ if ($dirins && $action == 'initapi' && !empty($module))
dolReplaceInFile($destfile, $arrayreplacement);
}
}
if ($dirins && $action == 'initphpunit' && !empty($module))
{
$modulename = ucfirst($module); // Force first letter in uppercase
$objectname = $tabobj;
dol_mkdir($dirins.'/'.strtolower($module).'/class');
$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
$srcfile = $srcdir.'/test/phpunit/MyObjectTest.php';
$destfile = $dirins.'/'.strtolower($module).'/test/phpunit/'.strtolower($objectname).'Test.php';
$result = dol_copy($srcfile, $destfile, 0, 0);
/*$srcfile = $srcdir.'/test/phpunit/MyModuleFunctionnalTest.class.php';
$destfile = $dirins.'/'.strtolower($module).'/test/phpunit/'.strtolower($module).'FunctionnalTest.class.php';
$result = dol_copy($srcfile, $destfile, 0, 0);*/
if ($result > 0)
{
//var_dump($phpfileval['fullname']);
$arrayreplacement=array(
'mymodule'=>strtolower($modulename),
'MyModule'=>$modulename,
'MYMODULE'=>strtoupper($modulename),
'My module'=>$modulename,
'my module'=>$modulename,
'Mon module'=>$modulename,
'mon module'=>$modulename,
'htdocs/modulebuilder/template'=>strtolower($modulename),
'myobject'=>strtolower($objectname),
'MyObject'=>$objectname,
'MYOBJECT'=>strtoupper($objectname),
'---Put here your own copyright and developer email---'=>dol_print_date($now, '%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
);
dolReplaceInFile($destfile, $arrayreplacement);
}
else
{
}
}
if ($dirins && $action == 'inithook' && !empty($module))
{
dol_mkdir($dirins.'/'.strtolower($module).'/class');
@ -518,7 +561,6 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
dol_mkdir($destdir.'/lib');
dol_mkdir($destdir.'/scripts');
dol_mkdir($destdir.'/sql');
dol_mkdir($destdir.'/test/phpunit');
// Scan dir class to find if an object with same name already exists.
if (! $error)
@ -548,7 +590,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
'myobject_agenda.php'=>strtolower($objectname).'_agenda.php',
'myobject_list.php'=>strtolower($objectname).'_list.php',
'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.$objectname.'Test.php',
//'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php',
'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
@ -912,7 +954,7 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname)
'myobject_list.php'=>strtolower($objectname).'_list.php',
'lib/mymodule.lib.php'=>'lib/'.strtolower($module).'.lib.php',
'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php',
'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.$objectname.'Test.php',
'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php',
'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql',
'sql/llx_mymodule_myobject_extrafields.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'_extrafields.sql',
'sql/llx_mymodule_myobject.key.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.key.sql',
@ -1803,17 +1845,17 @@ elseif (! empty($module))
$pathtodocument = strtolower($module).'/'.strtolower($tabobj).'_document.php';
$pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php';
$pathtonote = strtolower($module).'/'.strtolower($tabobj).'_note.php';
$pathtophpunit = strtolower($module).'/test/phpunit/'.$tabobj.'Test.php';
$pathtophpunit = strtolower($module).'/test/phpunit/'.strtolower($tabobj).'Test.php';
$pathtosql = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.sql';
$pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields.sql';
$pathtosqlkey = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.key.sql';
$pathtosqlextrakey = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields.key.sql';
$pathtolib = strtolower($module).'/lib/'.strtolower($module).'.lib.php';
$pathtoobjlib = strtolower($module).'/lib/'.strtolower($module).'_'.strtolower($tabobj).'.lib.php';
$pathtopicto = strtolower($module).'/img/object_'.strtolower($tabobj).'.png';
$pathtoscript = strtolower($module).'/scripts/'.strtolower($tabobj).'.php';
//var_dump($pathtolib);
$realpathtoclass = dol_buildpath($pathtoclass, 0, 2);
$realpathtoapi = dol_buildpath($pathtoapi, 0, 2);
$realpathtoagenda = dol_buildpath($pathtoagenda, 0, 2);
@ -1825,6 +1867,7 @@ elseif (! empty($module))
$realpathtosql = dol_buildpath($pathtosql, 0, 2);
$realpathtosqlextra = dol_buildpath($pathtosqlextra, 0, 2);
$realpathtosqlkey = dol_buildpath($pathtosqlkey, 0, 2);
$realpathtosqlextrakey = dol_buildpath($pathtosqlextrakey, 0, 2);
$realpathtolib = dol_buildpath($pathtolib, 0, 2);
$realpathtoobjlib = dol_buildpath($pathtoobjlib, 0, 2);
$realpathtopicto = dol_buildpath($pathtopicto, 0, 2);
@ -1855,9 +1898,21 @@ elseif (! empty($module))
//print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span> ';
print '<a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=initapi&format=php&file='.urlencode($pathtoapi).'"><input type="button" class="button" value="'.$langs->trans("Generate").'"></a>';
}
// PHPUnit
print '<br>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("TestClassFile").' : <strong>'.($realpathtophpunit?'':'<strike>').$pathtophpunit.($realpathtophpunit?'':'</strike>').'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=php&file='.urlencode($pathtophpunit).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
if ($realpathtophpunit)
{
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=php&file='.urlencode($pathtophpunit).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print ' &nbsp; ';
print '<a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=confirm_removefile&file='.urlencode($pathtophpunit).'">'.img_picto($langs->trans("Delete"), 'delete').'</a>';
}
else
{
//print '<span class="opacitymedium">'.$langs->trans("FileNotYetGenerated").'</span> ';
print '<a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=initphpunit&format=php&file='.urlencode($pathtophpunit).'"><input type="button" class="button" value="'.$langs->trans("Generate").'"></a>';
}
print '<br>';
print '<br>';
@ -1887,6 +1942,10 @@ elseif (! empty($module))
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=sql&file='.urlencode($pathtosqlkey).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
//print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
print '<br>';
print '<span class="fa fa-file-o"></span> '.$langs->trans("SqlFileKeyExtraFields").' : <strong>'.($realpathtosqlextrakey?'':'<strike>').$pathtosqlextrakey.($realpathtosqlextrakey?'':'</strike>').'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&tabobj='.$tabobj.'&module='.$module.($forceddirread?'@'.$dirread:'').'&action=editfile&format=sql&file='.urlencode($pathtosqlextrakey).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
//print ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'">'.$langs->trans("RunSql").'</a>';
print '<br>';
print '<br>';
print '</div>';

View File

@ -644,6 +644,30 @@ class MyObject extends CommonObject
$this->initAsSpecimenCommon();
}
/**
* Create an array of lines
*
* @return array|int array of lines if OK, <0 if KO
*/
public function getLinesArray()
{
$this->lines=array();
$objectline = new BOMLine($this->db);
$result = $objectline->fetchAll('', '', 0, 0, array('fk_myobject'=>$this->id));
if (is_numeric($result))
{
$this->error = $this->error;
$this->errors = $this->errors;
return $result;
}
else
{
$this->lines = $result;
return $this->lines();
}
}
/**
* Action executed by scheduler