Skip to content

Commit

Permalink
Debug modulebuilder for lines
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed May 19, 2019
1 parent 2900f88 commit 2debffe
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 8 deletions.
56 changes: 56 additions & 0 deletions htdocs/bom/bom_card.php
Expand Up @@ -325,6 +325,62 @@ function init_myfunc()
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";
Expand Down
25 changes: 25 additions & 0 deletions htdocs/bom/class/bom.class.php
Expand Up @@ -850,6 +850,31 @@ public function info($id)
}
}

/**
* 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
Expand Down
75 changes: 67 additions & 8 deletions htdocs/modulebuilder/index.php
Expand Up @@ -163,7 +163,10 @@
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');
Expand Down Expand Up @@ -223,6 +226,9 @@

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';
Expand All @@ -232,9 +238,41 @@

if ($result > 0)
{
$modulename = ucfirst($module); // Force first letter in uppercase
$objectname = $tabobj;
//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);
}
}

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),
Expand All @@ -253,7 +291,12 @@

dolReplaceInFile($destfile, $arrayreplacement);
}
else
{

}
}

if ($dirins && $action == 'inithook' && !empty($module))
{
dol_mkdir($dirins.'/'.strtolower($module).'/class');
Expand Down Expand Up @@ -518,7 +561,6 @@
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)
Expand Down Expand Up @@ -548,7 +590,7 @@
'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',
Expand Down Expand Up @@ -912,7 +954,7 @@
'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',
Expand Down Expand Up @@ -1803,17 +1845,17 @@
$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);
Expand All @@ -1825,6 +1867,7 @@
$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);
Expand Down Expand Up @@ -1855,9 +1898,21 @@
//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>';
Expand Down Expand Up @@ -1887,6 +1942,10 @@
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>';
Expand Down
24 changes: 24 additions & 0 deletions htdocs/modulebuilder/template/class/myobject.class.php
Expand Up @@ -644,6 +644,30 @@ public function initAsSpecimen()
$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
Expand Down

0 comments on commit 2debffe

Please sign in to comment.