@@ -172,6 +172,72 @@ function confirmation() {
172172 api_not_allowed (true );
173173 }
174174 break ;
175+ case 'download_certificates_report ' :
176+ $ exportData = array_map (function ($ learner ) {
177+ return [
178+ $ learner ['user_id ' ],
179+ $ learner ['username ' ],
180+ $ learner ['firstname ' ],
181+ $ learner ['lastname ' ],
182+ ];
183+ }, $ certificate_list );
184+
185+ $ csvContent = [];
186+ $ csvHeaders = [];
187+ $ csvHeaders [] = get_lang ('Id ' );
188+ $ csvHeaders [] = get_lang ('UserName ' );
189+ $ csvHeaders [] = get_lang ('FirstName ' );
190+ $ csvHeaders [] = get_lang ('LastName ' );
191+ $ csvHeaders [] = get_lang ('Score ' );
192+ $ csvHeaders [] = get_lang ('Date ' );
193+
194+ $ extraFields = [];
195+ $ extraFieldsFromSettings = [];
196+ $ extraFieldsFromSettings = api_get_configuration_value ('certificate_export_report_user_extra_fields ' );
197+
198+ if (!empty ($ extraFieldsFromSettings ) && isset ($ extraFieldsFromSettings ['extra_fields ' ])) {
199+ $ extraFields = $ extraFieldsFromSettings ['extra_fields ' ];
200+ $ usersProfileInfo = [];
201+
202+ $ userIds = array_column ($ certificate_list , 'user_id ' , 'user_id ' );
203+
204+ foreach ($ extraFields as $ fieldName ) {
205+ $ extraFieldInfo = UserManager::get_extra_field_information_by_name ($ fieldName );
206+
207+ if (!empty ($ extraFieldInfo )) {
208+ $ csvHeaders [] = $ fieldName ;
209+
210+ $ usersProfileInfo [$ extraFieldInfo ['id ' ]] = TrackingCourseLog::getAdditionalProfileInformationOfFieldByUser (
211+ $ extraFieldInfo ['id ' ],
212+ $ userIds
213+ );
214+ }
215+ }
216+
217+ foreach ($ exportData as $ key => $ row ) {
218+ $ list = GradebookUtils::get_list_gradebook_certificates_by_user_id (
219+ $ row [0 ],
220+ $ categoryId
221+ );
222+
223+ foreach ($ list as $ valueCertificate ) {
224+ $ row [] = $ valueCertificate ['score_certificate ' ];
225+ $ row [] = api_convert_and_format_date ($ valueCertificate ['created_at ' ]);
226+ }
227+
228+ foreach ($ usersProfileInfo as $ extraInfo ) {
229+ $ row [] = $ extraInfo [$ row [0 ]][0 ];
230+ }
231+
232+ $ csvContent [] = $ row ;
233+ }
234+ }
235+
236+ array_unshift ($ csvContent , $ csvHeaders );
237+
238+ $ fileName = 'learner_certificate_report_ ' .api_get_local_time ();
239+ Export::arrayToCsv ($ csvContent , $ fileName );
240+ break ;
175241}
176242
177243$ interbreadcrumb [] = [
@@ -290,6 +356,11 @@ function confirmation() {
290356 );
291357 }
292358
359+ $ actions .= Display::url (
360+ Display::return_icon ('export_csv.png ' , get_lang ('ExportCertificateReport ' ), [], ICON_SIZE_MEDIUM ),
361+ $ url .'&action=download_certificates_report '
362+ );
363+
293364 if ($ allowCustomCertificate ) {
294365 $ actions .= Display::url (
295366 Display::return_icon ('file_zip.png ' , get_lang ('ExportAllCertificatesToZIP ' ), [], ICON_SIZE_MEDIUM ),
0 commit comments