Enhance modulebuilder
This commit is contained in:
parent
13cd203502
commit
bfd1fa3984
@ -594,7 +594,7 @@ if (! $error && $massaction == 'delete' && $permtodelete)
|
||||
$nbok = 0;
|
||||
foreach($toselect as $toselectid)
|
||||
{
|
||||
$result=$objecttmp->fetch($toselectid);
|
||||
$result=$objecttmp->fetch($toselectid);
|
||||
if ($result > 0)
|
||||
{
|
||||
if (in_array($objecttmp->element, array('societe','member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1);
|
||||
|
||||
@ -5011,7 +5011,7 @@ abstract class CommonObject
|
||||
|
||||
if (!$notrigger) {
|
||||
// Call triggers
|
||||
$result=$this->call_trigger(strtoupper(get_class(self)).'_CREATE',$user);
|
||||
$result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user);
|
||||
if ($result < 0) { $error++; }
|
||||
// End call triggers
|
||||
}
|
||||
@ -5173,7 +5173,7 @@ abstract class CommonObject
|
||||
|
||||
if (! $error && ! $notrigger) {
|
||||
// Call triggers
|
||||
$result=$this->call_trigger(strtoupper(get_class(self)).'_MODIFY',$user);
|
||||
$result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user);
|
||||
if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail
|
||||
// End call triggers
|
||||
}
|
||||
@ -5204,7 +5204,7 @@ abstract class CommonObject
|
||||
if (! $error) {
|
||||
if (! $notrigger) {
|
||||
// Call triggers
|
||||
$result=$this->call_trigger(strtoupper(get_class(self)).'_DELETE', $user);
|
||||
$result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user);
|
||||
if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail
|
||||
// End call triggers
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ DescriptionLong=Long description
|
||||
EditorName=Name of editor
|
||||
EditorUrl=URL of editor
|
||||
DescriptorFile=Descriptor file of module
|
||||
ClassFile=File for PHP class
|
||||
ClassFile=File for PHP DAO CRUD class
|
||||
ApiClassFile=File for PHP API class
|
||||
PageForList=PHP page for list of record
|
||||
PageForCreateEditView=PHP page to create/edit/view a record
|
||||
|
||||
@ -109,6 +109,7 @@ if ($dirins && $action == 'initmodule' && $modulename)
|
||||
// Delete some files
|
||||
dol_delete_file($destdir.'/myobject_card.php');
|
||||
dol_delete_file($destdir.'/myobject_list.php');
|
||||
dol_delete_file($destdir.'/lib/myobject.lib.php');
|
||||
dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
|
||||
dol_delete_file($destdir.'/sql/llx_myobject.sql');
|
||||
dol_delete_file($destdir.'/sql/llx_myobject_extrafields.sql');
|
||||
@ -132,7 +133,7 @@ if ($dirins && $action == 'initmodule' && $modulename)
|
||||
'MyModule'=>$modulename,
|
||||
'MYMODULE'=>strtoupper($modulename),
|
||||
'My module'=>$modulename,
|
||||
'htdocs/modulebuilder/template/'=>'',
|
||||
'htdocs/modulebuilder/template/'=>strtolower($modulename),
|
||||
'---Put here your own copyright and developer email---'=>dol_print_date($now,'%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
|
||||
);
|
||||
|
||||
@ -189,7 +190,8 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
|
||||
$filetogenerate = array(
|
||||
'myobject_card.php'=>strtolower($objectname).'_card.php',
|
||||
'myobject_list.php'=>strtolower($objectname).'_list.php',
|
||||
'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.$objectname.'Test.php',
|
||||
'lib/myobject.lib.php'=>'lib/'.strtolower($objectname).'.lib.php',
|
||||
'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.$objectname.'Test.php',
|
||||
'sql/llx_myobject.sql'=>'sql/llx_'.strtolower($objectname).'.sql',
|
||||
'sql/llx_myobject_extrafields.sql'=>'sql/llx_'.strtolower($objectname).'_extrafields.sql',
|
||||
'sql/llx_myobject.key.sql'=>'sql/llx_'.strtolower($objectname).'.key.sql',
|
||||
@ -276,7 +278,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
|
||||
'MyModule'=>$module,
|
||||
'MYMODULE'=>strtoupper($module),
|
||||
'My module'=>$module,
|
||||
'htdocs/modulebuilder/template/'=>'',
|
||||
'htdocs/modulebuilder/template/'=>strtolower($modulename),
|
||||
'myobject'=>strtolower($objectname),
|
||||
'MyObject'=>$objectname
|
||||
);
|
||||
@ -378,7 +380,8 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname)
|
||||
$filetogenerate = array(
|
||||
'myobject_card.php'=>strtolower($objectname).'_card.php',
|
||||
'myobject_list.php'=>strtolower($objectname).'_list.php',
|
||||
'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.$objectname.'Test.php',
|
||||
'lib/myobject.lib.php'=>'lib/'.strtolower($objectname).'.lib.php',
|
||||
'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.$objectname.'Test.php',
|
||||
'sql/llx_myobject.sql'=>'sql/llx_'.strtolower($objectname).'.sql',
|
||||
'sql/llx_myobject_extrafields.sql'=>'sql/llx_'.strtolower($objectname).'_extrafields.sql',
|
||||
'sql/llx_myobject.key.sql'=>'sql/llx_'.strtolower($objectname).'.key.sql',
|
||||
|
||||
@ -128,6 +128,53 @@ class MyObject extends CommonObject
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create object into database
|
||||
*
|
||||
* @param User $user User that creates
|
||||
* @param bool $notrigger false=launch triggers after, true=disable triggers
|
||||
* @return int <0 if KO, Id of created object if OK
|
||||
*/
|
||||
public function create(User $user, $notrigger = false)
|
||||
{
|
||||
return $this->createCommon($user, $notrigger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load object in memory from the database
|
||||
*
|
||||
* @param int $id Id object
|
||||
* @param string $ref Ref
|
||||
* @return int <0 if KO, 0 if not found, >0 if OK
|
||||
*/
|
||||
public function fetch($id, $ref = null)
|
||||
{
|
||||
return $this->fetchCommon($id, $ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update object into database
|
||||
*
|
||||
* @param User $user User that modifies
|
||||
* @param bool $notrigger false=launch triggers after, true=disable triggers
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function update(User $user, $notrigger = false)
|
||||
{
|
||||
return $this->updateCommon($user, $notrigger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete object in database
|
||||
*
|
||||
* @param User $user User that deletes
|
||||
* @param bool $notrigger false=launch triggers after, true=disable triggers
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function delete(User $user, $notrigger = false)
|
||||
{
|
||||
return $this->deleteCommon($user, $trigger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a link to the object card (with optionaly the picto)
|
||||
@ -153,7 +200,7 @@ class MyObject extends CommonObject
|
||||
$label.= '<br>';
|
||||
$label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
|
||||
|
||||
$url = $url = dol_buildpath('/mymodule/m_card.php',1).'?id='.$this->id;
|
||||
$url = $url = dol_buildpath('/mymodule/myobject_card.php',1).'?id='.$this->id;
|
||||
|
||||
$linkclose='';
|
||||
if (empty($notooltip))
|
||||
|
||||
@ -16,11 +16,9 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file lib/mymodule.lib.php
|
||||
* \file htdocs/modulebuilder/template/lib/mymodule.lib.php
|
||||
* \ingroup mymodule
|
||||
* \brief Example module library.
|
||||
*
|
||||
* Put detailed description here.
|
||||
* \brief Library files with common functions for MyModule
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
67
htdocs/modulebuilder/template/lib/myobject.lib.php
Normal file
67
htdocs/modulebuilder/template/lib/myobject.lib.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/* Copyright (C) ---Put here your own copyright and developer email---
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/modulebuilder/template/lib/myobject.lib.php
|
||||
* \ingroup mymodule
|
||||
* \brief Library files with common functions for MyObject
|
||||
*/
|
||||
|
||||
/**
|
||||
* Prepare array of tabs for MyObject
|
||||
*
|
||||
* @param MyObject $object MyObject
|
||||
* @return array Array of tabs
|
||||
*/
|
||||
function myobjectPrepareHead($object)
|
||||
{
|
||||
global $langs, $conf;
|
||||
|
||||
$langs->load("mymodule@mymodule");
|
||||
|
||||
$h = 0;
|
||||
$head = array();
|
||||
|
||||
$head[$h][0] = dol_buildpath("/mymodule/myobject_card.php", 1).'?id='.$object->id;
|
||||
$head[$h][1] = $langs->trans("Card");
|
||||
$head[$h][2] = 'card';
|
||||
$h++;
|
||||
$head[$h][0] = dol_buildpath("/mymodule/myobject_note.php", 1).'?id='.$object->id;
|
||||
$head[$h][1] = $langs->trans("Notes");
|
||||
$head[$h][2] = 'note';
|
||||
$h++;
|
||||
$head[$h][0] = dol_buildpath("/mymodule/myobject_document.php", 1).'?id='.$object->id;
|
||||
$head[$h][1] = $langs->trans("Documents");
|
||||
$head[$h][2] = 'document';
|
||||
$h++;
|
||||
$head[$h][0] = dol_buildpath("/mymodule/myobject_agenda.php", 1).'?id='.$object->id;
|
||||
$head[$h][1] = $langs->trans("Events");
|
||||
$head[$h][2] = 'agenda';
|
||||
$h++;
|
||||
|
||||
// Show more tabs from modules
|
||||
// Entries must be declared in modules descriptor with line
|
||||
//$this->tabs = array(
|
||||
// 'entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'
|
||||
//); // to add new tab
|
||||
//$this->tabs = array(
|
||||
// 'entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'
|
||||
//); // to remove a tab
|
||||
complete_head_from_modules($conf, $langs, $object, $head, $h, 'myobject@mymodule');
|
||||
|
||||
return $head;
|
||||
}
|
||||
@ -52,7 +52,9 @@ if (! $res && file_exists("../../../main.inc.php")) $res=@include("../../../main
|
||||
if (! $res) die("Include of main fails");
|
||||
|
||||
include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
|
||||
include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php');
|
||||
dol_include_once('/mymodule/class/myobject.class.php');
|
||||
dol_include_once('/mymodule/lib/myobject.lib.php');
|
||||
|
||||
// Load traductions files requiredby by page
|
||||
$langs->loadLangs(array("mymodule","other"));
|
||||
@ -226,6 +228,7 @@ if (empty($reshook))
|
||||
*/
|
||||
|
||||
$form=new Form($db);
|
||||
$formfile=new FormFile($db);
|
||||
|
||||
llxHeader('','MyObject','');
|
||||
|
||||
@ -311,14 +314,14 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
{
|
||||
$res = $object->fetch_optionals($object->id, $extralabels);
|
||||
|
||||
$head = mymodule_prepare_head($object);
|
||||
dol_fiche_head($head, 'order', $langs->trans("CustomerOrder"), -1, 'order');
|
||||
$head = myobjectPrepareHead($object);
|
||||
dol_fiche_head($head, 'card', $langs->trans("MyObject"), -1, 'myobject@mymodule');
|
||||
|
||||
$formconfirm = '';
|
||||
|
||||
// Confirmation to delete
|
||||
if ($action == 'delete') {
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1);
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteMyObject'), $langs->trans('ConfirmDeleteMyObject'), 'confirm_delete', '', 0, 1);
|
||||
}
|
||||
|
||||
// Confirmation of action xxxx
|
||||
@ -346,12 +349,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
print $formconfirm;
|
||||
|
||||
|
||||
|
||||
// Object card
|
||||
// ------------------------------------------------------------
|
||||
|
||||
$linkback = '<a href="' . DOL_URL_ROOT . '/mymodule/myobject_list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
|
||||
|
||||
$linkback = '<a href="' .dol_buildpath('/mymodule/myobject_list.php',1) . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
|
||||
|
||||
$morehtmlref='<div class="refidno">';
|
||||
/*
|
||||
@ -477,7 +477,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
|
||||
|
||||
// Show links to link elements
|
||||
$linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
|
||||
$linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
|
||||
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
|
||||
|
||||
|
||||
@ -486,7 +486,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
// List of actions on element
|
||||
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
|
||||
$formactions = new FormActions($db);
|
||||
$somethingshown = $formactions->showactions($object, 'order', $socid);
|
||||
$somethingshown = $formactions->showactions($object, 'myobject', $socid);
|
||||
|
||||
print '</div></div></div>';
|
||||
}
|
||||
@ -534,7 +534,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
|
||||
print '<div class="clearboth"></div>';
|
||||
print '<br>';
|
||||
print load_fiche_titre($langs->trans('SendOrderByMail'));
|
||||
print load_fiche_titre($langs->trans('SendMyObjectByMail'));
|
||||
|
||||
dol_fiche_head('');
|
||||
|
||||
@ -562,9 +562,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
$formmail->withtocc = $liste;
|
||||
$formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
|
||||
if (empty($object->ref_client)) {
|
||||
$formmail->withtopic = $outputlangs->trans('SendOrderRef', '__ORDERREF__');
|
||||
$formmail->withtopic = $outputlangs->trans('SendMyObjectRef', '__REF__');
|
||||
} else if (! empty($object->ref_client)) {
|
||||
$formmail->withtopic = $outputlangs->trans('SendOrderRef', '__ORDERREF__ (__REFCLIENT__)');
|
||||
$formmail->withtopic = $outputlangs->trans('SendMyObjectRef', '__REF__ (__REFCLIENT__)');
|
||||
}
|
||||
$formmail->withfile = 2;
|
||||
$formmail->withbody = 1;
|
||||
@ -572,7 +572,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
$formmail->withcancel = 1;
|
||||
// Tableau des substitutions
|
||||
$formmail->setSubstitFromObject($object);
|
||||
$formmail->substit ['__ORDERREF__'] = $object->ref;
|
||||
$formmail->substit ['__REF__'] = $object->ref;
|
||||
|
||||
$custcontact = '';
|
||||
$contactarr = array();
|
||||
@ -596,9 +596,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
|
||||
// Tableau des parametres complementaires
|
||||
$formmail->param['action'] = 'send';
|
||||
$formmail->param['models'] = 'order_send';
|
||||
$formmail->param['models'] = 'myobject_send';
|
||||
$formmail->param['models_id']=GETPOST('modelmailselected','int');
|
||||
$formmail->param['orderid'] = $object->id;
|
||||
$formmail->param['myobjectid'] = $object->id;
|
||||
$formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;
|
||||
|
||||
// Init list of files
|
||||
|
||||
Loading…
Reference in New Issue
Block a user