| Conditions | 14 |
| Paths | 290 |
| Total Lines | 103 |
| Code Lines | 71 |
| 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_course_information_data() |
||
| 152 | { |
||
| 153 | $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); |
||
| 154 | $course_data = []; |
||
| 155 | $courses = $this->courses; |
||
| 156 | |||
| 157 | foreach ($courses as $row_course) { |
||
| 158 | $score = null; |
||
| 159 | $courseId = $row_course['c_id']; |
||
| 160 | $course_info = api_get_course_info_by_id($courseId); |
||
| 161 | $course_code = $course_info['code']; |
||
| 162 | if (empty($course_info)) { |
||
| 163 | continue; |
||
| 164 | } |
||
| 165 | |||
| 166 | // Attendance table |
||
| 167 | $table_course = Database::get_course_table(TABLE_ATTENDANCE); |
||
| 168 | |||
| 169 | $sql = "SELECT id, name, attendance_qualify_max FROM $table_course |
||
| 170 | WHERE c_id = ".$course_info['real_id']." AND active = 1 AND session_id = 0"; |
||
| 171 | $rs = Database::query($sql); |
||
| 172 | $attendance = []; |
||
| 173 | $attendances = []; |
||
| 174 | |||
| 175 | while ($row = Database::fetch_array($rs, 'ASSOC')) { |
||
| 176 | $attendance['done'] = $row['attendance_qualify_max']; |
||
| 177 | $attendance['id'] = $row['id']; |
||
| 178 | //$attendance['name'] = $row['name']; |
||
| 179 | $attendance['course_code'] = $course_info['code']; |
||
| 180 | |||
| 181 | if ($attendance['done'] != '0') { |
||
| 182 | $attendances[] = '<a href="'.api_get_path(WEB_PATH).'main/attendance/index.php?cidReq='.$attendance['course_code'].'&action=attendance_sheet_print&attendance_id='.$attendance['id'].'">'.Display::return_icon('printmgr.gif', get_lang('Print')).'</a>'; |
||
| 183 | } else { |
||
| 184 | $attendances[] = get_lang("NotAvailable"); |
||
| 185 | } |
||
| 186 | } |
||
| 187 | if (count($attendances) == 0) { |
||
| 188 | $attendances[] = get_lang("NotAvailable"); |
||
| 189 | } |
||
| 190 | |||
| 191 | // Number of students |
||
| 192 | |||
| 193 | $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user |
||
| 194 | WHERE course_rel_user.status=".STUDENT." AND course_rel_user.c_id=$courseId"; |
||
| 195 | $rs = Database::query($sql); |
||
| 196 | $users = []; |
||
| 197 | while ($row = Database::fetch_array($rs)) { |
||
| 198 | $users[] = $row['user_id']; |
||
| 199 | } |
||
| 200 | if (count($users) > 0) { |
||
| 201 | $nb_students_in_course = count($users); |
||
| 202 | } |
||
| 203 | |||
| 204 | if (!empty($tematic_advance)) { |
||
|
|
|||
| 205 | $tematic_advance_progress = '<a title="'.get_lang( |
||
| 206 | 'GoToThematicAdvance' |
||
| 207 | ).'" href="'.api_get_path( |
||
| 208 | WEB_CODE_PATH |
||
| 209 | ).'attendance/index.php?cidReq='.$course_code.'&action=attendance_sheet_print&attendance_id=">'.$tematic_advance.'%</a>'; |
||
| 210 | } else { |
||
| 211 | $tematic_advance_progress = '0%'; |
||
| 212 | } |
||
| 213 | |||
| 214 | // Score |
||
| 215 | $tbl_grade_categories = Database::get_main_table( |
||
| 216 | TABLE_MAIN_GRADEBOOK_CATEGORY |
||
| 217 | ); |
||
| 218 | $sql = "SELECT id from ".$tbl_grade_categories." |
||
| 219 | WHERE course_code ='".$course_code."'"; |
||
| 220 | $rs = Database::query($sql); |
||
| 221 | $category = null; |
||
| 222 | while ($row = Database::fetch_array($rs)) { |
||
| 223 | $category = $row['id']; |
||
| 224 | } |
||
| 225 | |||
| 226 | if (!empty($category)) { |
||
| 227 | $cat = Category::load($category); |
||
| 228 | $eval = $cat[0]->get_evaluations(); |
||
| 229 | if (count($eval) > 0) { |
||
| 230 | $i = 0; |
||
| 231 | foreach ($eval as $item) { |
||
| 232 | $score .= '<a href="'.api_get_path(WEB_PATH).'main/gradebook/gradebook_view_result.php?export=pdf&cat_code='.$cat[0]->get_id().'&official_code='.$cat[0]->get_course_code().'&selecteval='.$item->get_id().'">'.$item->get_name().'</a>'; |
||
| 233 | if (count($eval) - 1 != $i) { |
||
| 234 | $score .= ', '; |
||
| 235 | } |
||
| 236 | $i++; |
||
| 237 | } |
||
| 238 | } else { |
||
| 239 | $score = get_lang("NotAvailable"); |
||
| 240 | } |
||
| 241 | } else { |
||
| 242 | $score = get_lang("NotAvailable"); |
||
| 243 | } |
||
| 244 | |||
| 245 | $table_row = []; |
||
| 246 | $table_row[] = $row_course['title']; |
||
| 247 | $table_row[] = $nb_students_in_course; |
||
| 248 | $table_row[] = $score; |
||
| 249 | $table_row[] = $attendances[0]; |
||
| 250 | $course_data[] = $table_row; |
||
| 251 | } |
||
| 252 | |||
| 253 | return $course_data; |
||
| 254 | } |
||
| 256 |