Skip to content

Commit

Permalink
Enhance modulebuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 24, 2017
1 parent f6ab691 commit 13cd203
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
32 changes: 16 additions & 16 deletions htdocs/core/class/commonobject.class.php
Expand Up @@ -4736,19 +4736,6 @@ public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_pro




/**
* Function test if type is date
*
* @param array $info content informations of field
* @return bool
*/
protected function isDate($info)
{
if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true;
else return false;
}

/**
* Function test if type is array
*
Expand Down Expand Up @@ -4781,13 +4768,26 @@ protected function isNull($info)
else return false;
}


/**
* Function test if type is date
*
* @param array $info content informations of field
* @return bool
*/
public function isDate($info)
{
if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true;
else return false;
}

/**
* Function test if type is integer
*
* @param array $info content informations of field
* @return bool
*/
protected function isInt($info)
public function isInt($info)
{
if(is_array($info))
{
Expand All @@ -4803,7 +4803,7 @@ protected function isInt($info)
* @param array $info content informations of field
* @return bool
*/
protected function isFloat($info)
public function isFloat($info)
{
if(is_array($info))
{
Expand All @@ -4819,7 +4819,7 @@ protected function isFloat($info)
* @param array $info content informations of field
* @return bool
*/
protected function isText($info)
public function isText($info)
{
if(is_array($info))
{
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/en_US/modulebuilder.lang
Expand Up @@ -50,6 +50,7 @@ HooksFile=File for hooks code
WidgetFile=Widget file
ReadmeFile=Readme file
ChangeLog=ChangeLog file
TestClassFile=File for PHP Unit Test class
SqlFile=Sql file
SqlFileExtraFields=Sql file for complementary attributes
SqlFileKey=Sql file for keys
Expand Down
4 changes: 4 additions & 0 deletions htdocs/modulebuilder/index.php
Expand Up @@ -1210,6 +1210,7 @@
$pathtoapi = strtolower($module).'/class/api_'.strtolower($tabobj).'.class.php';
$pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php';
$pathtocard = strtolower($module).'/'.strtolower($tabobj).'_card.php';
$pathtophpunit = strtolower($module).'/test/phpunit/'.$tabobj.'Test.php';
$pathtosql = strtolower($module).'/sql/llx_'.strtolower($tabobj).'.sql';
$pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($tabobj).'_extrafields.sql';
$pathtosqlkey = strtolower($module).'/sql/llx_'.strtolower($tabobj).'.key.sql';
Expand All @@ -1220,6 +1221,9 @@
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&format=php&file='.urlencode($pathtoapi).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>';
print '<span class="fa fa-file"></span> '.$langs->trans("TestClassFile").' : <strong>'.$pathtophpunit.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=php&file='.urlencode($pathtophpunit).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>';
print '<span class="fa fa-file"></span> '.$langs->trans("SqlFile").' : <strong>'.$pathtosql.'</strong>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?tab='.$tab.'&module='.$module.'&action=editfile&format=sql&file='.urlencode($pathtosql).'">'.img_picto($langs->trans("Edit"), 'edit').'</a>';
print '<br>';
Expand Down
5 changes: 3 additions & 2 deletions htdocs/modulebuilder/template/class/myobject.class.php
Expand Up @@ -82,9 +82,10 @@ class MyObject extends CommonObject
'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000),
'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
//'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>500),
'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
//'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValid', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'position'=>500),
//'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValid', 'enabled'=>1, 'visible'=>-1, 'position'=>500),
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500),
'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>true, 'position'=>1000, 'nullifempty'=>1),
);
Expand Down
5 changes: 4 additions & 1 deletion htdocs/modulebuilder/template/myobject_list.php
Expand Up @@ -216,7 +216,8 @@
$sql.= " WHERE t.entity IN (".getEntity('myobject').")";
foreach($search as $key => $val)
{
if ($search[$key] != '') $sql.=natural_search($key, $search[$key], (($key == 'status')?2:($object->fields[$key]['type'] == 'integer'?1:0)));
$mode=(($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key]))?1:0);
if ($search[$key] != '') $sql.=natural_search($key, $search[$key], (($key == 'status')?2:$mode));
}
if ($search_all) $sql.= natural_search(array_keys($fieldstosearchall), $search_all);
// Add where from extra fields
Expand Down Expand Up @@ -404,6 +405,7 @@ function init_myfunc()
$align='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap';
if ($key == 'status') $align.=($align?' ':'').'center';
if (! empty($arrayfields['t.'.$key]['checked'])) print '<td class="liste_titre'.($align?' '.$align:'').'"><input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'"></td>';
}
// Action column
Expand Down Expand Up @@ -451,6 +453,7 @@ function init_myfunc()
$align='';
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap';
if ($key == 'status') $align.=($align?' ':'').'center';
if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n";
}
print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ')."\n";
Expand Down

0 comments on commit 13cd203

Please sign in to comment.