| Conditions | 11 |
| Paths | 216 |
| Total Lines | 83 |
| Code Lines | 59 |
| 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 |
||
| 173 | public static function display_notes() |
||
| 174 | { |
||
| 175 | $sessionId = api_get_session_id(); |
||
| 176 | $_user = api_get_user_info(); |
||
| 177 | if (!isset($_GET['direction'])) { |
||
| 178 | $sort_direction = 'ASC'; |
||
| 179 | $link_sort_direction = 'DESC'; |
||
| 180 | } elseif ('ASC' == $_GET['direction']) { |
||
| 181 | $sort_direction = 'ASC'; |
||
| 182 | $link_sort_direction = 'DESC'; |
||
| 183 | } else { |
||
| 184 | $sort_direction = 'DESC'; |
||
| 185 | $link_sort_direction = 'ASC'; |
||
| 186 | } |
||
| 187 | |||
| 188 | // action links |
||
| 189 | echo '<div class="actions">'; |
||
| 190 | if (!api_is_anonymous()) { |
||
| 191 | if (0 == $sessionId || api_is_allowed_to_session_edit(false, true)) { |
||
| 192 | echo '<a href="index.php?'.api_get_cidreq().'&action=addnote">'. |
||
| 193 | Display::return_icon('new_note.png', get_lang('Add new note in my personal notebook'), '', '32'). |
||
| 194 | '</a>'; |
||
| 195 | } |
||
| 196 | } |
||
| 197 | |||
| 198 | echo '<a |
||
| 199 | href="index.php?'.api_get_cidreq().'&action=changeview&view=creation_date&direction='.$link_sort_direction.'">'. |
||
| 200 | Display::return_icon('notes_order_by_date_new.png', get_lang('Sort by date created'), '', '32'). |
||
| 201 | '</a>'; |
||
| 202 | echo '<a |
||
| 203 | href="index.php?'.api_get_cidreq().'&action=changeview&view=update_date&direction='.$link_sort_direction.'">'. |
||
| 204 | Display::return_icon('notes_order_by_date_mod.png', get_lang('Sort by date last modified'), '', '32'). |
||
| 205 | '</a>'; |
||
| 206 | echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=title&direction='.$link_sort_direction.'">'. |
||
| 207 | Display::return_icon('notes_order_by_title.png', get_lang('Sort by title'), '', '32').'</a>'; |
||
| 208 | echo '</div>'; |
||
| 209 | |||
| 210 | $notebookView = Session::read('notebook_view'); |
||
| 211 | if (empty($notebookView)) { |
||
| 212 | $notebookView = 'creation_date'; |
||
| 213 | } |
||
| 214 | |||
| 215 | if (!in_array($notebookView, ['creation_date', 'update_date', 'title'])) { |
||
| 216 | Session::write('notebook_view', 'creation_date'); |
||
| 217 | } |
||
| 218 | |||
| 219 | // Database table definition |
||
| 220 | $table = Database::get_course_table(TABLE_NOTEBOOK); |
||
| 221 | $order_by = ' ORDER BY '.$notebookView." $sort_direction "; |
||
| 222 | |||
| 223 | // Condition for the session |
||
| 224 | $condition_session = api_get_session_condition($sessionId); |
||
| 225 | |||
| 226 | $cond_extra = 'update_date' === $notebookView ? " AND update_date <> ''" : ' '; |
||
| 227 | $course_id = api_get_course_int_id(); |
||
| 228 | |||
| 229 | $sql = "SELECT * FROM $table |
||
| 230 | WHERE |
||
| 231 | c_id = $course_id AND |
||
| 232 | user_id = '".api_get_user_id()."' |
||
| 233 | $condition_session |
||
| 234 | $cond_extra $order_by |
||
| 235 | "; |
||
| 236 | $result = Database::query($sql); |
||
| 237 | while ($row = Database::fetch_array($result)) { |
||
| 238 | // Validation when belongs to a session |
||
| 239 | $session_img = api_get_session_image($row['session_id'], $_user['status']); |
||
| 240 | $updateValue = ''; |
||
| 241 | if ($row['update_date'] != $row['creation_date']) { |
||
| 242 | $updateValue = ', '.get_lang('Updated').': '.Display::dateToStringAgoAndLongDate($row['update_date']); |
||
| 243 | } |
||
| 244 | |||
| 245 | $actions = '<a href="'.api_get_self().'?action=editnote¬ebook_id='.$row['notebook_id'].'">'. |
||
| 246 | Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 247 | $actions .= '<a |
||
| 248 | href="'.api_get_self().'?action=deletenote¬ebook_id='.$row['notebook_id'].'" |
||
| 249 | onclick="return confirmation(\''.$row['title'].'\');">'. |
||
| 250 | Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'; |
||
| 251 | |||
| 252 | echo Display::panel( |
||
| 253 | $row['description'], |
||
| 254 | $row['title'].$session_img.' <div class="pull-right">'.$actions.'</div>', |
||
| 255 | get_lang('Creation date').': '.Display::dateToStringAgoAndLongDate($row['creation_date']).$updateValue |
||
| 256 | ); |
||
| 260 |