Skip to content

Commit 872c79e

Browse files
authored
Tracking: add global parameter to enable theoretical time for course on myStudent tracking and resume session - refs BT#22723 (#6434)
Author: @yverhenne
1 parent 3322b97 commit 872c79e

File tree

3 files changed

+177
-53
lines changed

3 files changed

+177
-53
lines changed

main/install/configuration.dist.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,10 @@
19481948

19491949
// Default items per page in main/mySpace/users.php
19501950
// $_configuration['my_space_users_items_per_page'] = 10;
1951+
1952+
//Add an expected theorical time spent in a course to show in main/mySpace/myStudents.php and main/session/resume_session.php
1953+
//Create an extra field for courses with identifier "theoretical_time"
1954+
//$_configuration['display_theoretical_time'] = false;
19511955

19521956
// Add teachers column in course list.
19531957
// $_configuration['add_teachers_in_course_list'] = false;

main/mySpace/myStudents.php

Lines changed: 125 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,19 +1229,33 @@
12291229
echo MyStudents::getBlockForClasses($student_id);
12301230
echo '</div></div>';
12311231

1232+
$theoreticalTimeEnabled = api_get_configuration_value('display_theoretical_time');
12321233
$exportCourseList = [];
12331234
$lpIdList = [];
12341235
if (empty($details)) {
12351236
$csv_content[] = [];
1236-
$csv_content[] = [
1237-
get_lang('Session'),
1238-
get_lang('Course'),
1239-
get_lang('Time'),
1240-
get_lang('Progress'),
1241-
get_lang('Score'),
1242-
get_lang('AttendancesFaults'),
1243-
get_lang('Evaluations'),
1244-
];
1237+
if($theoreticalTimeEnabled) {
1238+
$csv_content[] = [
1239+
get_lang('Session'),
1240+
get_lang('Course'),
1241+
get_lang('Time'),
1242+
get_lang('Progress'),
1243+
get_lang('Score'),
1244+
get_lang('TheoreticalTime'),
1245+
get_lang('AttendancesFaults'),
1246+
get_lang('Evaluations'),
1247+
];
1248+
} else {
1249+
$csv_content[] = [
1250+
get_lang('Session'),
1251+
get_lang('Course'),
1252+
get_lang('Time'),
1253+
get_lang('Progress'),
1254+
get_lang('Score'),
1255+
get_lang('AttendancesFaults'),
1256+
get_lang('Evaluations'),
1257+
];
1258+
}
12451259

12461260
$attendance = new Attendance();
12471261
$extraFieldValueSession = new ExtraFieldValue('session');
@@ -1281,24 +1295,41 @@
12811295
<th>'.get_lang('Course').'</th>
12821296
<th>'.get_lang('Time').'</th>
12831297
<th>'.get_lang('Progress').' '.Display::return_icon('info3.gif', get_lang('progressBasedOnVisiblesLPsInEachCourse'), [], ICON_SIZE_TINY).' </th>
1284-
<th>'.get_lang('Score').'</th>
1285-
<th>'.get_lang('AttendancesFaults').'</th>
1298+
<th>'.get_lang('Score').'</th>';
1299+
if($theoreticalTimeEnabled) {
1300+
echo '<th>'.get_lang('TheoreticalTime').'</th>';
1301+
}
1302+
echo '<th>'.get_lang('AttendancesFaults').'</th>
12861303
<th>'.get_lang('Evaluations').'</th>
12871304
<th>'.get_lang('Details').'</th>
12881305
</tr>';
12891306
echo '</thead>';
12901307
echo '<tbody>';
12911308

1292-
$csvRow = [
1293-
'',
1294-
get_lang('Course'),
1295-
get_lang('Time'),
1296-
get_lang('Progress'),
1297-
get_lang('Score'),
1298-
get_lang('AttendancesFaults'),
1299-
get_lang('Evaluations'),
1300-
get_lang('Details'),
1301-
];
1309+
if($theoreticalTimeEnabled) {
1310+
$csvRow = [
1311+
'',
1312+
get_lang('Course'),
1313+
get_lang('Time'),
1314+
get_lang('Progress'),
1315+
get_lang('Score'),
1316+
get_lang('TheoreticalTime'),
1317+
get_lang('AttendancesFaults'),
1318+
get_lang('Evaluations'),
1319+
get_lang('Details'),
1320+
];
1321+
} else {
1322+
$csvRow = [
1323+
'',
1324+
get_lang('Course'),
1325+
get_lang('Time'),
1326+
get_lang('Progress'),
1327+
get_lang('Score'),
1328+
get_lang('AttendancesFaults'),
1329+
get_lang('Evaluations'),
1330+
get_lang('Details'),
1331+
];
1332+
}
13021333

13031334
$exportCourseList[$sId][] = $csvRow;
13041335

@@ -1310,6 +1341,8 @@
13101341
$gradeBookTotal = [0, 0];
13111342
$totalCourses = count($courses);
13121343
$scoreDisplay = ScoreDisplay::instance();
1344+
$theoreticalTime = 0;
1345+
$totalTheoreticalTime = 0;
13131346

13141347
foreach ($courses as $courseId) {
13151348
$courseInfoItem = api_get_course_info_by_id($courseId);
@@ -1416,18 +1449,43 @@
14161449
$totalScore += $score;
14171450
}
14181451

1452+
if($theoreticalTimeEnabled) {
1453+
$theoreticalTime = CourseManager::get_course_extra_field_value('theoretical_time', $courseCodeItem);
1454+
if (is_numeric($theoreticalTime) && (float)$theoreticalTime != 0) {
1455+
$totalTheoreticalTime += (float)$theoreticalTime;
1456+
$hours = floor($theoreticalTime / 60);
1457+
$minutes = $theoreticalTime % 60;
1458+
$theoreticalTimeDisplay = sprintf('%02d:%02d', $hours, $minutes);
1459+
} else {
1460+
$theoreticalTimeDisplay = '00:00';
1461+
}
1462+
}
1463+
14191464
$progress = empty($progress) ? '0%' : $progress.'%';
14201465
$score = empty($score) ? '0%' : $score.'%';
14211466

1422-
$csvRow = [
1423-
$session_name,
1424-
$courseInfoItem['title'],
1425-
$time_spent_on_course,
1426-
$progress,
1427-
$score,
1428-
$attendances_faults_avg,
1429-
$scoretotal_display,
1430-
];
1467+
if($theoreticalTimeEnabled) {
1468+
$csvRow = [
1469+
$session_name,
1470+
$courseInfoItem['title'],
1471+
$time_spent_on_course,
1472+
$progress,
1473+
$score,
1474+
$theoreticalTimeDisplay,
1475+
$attendances_faults_avg,
1476+
$scoretotal_display,
1477+
];
1478+
} else {
1479+
$csvRow = [
1480+
$session_name,
1481+
$courseInfoItem['title'],
1482+
$time_spent_on_course,
1483+
$progress,
1484+
$score,
1485+
$attendances_faults_avg,
1486+
$scoretotal_display,
1487+
];
1488+
}
14311489

14321490
$csv_content[] = $csvRow;
14331491
$exportCourseList[$sId][] = $csvRow;
@@ -1440,8 +1498,11 @@
14401498
</td>
14411499
<td>'.$time_spent_on_course.'</td>
14421500
<td>'.$progress.'</td>
1443-
<td>'.$score.'</td>
1444-
<td>'.$attendances_faults_avg.'</td>
1501+
<td>'.$score.'</td>';
1502+
if($theoreticalTimeEnabled) {
1503+
echo '<td>'.$theoreticalTimeDisplay.'</td>';
1504+
}
1505+
echo '<td>'.$attendances_faults_avg.'</td>
14451506
<td>'.$scoretotal_display.'</td>';
14461507
if (!empty($coachId)) {
14471508
echo '<td width="10"><a href="'.api_get_self().'?student='.$student_id
@@ -1470,22 +1531,42 @@
14701531
<th>'.get_lang('Total').'</th>
14711532
<th>'.$totalTimeFormatted.'</th>
14721533
<th>'.$totalProgressFormatted.'</th>
1473-
<th>'.$totalScoreFormatted.'</th>
1474-
<th>'.$totalAttendanceFormatted.'</th>
1534+
<th>'.$totalScoreFormatted.'</th>';
1535+
if($theoreticalTimeEnabled) {
1536+
$totalHours = floor($totalTheoreticalTime / 60);
1537+
$totalMinutes = $totalTheoreticalTime % 60;
1538+
$totalTheoreticalTimeDisplay = sprintf('%02d:%02d', $totalHours, $totalMinutes);
1539+
echo '<td>'.$totalTheoreticalTimeDisplay.'</td>';
1540+
}
1541+
echo '<th>'.$totalAttendanceFormatted.'</th>
14751542
<th>'.$totalEvaluations.'</th>
14761543
<th></th>
14771544
</tr>';
14781545

1479-
$csvRow = [
1480-
get_lang('Total'),
1481-
'',
1482-
$totalTimeFormatted,
1483-
$totalProgressFormatted,
1484-
$totalScoreFormatted,
1485-
$totalAttendanceFormatted,
1486-
$totalEvaluations,
1487-
'',
1488-
];
1546+
if($theoreticalTimeEnabled) {
1547+
$csvRow = [
1548+
get_lang('Total'),
1549+
'',
1550+
$totalTimeFormatted,
1551+
$totalProgressFormatted,
1552+
$totalScoreFormatted,
1553+
$totalTheoreticalTimeDisplay,
1554+
$totalAttendanceFormatted,
1555+
$totalEvaluations,
1556+
'',
1557+
];
1558+
} else {
1559+
$csvRow = [
1560+
get_lang('Total'),
1561+
'',
1562+
$totalTimeFormatted,
1563+
$totalProgressFormatted,
1564+
$totalScoreFormatted,
1565+
$totalAttendanceFormatted,
1566+
$totalEvaluations,
1567+
'',
1568+
];
1569+
}
14891570

14901571
$csv_content[] = $csvRow;
14911572
$exportCourseList[$sId][] = $csvRow;

main/session/resume_session.php

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,28 @@
176176
Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL),
177177
"add_courses_to_session.php?page=resume_session.php&id_session=$sessionId"
178178
);
179+
180+
$theoreticalTimeEnabled = api_get_configuration_value('display_theoretical_time');
179181
$courseListToShow = Display::page_subheader(get_lang('CourseList').$url);
180182

