Completed
Branch develop (aca1c1)
by
unknown
24:57
created

modMyModule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 257
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 257
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 216 3
A init() 0 8 1
A remove() 0 6 1
1
<?php
2
/* Copyright (C) 2003      Rodolphe Quiedeville <[email protected]>
3
 * Copyright (C) 2004-2015 Laurent Destailleur  <[email protected]>
4
 * Copyright (C) 2005-2016 Regis Houssin        <[email protected]>
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
/**
21
 * 	\defgroup   mymodule     Module MyModule
22
 *  \brief      Example of a module descriptor.
23
 *				Such a file must be copied into htdocs/mymodule/core/modules directory.
24
 *  \file       htdocs/mymodule/core/modules/modMyModule.class.php
25
 *  \ingroup    mymodule
26
 *  \brief      Description and activation file for module MyModule
27
 */
28
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
29
30
31
/**
32
 *  Description and activation class for module MyModule
33
 */
34
class modMyModule extends DolibarrModules
35
{
36
	/**
37
	 * Constructor. Define names, constants, directories, boxes, permissions
38
	 *
39
	 * @param DoliDB $db Database handler
40
	 */
41
	public function __construct($db)
42
	{
43
        global $langs,$conf;
44
45
        $this->db = $db;
46
47
		// Id for module (must be unique).
48
		// Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
49
		$this->numero = 500000;		// TODO Go on page http://wiki.dolibarr.org/index.php/List_of_modules_id to reserve id number for your module
50
		// Key text used to identify module (for permissions, menus, etc...)
51
		$this->rights_class = 'mymodule';
52
53
		// Family can be 'crm','financial','hr','projects','products','ecm','technic','interface','other'
54
		// It is used to group modules by family in module setup page
55
		$this->family = "other";
56
		// Module position in the family
57
		$this->module_position = 500;
58
		// Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
59
		//$this->familyinfo = array('myownfamily' => array('position' => '001', 'label' => $langs->trans("MyOwnFamily")));
60
61
		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
62
		$this->name = preg_replace('/^mod/i','',get_class($this));
63
		// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
64
		$this->description = "Description of module MyModule";
65
		$this->descriptionlong = "A very long description. Can be a full HTML content";
66
		$this->editor_name = 'Editor name';
67
		$this->editor_url = 'https://www.dolibarr.org';
68
		
69
		// Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
70
		$this->version = '1.0';
71
		// Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
72
		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
73
		// Name of image file used for this module.
74
		// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
75
		// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
76
		$this->picto='generic';
77
78
		// Defined all module parts (triggers, login, substitutions, menus, css, etc...)
79
		// for default path (eg: /mymodule/core/xxxxx) (0=disable, 1=enable)
80
		// for specific path of parts (eg: /mymodule/core/modules/barcode)
81
		// for specific css file (eg: /mymodule/css/mymodule.css.php)
82
		//$this->module_parts = array(
83
		//                        	'triggers' => 0,                                 	// Set this to 1 if module has its own trigger directory (core/triggers)
84
		//							'login' => 0,                                    	// Set this to 1 if module has its own login method directory (core/login)
85
		//							'substitutions' => 0,                            	// Set this to 1 if module has its own substitution function file (core/substitutions)
86
		//							'menus' => 0,                                    	// Set this to 1 if module has its own menus handler directory (core/menus)
87
		//							'theme' => 0,                                    	// Set this to 1 if module has its own theme directory (theme)
88
		//                        	'tpl' => 0,                                      	// Set this to 1 if module overwrite template dir (core/tpl)
89
		//							'barcode' => 0,                                  	// Set this to 1 if module has its own barcode directory (core/modules/barcode)
90
		//							'models' => 0,                                   	// Set this to 1 if module has its own models directory (core/modules/xxx)
91
		//							'css' => array('/mymodule/css/mymodule.css.php'),	// Set this to relative path of css file if module has its own css file
92
	 	//							'js' => array('/mymodule/js/mymodule.js'),          // Set this to relative path of js file if module must load a js on all pages
93
		//							'hooks' => array('hookcontext1','hookcontext2',...) // Set here all hooks context managed by module. You can also set hook context 'all'
94
		//							'dir' => array('output' => 'othermodulename'),      // To force the default directories names
95
		//							'workflow' => array('WORKFLOW_MODULE1_YOURACTIONTYPE_MODULE2'=>array('enabled'=>'! empty($conf->module1->enabled) && ! empty($conf->module2->enabled)', 'picto'=>'yourpicto@mymodule')) // Set here all workflow context managed by module
96
		//                        );
97
		$this->module_parts = array();
98
99
		// Data directories to create when module is enabled.
100
		// Example: this->dirs = array("/mymodule/temp");
101
		$this->dirs = array();
102
103
		// Config pages. Put here list of php page, stored into mymodule/admin directory, to use to setup module.
104
		$this->config_page_url = array("mysetuppage.php@mymodule");
105
106
		// Dependencies
107
		$this->hidden = false;			// A condition to hide module
108
		$this->depends = array();		// List of module class names as string that must be enabled if this module is enabled
109
		$this->requiredby = array();	// List of module ids to disable if this one is disabled
110
		$this->conflictwith = array();	// List of module class names as string this module is in conflict with
111
		$this->phpmin = array(5,0);					// Minimum version of PHP required by module
112
		$this->need_dolibarr_version = array(3,0);	// Minimum version of Dolibarr required by module
113
		$this->langfiles = array("mylangfile@mymodule");
114
115
		// Constants
116
		// List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
117
		// Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1),
118
		//                             1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1)
119
		// );
120
		$this->const = array();
121
122
		// Array to add new pages in new tabs
123
		// Example: $this->tabs = array('objecttype:+tabname1:Title1:mylangfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__',  					// To add a new tab identified by code tabname1
124
        //                              'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@mymodule:$user->rights->othermodule->read:/mymodule/mynewtab2.php?id=__ID__',  	// To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
125
        //                              'objecttype:-tabname:NU:conditiontoremove');                                                     										// To remove an existing tab identified by code tabname
126
		// where objecttype can be
127
		// 'categories_x'	  to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
128
		// 'contact'          to add a tab in contact view
129
		// 'contract'         to add a tab in contract view
130
		// 'group'            to add a tab in group view
131
		// 'intervention'     to add a tab in intervention view
132
		// 'invoice'          to add a tab in customer invoice view
133
		// 'invoice_supplier' to add a tab in supplier invoice view
134
		// 'member'           to add a tab in fundation member view
135
		// 'opensurveypoll'	  to add a tab in opensurvey poll view
136
		// 'order'            to add a tab in customer order view
137
		// 'order_supplier'   to add a tab in supplier order view
138
		// 'payment'		  to add a tab in payment view
139
		// 'payment_supplier' to add a tab in supplier payment view
140
		// 'product'          to add a tab in product view
141
		// 'propal'           to add a tab in propal view
142
		// 'project'          to add a tab in project view
143
		// 'stock'            to add a tab in stock view
144
		// 'thirdparty'       to add a tab in third party view
145
		// 'user'             to add a tab in user view
146
        $this->tabs = array();
147
148
		if (! isset($conf->mymodule) || ! isset($conf->mymodule->enabled))
149
        {
150
        	$conf->mymodule=new stdClass();
151
        	$conf->mymodule->enabled=0;
152
        }
153
        
154
        // Dictionaries
155
		$this->dictionaries=array();
156
        /* Example:
157
        $this->dictionaries=array(
158
            'langs'=>'mylangfile@mymodule',
159
            'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"),		// List of tables we want to see into dictonnary editor
160
            'tablib'=>array("Table1","Table2","Table3"),													// Label of tables
161
            'tabsql'=>array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f','SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'),	// Request to select fields
162
            'tabsqlsort'=>array("label ASC","label ASC","label ASC"),																					// Sort order
163
            'tabfield'=>array("code,label","code,label","code,label"),																					// List of fields (result of select to show dictionary)
164
            'tabfieldvalue'=>array("code,label","code,label","code,label"),																				// List of fields (list of fields to edit a record)
165
            'tabfieldinsert'=>array("code,label","code,label","code,label"),																			// List of fields (list of fields for insert)
166
            'tabrowid'=>array("rowid","rowid","rowid"),																									// Name of columns with primary key (try to always name it 'rowid')
167
            'tabcond'=>array($conf->mymodule->enabled,$conf->mymodule->enabled,$conf->mymodule->enabled)												// Condition to show each dictionary
168
        );
169
        */
170
171
        // Boxes
172
		// Add here list of php file(s) stored in core/boxes that contains class to show a box.
173
        $this->boxes = array();			// List of boxes
174
		// Example:
175
		//$this->boxes=array(
176
		//    0=>array('file'=>'myboxa.php@mymodule','note'=>'','enabledbydefaulton'=>'Home'),
177
		//    1=>array('file'=>'myboxb.php@mymodule','note'=>''),
178
		//    2=>array('file'=>'myboxc.php@mymodule','note'=>'')
179
		//);
180
181
		// Cronjobs
182
		$this->cronjobs = array();			// List of cron jobs entries to add
183
		// Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'test'=>true),
184
		//                                1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'test'=>true)
185
		// );
186
187
		// Permissions
188
		$this->rights = array();		// Permission array used by this module
189
		$r=0;
190
191
		// Add here list of permission defined by an id, a label, a boolean and two constant strings.
192
		// Example:
193
		// $this->rights[$r][0] = $this->numero + $r;	// Permission id (must not be already used)
194
		// $this->rights[$r][1] = 'Permision label';	// Permission label
195
		// $this->rights[$r][3] = 1; 					// Permission by default for new user (0/1)
196
		// $this->rights[$r][4] = 'level1';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
197
		// $this->rights[$r][5] = 'level2';				// In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
198
		// $r++;
199
200
		// Main menu entries
201
		$this->menu = array();			// List of menus to add
202
		$r=0;
203
204
		// Add here entries to declare new menus
205
		//
206
		// Example to declare a new Top Menu entry and its Left menu entry:
207
		// $this->menu[$r]=array(	'fk_menu'=>'',			                // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
208
		//							'type'=>'top',			                // This is a Top menu entry
209
		//							'titre'=>'MyModule top menu',
210
		//							'mainmenu'=>'mymodule',
211
		//							'leftmenu'=>'mymodule',
212
		//							'url'=>'/mymodule/pagetop.php',
213
		//							'langs'=>'mylangfile@mymodule',	        // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
214
		//							'position'=>100,
215
		//							'enabled'=>'$conf->mymodule->enabled',	// Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
216
		//							'perms'=>'1',			                // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
217
		//							'target'=>'',
218
		//							'user'=>2);				                // 0=Menu for internal users, 1=external users, 2=both
219
		// $r++;
220
		//
221
		// Example to declare a Left Menu entry into an existing Top menu entry:
222
		// $this->menu[$r]=array(	'fk_menu'=>'fk_mainmenu=xxx',		    // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
223
		//							'type'=>'left',			                // This is a Left menu entry
224
		//							'titre'=>'MyModule left menu',
225
		//							'mainmenu'=>'xxx',
226
		//							'leftmenu'=>'mymodule',
227
		//							'url'=>'/mymodule/pagelevel2.php',
228
		//							'langs'=>'mylangfile@mymodule',	        // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
229
		//							'position'=>100,
230
		//							'enabled'=>'$conf->mymodule->enabled',  // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
231
		//							'perms'=>'1',			                // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
232
		//							'target'=>'',
233
		//							'user'=>2);				                // 0=Menu for internal users, 1=external users, 2=both
234
		// $r++;
235
236
237
		// Exports
238
		$r=1;
239
240
		// Example:
241
		// $this->export_code[$r]=$this->rights_class.'_'.$r;
242
		// $this->export_label[$r]='MyModule';	// Translation key (used only if key ExportDataset_xxx_z not found)
243
        // $this->export_enabled[$r]='1';                               // Condition to show export in list (ie: '$user->id==3'). Set to 1 to always show when module is enabled.
244
        // $this->export_icon[$r]='generic:MyModule';					// Put here code of icon then string for translation key of module name
245
		// $this->export_permission[$r]=array(array("mymodule","level1","level2"));
246
		// $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef');
247
		// $this->export_TypeFields_array[$r]=array('t.date'=>'Date', 't.qte'=>'Numeric', 't.poids'=>'Numeric', 't.fad'=>'Numeric', 't.paq'=>'Numeric', 't.stockage'=>'Numeric', 't.fadparliv'=>'Numeric', 't.livau100'=>'Numeric', 't.forfait'=>'Numeric', 's.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text','s.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text','f.facnumber'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.date_lim_reglement'=>"Date",'f.total'=>"Numeric",'f.total_ttc'=>"Numeric",'f.tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_private'=>"Text",'f.note_public'=>"Text",'fd.description'=>"Text",'fd.subprice'=>"Numeric",'fd.tva_tx'=>"Numeric",'fd.qty'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_tva'=>"Numeric",'fd.total_ttc'=>"Numeric",'fd.date_start'=>"Date",'fd.date_end'=>"Date",'fd.special_code'=>'Numeric','fd.product_type'=>"Numeric",'fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text','p.accountancy_code_sell'=>'Text');
248
		// $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','f.rowid'=>"invoice",'f.facnumber'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total'=>"invoice",'f.total_ttc'=>"invoice",'f.tva'=>"invoice",'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product');
249
		// $this->export_dependencies_array[$r]=array('invoice_line'=>'fd.rowid','product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
250
		// $this->export_sql_start[$r]='SELECT DISTINCT ';
251
		// $this->export_sql_end[$r]  =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)';
252
		// $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
253
		// $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
254
		// $this->export_sql_order[$r] .=' ORDER BY s.nom';
255
		// $r++;
256
	}
257
258
	/**
259
	 *		Function called when module is enabled.
260
	 *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
261
	 *		It also creates data directories
262
	 *
263
     *      @param      string	$options    Options when enabling module ('', 'noboxes')
264
	 *      @return     int             	1 if OK, 0 if KO
265
	 */
266
	public function init($options='')
267
	{
268
		$sql = array();
269
270
		//$this->_load_tables('/mymodule/sql/');
271
272
		return $this->_init($sql, $options);
273
	}
274
275
	/**
276
	 * Function called when module is disabled.
277
	 * Remove from database constants, boxes and permissions from Dolibarr database.
278
	 * Data directories are not deleted
279
	 *
280
	 * @param      string	$options    Options when enabling module ('', 'noboxes')
281
	 * @return     int             	1 if OK, 0 if KO
282
	 */
283
	public function remove($options = '')
284
	{
285
		$sql = array();
286
287
		return $this->_remove($sql, $options);
288
	}
289
290
}
291
292