| Conditions | 9 |
| Paths | 96 |
| Total Lines | 84 |
| Code Lines | 43 |
| 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 index(bool $executeActions = true): bool |
||
| 50 | { |
||
| 51 | global $conf; |
||
| 52 | global $db; |
||
| 53 | global $user; |
||
| 54 | global $hookmanager; |
||
| 55 | global $user; |
||
| 56 | global $menumanager; |
||
| 57 | global $langs; |
||
| 58 | |||
| 59 | |||
| 60 | // Load translation files required by the page |
||
| 61 | $langs->loadLangs(["agenda", "companies"]); |
||
| 62 | |||
| 63 | // Get parameters |
||
| 64 | $id = GETPOSTINT('id'); |
||
| 65 | $ref = GETPOST('ref', 'alpha'); |
||
| 66 | $action = GETPOST('action', 'aZ09'); |
||
| 67 | $cancel = GETPOST('cancel', 'aZ09'); |
||
| 68 | $backtopage = GETPOST('backtopage', 'alpha'); |
||
| 69 | |||
| 70 | // Initialize technical objects |
||
| 71 | $object = new Availabilities($db); |
||
| 72 | $extrafields = new ExtraFields($db); |
||
| 73 | $diroutputmassaction = $conf->bookcal->dir_output . '/temp/massgeneration/' . $user->id; |
||
| 74 | $hookmanager->initHooks(['availabilitiesnote', 'globalcard']); // Note that conf->hooks_modules contains array |
||
| 75 | // Fetch optionals attributes and labels |
||
| 76 | $extrafields->fetch_name_optionals_label($object->table_element); |
||
| 77 | |||
| 78 | // Load object |
||
| 79 | include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals |
||
| 80 | if ($id > 0 || !empty($ref)) { |
||
| 81 | $upload_dir = $conf->bookcal->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity] . "/" . $object->id; |
||
| 82 | } |
||
| 83 | |||
| 84 | |||
| 85 | // There is several ways to check permission. |
||
| 86 | // Set $enablepermissioncheck to 1 to enable a minimum low level of checks |
||
| 87 | $enablepermissioncheck = 0; |
||
| 88 | if ($enablepermissioncheck) { |
||
| 89 | $permissiontoread = $user->hasRight('bookcal', 'availabilities', 'read'); |
||
| 90 | $permissiontoadd = $user->hasRight('bookcal', 'availabilities', 'write'); |
||
| 91 | $permissionnote = $user->hasRight('bookcal', 'availabilities', 'write'); // Used by the include of actions_setnotes.inc.php |
||
| 92 | } else { |
||
| 93 | $permissiontoread = 1; |
||
| 94 | $permissiontoadd = 1; |
||
| 95 | $permissionnote = 1; |
||
| 96 | } |
||
| 97 | |||
| 98 | // Security check (enable the most restrictive one) |
||
| 99 | //if ($user->socid > 0) accessforbidden(); |
||
| 100 | //if ($user->socid > 0) $socid = $user->socid; |
||
| 101 | //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); |
||
| 102 | //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft); |
||
| 103 | if (!isModEnabled('bookcal')) { |
||
| 104 | accessforbidden(); |
||
| 105 | } |
||
| 106 | if (!$permissiontoread) { |
||
| 107 | accessforbidden(); |
||
| 108 | } |
||
| 109 | |||
| 110 | |||
| 111 | /* |
||
| 112 | * Actions |
||
| 113 | */ |
||
| 114 | |||
| 115 | $parameters = []; |
||
| 116 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 117 | if ($reshook < 0) { |
||
| 118 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 119 | } |
||
| 120 | if (empty($reshook)) { |
||
| 121 | include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not include_once |
||
| 122 | } |
||
| 123 | |||
| 124 | |||
| 125 | /* |
||
| 126 | * View |
||
| 127 | */ |
||
| 128 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/BookCal/Views/availabilities_note.php'); |
||
| 129 | |||
| 130 | $db->close(); |
||
| 131 | |||
| 132 | return true; |
||
| 133 | } |
||
| 135 |