| Conditions | 13 |
| Paths | 288 |
| Total Lines | 91 |
| Code Lines | 65 |
| Lines | 7 |
| Ratio | 7.69 % |
| 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 |
||
| 218 | public static function display_notes() |
||
| 219 | { |
||
| 220 | $_user = api_get_user_info(); |
||
| 221 | if (!isset($_GET['direction'])) { |
||
| 222 | $sort_direction = 'ASC'; |
||
| 223 | $link_sort_direction = 'DESC'; |
||
| 224 | } elseif ($_GET['direction'] == 'ASC') { |
||
| 225 | $sort_direction = 'ASC'; |
||
| 226 | $link_sort_direction = 'DESC'; |
||
| 227 | } else { |
||
| 228 | $sort_direction = 'DESC'; |
||
| 229 | $link_sort_direction = 'ASC'; |
||
| 230 | } |
||
| 231 | |||
| 232 | // action links |
||
| 233 | echo '<div class="actions">'; |
||
| 234 | if (!api_is_anonymous()) { |
||
| 235 | View Code Duplication | if (api_get_session_id() == 0) { |
|
| 236 | echo '<a href="index.php?'.api_get_cidreq().'&action=addnote">'. |
||
| 237 | Display::return_icon( |
||
| 238 | 'new_note.png', |
||
| 239 | get_lang('NoteAddNew'), |
||
| 240 | '', |
||
| 241 | '32' |
||
| 242 | ).'</a>'; |
||
| 243 | } elseif (api_is_allowed_to_session_edit(false, true)) { |
||
| 244 | echo '<a href="index.php?' . api_get_cidreq() . '&action=addnote">' . |
||
| 245 | Display::return_icon('new_note.png', get_lang('NoteAddNew'), '', '32') . '</a>'; |
||
| 246 | } |
||
| 247 | } else { |
||
| 248 | echo '<a href="javascript:void(0)">' . |
||
| 249 | Display::return_icon('new_note.png', get_lang('NoteAddNew'), '', '32') . '</a>'; |
||
| 250 | } |
||
| 251 | |||
| 252 | echo '<a href="index.php?' . api_get_cidreq() . '&action=changeview&view=creation_date&direction=' . $link_sort_direction . '">' . |
||
| 253 | Display::return_icon('notes_order_by_date_new.png', get_lang('OrderByCreationDate'), '', '32') . '</a>'; |
||
| 254 | echo '<a href="index.php?' . api_get_cidreq() . '&action=changeview&view=update_date&direction=' . $link_sort_direction . '">' . |
||
| 255 | Display::return_icon('notes_order_by_date_mod.png', get_lang('OrderByModificationDate'), '', '32') . '</a>'; |
||
| 256 | echo '<a href="index.php?' . api_get_cidreq() . '&action=changeview&view=title&direction=' . $link_sort_direction . '">' . |
||
| 257 | Display::return_icon('notes_order_by_title.png', get_lang('OrderByTitle'), '', '32') . '</a>'; |
||
| 258 | echo '</div>'; |
||
| 259 | |||
| 260 | if (!isset($_SESSION['notebook_view']) || |
||
| 261 | !in_array($_SESSION['notebook_view'], array('creation_date', 'update_date', 'title')) |
||
| 262 | ) { |
||
| 263 | $_SESSION['notebook_view'] = 'creation_date'; |
||
| 264 | } |
||
| 265 | |||
| 266 | // Database table definition |
||
| 267 | $t_notebook = Database::get_course_table(TABLE_NOTEBOOK); |
||
| 268 | if ($_SESSION['notebook_view'] == 'creation_date' || $_SESSION['notebook_view'] == 'update_date') { |
||
| 269 | $order_by = " ORDER BY " . $_SESSION['notebook_view'] . " $sort_direction "; |
||
| 270 | } else { |
||
| 271 | $order_by = " ORDER BY " . $_SESSION['notebook_view'] . " $sort_direction "; |
||
| 272 | } |
||
| 273 | |||
| 274 | //condition for the session |
||
| 275 | $session_id = api_get_session_id(); |
||
| 276 | $condition_session = api_get_session_condition($session_id); |
||
| 277 | |||
| 278 | $cond_extra = ($_SESSION['notebook_view'] == 'update_date') ? " AND update_date <> ''" : " "; |
||
| 279 | $course_id = api_get_course_int_id(); |
||
| 280 | |||
| 281 | $sql = "SELECT * FROM $t_notebook |
||
| 282 | WHERE |
||
| 283 | c_id = $course_id AND |
||
| 284 | user_id = '" . api_get_user_id() . "' |
||
| 285 | $condition_session |
||
| 286 | $cond_extra $order_by |
||
| 287 | "; |
||
| 288 | $result = Database::query($sql); |
||
| 289 | while ($row = Database::fetch_array($result)) { |
||
| 290 | // Validation when belongs to a session |
||
| 291 | $session_img = api_get_session_image($row['session_id'], $_user['status']); |
||
| 292 | $updateValue = ''; |
||
| 293 | if ($row['update_date'] <> $row['creation_date']) { |
||
| 294 | $updateValue = ', ' . get_lang('UpdateDate') . ': ' . Display::dateToStringAgoAndLongDate($row['update_date']); |
||
| 295 | } |
||
| 296 | |||
| 297 | $actions = '<a href="' . api_get_self() . '?action=editnote¬ebook_id=' . $row['notebook_id'] . '">' . |
||
| 298 | Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . '</a>'; |
||
| 299 | $actions .= '<a href="' . api_get_self() . '?action=deletenote¬ebook_id=' . $row['notebook_id'] . '" onclick="return confirmation(\'' . $row['title'] . '\');">' . |
||
| 300 | Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>'; |
||
| 301 | |||
| 302 | echo Display::panel( |
||
| 303 | $row['description'], |
||
| 304 | $row['title'] . $session_img.' <div class="pull-right">'.$actions.'</div>', |
||
| 305 | get_lang('CreationDate') . ': ' . Display::dateToStringAgoAndLongDate($row['creation_date']). $updateValue |
||
| 306 | ); |
||
| 307 | } |
||
| 308 | } |
||
| 309 | } |
||
| 310 |