Debug modulebuilder

This commit is contained in:
Laurent Destailleur 2017-07-24 21:03:35 +02:00
parent dcb79e66cc
commit 8303cee676
3 changed files with 23 additions and 30 deletions

View File

@ -58,7 +58,7 @@ class MyObject extends CommonObject
public $picto = 'myobject'; public $picto = 'myobject';
/* /**
* 'type' if the field format, 'label' the translation key, 'enabled' is a condition when the filed must be managed, * 'type' if the field format, 'label' the translation key, 'enabled' is a condition when the filed must be managed,
* 'visible' says if field is visible in list (-1 means not shown by default but can be aded into list to be viewed) * 'visible' says if field is visible in list (-1 means not shown by default but can be aded into list to be viewed)
* 'notnull' if not null in database * 'notnull' if not null in database
@ -84,8 +84,8 @@ class MyObject extends CommonObject
'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>true, 'position'=>1000, 'nullifempty'=>1), 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>true, 'position'=>1000, 'nullifempty'=>1),
); );
// END MODULEBUILDER PROPERTIES // END MODULEBUILDER PROPERTIES
// If this object has a subtable with lines // If this object has a subtable with lines

View File

@ -110,6 +110,8 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
if (empty($reshook)) if (empty($reshook))
{ {
$error=0;
if ($cancel) if ($cancel)
{ {
if ($action != 'addlink') if ($action != 'addlink')
@ -125,19 +127,10 @@ if (empty($reshook))
// Action to add record // Action to add record
if ($action == 'add' && ! empty($user->rights->mymodule->create)) if ($action == 'add' && ! empty($user->rights->mymodule->create))
{ {
if ($cancel)
{
$urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/myobject_list.php',1);
header("Location: ".$urltogo);
exit;
}
$error=0;
foreach ($object->fields as $key => $val) foreach ($object->fields as $key => $val)
{ {
if (in_array($key, array('entity', 'date_creation', 'tms', 'import_key'))) continue; // Ignore special fields if (in_array($key, array('entity', 'date_creation', 'tms', 'import_key'))) continue; // Ignore special fields
$object->$key=GETPOST($key,'alpha'); $object->$key=GETPOST($key,'alpha');
if ($val['notnull'] && $object->$key == '') if ($val['notnull'] && $object->$key == '')
{ {
@ -173,20 +166,20 @@ if (empty($reshook))
// Action to update record // Action to update record
if ($action == 'update' && ! empty($user->rights->mymodule->create)) if ($action == 'update' && ! empty($user->rights->mymodule->create))
{ {
$error=0; foreach ($object->fields as $key => $val)
{
$object->prop1=GETPOST("field1"); $object->$key=GETPOST($key,'alpha');
$object->prop2=GETPOST("field2"); if (in_array($key, array('entity', 'datec', 'tms'))) continue;
if ($val['notnull'] && $object->$key == '')
if (empty($object->ref)) {
{ $error++;
$error++; setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors');
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors'); }
} }
if (! $error) if (! $error)
{ {
$result=$object->update($user); $result=$object->updateCommon($user);
if ($result > 0) if ($result > 0)
{ {
$action='view'; $action='view';
@ -208,7 +201,7 @@ if (empty($reshook))
// Action to delete // Action to delete
if ($action == 'confirm_delete' && ! empty($user->rights->mymodule->delete)) if ($action == 'confirm_delete' && ! empty($user->rights->mymodule->delete))
{ {
$result=$object->delete($user); $result=$object->deleteCommon($user);
if ($result > 0) if ($result > 0)
{ {
// Delete OK // Delete OK

View File

@ -510,11 +510,11 @@ while ($i < min($num, $limit))
print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1); print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
print '</td>'; print '</td>';
if (! $i) $totalarray['nbfield']++; if (! $i) $totalarray['nbfield']++;
if (! empty($val['isameasure'])) if (! empty($val['isameasure']))
{ {
if (! $i) $totalarray['pos'][$totalarray['nbfield']]='ef.'.$tmpkey; if (! $i) $totalarray['pos'][$totalarray['nbfield']]='ef.'.$tmpkey;
$totalarray['val']['ef.'.$tmpkey] += $obj->$tmpkey; $totalarray['val']['ef.'.$tmpkey] += $obj->$tmpkey;
} }
} }
} }
} }