181183
$courseListToShow .= '<table id="session-list-course" class="table table-hover table-striped data_table">
182-
<thead>
183-
<tr>
184-
<th></th>
185-
<th width="35%">'.get_lang('CourseTitle').'</th>
186-
<th width="30%">'.get_lang('CourseCoach').'</th>
187-
<th width="10%">'.get_lang('UsersNumber').'</th>
188-
<th width="25%">'.get_lang('Actions').'</th>
189-
</tr></thead><tbody id="sortable-course-list">';
184+
<thead>+<tr>';
185+
if ($theoreticalTimeEnabled) {
186+
$courseListToShow .= '<th></th>
187+
<th width="30%">'.get_lang('CourseTitle').'</th>
188+
<th width="20%">'.get_lang('TheoreticalTime').'</th>
189+
<th width="15%">'.get_lang('CourseCoach').'</th>
190+
<th width="10%">'.get_lang('UsersNumber').'</th>
191+
<th width="25%">'.get_lang('Actions').'</th>
192+
</tr></thead><tbody id="sortable-course-list">';
193+
} else {
194+
$courseListToShow .= '<th></th>
195+
<th width="35%">'.get_lang('CourseTitle').'</th>
196+
<th width="30%">'.get_lang('CourseCoach').'</th>
197+
<th width="10%">'.get_lang('UsersNumber').'</th>
198+
<th width="25%">'.get_lang('Actions').'</th>
199+
</tr></thead><tbody id="sortable-course-list">';
200+
}
190201

