Skip to content

Commit a8974e8

Browse files
committed
Add configuration "exercise_category_report_user_extra_fields" BT#13789
- Option to add extra fields to the exercise_category_report.php page
1 parent 1e4f1c5 commit a8974e8

File tree

4 files changed

+134
-42
lines changed

4 files changed

+134
-42
lines changed

main/inc/ajax/model.ajax.php

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,28 +1228,49 @@ function getWhereClause($col, $oper, $val)
12281228
$documentPath = api_get_path(SYS_COURSE_PATH).$courseInfo['path']."/document";
12291229
$sessionId = api_get_session_id();
12301230

1231-
$columns = array(
1231+
$columns = [
12321232
'firstname',
12331233
'lastname',
1234-
'username',
1235-
'session',
1236-
'session_access_start_date',
1237-
'exe_date',
1238-
'score'
1239-
);
1234+
'username'
1235+
];
1236+
$extraFieldsToAdd = [];
1237+
$extraFields = api_get_configuration_value('exercise_category_report_user_extra_fields');
1238+
if (!empty($extraFields) && isset($extraFields['fields'])) {
1239+
$extraField = new ExtraField('user');
1240+
foreach ($extraFields['fields'] as $variable) {
1241+
$info = $extraField->get_handler_field_info_by_field_variable($variable);
1242+
if ($info) {
1243+
$extraFieldsToAdd[] = $variable;
1244+
}
1245+
}
1246+
}
1247+
if (!empty($extraFieldsToAdd)) {
1248+
$columns = array_merge($columns, $extraFieldsToAdd);
1249+
}
1250+
1251+
$columns[] = 'session';
1252+
$columns[] = 'session_access_start_date';
1253+
$columns[] = 'exe_date';
1254+
$columns[] = 'score';
12401255

