@@ -312,6 +312,27 @@ function mod_customcert_output_fragment_editelement($args) {
312
312
return $ form ->render ();
313
313
}
314
314
315
+ /**
316
+ * This function extends the course navigation block for the site.
317
+ *
318
+ * @param \navigation_node $parentnode
319
+ * @param \stdClass $course
320
+ * @param \context_course $context
321
+ */
322
+ function customcert_extend_navigation_course (\navigation_node $ parentnode , \stdClass $ course , \context_course $ context ) {
323
+ global $ PAGE ;
324
+
325
+ $ addnode = $ context ->contextlevel === 50 ;
326
+ $ addnode = $ addnode && !($ context ->instanceid === SITEID );
327
+ $ addnode = $ addnode && has_capability ('mod/customcert:viewallcertificates ' , $ context );
328
+ $ isCourseNav = is_null ($ PAGE ->cm ->instance );
329
+ if ($ addnode && $ isCourseNav ) {
330
+ if ($ node = build_downloadall_node ($ isCourseNav , $ course , $ context )) {
331
+ $ parentnode ->add_node ($ node );
332
+ }
333
+ }
334
+ }
335
+
315
336
/**
316
337
* This function extends the settings navigation block for the site.
317
338
*
@@ -343,6 +364,12 @@ function customcert_extend_settings_navigation(settings_navigation $settings, na
343
364
$ customcertnode ->add_node ($ node , $ beforekey );
344
365
}
345
366
367
+ if (has_capability ('mod/customcert:viewallcertificates ' , $ PAGE ->cm ->context )) {
368
+ if ($ node = build_downloadall_node (false , $ PAGE ->cm ->get_course (), null )) {
369
+ $ customcertnode ->add_node ($ node , $ beforekey );
370
+ }
371
+ }
372
+
346
373
if (has_capability ('mod/customcert:verifycertificate ' , $ settings ->get_page ()->cm ->context )) {
347
374
$ node = navigation_node::create (get_string ('verifycertificate ' , 'customcert ' ),
348
375
new moodle_url ('/mod/customcert/verify_certificate.php ' , array ('contextid ' => $ settings ->get_page ()->cm ->context ->id )),
@@ -354,6 +381,50 @@ function customcert_extend_settings_navigation(settings_navigation $settings, na
354
381
return $ customcertnode ->trim_if_empty ();
355
382
}
356
383
384
+ /**
385
+ * Build the navigation node for the 'Download certificates' item.
386
+ *
387
+ * @param boolean $isCourseNav
388
+ * @param \stdClass $course
389
+ * @param \course_context $context
390
+ * @return \navigation_node|null null if there are no certifcates available for the download
391
+ */
392
+ function build_downloadall_node (bool $ isCourseNav , stdClass $ course , \context_course $ context = null ) {
393
+
394
+ global $ DB , $ PAGE ;
395
+
396
+ if (!$ isCourseNav ) {
397
+ $ courseContext = \context_course::instance ($ course ->id );
398
+ //Check if there is available certs
399
+ $ certs = $ DB ->get_records ('customcert ' , ['id ' => $ PAGE ->cm ->instance ]);
400
+ $ users = $ DB ->get_records ('role_assignments ' , ['contextid ' => $ courseContext ->id ]);
401
+ $ urlparams = ['customcertid ' => $ PAGE ->cm ->instance ];
402
+ } else {
403
+ $ certs = $ DB ->get_records ('customcert ' , ['course ' => $ context ->instanceid ]);
404
+ $ users = $ DB ->get_records ('role_assignments ' , ['contextid ' => $ context ->id ]);
405
+ $ urlparams = ['courseid ' => $ course ->id ];
406
+ }
407
+ $ availablecerts = false ;
408
+ foreach ($ certs as $ certid => $ cert_fields ) {
409
+ foreach ($ users as $ userid => $ user_fields ) {
410
+ if (!$ DB ->get_record ('customcert_issues ' , ['userid ' => $ user_fields ->userid , 'customcertid ' => $ certid ])) {
411
+ continue ;
412
+ }
413
+ $ availablecerts = true ;
414
+ break ;
415
+ }
416
+ if ($ availablecerts ) break ;
417
+ }
418
+ if ($ availablecerts ) {
419
+ $ node = \navigation_node::create (get_string ('bulkdownloadlink ' , 'mod_customcert ' ),
420
+ new \moodle_url ('/mod/customcert/downloadcerts.php ' , $ urlparams ),
421
+ \navigation_node::TYPE_SETTING , null , 'mod_customcert_downloadcerts ' ,
422
+ new \pix_icon ('a/download_all ' , 'certificates ' ));
423
+ return $ node ;
424
+ }
425
+ return null ;
426
+ }
427
+
357
428
/**
358
429
* Add nodes to myprofile page.
359
430
*
@@ -420,7 +491,8 @@ function mod_customcert_inplace_editable($itemtype, $itemid, $newvalue) {
420
491
*/
421
492
function mod_customcert_get_fontawesome_icon_map () {
422
493
return [
423
- 'mod_customcert:download ' => 'fa-download '
494
+ 'mod_customcert:deletelocalcopy ' => 'fa-minus-square ' ,
495
+ 'mod_customcert:download ' => 'fa-download ' ,
424
496
];
425
497
}
426
498
0 commit comments