This case study will cover adding and configuring a Derived Table to a Domain that identifies the LMS Role of the user in the Table (e.g. student, editing teacher, etc.).
For the purposes of this case study, we will add the Roles Derived Table to the Course Completions Domain. In order to edit the Domain, you will need to copy it from the Public folder of the Repository to a folder in your private organizational folder tree —copying the Domain requires you to have the Zoola To copy the Course Completions Domain for editing, complete the following steps:
- In the Repository, navigate to Public > Moodle/Totara > Domains.
- Right-click the Course Completions Domain and select Copy.
- Navigate to the Domains folder of your private organizational tree.
- Right click the Domains folder and select Paste. An editable copy of the Course Completions Domain now exists in your private Domains folder.
To edit the Course Completions Domain and add and configure the Roles Derived Table, complete the following steps:
- Right-click your newly copied Course Completions Domain and select Edit. The Edit Domain page appears.
- Below the Domain Design heading, click the Edit with Domain Designer link. The Domain Designer opens to the Display tab.
- Navigate to the Derived Tables tab:
- The 'roles' Derived Table will pull user roles from the mdl_role_assignments and mdl_context tables. To create this Derived Table, complete the following steps:
- In the Query ID field, enter "roles".
In the Query field, enter the following SQL query:
select distinct ra.userid, ctx.instanceid as courseid, ra.roleid, if(length(r.name) > 0, r.name, r.shortname) as role from mdl_role_assignments ra join mdl_context ctx on (ra.contextid = ctx.id and ctx.contextlevel = 50) join mdl_role r on ra.roleid = r.id
- Click the Run Query button.
- A list of query results will appear below the Run Query button. Select all of the resulting fields by holding Command/CTRL/Shift and selecting each individual field:
- Click the Save Table button. Your new "roles" Derived Table will now appear in the Available Objects panel with the unique Derived Table/Calculated Field identifier:
- Navigate to the Joins tab and create the following joins:
- From the Left Table, select the course field from the mdl_course_completions table, then select the courseid field from the roles Derived Table. Click the Inner Join button.
- From the Left Table, select the userid field from the mdl_course_completions table, then select the userid field from the roles Derived Table. Click the Inner Join button.
- A modal window appears, notifying you that the tables have already been joined, and that a composite key will be created. Click the OK button to complete your second join:
- Navigate to the Display tab.
- In the Resources panel, select to View as: Join Tree.
- Expand JoinTree_1, then expand the roles table:
- Select the role field and drag it into the Course Completions set in the Sets and Items panel.
0 Comments