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