Conditions | 2 |
Paths | 2 |
Total Lines | 131 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
49 | public function __construct($db) |
||
50 | { |
||
51 | global $langs, $conf; |
||
52 | |||
53 | $this->db = $db; |
||
54 | |||
55 | // Id for module (must be unique). |
||
56 | // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). |
||
57 | $this->numero = 2610; |
||
58 | // Key text used to identify module (for permissions, menus, etc...) |
||
59 | $this->rights_class = 'api'; |
||
60 | |||
61 | // Family can be 'crm','financial','hr','projects','products','ecm','technic','other' |
||
62 | // It is used to group modules in module setup page |
||
63 | $this->family = "interface"; |
||
64 | $this->module_position = '24'; |
||
65 | // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
||
66 | $this->name = preg_replace('/^mod/i', '', get_only_class($this)); |
||
67 | // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) |
||
68 | $this->description = "REST interface"; |
||
69 | // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version |
||
70 | $this->version = 'dolibarr'; |
||
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_' . static::getNameOf($this->name); // strtoupper($this->name); |
||
73 | // Can be enabled / disabled only in the main company with superadmin account |
||
74 | $this->core_enabled = 1; |
||
75 | // Name of image file used for this module. |
||
76 | // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' |
||
77 | // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' |
||
78 | $this->picto = 'technic'; |
||
79 | |||
80 | $this->module_parts = array(); |
||
81 | |||
82 | // Data directories to create when module is enabled. |
||
83 | // Example: this->dirs = array("/api/temp"); |
||
84 | $this->dirs = array('/api/temp'); |
||
85 | |||
86 | // Config pages. Put here list of php page, stored into api/admin directory, to use to setup module. |
||
87 | $this->config_page_url = array("index.php@api"); |
||
88 | |||
89 | // Dependencies |
||
90 | $this->hidden = false; // A condition to hide module |
||
91 | $this->depends = array(); // List of modules id that must be enabled if this module is enabled |
||
92 | $this->requiredby = array('modZapier'); // List of modules id to disable if this one is disabled |
||
93 | $this->conflictwith = array(); // List of modules id this module is in conflict with |
||
94 | $this->phpmin = array(7, 0); // Minimum version of PHP required by module |
||
95 | $this->langfiles = array("other"); |
||
96 | |||
97 | // Constants |
||
98 | // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive) |
||
99 | // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',1), |
||
100 | // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1) |
||
101 | // ); |
||
102 | $this->const = array(); |
||
103 | |||
104 | // Array to add new pages in new tabs |
||
105 | // Example: $this->tabs = array('objecttype:+tabname1:Title1:mylangfile@api:$user->hasRight('api','read'):/api/mynewtab1.php?id=__ID__', // To add a new tab identified by code tabname1 |
||
106 | // 'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@api:$user->hasRight('othermodule','read'):/api/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. |
||
107 | // 'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname |
||
108 | // where objecttype can be |
||
109 | // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member) |
||
110 | // 'contact' to add a tab in contact view |
||
111 | // 'contract' to add a tab in contract view |
||
112 | // 'group' to add a tab in group view |
||
113 | // 'intervention' to add a tab in intervention view |
||
114 | // 'invoice' to add a tab in customer invoice view |
||
115 | // 'invoice_supplier' to add a tab in supplier invoice view |
||
116 | // 'member' to add a tab in foundation member view |
||
117 | // 'opensurveypoll' to add a tab in opensurvey poll view |
||
118 | // 'order' to add a tab in sales order view |
||
119 | // 'order_supplier' to add a tab in supplier order view |
||
120 | // 'payment' to add a tab in payment view |
||
121 | // 'payment_supplier' to add a tab in supplier payment view |
||
122 | // 'product' to add a tab in product view |
||
123 | // 'propal' to add a tab in propal view |
||
124 | // 'project' to add a tab in project view |
||
125 | // 'stock' to add a tab in stock view |
||
126 | // 'thirdparty' to add a tab in third party view |
||
127 | // 'user' to add a tab in user view |
||
128 | $this->tabs = array(); |
||
129 | |||
130 | // Dictionaries |
||
131 | if (!isset($conf->api->enabled)) { |
||
132 | $conf->api = new stdClass(); |
||
133 | $conf->api->enabled = 0; |
||
134 | } |
||
135 | $this->dictionaries = array(); |
||
136 | |||
137 | // Boxes |
||
138 | // Add here list of php file(s) stored in core/boxes that contains class to show a box. |
||
139 | $this->boxes = array(); // List of boxes |
||
140 | // Example: |
||
141 | //$this->boxes=array(array(0=>array('file'=>'myboxa.php','note'=>'','enabledbydefaulton'=>'Home'),1=>array('file'=>'myboxb.php','note'=>''),2=>array('file'=>'myboxc.php','note'=>''));); |
||
142 | |||
143 | // Permissions |
||
144 | $this->rights = array(); // Permission array used by this module |
||
145 | $this->rights_admin_allowed = 1; // Admin is always granted of permission (even when module is disabled) |
||
146 | |||
147 | $r = 0; |
||
148 | |||
149 | // Add here list of permission defined by an id, a label, a boolean and two constant strings. |
||
150 | // Example: |
||
151 | $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) |
||
152 | $this->rights[$r][1] = 'Generate/modify users API key'; // Permission label |
||
153 | $this->rights[$r][3] = 0; // Permission by default for new user (0/1) |
||
154 | $this->rights[$r][4] = 'apikey'; // In php code, permission will be checked by test if ($user->hasRight('permkey','level1','level2')) |
||
155 | $this->rights[$r][5] = 'generate'; // In php code, permission will be checked by test if ($user->hasRight('permkey','level1','level2')) |
||
156 | $r++; |
||
157 | |||
158 | |||
159 | // Main menu entries |
||
160 | $this->menu = array(); // List of menus to add |
||
161 | $r = 0; |
||
162 | |||
163 | $this->menu[$r] = array('fk_menu' => 'fk_mainmenu=tools', |
||
164 | 'type' => 'left', |
||
165 | 'titre' => 'ApiExplorer', |
||
166 | 'prefix' => img_picto('', $this->picto, 'class="paddingright pictofixedwidth"'), |
||
167 | 'mainmenu' => 'tools', |
||
168 | 'leftmenu' => 'devtools_api', |
||
169 | 'url' => '/api/index.php/explorer', |
||
170 | 'langs' => 'modulebuilder', |
||
171 | 'position' => 100, |
||
172 | 'perms' => '1', |
||
173 | 'enabled' => 'isModEnabled("api")', |
||
174 | 'target' => '_apiexplorer', |
||
175 | 'user' => 0); |
||
176 | |||
177 | |||
178 | // Exports |
||
179 | $r = 1; |
||
180 | |||
256 |