| Conditions | 11 |
| Paths | 4 |
| Total Lines | 84 |
| 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 |
||
| 151 | public function get_students_content_html_for_drh() |
||
| 152 | { |
||
| 153 | $attendance = new Attendance(); |
||
| 154 | $students = $this->students; |
||
| 155 | $content = '<h4>'.get_lang('YourStudents').'</h4>'; |
||
| 156 | $students_table = null; |
||
| 157 | if (count($students) > 0) { |
||
| 158 | $students_table .= '<table class="data_table">'; |
||
| 159 | $students_table .= '<tr> |
||
| 160 | <th>'.get_lang('User').'</th> |
||
| 161 | <th>'.get_lang('AttendancesFaults').'</th> |
||
| 162 | <th>'.get_lang('Evaluations').'</th> |
||
| 163 | </tr>'; |
||
| 164 | $i = 1; |
||
| 165 | foreach ($students as $student) { |
||
| 166 | $student_id = $student['user_id']; |
||
| 167 | $firstname = $student['firstname']; |
||
| 168 | $lastname = $student['lastname']; |
||
| 169 | $username = $student['username']; |
||
| 170 | // get average of faults in attendances by student |
||
| 171 | $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id); |
||
| 172 | if (!empty($results_faults_avg)) { |
||
| 173 | $attendances_faults_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.$results_faults_avg['faults'].'/'.$results_faults_avg['total'].' ('.$results_faults_avg['porcent'].'%)</a>'; |
||
| 174 | } else { |
||
| 175 | $attendances_faults_avg = '0%'; |
||
| 176 | } |
||
| 177 | |||
| 178 | $courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true); |
||
| 179 | $evaluations_avg = 0; |
||
| 180 | $score = $weight = 0; |
||
| 181 | foreach ($courses_by_user as $course) { |
||
| 182 | $course_code = $course['code']; |
||
| 183 | $cats = Category::load( |
||
| 184 | null, |
||
| 185 | null, |
||
| 186 | $course_code, |
||
| 187 | null, |
||
| 188 | null, |
||
| 189 | null, |
||
| 190 | false |
||
| 191 | ); |
||
| 192 | $scoretotal = []; |
||
| 193 | if (isset($cats) && isset($cats[0])) { |
||
| 194 | $scoretotal = $cats[0]->calc_score($student_id, null, $course_code); |
||
| 195 | } |
||
| 196 | |||
| 197 | if (!empty($scoretotal)) { |
||
| 198 | $score += $scoretotal[0]; |
||
| 199 | $weight += $scoretotal[1]; |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | if (!empty($weight)) { |
||
| 204 | $evaluations_avg = '<a title="'.get_lang('GoToStudentDetails').'" href="'.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id.'">'.round($score, 2).'/'.round($weight, 2).'('.round(($score / $weight) * 100, 2).' %)</a>'; |
||
| 205 | } |
||
| 206 | |||
| 207 | if ($i % 2 == 0) { |
||
| 208 | $class_tr = 'row_odd'; |
||
| 209 | } else { |
||
| 210 | $class_tr = 'row_even'; |
||
| 211 | } |
||
| 212 | $students_table .= '<tr class="'.$class_tr.'"> |
||
| 213 | <td>'.api_get_person_name($firstname, $lastname).' ('.$username.')</td> |
||
| 214 | <td>'.$attendances_faults_avg.'</td> |
||
| 215 | <td>'.$evaluations_avg.'</td> |
||
| 216 | </tr>'; |
||
| 217 | |||
| 218 | $i++; |
||
| 219 | } |
||
| 220 | $students_table .= '</table>'; |
||
| 221 | } else { |
||
| 222 | $students_table .= get_lang('ThereIsNoInformationAboutYourStudents'); |
||
| 223 | } |
||
| 224 | |||
| 225 | $content .= $students_table; |
||
| 226 | |||
| 227 | if (count($students) > 0) { |
||
| 228 | $content .= '<div style="text-align:right;margin-top:10px;"> |
||
| 229 | <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=admin&display=yourstudents">'.get_lang('SeeMore').'</a> |
||
| 230 | </div>'; |
||
| 231 | } |
||
| 232 | //$content .= '</div>'; |
||
| 233 | |||
| 234 | return $content; |
||
| 235 | } |
||
| 247 |