Show all courses where I am enrolled as trainer

Show all courses where I am enrolled as trainer

by Andreas Schenkel -
Number of replies: 3
Picture of Plugin developers

I am trying to develop a Block "course list new" that shows a list of all courses where I am enrolled as a trainer.

At the moment I use

          $editingteachers = get_users_by_capability($coursecontext, 'moodle/course:manageactivities');

and this works fine. I would prefere the use of something like

         $editingteachers = get_users_by_role_on_context($coursecontext);

to focus on the role instead of the capability.

Does there already exists a function like  get_users_by_role_on_context($coursecontext) ?

In the screenshot you can see two red marked courses with the cabability manageactivities.

The list with only this courses is below  "Übersicht über alle Kurse als Trainer".

Attachment Bildschirmfoto zu 2021-08-09 10-51-04.png
Average of ratings: -
In reply to Andreas Schenkel

Re: Show all courses where I am enrolled as trainer

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

Well. I would say you are doing it right. You should always check capabilities instead of asking for specific role. If you wish to not bind your "trainer" to managing activities (i.e. editing mode) your block can declare a new capability named like "betrainer" that would have teacher and editing teacher set as its archetype. And you would then use this.

If you insist to check for specific role, you can take a look at what core_course_category:: preload_course_contacts() does.

Average of ratings: Useful (1)
In reply to David Mudrák

Re: Show all courses where I am enrolled as trainer

by Andreas Schenkel -
Picture of Plugin developers
I build my first moodle block and have just created a version 0.8-beta of the block.
https://github.com/andreasschenkel/moodle-block_course_list_advanced
It shows one list with the courses the user has the capability 'moodle/course:manageactivities') and a second list with all other course.
So the second lsit includes all courses where the usere is enrolled and has NOT this capability (e.g student, noneditingteacher, guest, ...)
Do not now if it might be to expensive in large installations.
Thank you for the answer that helps me to with the first steps.
(languagestring ist missing)