| Conditions | 23 |
| Paths | 84 |
| Total Lines | 163 |
| Code Lines | 72 |
| 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 |
||
| 57 | public function index(bool $executeActions = true): bool |
||
| 58 | { |
||
| 59 | global $conf; |
||
| 60 | global $db; |
||
| 61 | global $user; |
||
| 62 | global $hookmanager; |
||
| 63 | global $user; |
||
| 64 | global $menumanager; |
||
| 65 | global $langs; |
||
| 66 | |||
| 67 | |||
| 68 | // Translations |
||
| 69 | $langs->loadLangs(["admin", "agenda"]); |
||
| 70 | |||
| 71 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
||
| 72 | $hookmanager->initHooks(['bookcalsetup', 'globalsetup']); |
||
| 73 | |||
| 74 | // Access control |
||
| 75 | if (!$user->admin) { |
||
| 76 | accessforbidden(); |
||
| 77 | } |
||
| 78 | |||
| 79 | // Parameters |
||
| 80 | $action = GETPOST('action', 'aZ09'); |
||
| 81 | $backtopage = GETPOST('backtopage', 'alpha'); |
||
| 82 | $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php |
||
| 83 | |||
| 84 | $value = GETPOST('value', 'alpha'); |
||
| 85 | $label = GETPOST('label', 'alpha'); |
||
| 86 | $scandir = GETPOST('scan_dir', 'alpha'); |
||
| 87 | $type = 'myobject'; |
||
| 88 | |||
| 89 | |||
| 90 | $error = 0; |
||
| 91 | $setupnotempty = 0; |
||
| 92 | |||
| 93 | // Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only |
||
| 94 | $useFormSetup = 1; |
||
| 95 | |||
| 96 | $formSetup = new FormSetup($db); |
||
| 97 | |||
| 98 | // Setup conf BOOKCAL_PUBLIC_INTERFACE_TOPIC |
||
| 99 | $item = $formSetup->newItem('BOOKCAL_PUBLIC_INTERFACE_TOPIC'); |
||
| 100 | $item->defaultFieldValue = 'MyBigCompany public interface for Bookcal'; |
||
| 101 | /*// Setup conf BOOKCAL_MYPARAM8 |
||
| 102 | $item = $formSetup->newItem('BOOKCAL_MYPARAM8'); |
||
| 103 | $TField = array( |
||
| 104 | 'test01' => $langs->trans('test01'), |
||
| 105 | 'test02' => $langs->trans('test02'), |
||
| 106 | 'test03' => $langs->trans('test03'), |
||
| 107 | 'test04' => $langs->trans('test04'), |
||
| 108 | 'test05' => $langs->trans('test05'), |
||
| 109 | 'test06' => $langs->trans('test06'), |
||
| 110 | ); |
||
| 111 | $item->setAsMultiSelect($TField); |
||
| 112 | $item->helpText = $langs->transnoentities('BOOKCAL_MYPARAM8'); |
||
| 113 | |||
| 114 | |||
| 115 | // Setup conf BOOKCAL_MYPARAM9 |
||
| 116 | $formSetup->newItem('BOOKCAL_MYPARAM9')->setAsSelect($TField); |
||
| 117 | |||
| 118 | |||
| 119 | // Setup conf BOOKCAL_MYPARAM10 |
||
| 120 | $item = $formSetup->newItem('BOOKCAL_MYPARAM10'); |
||
| 121 | $item->setAsColor(); |
||
| 122 | $item->defaultFieldValue = '#FF0000'; |
||
| 123 | $item->nameText = $item->getNameText().' more html text '; |
||
| 124 | $item->fieldInputOverride = ''; |
||
| 125 | $item->helpText = $langs->transnoentities('AnHelpMessage');*/ |
||
| 126 | //$item->fieldValue = ''; |
||
| 127 | //$item->fieldAttr = array() ; // fields attribute only for compatible fields like input text |
||
| 128 | //$item->fieldOverride = false; // set this var to override field output will override $fieldInputOverride and $fieldOutputOverride too |
||
| 129 | //$item->fieldInputOverride = false; // set this var to override field input |
||
| 130 | //$item->fieldOutputOverride = false; // set this var to override field output |
||
| 131 | |||
| 132 | |||
| 133 | $setupnotempty = +count($formSetup->items); |
||
| 134 | |||
| 135 | |||
| 136 | $dirmodels = array_merge(['/'], (array) $conf->modules_parts['models']); |
||
| 137 | |||
| 138 | |||
| 139 | /* |
||
| 140 | * Actions |
||
| 141 | */ |
||
| 142 | |||
| 143 | // For retrocompatibility Dolibarr < 15.0 |
||
| 144 | if (versioncompare(explode('.', DOL_VERSION), [15]) < 0 && $action == 'update' && !empty($user->admin)) { |
||
|
|
|||
| 145 | $formSetup->saveConfFromPost(); |
||
| 146 | } |
||
| 147 | |||
| 148 | include DOL_DOCUMENT_ROOT . '/core/actions_setmoduleoptions.inc.php'; |
||
| 149 | |||
| 150 | if ($action == 'updateMask') { |
||
| 151 | $maskconst = GETPOST('maskconst', 'aZ09'); |
||
| 152 | $maskvalue = GETPOST('maskvalue', 'alpha'); |
||
| 153 | |||
| 154 | if ($maskconst && preg_match('/_MASK$/', $maskconst)) { |
||
| 155 | $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity); |
||
| 156 | if (!($res > 0)) { |
||
| 157 | $error++; |
||
| 158 | } |
||
| 159 | } |
||
| 160 | |||
| 161 | if (!$error) { |
||
| 162 | setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); |
||
| 163 | } else { |
||
| 164 | setEventMessages($langs->trans("Error"), null, 'errors'); |
||
| 165 | } |
||
| 166 | } elseif ($action == 'setmod') { |
||
| 167 | // TODO Check if numbering module chosen can be activated by calling method canBeActivated |
||
| 168 | $tmpobjectkey = GETPOST('object', 'aZ09'); |
||
| 169 | if (!empty($tmpobjectkey)) { |
||
| 170 | $constforval = 'BOOKCAL_' . strtoupper($tmpobjectkey) . "_ADDON"; |
||
| 171 | dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity); |
||
| 172 | } |
||
| 173 | } elseif ($action == 'set') { |
||
| 174 | // Activate a model |
||
| 175 | $ret = addDocumentModel($value, $type, $label, $scandir); |
||
| 176 | } elseif ($action == 'del') { |
||
| 177 | $ret = delDocumentModel($value, $type); |
||
| 178 | if ($ret > 0) { |
||
| 179 | $tmpobjectkey = GETPOST('object', 'aZ09'); |
||
| 180 | if (!empty($tmpobjectkey)) { |
||
| 181 | $constforval = 'BOOKCAL_' . strtoupper($tmpobjectkey) . '_ADDON_PDF'; |
||
| 182 | if (getDolGlobalString($constforval) == "$value") { |
||
| 183 | dolibarr_del_const($db, $constforval, $conf->entity); |
||
| 184 | } |
||
| 185 | } |
||
| 186 | } |
||
| 187 | } elseif ($action == 'setdoc') { |
||
| 188 | // Set or unset default model |
||
| 189 | $tmpobjectkey = GETPOST('object', 'aZ09'); |
||
| 190 | if (!empty($tmpobjectkey)) { |
||
| 191 | $constforval = 'BOOKCAL_' . strtoupper($tmpobjectkey) . '_ADDON_PDF'; |
||
| 192 | if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) { |
||
| 193 | // The constant that was read before the new set |
||
| 194 | // We therefore requires a variable to have a coherent view |
||
| 195 | $conf->global->$constforval = $value; |
||
| 196 | } |
||
| 197 | |||
| 198 | // We disable/enable the document template (into llx_document_model table) |
||
| 199 | $ret = delDocumentModel($value, $type); |
||
| 200 | if ($ret > 0) { |
||
| 201 | $ret = addDocumentModel($value, $type, $label, $scandir); |
||
| 202 | } |
||
| 203 | } |
||
| 204 | } elseif ($action == 'unsetdoc') { |
||
| 205 | $tmpobjectkey = GETPOST('object', 'aZ09'); |
||
| 206 | if (!empty($tmpobjectkey)) { |
||
| 207 | $constforval = 'BOOKCAL_' . strtoupper($tmpobjectkey) . '_ADDON_PDF'; |
||
| 208 | dolibarr_del_const($db, $constforval, $conf->entity); |
||
| 209 | } |
||
| 210 | } |
||
| 211 | |||
| 212 | /* |
||
| 213 | * View |
||
| 214 | */ |
||
| 215 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/BookCal/Views/admin_setup.php'); |
||
| 216 | |||
| 217 | $db->close(); |
||
| 218 | |||
| 219 | return true; |
||
| 220 | } |
||
| 222 |