12411256
if ($operation == 'excel') {
1242-
$columns = array(
1257+
$columns = [
12431258
'firstname',
12441259
'lastname',
1245-
'username',
1246-
'session',
1247-
'session_access_start_date',
1248-
'exe_date',
1249-
'score_percentage',
1250-
'only_score',
1251-
'total'
1252-
);
1260+
'username'
1261+
];
1262+
1263+
if (!empty($extraFieldsToAdd)) {
1264+
$columns = array_merge($columns, $extraFieldsToAdd);
1265+
}
1266+
1267+
$columns[] = 'session';
1268+
$columns[] = 'session_access_start_date';
1269+
$columns[] = 'exe_date';
1270+
$columns[] = 'score_percentage';
1271+
$columns[] = 'only_score';
1272+
$columns[] = 'total';
1273+
12531274
$overwriteColumnHeaderExport['session_access_start_date'] = get_lang('SessionStartDate');
12541275
$overwriteColumnHeaderExport['exe_date'] = get_lang('StartDate');
12551276
$overwriteColumnHeaderExport['score_percentage'] = get_lang('Score');
@@ -1262,7 +1283,6 @@ function getWhereClause($col, $oper, $val)
12621283
if (!empty($categoryList)) {
12631284
foreach ($categoryList as $categoryInfo) {
12641285
$label = 'category_'.$categoryInfo['id'];
1265-
12661286
if ($operation == 'excel') {
12671287
$columns[] = $label.'_score_percentage';
12681288
$columns[] = $label.'_only_score';
@@ -1292,7 +1312,7 @@ function getWhereClause($col, $oper, $val)
12921312
$courseInfo['code'],
12931313
true,
12941314
true,
1295-
!empty($sessionId)
1315+
$extraFieldsToAdd
12961316
);
12971317
break;
12981318
case 'get_hotpotatoes_exercise_results':

main/inc/lib/exercise.lib.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,7 @@ public static function getLatestHotPotatoResult(
16601660
* @param string $courseCode
16611661
* @param bool $showSessionField
16621662
* @param bool $showExerciseCategories
1663+
* @param array $userExtraFieldsToAdd
16631664
*
16641665
* @return array
16651666
*/
@@ -1673,7 +1674,8 @@ public static function get_exam_results_data(
16731674
$get_count = false,
16741675
$courseCode = null,
16751676
$showSessionField = false,
1676-
$showExerciseCategories = false
1677+
$showExerciseCategories = false,
1678+
$userExtraFieldsToAdd = []
16771679
) {
16781680
//@todo replace all this globals
16791681
global $documentPath, $filter;
@@ -1954,7 +1956,7 @@ public static function get_exam_results_data(
19541956
$oldIds = array_column($lp_list, 'lp_old_id', 'iid');
19551957

19561958
if (is_array($results)) {
1957-
$users_array_id = array();
1959+
$users_array_id = [];
19581960
$from_gradebook = false;
19591961
if (isset($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
19601962
$from_gradebook = true;
@@ -2045,24 +2047,18 @@ public static function get_exam_results_data(
20452047
$dt = api_convert_and_format_date($results[$i]['exe_weighting']);
20462048

20472049
// we filter the results if we have the permission to
2050+
$result_disabled = 0;
20482051
if (isset($results[$i]['results_disabled'])) {
20492052
$result_disabled = intval(
20502053
$results[$i]['results_disabled']
20512054
);
2052-
} else {
2053-
$result_disabled = 0;
20542055
}
2055-
20562056
if ($result_disabled == 0) {
20572057
$my_res = $results[$i]['exe_result'];
20582058
$my_total = $results[$i]['exe_weighting'];
20592059

2060-
$results[$i]['start_date'] = api_get_local_time(
2061-
$results[$i]['start_date']
2062-
);
2063-
$results[$i]['exe_date'] = api_get_local_time(
2064-
$results[$i]['exe_date']
2065-
);
2060+
$results[$i]['start_date'] = api_get_local_time($results[$i]['start_date']);
2061+
$results[$i]['exe_date'] = api_get_local_time($results[$i]['exe_date']);
20662062

20672063
if (!$results[$i]['propagate_neg'] && $my_res < 0) {
20682064
$my_res = 0;
@@ -2218,6 +2214,20 @@ public static function get_exam_results_data(
22182214
$actions .= $attempt_link;
22192215
}
22202216
$actions .= '</div>';
2217+
2218+
if (!empty($userExtraFieldsToAdd)) {
2219+
foreach ($userExtraFieldsToAdd as $variable) {
2220+
$extraFieldValue = new ExtraFieldValue('user');
2221+
$values = $extraFieldValue->get_values_by_handler_and_field_variable(
2222+
$results[$i]['user_id'],
2223+
$variable
2224+
);
2225+
if (isset($values['value'])) {
2226+
$results[$i][$variable] = $values['value'];
2227+
}
2228+
}
2229+
}
2230+
22212231
$exeId = $results[$i]['exe_id'];
22222232
$results[$i]['id'] = $exeId;
22232233
$category_list = [];

main/install/configuration.dist.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@
711711
// Block access to any user to "my progress" page
712712
//$_configuration['block_my_progress_page'] = false;
713713

714+
// Add user extra fields in report: main/mySpace/exercise_category_report.php
715+
//$_configuration['exercise_category_report_user_extra_fields'] = ['fields' => ['skype', 'rssfeeds']];
716+
714717

715718
// ------ Custom DB changes
716719
// Add user activation by confirmation email

main/mySpace/exercise_category_report.php

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
Display::display_header($nameTools);
8383
$form->display();
8484

85+
$extraFields = api_get_configuration_value('exercise_category_report_user_extra_fields');
86+
8587
if ($form->validate() && !empty($courseInfo)) {
8688
$values = $form->getSubmitValues();
8789
$exerciseId = isset($values['exercise_id']) ? $values['exercise_id'] : 0;
@@ -93,13 +95,24 @@
9395
$columns = [
9496
get_lang('FirstName'),
9597
get_lang('LastName'),
96-
get_lang('LoginName'),
97-
get_lang('Session'),
98-
get_lang('SessionStartDate'),
99-
get_lang('StartDate'),
100-
get_lang('Score')
98+
get_lang('LoginName')
10199
];
102100

101+
if (!empty($extraFields) && isset($extraFields['fields'])) {
102+
$extraField = new ExtraField('user');
103+
foreach ($extraFields['fields'] as $variable) {
104+
$info = $extraField->get_handler_field_info_by_field_variable($variable);
105+
if ($info) {
106+
$columns[] = $info['display_text'];
107+
}
108+
}
109+
}
110+
111+
$columns[] = get_lang('Session');
112+
$columns[] = get_lang('SessionStartDate');
113+
$columns[] = get_lang('StartDate');
114+
$columns[] = get_lang('Score');
115+
103116
if (!empty($categoryList)) {
104117
foreach ($categoryList as $categoryInfo) {
105118
$columns[] = $categoryInfo['title'];
@@ -109,18 +122,64 @@
109122

110123
$columnModel = [
111124
['name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'true'],
112-
['name' => 'lastname', 'index' => 'lastname', 'width' => '50', 'align' => 'left', 'formatter' => 'action_formatter', 'search' => 'true'],
113-
['name' => 'login', 'index' => 'username', 'width' => '40', 'align' => 'left', 'search' => 'true', 'hidden' => 'true'],
114-
['name' => 'session', 'index' => 'session', 'width' => '40', 'align' => 'left', 'search' => 'false'],
115125
[
116-
'name' => 'session_access_start_date',
117-
'index' => 'session_access_start_date',
126+
'name' => 'lastname',
127+
'index' => 'lastname',
118128
'width' => '50',
119-
'align' => 'center',
129+
'align' => 'left',
130+
'formatter' => 'action_formatter',
120131
'search' => 'true',
121132
],
122-
['name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'true'],
123-
['name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'center', 'search' => 'true'],
133+
[
134+
'name' => 'login',
135+
'index' => 'username',
136+
'width' => '40',
137+
'align' => 'left',
138+
'search' => 'true',
139+
'hidden' => 'true',
140+
],
141+
];
142+
143+
if (!empty($extraFields) && isset($extraFields['fields'])) {
144+
$extraField = new ExtraField('user');
145+
foreach ($extraFields['fields'] as $variable) {
146+
$columnModel[] = [
147+
'name' => $variable,
148+
'index' => $variable,
149+
'width' => '40',
150+
'align' => 'left',
151+
'search' => 'false',
152+
];
153+
}
154+
}
155+
156+
$columnModel[] = [
157+
'name' => 'session',
158+
'index' => 'session',
159+
'width' => '40',
160+
'align' => 'left',
161+
'search' => 'false',
162+
];
163+
$columnModel[] = [
164+
'name' => 'session_access_start_date',
165+
'index' => 'session_access_start_date',
166+
'width' => '50',
167+
'align' => 'center',
168+
'search' => 'true',
169+
];
170+
$columnModel[] = [
171+
'name' => 'exe_date',
172+
'index' => 'exe_date',
173+
'width' => '60',
174+
'align' => 'left',
175+
'search' => 'true',
176+
];
177+
$columnModel[] = [
178+
'name' => 'score',
179+
'index' => 'exe_result',
180+
'width' => '50',
181+
'align' => 'center',
182+
'search' => 'true',
124183
];
125184

126185
if (!empty($categoryList)) {

0 commit comments

Comments
 (0)