| Conditions | 3 |
| Paths | 2 |
| Total Lines | 171 |
| Code Lines | 36 |
| 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 |
||
| 39 | public function __construct($db) |
||
| 40 | { |
||
| 41 | global $langs,$conf; |
||
| 42 | |||
| 43 | $this->db = $db; |
||
| 44 | |||
| 45 | // Id for module (must be unique). |
||
| 46 | // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). |
||
| 47 | $this->numero = 50320; |
||
| 48 | // Key text used to identify module (for permissions, menus, etc...) |
||
| 49 | $this->rights_class = 'emailcollector'; |
||
| 50 | |||
| 51 | // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...' |
||
| 52 | // It is used to group modules by family in module setup page |
||
| 53 | $this->family = "interface"; |
||
| 54 | // Module position in the family on 2 digits ('01', '10', '20', ...) |
||
| 55 | $this->module_position = '12'; |
||
| 56 | // 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) |
||
| 57 | //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily"))); |
||
| 58 | |||
| 59 | // Module label (no space allowed), used if translation string 'ModuledavName' not found (MyModue is name of module). |
||
| 60 | $this->name = preg_replace('/^mod/i', '', get_class($this)); |
||
| 61 | // Module description, used if translation string 'ModuledavDesc' not found (MyModue is name of module). |
||
| 62 | $this->description = "EmailCollectorDescription"; |
||
| 63 | // Used only if file README.md and README-LL.md not found. |
||
| 64 | $this->descriptionlong = "EmailCollectorDescription"; |
||
| 65 | |||
| 66 | // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z' |
||
| 67 | $this->version = 'dolibarr'; |
||
| 68 | // Key used in llx_const table to save module status enabled/disabled (where DAV is value of property name of module in uppercase) |
||
| 69 | $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
||
| 70 | // Name of image file used for this module. |
||
| 71 | // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' |
||
| 72 | // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' |
||
| 73 | $this->picto='email'; |
||
| 74 | |||
| 75 | // Defined all module parts (triggers, login, substitutions, menus, css, etc...) |
||
| 76 | // for default path (eg: /dav/core/xxxxx) (0=disable, 1=enable) |
||
| 77 | // for specific path of parts (eg: /dav/core/modules/barcode) |
||
| 78 | // for specific css file (eg: /dav/css/dav.css.php) |
||
| 79 | $this->module_parts = array(); |
||
| 80 | |||
| 81 | // Data directories to create when module is enabled. |
||
| 82 | // Example: this->dirs = array("/dav/temp","/dav/subdir"); |
||
| 83 | $this->dirs = array(); |
||
| 84 | |||
| 85 | // Config pages. Put here list of php page, stored into dav/admin directory, to use to setup module. |
||
| 86 | $this->config_page_url = array("emailcollector_list.php"); |
||
| 87 | |||
| 88 | // Dependencies |
||
| 89 | $this->hidden = false; // A condition to hide module |
||
| 90 | $this->depends = array('always'=>'modCron'); // List of module class names as string that must be enabled if this module is enabled |
||
| 91 | $this->requiredby = array(); // List of module ids to disable if this one is disabled |
||
| 92 | $this->conflictwith = array(); // List of module class names as string this module is in conflict with |
||
| 93 | $this->langfiles = array("admin"); |
||
| 94 | $this->phpmin = array(5,4); // Minimum version of PHP required by module |
||
| 95 | $this->need_dolibarr_version = array(7,0); // Minimum version of Dolibarr required by module |
||
| 96 | $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
||
| 97 | $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
||
| 98 | //$this->automatic_activation = array('FR'=>'davWasAutomaticallyActivatedBecauseOfYourCountryChoice'); |
||
| 99 | //$this->always_enabled = true; // If true, can't be disabled |
||
| 100 | |||
| 101 | // Constants |
||
| 102 | // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive) |
||
| 103 | // Example: $this->const=array(0=>array('DAV_MYNEWCONST1','chaine','myvalue','This is a constant to add',1), |
||
| 104 | // 1=>array('DAV_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1) |
||
| 105 | // ); |
||
| 106 | $this->const = array( |
||
| 107 | //1=>array('DAV_MYCONSTANT', 'chaine', 'avalue', 'This is a constant to add', 1, 'allentities', 1) |
||
| 108 | ); |
||
| 109 | |||
| 110 | |||
| 111 | if (! isset($conf->dav) || ! isset($conf->dav->enabled)) |
||
| 112 | { |
||
| 113 | $conf->dav=new stdClass(); |
||
| 114 | $conf->dav->enabled=0; |
||
| 115 | } |
||
| 116 | |||
| 117 | |||
| 118 | // Array to add new pages in new tabs |
||
| 119 | $this->tabs = array(); |
||
| 120 | // Example: |
||
| 121 | // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@dav:$user->rights->dav->read:/dav/mynewtab1.php?id=__ID__'); // To add a new tab identified by code tabname1 |
||
| 122 | // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@dav:$user->rights->othermodule->read:/dav/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. |
||
| 123 | // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname |
||
| 124 | // |
||
| 125 | // Where objecttype can be |
||
| 126 | // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member) |
||
| 127 | // 'contact' to add a tab in contact view |
||
| 128 | // 'contract' to add a tab in contract view |
||
| 129 | // 'group' to add a tab in group view |
||
| 130 | // 'intervention' to add a tab in intervention view |
||
| 131 | // 'invoice' to add a tab in customer invoice view |
||
| 132 | // 'invoice_supplier' to add a tab in supplier invoice view |
||
| 133 | // 'member' to add a tab in fundation member view |
||
| 134 | // 'opensurveypoll' to add a tab in opensurvey poll view |
||
| 135 | // 'order' to add a tab in customer order view |
||
| 136 | // 'order_supplier' to add a tab in supplier order view |
||
| 137 | // 'payment' to add a tab in payment view |
||
| 138 | // 'payment_supplier' to add a tab in supplier payment view |
||
| 139 | // 'product' to add a tab in product view |
||
| 140 | // 'propal' to add a tab in propal view |
||
| 141 | // 'project' to add a tab in project view |
||
| 142 | // 'stock' to add a tab in stock view |
||
| 143 | // 'thirdparty' to add a tab in third party view |
||
| 144 | // 'user' to add a tab in user view |
||
| 145 | |||
| 146 | |||
| 147 | // Dictionaries |
||
| 148 | $this->dictionaries=array(); |
||
| 149 | /* Example: |
||
| 150 | $this->dictionaries=array( |
||
| 151 | 'langs'=>'mylangfile@dav', |
||
| 152 | 'tabname'=>array(MAIN_DB_PREFIX."table1",MAIN_DB_PREFIX."table2",MAIN_DB_PREFIX."table3"), // List of tables we want to see into dictonnary editor |
||
| 153 | 'tablib'=>array("Table1","Table2","Table3"), // Label of tables |
||
| 154 | '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 |
||
| 155 | 'tabsqlsort'=>array("label ASC","label ASC","label ASC"), // Sort order |
||
| 156 | 'tabfield'=>array("code,label","code,label","code,label"), // List of fields (result of select to show dictionary) |
||
| 157 | 'tabfieldvalue'=>array("code,label","code,label","code,label"), // List of fields (list of fields to edit a record) |
||
| 158 | 'tabfieldinsert'=>array("code,label","code,label","code,label"), // List of fields (list of fields for insert) |
||
| 159 | 'tabrowid'=>array("rowid","rowid","rowid"), // Name of columns with primary key (try to always name it 'rowid') |
||
| 160 | 'tabcond'=>array($conf->dav->enabled,$conf->dav->enabled,$conf->dav->enabled) // Condition to show each dictionary |
||
| 161 | ); |
||
| 162 | */ |
||
| 163 | |||
| 164 | |||
| 165 | // Boxes/Widgets |
||
| 166 | // Add here list of php file(s) stored in dav/core/boxes that contains class to show a widget. |
||
| 167 | $this->boxes = array( |
||
| 168 | //0=>array('file'=>'davwidget1.php@dav','note'=>'Widget provided by dav','enabledbydefaulton'=>'Home'), |
||
| 169 | //1=>array('file'=>'davwidget2.php@dav','note'=>'Widget provided by dav'), |
||
| 170 | //2=>array('file'=>'davwidget3.php@dav','note'=>'Widget provided by dav') |
||
| 171 | ); |
||
| 172 | |||
| 173 | |||
| 174 | // Cronjobs (List of cron jobs entries to add when module is enabled) |
||
| 175 | // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week |
||
| 176 | $this->cronjobs = array( |
||
| 177 | 0=>array('label'=>'Email collector', 'priority'=>50, 'jobtype'=>'method', 'class'=>'/emailcollector/class/emailcollector.class.php', 'objectname'=>'EmailCollector', 'method'=>'doCollect', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>5, 'unitfrequency'=>60, 'status'=>1, 'test'=>'$conf->emailcollector->enabled') |
||
| 178 | ); |
||
| 179 | |||
| 180 | |||
| 181 | // Permissions |
||
| 182 | $this->rights = array(); // Permission array used by this module |
||
| 183 | |||
| 184 | /* |
||
| 185 | $r=0; |
||
| 186 | $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) |
||
| 187 | $this->rights[$r][1] = 'Read myobject of dav'; // Permission label |
||
| 188 | $this->rights[$r][3] = 0; // Permission by default for new user (0/1) |
||
| 189 | $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->dav->level1->level2) |
||
| 190 | $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->dav->level1->level2) |
||
| 191 | |||
| 192 | $r++; |
||
| 193 | $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) |
||
| 194 | $this->rights[$r][1] = 'Create/Update myobject of dav'; // Permission label |
||
| 195 | $this->rights[$r][3] = 0; // Permission by default for new user (0/1) |
||
| 196 | $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->dav->level1->level2) |
||
| 197 | $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->dav->level1->level2) |
||
| 198 | |||
| 199 | $r++; |
||
| 200 | $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) |
||
| 201 | $this->rights[$r][1] = 'Delete myobject of dav'; // Permission label |
||
| 202 | $this->rights[$r][3] = 0; // Permission by default for new user (0/1) |
||
| 203 | $this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->dav->level1->level2) |
||
| 204 | $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->dav->level1->level2) |
||
| 205 | */ |
||
| 206 | |||
| 207 | // Main menu entries |
||
| 208 | $this->menu = array(); // List of menus to add |
||
| 209 | $r=0; |
||
| 210 | |||
| 353 |