191202
if ($session->getNbrCourses() === 0) {
192203
$courseListToShow .= '<tr>
@@ -227,6 +238,8 @@
227238
$courseList = $newCourseList;
228239
}
229240

241+
$totalTheoreticalTime = 0;
242+
230243
/** @var Course $course */
231244
foreach ($courseList as $course) {
232245
// Select the number of users
@@ -245,6 +258,18 @@
245258

246259
$courseUrl = api_get_course_url($course->getCode(), $sessionId);
247260
$courseBaseUrl = api_get_course_url($course->getCode());
261+
262+
if ($theoreticalTimeEnabled) {
263+
$theoreticalTime = CourseManager::get_course_extra_field_value('theoretical_time',$course->getCode());
264+
if (is_numeric($theoreticalTime) && (float)$theoreticalTime != 0) {
265+
$totalTheoreticalTime += (float)$theoreticalTime;
266+
$hours = floor($theoreticalTime / 60);
267+
$minutes = $theoreticalTime % 60;
268+
$theoreticalTimeDisplay = sprintf('%02d:%02d', $hours, $minutes);
269+
} else {
270+
$theoreticalTimeDisplay = '00:00';
271+
}
272+
}
248273

249274
// hide_course_breadcrumb the parameter has been added to hide the name
250275
// of the course, that appeared in the default $interbreadcrumb
@@ -256,6 +281,9 @@
256281
$courseUrl
257282
)
258283
.'</td>';
284+
if ($theoreticalTimeEnabled) {
285+
$courseItem .= '<td>'.$theoreticalTimeDisplay.'</td>';
286+
}
259287
$courseItem .= '<td>'.($namesOfCoaches ? implode('<br>', $namesOfCoaches) : get_lang('None')).'</td>';
260288
$courseItem .= '<td>'.$numberOfUsers.'</td>';
261289
$courseItem .= '<td>';
@@ -327,9 +355,20 @@
327355
$courseItem .= '</td></tr>';
328356
$count++;
329357
}
358+
if ($theoreticalTimeEnabled) {
359+
$totalHours = floor($totalTheoreticalTime / 60);
360+
$totalMinutes = $totalTheoreticalTime % 60;
361+
$totalTheoreticalTimeDisplay = sprintf('%02d:%02d', $totalHours, $totalMinutes);
362+
$courseItem .= '<tr style="font-weight:bold"><td></td><td>Total</td>';
363+
$courseItem .= '<td>'.$totalTheoreticalTimeDisplay.'</td>';
364+
$courseItem .= '<td>-</td>';
365+
$courseItem .= '<td>-</td>';
366+
$courseItem .= '<td>-</td></tr>';
367+
}
368+
330369
$courseListToShow .= $courseItem;
331370
}
332-
$courseListToShow .= '</table><br />';
371+
$courseListToShow .= '</tbody></table><br />';
333372

334373
$url = '&nbsp;'.Display::url(
335374
Display::return_icon('user_subscribe_session.png', get_lang('Add')),

0 commit comments

Comments
 (0)