| Conditions | 33 |
| Paths | > 20000 |
| Total Lines | 157 |
| Code Lines | 83 |
| 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", "other"]); |
||
| 63 | |||
| 64 | // Get parameters |
||
| 65 | $id = GETPOSTINT('id'); |
||
| 66 | $ref = GETPOST('ref', 'alpha'); |
||
| 67 | $lineid = GETPOSTINT('lineid'); |
||
| 68 | |||
| 69 | $action = GETPOST('action', 'aZ09'); |
||
| 70 | $confirm = GETPOST('confirm', 'alpha'); |
||
| 71 | $cancel = GETPOST('cancel', 'aZ09'); |
||
| 72 | $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)) . basename(__FILE__, '.php')); // To manage different context of search |
||
| 73 | $backtopage = GETPOST('backtopage', 'alpha'); // if not set, a default page will be used |
||
| 74 | $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); // if not set, $backtopage will be used |
||
| 75 | $backtopagejsfields = GETPOST('backtopagejsfields', 'alpha'); |
||
| 76 | $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09'); |
||
| 77 | |||
| 78 | if (!empty($backtopagejsfields)) { |
||
| 79 | $tmpbacktopagejsfields = explode(':', $backtopagejsfields); |
||
| 80 | $dol_openinpopup = $tmpbacktopagejsfields[0]; |
||
| 81 | } |
||
| 82 | |||
| 83 | // Initialize technical objects |
||
| 84 | $object = new Calendar($db); |
||
| 85 | $extrafields = new ExtraFields($db); |
||
| 86 | $diroutputmassaction = $conf->bookcal->dir_output . '/temp/massgeneration/' . $user->id; |
||
| 87 | $hookmanager->initHooks(['calendarcard', 'globalcard']); // Note that conf->hooks_modules contains array |
||
| 88 | |||
| 89 | // Fetch optionals attributes and labels |
||
| 90 | $extrafields->fetch_name_optionals_label($object->table_element); |
||
| 91 | |||
| 92 | $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); |
||
| 93 | |||
| 94 | // Initialize array of search criteria |
||
| 95 | $search_all = GETPOST("search_all", 'alpha'); |
||
| 96 | $search = []; |
||
| 97 | foreach ($object->fields as $key => $val) { |
||
| 98 | if (GETPOST('search_' . $key, 'alpha')) { |
||
| 99 | $search[$key] = GETPOST('search_' . $key, 'alpha'); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | if (empty($action) && empty($id) && empty($ref)) { |
||
| 104 | $action = 'view'; |
||
| 105 | } |
||
| 106 | |||
| 107 | // Load object |
||
| 108 | include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once. |
||
| 109 | |||
| 110 | // There is several ways to check permission. |
||
| 111 | // Set $enablepermissioncheck to 1 to enable a minimum low level of checks |
||
| 112 | $enablepermissioncheck = 0; |
||
| 113 | if ($enablepermissioncheck) { |
||
| 114 | $permissiontoread = $user->hasRight('bookcal', 'calendar', 'read'); |
||
| 115 | $permissiontoadd = $user->hasRight('bookcal', 'calendar', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php |
||
| 116 | $permissiontodelete = $user->hasRight('bookcal', 'calendar', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); |
||
| 117 | $permissionnote = $user->hasRight('bookcal', 'calendar', 'write'); // Used by the include of actions_setnotes.inc.php |
||
| 118 | $permissiondellink = $user->hasRight('bookcal', 'calendar', 'write'); // Used by the include of actions_dellink.inc.php |
||
| 119 | } else { |
||
| 120 | $permissiontoread = 1; |
||
| 121 | $permissiontoadd = 1; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php |
||
| 122 | $permissiontodelete = 1; |
||
| 123 | $permissionnote = 1; |
||
| 124 | $permissiondellink = 1; |
||
| 125 | } |
||
| 126 | |||
| 127 | $upload_dir = $conf->bookcal->multidir_output[isset($object->entity) ? $object->entity : 1] . '/calendar'; |
||
| 128 | |||
| 129 | // Security check (enable the most restrictive one) |
||
| 130 | //if ($user->socid > 0) accessforbidden(); |
||
| 131 | //if ($user->socid > 0) $socid = $user->socid; |
||
| 132 | //$isdraft = (isset($object->status) && ($object->status == $object::STATUS_DRAFT) ? 1 : 0); |
||
| 133 | //restrictedArea($user, $object->module, $object, $object->table_element, $object->element, 'fk_soc', 'rowid', $isdraft); |
||
| 134 | if (!isModEnabled("bookcal")) { |
||
| 135 | accessforbidden(); |
||
| 136 | } |
||
| 137 | if (!$permissiontoread) { |
||
| 138 | accessforbidden(); |
||
| 139 | } |
||
| 140 | |||
| 141 | |||
| 142 | /* |
||
| 143 | * Actions |
||
| 144 | */ |
||
| 145 | |||
| 146 | $parameters = []; |
||
| 147 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 148 | if ($reshook < 0) { |
||
| 149 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 150 | } |
||
| 151 | |||
| 152 | if (empty($reshook)) { |
||
| 153 | $error = 0; |
||
| 154 | |||
| 155 | $backurlforlist = dol_buildpath('/bookcal/calendar_list.php', 1); |
||
| 156 | |||
| 157 | if (empty($backtopage) || ($cancel && empty($id))) { |
||
| 158 | if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) { |
||
| 159 | if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) { |
||
| 160 | $backtopage = $backurlforlist; |
||
| 161 | } else { |
||
| 162 | $backtopage = dol_buildpath('/bookcal/calendar_card.php', 1) . '?id=' . ((!empty($id) && $id > 0) ? $id : '__ID__'); |
||
| 163 | } |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | $triggermodname = 'BOOKCAL_MYOBJECT_MODIFY'; // Name of trigger action code to execute when we modify record |
||
| 168 | |||
| 169 | // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen |
||
| 170 | include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php'; |
||
| 171 | |||
| 172 | // Actions when linking object each other |
||
| 173 | include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php'; |
||
| 174 | |||
| 175 | // Actions when printing a doc from card |
||
| 176 | include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php'; |
||
| 177 | |||
| 178 | // Action to move up and down lines of object |
||
| 179 | //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; |
||
| 180 | |||
| 181 | // Action to build doc |
||
| 182 | include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php'; |
||
| 183 | |||
| 184 | if ($action == 'set_thirdparty' && $permissiontoadd) { |
||
| 185 | $object->setValueFrom('fk_soc', GETPOSTINT('fk_soc'), '', '', 'date', '', $user, $triggermodname); |
||
| 186 | } |
||
| 187 | if ($action == 'classin' && $permissiontoadd) { |
||
| 188 | $object->setProject(GETPOSTINT('projectid')); |
||
| 189 | } |
||
| 190 | |||
| 191 | // Actions to send emails |
||
| 192 | $triggersendname = 'BOOKCAL_MYOBJECT_SENTBYMAIL'; |
||
| 193 | $autocopy = 'MAIN_MAIL_AUTOCOPY_MYOBJECT_TO'; |
||
| 194 | $trackid = 'calendar' . $object->id; |
||
| 195 | include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php'; |
||
| 196 | } |
||
| 197 | |||
| 198 | |||
| 199 | /* |
||
| 200 | * View |
||
| 201 | */ |
||
| 202 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/BookCal/Views/calendar_card.php'); |
||
| 203 | |||
| 204 | $db->close(); |
||
| 205 | |||
| 206 | return true; |
||
| 207 | } |
||
| 209 |