| Conditions | 2 |
| Paths | 2 |
| Total Lines | 243 |
| Code Lines | 52 |
| 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 |
||
| 46 | public function __construct($db) |
||
| 47 | { |
||
| 48 | global $conf; |
||
| 49 | $this->db = $db; |
||
| 50 | |||
| 51 | // Id for module (must be unique). |
||
| 52 | // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). |
||
| 53 | $this->numero = 11000; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve an id number for your module |
||
| 54 | |||
| 55 | // Key text used to identify module (for permissions, menus, etc...) |
||
| 56 | $this->rights_class = 'webportal'; |
||
| 57 | |||
| 58 | // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...' |
||
| 59 | // It is used to group modules by family in module setup page |
||
| 60 | $this->family = "portal"; |
||
| 61 | |||
| 62 | // Module position in the family on 2 digits ('01', '10', '20', ...) |
||
| 63 | $this->module_position = '47'; |
||
| 64 | |||
| 65 | // Gives the possibility for the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this) |
||
| 66 | //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily"))); |
||
| 67 | // Module label (no space allowed), used if translation string 'ModuleWebPortalName' not found (WebPortal is name of module). |
||
| 68 | $this->name = preg_replace('/^mod/i', '', get_only_class($this)); |
||
| 69 | |||
| 70 | // Module description, used if translation string 'ModuleWebPortalDesc' not found (WebPortal is name of module). |
||
| 71 | $this->description = "WebPortalDescription"; |
||
| 72 | // Used only if file README.md and README-LL.md not found. |
||
| 73 | $this->descriptionlong = "WebPortalDescription"; |
||
| 74 | |||
| 75 | // Author |
||
| 76 | //$this->editor_name = 'Dolibarr'; |
||
| 77 | //$this->editor_url = 'dolibarr.org'; |
||
| 78 | |||
| 79 | // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated', 'experimental_deprecated' or a version string like 'x.y.z' |
||
| 80 | $this->version = 'experimental'; |
||
| 81 | // Url to the file with your last numberversion of this module |
||
| 82 | //$this->url_last_version = 'http://www.example.com/versionmodule.txt'; |
||
| 83 | |||
| 84 | // Key used in llx_const table to save module status enabled/disabled (where WEBPORTAL is value of property name of module in uppercase) |
||
| 85 | $this->const_name = 'MAIN_MODULE_' . static::getNameOf($this->name); // strtoupper($this->name); |
||
| 86 | |||
| 87 | // Name of image file used for this module. |
||
| 88 | // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' |
||
| 89 | // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' |
||
| 90 | // To use a supported fa-xxx css style of font awesome, use this->picto='xxx' |
||
| 91 | $this->picto = 'fa-door-open'; |
||
| 92 | |||
| 93 | // Define some features supported by module (triggers, login, substitutions, menus, css, etc...) |
||
| 94 | $this->module_parts = array( |
||
| 95 | // Set this to 1 if module has its own trigger directory (core/triggers) |
||
| 96 | 'triggers' => 0, |
||
| 97 | // Set this to 1 if module has its own login method file (core/login) |
||
| 98 | 'login' => 0, |
||
| 99 | // Set this to 1 if module has its own substitution function file (core/substitutions) |
||
| 100 | 'substitutions' => 0, |
||
| 101 | // Set this to 1 if module has its own menus handler directory (core/menus) |
||
| 102 | 'menus' => 0, |
||
| 103 | // Set this to 1 if module overwrite template dir (core/tpl) |
||
| 104 | 'tpl' => 0, |
||
| 105 | // Set this to 1 if module has its own barcode directory (core/modules/barcode) |
||
| 106 | 'barcode' => 0, |
||
| 107 | // Set this to 1 if module has its own models directory (core/modules/xxx) |
||
| 108 | 'models' => 0, |
||
| 109 | // Set this to 1 if module has its own printing directory (core/modules/printing) |
||
| 110 | 'printing' => 0, |
||
| 111 | // Set this to 1 if module has its own theme directory (theme) |
||
| 112 | 'theme' => 0, |
||
| 113 | // Set this to relative path of css file if module has its own css file |
||
| 114 | 'css' => array(// '/webportal/css/webportal.css.php', |
||
| 115 | ), |
||
| 116 | // Set this to relative path of js file if module must load a js on all pages |
||
| 117 | 'js' => array(// '/webportal/js/webportal.js.php', |
||
| 118 | ), |
||
| 119 | // Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context to 'all' |
||
| 120 | 'hooks' => array( |
||
| 121 | // 'data' => array( |
||
| 122 | // 'hookcontext1', |
||
| 123 | // 'hookcontext2', |
||
| 124 | // ), |
||
| 125 | // 'entity' => '0', |
||
| 126 | ), |
||
| 127 | // Set this to 1 if features of module are opened to external users |
||
| 128 | 'moduleforexternal' => 0, |
||
| 129 | ); |
||
| 130 | |||
| 131 | // Data directories to create when module is enabled. |
||
| 132 | // Example: this->dirs = array("/webportal/temp","/webportal/subdir"); |
||
| 133 | $this->dirs = array("/webportal/temp"); |
||
| 134 | |||
| 135 | // Config pages. Put here list of php page, stored into webportal/admin directory, to use to setup module. |
||
| 136 | $this->config_page_url = array("setup.php@webportal"); |
||
| 137 | |||
| 138 | // Dependencies |
||
| 139 | // A condition to hide module |
||
| 140 | $this->hidden = false; |
||
| 141 | // List of module class names that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR')...) |
||
| 142 | $this->depends = array(); |
||
| 143 | // List of module class names to disable if this one is disabled. Example: array('modModuleToDisable1', ...) |
||
| 144 | $this->requiredby = array(); |
||
| 145 | // List of module class names this module is in conflict with. Example: array('modModuleToDisable1', ...) |
||
| 146 | $this->conflictwith = array(); |
||
| 147 | |||
| 148 | // The language file dedicated to your module |
||
| 149 | $this->langfiles = array("website"); |
||
| 150 | |||
| 151 | // Prerequisites |
||
| 152 | $this->phpmin = array(7, 0); // Minimum version of PHP required by module |
||
| 153 | //$this->need_dolibarr_version = array(11, -3); // Minimum version of Dolibarr required by module |
||
| 154 | //$this->need_javascript_ajax = 0; |
||
| 155 | |||
| 156 | // Messages at activation |
||
| 157 | $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','MX'='textmx'...) |
||
| 158 | $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','MX'='textmx'...) |
||
| 159 | //$this->automatic_activation = array('FR'=>'WebPortalWasAutomaticallyActivatedBecauseOfYourCountryChoice'); |
||
| 160 | //$this->always_enabled = true; // If true, can't be disabled |
||
| 161 | |||
| 162 | // Constants |
||
| 163 | // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive) |
||
| 164 | // Example: $this->const=array(1 => array('WEBPORTAL_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1), |
||
| 165 | // 2 => array('WEBPORTAL_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1) |
||
| 166 | // ); |
||
| 167 | $this->const = array(); |
||
| 168 | |||
| 169 | // Some keys to add into the overwriting translation tables |
||
| 170 | /*$this->overwrite_translation = array( |
||
| 171 | 'en_US:ParentCompany'=>'Parent company or reseller', |
||
| 172 | 'fr_FR:ParentCompany'=>'Maison mère ou revendeur' |
||
| 173 | )*/ |
||
| 174 | |||
| 175 | // To avoid warnings |
||
| 176 | if (isModEnabled('webportal')) { |
||
| 177 | $conf->webportal = new stdClass(); |
||
| 178 | $conf->webportal->enabled = 0; |
||
| 179 | } |
||
| 180 | |||
| 181 | // Array to add new pages in new tabs |
||
| 182 | $this->tabs = array(); |
||
| 183 | // Example: |
||
| 184 | // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@webportal:$user->rights->webportal->read:/webportal/mynewtab1.php?id=__ID__'); // To add a new tab identified by code tabname1 |
||
| 185 | // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@webportal:$user->rights->othermodule->read:/webportal/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. |
||
| 186 | // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname |
||
| 187 | // |
||
| 188 | // Where objecttype can be |
||
| 189 | // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member) |
||
| 190 | // 'contact' to add a tab in contact view |
||
| 191 | // 'contract' to add a tab in contract view |
||
| 192 | // 'group' to add a tab in group view |
||
| 193 | // 'intervention' to add a tab in intervention view |
||
| 194 | // 'invoice' to add a tab in customer invoice view |
||
| 195 | // 'invoice_supplier' to add a tab in supplier invoice view |
||
| 196 | // 'member' to add a tab in foundation member view |
||
| 197 | // 'opensurveypoll' to add a tab in opensurvey poll view |
||
| 198 | // 'order' to add a tab in sale order view |
||
| 199 | // 'order_supplier' to add a tab in supplier order view |
||
| 200 | // 'payment' to add a tab in payment view |
||
| 201 | // 'payment_supplier' to add a tab in supplier payment view |
||
| 202 | // 'product' to add a tab in product view |
||
| 203 | // 'propal' to add a tab in propal view |
||
| 204 | // 'project' to add a tab in project view |
||
| 205 | // 'stock' to add a tab in stock view |
||
| 206 | // 'thirdparty' to add a tab in third party view |
||
| 207 | // 'user' to add a tab in user view |
||
| 208 | |||
| 209 | // Dictionaries |
||
| 210 | $this->dictionaries = array(); |
||
| 211 | /* Example: |
||
| 212 | $this->dictionaries=array( |
||
| 213 | 'langs'=>'website', |
||
| 214 | // List of tables we want to see into dictonnary editor |
||
| 215 | 'tabname'=>array("table1", "table2", "table3"), |
||
| 216 | // Label of tables |
||
| 217 | 'tablib'=>array("Table1", "Table2", "Table3"), |
||
| 218 | // Request to select fields |
||
| 219 | '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'), |
||
| 220 | // Sort order |
||
| 221 | 'tabsqlsort'=>array("label ASC", "label ASC", "label ASC"), |
||
| 222 | // List of fields (result of select to show dictionary) |
||
| 223 | 'tabfield'=>array("code,label", "code,label", "code,label"), |
||
| 224 | // List of fields (list of fields to edit a record) |
||
| 225 | 'tabfieldvalue'=>array("code,label", "code,label", "code,label"), |
||
| 226 | // List of fields (list of fields for insert) |
||
| 227 | 'tabfieldinsert'=>array("code,label", "code,label", "code,label"), |
||
| 228 | // Name of columns with primary key (try to always name it 'rowid') |
||
| 229 | 'tabrowid'=>array("rowid", "rowid", "rowid"), |
||
| 230 | // Condition to show each dictionary |
||
| 231 | 'tabcond'=>array(isModEnabled('webportal'), isModEnabled('webportal'), isModEnabled('webportal')), |
||
| 232 | // Tooltip for every fields of dictionaries: DO NOT PUT AN EMPTY ARRAY |
||
| 233 | 'tabhelp'=>array(array('code'=>$langs->trans('CodeTooltipHelp'), 'field2' => 'field2tooltip'), array('code'=>$langs->trans('CodeTooltipHelp'), 'field2' => 'field2tooltip'), ...), |
||
| 234 | ); |
||
| 235 | */ |
||
| 236 | |||
| 237 | // Boxes/Widgets |
||
| 238 | // Add here list of php file(s) stored in webportal/core/boxes that contains a class to show a widget. |
||
| 239 | $this->boxes = array( |
||
| 240 | // 0 => array( |
||
| 241 | // 'file' => 'webportalwidget1.php@webportal', |
||
| 242 | // 'note' => 'Widget provided by WebPortal', |
||
| 243 | // 'enabledbydefaulton' => 'Home', |
||
| 244 | // ), |
||
| 245 | // ... |
||
| 246 | ); |
||
| 247 | |||
| 248 | // Cronjobs (List of cron jobs entries to add when module is enabled) |
||
| 249 | // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week |
||
| 250 | $this->cronjobs = array( |
||
| 251 | // 0 => array( |
||
| 252 | // 'label' => 'MyJob label', |
||
| 253 | // 'jobtype' => 'method', |
||
| 254 | // 'class' => '/webportal/class/webportalpropal.class.php', |
||
| 255 | // 'objectname' => 'WebPortalPropal', |
||
| 256 | // 'method' => 'doScheduledJob', |
||
| 257 | // 'parameters' => '', |
||
| 258 | // 'comment' => 'Comment', |
||
| 259 | // 'frequency' => 2, |
||
| 260 | // 'unitfrequency' => 3600, |
||
| 261 | // 'status' => 0, |
||
| 262 | // 'test' => 'isModEnabled("webportal")', |
||
| 263 | // 'priority' => 50, |
||
| 264 | // ), |
||
| 265 | ); |
||
| 266 | // Example: $this->cronjobs=array( |
||
| 267 | // 0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>'isModEnabled("webportal")', 'priority'=>50), |
||
| 268 | // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>'isModEnabled("webportal")', 'priority'=>50) |
||
| 269 | // ); |
||
| 270 | |||
| 271 | // Permissions provided by this module |
||
| 272 | $this->rights = array(); |
||
| 273 | $r = 0; |
||
| 274 | // Add here entries to declare new permissions |
||
| 275 | $this->rights[$r][0] = $this->numero . sprintf("%02d", $r + 1); // Permission id (must not be already used) |
||
| 276 | $this->rights[$r][1] = 'Administer users of the customer/partner webportal module'; // Permission label |
||
| 277 | $this->rights[$r][3] = 0; |
||
| 278 | $this->rights[$r][4] = 'write'; |
||
| 279 | //$r++; |
||
| 280 | //$this->rights[$r][0] = $this->numero . sprintf("%02d", $r + 1); // Permission id (must not be already used) |
||
| 281 | //$this->rights[$r][1] = 'Delete objects of WebPortal'; // Permission label |
||
| 282 | //$this->rights[$r][3] = 0; |
||
| 283 | //$this->rights[$r][4] = 'delete'; |
||
| 284 | //$r++; |
||
| 285 | |||
| 286 | // Main menu entries to add |
||
| 287 | $this->menu = array(); |
||
| 288 | $r = 0; |
||
| 289 | // Add here entries to declare new menus |
||
| 384 |