| Conditions | 8 |
| Paths | 4 |
| Total Lines | 65 |
| Code Lines | 43 |
| 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 |
||
| 81 | public function getContent() |
||
| 82 | { |
||
| 83 | $students = $this->students; |
||
| 84 | $students_table = null; |
||
| 85 | if (count($students) > 0) { |
||
| 86 | $students_table .= '<table class="data_table">'; |
||
| 87 | $students_table .= '<tr> |
||
| 88 | <th width="10%" rowspan="2">'.get_lang('FirstName').'</th> |
||
| 89 | <th width="10%" rowspan="2">'.get_lang('LastName').'</th> |
||
| 90 | <th width="30%" colspan="2">'.get_lang('CourseInformation').'</th> |
||
| 91 | </tr> |
||
| 92 | <tr> |
||
| 93 | <th width="10%">'.get_lang('Courses').'</th> |
||
| 94 | <th width="10%">'.get_lang('Time').'</th> |
||
| 95 | </tr>'; |
||
| 96 | |||
| 97 | $i = 1; |
||
| 98 | foreach ($students as $student) { |
||
| 99 | $courses_by_user = CourseManager::get_courses_list_by_user_id($student['user_id'], true); |
||
| 100 | $count_courses = count($courses_by_user); |
||
| 101 | $rowspan = $count_courses ? $count_courses + 1 : 2; |
||
| 102 | |||
| 103 | if ($i % 2 == 0) { |
||
| 104 | $style = ' style="background-color:#F2F2F2" '; |
||
| 105 | } else { |
||
| 106 | $style = ' style="background-color:#FFF" '; |
||
| 107 | } |
||
| 108 | |||
| 109 | $students_table .= '<tr '.$style.'> |
||
| 110 | <td rowspan="'.$rowspan.'">'.$student['firstname'].'</td> |
||
| 111 | <td rowspan="'.$rowspan.'">'.$student['lastname'].'</td> |
||
| 112 | </tr>'; |
||
| 113 | |||
| 114 | // courses information about the student |
||
| 115 | if (!empty($courses_by_user)) { |
||
| 116 | foreach ($courses_by_user as $course) { |
||
| 117 | $course_code = $course['code']; |
||
| 118 | $courseInfo = api_get_course_info($course_code); |
||
| 119 | $courseId = $courseInfo['real_id']; |
||
| 120 | $course_title = $course['title']; |
||
| 121 | $time = api_time_to_hms(Tracking::get_time_spent_on_the_course($student['user_id'], $courseId)); |
||
| 122 | $students_table .= '<tr '.$style.'> |
||
| 123 | <td align="right">'.$course_title.'</td> |
||
| 124 | <td align="right">'.$time.'</td> |
||
| 125 | </tr>'; |
||
| 126 | } |
||
| 127 | } else { |
||
| 128 | $students_table .= '<tr '.$style.'> |
||
| 129 | <td align="center" colspan="2"><i>'.get_lang('Empty').'</i></td> |
||
| 130 | </tr>'; |
||
| 131 | } |
||
| 132 | $i++; |
||
| 133 | } |
||
| 134 | $students_table .= '</table>'; |
||
| 135 | } else { |
||
| 136 | $students_table .= get_lang('ThereIsNoInformationAboutYourStudents'); |
||
| 137 | } |
||
| 138 | |||
| 139 | $content = $students_table; |
||
| 140 | |||
| 141 | if (count($students) > 0) { |
||
| 142 | $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=useroverview">'.get_lang('SeeMore').'</a></div>'; |
||
| 143 | } |
||
| 144 | |||
| 145 | return $content; |
||
| 146 | } |
||
| 247 |