| Conditions | 15 |
| Paths | 1600 |
| Total Lines | 81 |
| Code Lines | 47 |
| 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 |
||
| 60 | public function index(bool $executeActions = true): bool |
||
| 61 | { |
||
| 62 | global $conf; |
||
| 63 | global $db; |
||
| 64 | global $user; |
||
| 65 | global $hookmanager; |
||
| 66 | global $user; |
||
| 67 | global $menumanager; |
||
| 68 | global $langs; |
||
| 69 | |||
| 70 | |||
| 71 | // Load translation files required by the page |
||
| 72 | $langs->loadLangs(["agenda", "other"]); |
||
| 73 | |||
| 74 | $id = (GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility |
||
| 75 | $ref = GETPOST('ref', 'alpha'); |
||
| 76 | $socid = GETPOSTINT('socid'); |
||
| 77 | $action = GETPOST('action', 'aZ09'); |
||
| 78 | $type = GETPOST('type', 'aZ09'); |
||
| 79 | |||
| 80 | $fieldid = (!empty($ref) ? 'ref' : 'rowid'); |
||
| 81 | if ($user->socid) { |
||
| 82 | $socid = $user->socid; |
||
| 83 | } |
||
| 84 | |||
| 85 | $moreparam = ''; |
||
| 86 | |||
| 87 | $object = new Calendar($db); |
||
| 88 | |||
| 89 | // Load object |
||
| 90 | if ($id > 0 || !empty($ref)) { |
||
| 91 | $ret = $object->fetch($id, $ref); |
||
| 92 | $isdraft = (($object->status == Calendar::STATUS_DRAFT) ? 1 : 0); |
||
| 93 | if ($ret > 0) { |
||
| 94 | $object->fetch_thirdparty(); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | // There is several ways to check permission. |
||
| 99 | // Set $enablepermissioncheck to 1 to enable a minimum low level of checks |
||
| 100 | $enablepermissioncheck = 0; |
||
| 101 | if ($enablepermissioncheck) { |
||
| 102 | $permissiontoread = $user->hasRight('bookcal', 'calendar', 'read'); |
||
| 103 | $permissiontoadd = $user->hasRight('bookcal', 'calendar', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php |
||
| 104 | $permissiontodelete = $user->hasRight('bookcal', 'calendar', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); |
||
| 105 | $permissionnote = $user->hasRight('bookcal', 'calendar', 'write'); // Used by the include of actions_setnotes.inc.php |
||
| 106 | $permissiondellink = $user->hasRight('bookcal', 'calendar', 'write'); // Used by the include of actions_dellink.inc.php |
||
| 107 | } else { |
||
| 108 | $permissiontoread = 1; |
||
| 109 | $permissiontoadd = 1; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php |
||
| 110 | $permissiontodelete = 1; |
||
| 111 | $permissionnote = 1; |
||
| 112 | $permissiondellink = 1; |
||
| 113 | } |
||
| 114 | |||
| 115 | if (!isModEnabled("bookcal")) { |
||
| 116 | accessforbidden(); |
||
| 117 | } |
||
| 118 | if (!$permissiontoread) { |
||
| 119 | accessforbidden(); |
||
| 120 | } |
||
| 121 | |||
| 122 | /* |
||
| 123 | * Actions |
||
| 124 | */ |
||
| 125 | |||
| 126 | $parameters = ''; |
||
| 127 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 128 | if ($reshook < 0) { |
||
| 129 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 130 | } |
||
| 131 | |||
| 132 | |||
| 133 | /* |
||
| 134 | * View |
||
| 135 | */ |
||
| 136 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/BookCal/Views/booking_list.php'); |
||
| 137 | |||
| 138 | $db->close(); |
||
| 139 | |||
| 140 | return true; |
||
| 141 | } |
||
| 143 |