Conditions | 27 |
Paths | 8448 |
Total Lines | 113 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
48 | public function index(bool $executeActions = true): bool |
||
49 | { |
||
50 | global $conf; |
||
51 | global $db; |
||
52 | global $user; |
||
53 | global $hookmanager; |
||
54 | global $user; |
||
55 | global $menumanager; |
||
56 | global $langs; |
||
57 | global $mysoc; |
||
58 | |||
59 | // Load translation files required by the page |
||
60 | $langs->loadLangs(["mrp", "other", "stocks"]); |
||
61 | |||
62 | // Get parameters |
||
63 | $id = GETPOSTINT('id'); |
||
64 | $lineid = GETPOSTINT('lineid'); |
||
65 | $ref = GETPOST('ref', 'alpha'); |
||
66 | $action = GETPOST('action', 'aZ09'); |
||
67 | $confirm = GETPOST('confirm', 'alpha'); |
||
68 | $cancel = GETPOST('cancel', 'aZ09'); |
||
69 | $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'bomnet_needs'; // To manage different context of search |
||
70 | $backtopage = GETPOST('backtopage', 'alpha'); |
||
71 | |||
72 | |||
73 | // Initialize technical objects |
||
74 | $object = new Bom($db); |
||
75 | $extrafields = new ExtraFields($db); |
||
76 | |||
77 | // Initialize technical objects for hooks |
||
78 | $hookmanager->initHooks(['bomnetneeds']); // Note that conf->hooks_modules contains array |
||
79 | |||
80 | // Massaction |
||
81 | $diroutputmassaction = $conf->bom->dir_output . '/temp/massgeneration/' . $user->id; |
||
82 | |||
83 | // Fetch optionals attributes and labels |
||
84 | $extrafields->fetch_name_optionals_label($object->table_element); |
||
85 | $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); |
||
86 | |||
87 | // Initialize array of search criteria |
||
88 | $search_all = GETPOST("search_all", 'alpha'); |
||
89 | $search = []; |
||
90 | foreach ($object->fields as $key => $val) { |
||
91 | if (GETPOST('search_' . $key, 'alpha')) { |
||
92 | $search[$key] = GETPOST('search_' . $key, 'alpha'); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | if (empty($action) && empty($id) && empty($ref)) { |
||
97 | $action = 'view'; |
||
98 | } |
||
99 | |||
100 | // Load object |
||
101 | include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once. |
||
102 | if ($object->id > 0) { |
||
103 | $object->calculateCosts(); |
||
104 | } |
||
105 | |||
106 | |||
107 | // Security check - Protection if external user |
||
108 | //if ($user->socid > 0) accessforbidden(); |
||
109 | //if ($user->socid > 0) $socid = $user->socid; |
||
110 | $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0); |
||
111 | $result = restrictedArea($user, 'bom', $object->id, $object->table_element, '', '', 'rowid', $isdraft); |
||
112 | |||
113 | // Permissions |
||
114 | $permissionnote = $user->hasRight('bom', 'write'); // Used by the include of actions_setnotes.inc.php |
||
115 | $permissiondellink = $user->hasRight('bom', 'write'); // Used by the include of actions_dellink.inc.php |
||
116 | $permissiontoadd = $user->hasRight('bom', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php |
||
117 | $permissiontodelete = $user->hasRight('bom', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); |
||
118 | $upload_dir = $conf->bom->multidir_output[isset($object->entity) ? $object->entity : 1]; |
||
119 | |||
120 | |||
121 | /* |
||
122 | * Actions |
||
123 | */ |
||
124 | |||
125 | $parameters = []; |
||
126 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
127 | if ($reshook < 0) { |
||
128 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
129 | } |
||
130 | |||
131 | if (empty($reshook)) { |
||
132 | $error = 0; |
||
133 | |||
134 | $backurlforlist = '/bom/bom_list.php'; |
||
135 | |||
136 | if (empty($backtopage) || ($cancel && empty($id))) { |
||
137 | if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) { |
||
138 | if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) { |
||
139 | $backtopage = $backurlforlist; |
||
140 | } else { |
||
141 | $backtopage = '/bom/bom_net_needs.php?id=' . ($id > 0 ? $id : '__ID__'); |
||
142 | } |
||
143 | } |
||
144 | } |
||
145 | if ($action == 'treeview') { |
||
146 | $object->getNetNeedsTree($TChildBom, 1); |
||
147 | } else { |
||
148 | $object->getNetNeeds($TChildBom, 1); |
||
149 | } |
||
150 | } |
||
151 | |||
152 | |||
153 | /* |
||
154 | * View |
||
155 | */ |
||
156 | require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Bom/Views/bom_net_needs.php'); |
||
157 | |||
158 | |||
159 | $db->close(); |
||
160 | return true; |
||
161 | } |
||
163 |