| Conditions | 12 |
| Paths | 100 |
| Total Lines | 117 |
| Code Lines | 78 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 52 | function get_users($from, $number_of_items, $column, $direction) |
||
| 53 | { |
||
| 54 | $consideredWorkingTime = api_get_configuration_value('considered_working_time'); |
||
| 55 | |||
| 56 | $courseId = api_get_course_int_id(); |
||
| 57 | $courseCode = api_get_course_id(); |
||
| 58 | $sessionId = api_get_session_id(); |
||
| 59 | $webCodePath = api_get_path(WEB_CODE_PATH); |
||
| 60 | |||
| 61 | $lastConnectionDate = null; |
||
| 62 | $is_western_name_order = api_is_western_name_order(); |
||
| 63 | $limit = null; |
||
| 64 | $from = (int) $from; |
||
| 65 | $number_of_items = (int) $number_of_items; |
||
| 66 | $limit = 'LIMIT '.$from.','.$number_of_items; |
||
| 67 | |||
| 68 | $students = CourseManager::get_user_list_from_course_code( |
||
| 69 | $courseCode, |
||
| 70 | $sessionId, |
||
| 71 | $limit, |
||
| 72 | null, |
||
| 73 | null, |
||
| 74 | false |
||
| 75 | ); |
||
| 76 | $url = $webCodePath.'mySpace/myStudents.php'; |
||
| 77 | |||
| 78 | $workList = getWorkListTeacher(0, 100, null, null, null); |
||
| 79 | |||
| 80 | $totalCourseWorkTime = 0; |
||
| 81 | $workTimeList = []; |
||
| 82 | foreach ($workList as $work) { |
||
| 83 | $fieldValue = new ExtraFieldValue('work'); |
||
| 84 | $resultExtra = $fieldValue->getAllValuesForAnItem( |
||
| 85 | $work['id'], |
||
| 86 | true |
||
| 87 | ); |
||
| 88 | |||
| 89 | foreach ($resultExtra as $field) { |
||
| 90 | $field = $field['value']; |
||
| 91 | if ($consideredWorkingTime == $field->getField()->getVariable()) { |
||
| 92 | $time = $field->getValue(); |
||
| 93 | $parsed = date_parse($time); |
||
| 94 | $workTimeList[$work['id']] = $parsed['hour'] * 3600 + $parsed['minute'] * 60 + $parsed['second']; |
||
| 95 | |||
| 96 | break; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | $all_datas = []; |
||
| 102 | foreach ($students as $studentData) { |
||
| 103 | $studentId = $studentData['user_id']; |
||
| 104 | $studentData = api_get_user_info($studentId); |
||
| 105 | $urlDetails = $url."?student=$studentId"; |
||
| 106 | $row = []; |
||
| 107 | if ($is_western_name_order) { |
||
| 108 | $first = Display::url($studentData['firstname'], $urlDetails); |
||
| 109 | $last = Display::url($studentData['lastname'], $urlDetails); |
||
| 110 | } else { |
||
| 111 | $first = Display::url($studentData['lastname'], $urlDetails); |
||
| 112 | $last = Display::url($studentData['firstname'], $urlDetails); |
||
| 113 | } |
||
| 114 | |||
| 115 | $row[] = $first; |
||
| 116 | $row[] = $last; |
||
| 117 | |||
| 118 | $timeInSeconds = Tracking::get_time_spent_on_the_course( |
||
| 119 | $studentId, |
||
| 120 | $courseId, |
||
| 121 | $sessionId |
||
| 122 | ); |
||
| 123 | |||
| 124 | $row[] = api_time_to_hms($timeInSeconds); |
||
| 125 | |||
| 126 | $userWorkTime = 0; |
||
| 127 | foreach ($workList as $work) { |
||
| 128 | $userWorks = get_work_user_list( |
||
| 129 | 0, |
||
| 130 | 100, |
||
| 131 | null, |
||
| 132 | null, |
||
| 133 | $work['id'], |
||
| 134 | null, |
||
| 135 | $studentId, |
||
| 136 | false, |
||
| 137 | $courseId, |
||
| 138 | $sessionId |
||
| 139 | ); |
||
| 140 | |||
| 141 | if ($userWorks) { |
||
| 142 | foreach ($userWorks as $work) { |
||
| 143 | $userWorkTime += $workTimeList[$work['parent_id']]; |
||
| 144 | } |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | $row[] = api_time_to_hms($userWorkTime); |
||
| 149 | $status = ''; |
||
| 150 | if ($userWorkTime && $timeInSeconds) { |
||
| 151 | if ($userWorkTime > $timeInSeconds) { |
||
| 152 | $status = Display::label('TimeToFix', 'warning'); |
||
| 153 | } else { |
||
| 154 | $status = Display::label('Ok', 'success'); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | $row[] = $status; |
||
| 159 | /*$detailsLink = Display::url( |
||
| 160 | Display::return_icon('2rightarrow.png', get_lang('Details').' '.$studentData['username']), |
||
| 161 | $urlDetails, |
||
| 162 | ['id' => 'details_'.$studentData['username']] |
||
| 163 | ); |
||
| 164 | $row[] = $detailsLink;*/ |
||
| 165 | $all_datas[] = $row; |
||
| 166 | } |
||
| 167 | |||
| 168 | return $all_datas; |
||
| 169 | } |
||
| 212 |