| Conditions | 11 |
| Paths | 216 |
| Total Lines | 86 |
| Code Lines | 60 |
| 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 |
||
| 235 | public static function display_notes() |
||
| 236 | { |
||
| 237 | $cidReq = api_get_cidreq(); |
||
| 238 | $sessionId = api_get_session_id(); |
||
| 239 | $_user = api_get_user_info(); |
||
| 240 | if (!isset($_GET['direction'])) { |
||
| 241 | $sort_direction = 'ASC'; |
||
| 242 | $link_sort_direction = 'DESC'; |
||
| 243 | } elseif ($_GET['direction'] == 'ASC') { |
||
| 244 | $sort_direction = 'ASC'; |
||
| 245 | $link_sort_direction = 'DESC'; |
||
| 246 | } else { |
||
| 247 | $sort_direction = 'DESC'; |
||
| 248 | $link_sort_direction = 'ASC'; |
||
| 249 | } |
||
| 250 | |||
| 251 | // action links |
||
| 252 | echo '<div class="actions">'; |
||
| 253 | if (!api_is_anonymous()) { |
||
| 254 | if ($sessionId == 0 || api_is_allowed_to_session_edit(false, true)) { |
||
| 255 | echo '<a href="index.php?'.$cidReq.'&action=addnote">'. |
||
| 256 | Display::return_icon('new_note.png', get_lang('NoteAddNew'), '', '32').'</a>'; |
||
| 257 | } |
||
| 258 | } |
||
| 259 | |||
| 260 | echo '<a href="index.php?'.$cidReq.'&action=changeview&view=creation_date&direction='.$link_sort_direction.'">'. |
||
| 261 | Display::return_icon('notes_order_by_date_new.png', get_lang('OrderByCreationDate'), '', '32').'</a>'; |
||
| 262 | echo '<a href="index.php?'.$cidReq.'&action=changeview&view=update_date&direction='.$link_sort_direction.'">'. |
||
| 263 | Display::return_icon('notes_order_by_date_mod.png', get_lang('OrderByModificationDate'), '', '32').'</a>'; |
||
| 264 | echo '<a href="index.php?'.$cidReq.'&action=changeview&view=title&direction='.$link_sort_direction.'">'. |
||
| 265 | Display::return_icon('notes_order_by_title.png', get_lang('OrderByTitle'), '', '32').'</a>'; |
||
| 266 | echo '</div>'; |
||
| 267 | |||
| 268 | $notebookView = Session::read('notebook_view'); |
||
| 269 | if (empty($notebookView)) { |
||
| 270 | $notebookView = 'creation_date'; |
||
| 271 | } |
||
| 272 | |||
| 273 | if (!in_array($notebookView, ['creation_date', 'update_date', 'title'])) { |
||
| 274 | Session::write('notebook_view', 'creation_date'); |
||
| 275 | } |
||
| 276 | |||
| 277 | // Database table definition |
||
| 278 | $table = Database::get_course_table(TABLE_NOTEBOOK); |
||
| 279 | $order_by = " ORDER BY `$notebookView` $sort_direction "; |
||
| 280 | |||
| 281 | // Condition for the session |
||
| 282 | $condition_session = api_get_session_condition($sessionId); |
||
| 283 | |||
| 284 | $cond_extra = $notebookView === 'update_date' ? " AND update_date <> ''" : ' '; |
||
| 285 | $course_id = api_get_course_int_id(); |
||
| 286 | |||
| 287 | $sql = "SELECT * FROM $table |
||
| 288 | WHERE |
||
| 289 | c_id = $course_id AND |
||
| 290 | user_id = '".api_get_user_id()."' |
||
| 291 | $condition_session |
||
| 292 | $cond_extra $order_by |
||
| 293 | "; |
||
| 294 | $result = Database::query($sql); |
||
| 295 | $iconEdit = Display::return_icon('edit.png', get_lang('Edit')); |
||
| 296 | $iconDelete = Display::return_icon('delete.png', get_lang('Delete')); |
||
| 297 | while ($row = Database::fetch_array($result)) { |
||
| 298 | // Validation when belongs to a session |
||
| 299 | $session_img = api_get_session_image($row['session_id'], $_user['status']); |
||
| 300 | $updateValue = ''; |
||
| 301 | if ($row['update_date'] != $row['creation_date']) { |
||
| 302 | $updateValue = ', '.get_lang('UpdateDate').': '.Display::dateToStringAgoAndLongDate($row['update_date']); |
||
| 303 | } |
||
| 304 | |||
| 305 | $actions = Display::url( |
||
| 306 | $iconEdit, |
||
| 307 | api_get_self().'?action=editnote¬ebook_id='.$row['notebook_id'].'&'.$cidReq |
||
| 308 | ); |
||
| 309 | $actions .= Display::url( |
||
| 310 | $iconDelete, |
||
| 311 | api_get_self().'?action=deletenote¬ebook_id='.$row['notebook_id'].'&'.$cidReq, |
||
| 312 | ['onclick' => 'return confirmation(\''.$row['title'].'\');'] |
||
| 313 | ); |
||
| 314 | |||
| 315 | echo Display::panel( |
||
| 316 | Security::remove_XSS($row['description']), |
||
| 317 | Security::remove_XSS($row['title']).$session_img. |
||
| 318 | ' <div class="pull-right">'.$actions.'</div>', |
||
| 319 | get_lang('CreationDate').': '.Display::dateToStringAgoAndLongDate($row['creation_date']). |
||
| 320 | $updateValue |
||
| 321 | ); |
||
| 325 |