| Conditions | 1 |
| Paths | 1 |
| Total Lines | 99 |
| 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 | function __construct($db) |
||
| 40 | { |
||
| 41 | global $langs,$conf; |
||
| 42 | |||
| 43 | $this->db = $db; |
||
| 44 | $this->numero = 10000; |
||
| 45 | |||
| 46 | // Family can be 'crm','financial','hr','projects','products','ecm','technic','other' |
||
| 47 | // It is used to group modules in module setup page |
||
| 48 | $this->family = "portal"; |
||
| 49 | $this->module_position = 50; |
||
| 50 | // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
||
| 51 | $this->name = preg_replace('/^mod/i','',get_class($this)); |
||
| 52 | $this->description = "Enable to build and serve public web sites with CMS features"; |
||
| 53 | // Possible values for version are: 'development', 'experimental', 'dolibarr' or version |
||
| 54 | $this->version = 'dolibarr'; |
||
| 55 | // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) |
||
| 56 | $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
||
| 57 | // Name of image file used for this module. |
||
| 58 | $this->picto='globe'; |
||
| 59 | |||
| 60 | // Data directories to create when module is enabled |
||
| 61 | $this->dirs = array("/website/temp"); |
||
| 62 | |||
| 63 | // Config pages |
||
| 64 | $this->config_page_url = array('website.php'); |
||
| 65 | |||
| 66 | // Dependencies |
||
| 67 | $this->hidden = ! empty($conf->global->MODULE_WEBSITE_DISABLED); // A condition to disable module |
||
| 68 | $this->depends = array('modFckeditor'); // List of modules id that must be enabled if this module is enabled |
||
| 69 | $this->requiredby = array(); // List of modules id to disable if this one is disabled |
||
| 70 | $this->conflictwith = array(); // List of modules id this module is in conflict with |
||
| 71 | $this->phpmin = array(5,4); // Minimum version of PHP required by module |
||
| 72 | $this->langfiles = array("website"); |
||
| 73 | |||
| 74 | // Constants |
||
| 75 | $this->const = array(); |
||
| 76 | |||
| 77 | // New pages on tabs |
||
| 78 | //$this->tabs[] = array(); // To add a new tab identified by code tabname1 |
||
| 79 | |||
| 80 | // Boxes |
||
| 81 | $this->boxes = array(); |
||
| 82 | |||
| 83 | // Permissions |
||
| 84 | $this->rights = array(); // Permission array used by this module |
||
| 85 | $this->rights_class = 'website'; |
||
| 86 | $r=0; |
||
| 87 | |||
| 88 | $this->rights[$r][0] = 10001; |
||
| 89 | $this->rights[$r][1] = 'Read website content'; |
||
| 90 | $this->rights[$r][3] = 0; |
||
| 91 | $this->rights[$r][4] = 'read'; |
||
| 92 | $r++; |
||
| 93 | |||
| 94 | $this->rights[$r][0] = 10002; |
||
| 95 | $this->rights[$r][1] = 'Create/modify website content'; |
||
| 96 | $this->rights[$r][3] = 0; |
||
| 97 | $this->rights[$r][4] = 'write'; |
||
| 98 | $r++; |
||
| 99 | |||
| 100 | $this->rights[$r][0] = 10003; |
||
| 101 | $this->rights[$r][1] = 'Delete website content'; |
||
| 102 | $this->rights[$r][3] = 0; |
||
| 103 | $this->rights[$r][4] = 'delete'; |
||
| 104 | $r++; |
||
| 105 | |||
| 106 | // Main menu entries |
||
| 107 | $r=0; |
||
| 108 | $this->menu[$r]=array( 'fk_menu'=>'0', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode |
||
| 109 | 'type'=>'top', // This is a Left menu entry |
||
| 110 | 'titre'=>'Websites', |
||
| 111 | 'mainmenu'=>'website', |
||
| 112 | 'url'=>'/website/index.php', |
||
| 113 | 'langs'=>'website', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. |
||
| 114 | 'position'=>100, |
||
| 115 | 'enabled'=>'$conf->website->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. |
||
| 116 | 'perms'=>'$user->rights->website->read', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules |
||
| 117 | 'target'=>'', |
||
| 118 | 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both |
||
| 119 | $r++; |
||
| 120 | |||
| 121 | // Exports |
||
| 122 | $r=1; |
||
| 123 | |||
| 124 | $this->export_code[$r]=$this->rights_class.'_'.$r; |
||
| 125 | $this->export_label[$r]='MyWebsitePages'; // Translation key (used only if key ExportDataset_xxx_z not found) |
||
| 126 | $this->export_icon[$r]='globe'; |
||
| 127 | $keyforclass = 'WebsitePage'; $keyforclassfile='/website/class/websitepage.class.php'; $keyforelement='Website'; |
||
| 128 | include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php'; |
||
| 129 | //$keyforselect='myobject'; $keyforelement='myobject'; $keyforaliasextra='extra'; |
||
| 130 | //include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
||
| 131 | //$this->export_dependencies_array[$r]=array('mysubobject'=>'ts.rowid', 't.myfield'=>array('t.myfield2','t.myfield3')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields) |
||
| 132 | $this->export_sql_start[$r]='SELECT DISTINCT '; |
||
| 133 | $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'website_page as t, '.MAIN_DB_PREFIX.'website as p'; |
||
| 134 | $this->export_sql_end[$r] .=' WHERE t.fk_website = p.rowid'; |
||
| 135 | $this->export_sql_end[$r] .=' AND p.entity IN ('.getEntity('website').')'; |
||
| 136 | $r++; |
||
| 137 | } |
||
| 138 | |||
| 181 |