Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-79397

Automatically generate report entity table aliases (simplify API)

XMLWordPrintable

    • MOODLE_404_STABLE
    • MOODLE_404_STABLE
    • Hide
      1. Automated tests will detect regressions

      Manual test

      1. Log in as admin
      2. Navigate to Development > Debugging in site administration
      3. Set Debug messages to DEVELOPER and save

      Course categories

      1. Create a new course in the default category
      2. Create a new cohort in the default category context
      3. Navigate to Reports from user menu
      4. Create new report from Course categories report source
        • Include default setup: Yes
      5. In report editor add the following columns:
        • Course > Course full name
        • Cohort > Name
      6. Confirm the report lists the default category, and course/cohort you previously created
      7. Open the Debug panel under the report
      8. Confirm the alias for the '{course}' and '{cohort}' tables differ (they'll look like LEFT JOIN {course} rbaliasX ON ... and LEFT JOIN {cohort} rbaliasY ON ... - where the actual values for X & Y differ)

      Notes

      1. Create a new user
      2. Enrol user in the course you previously created
      3. From course participants page, click the new user to view their course profile
      4. Press Miscellaneous > Notes
      5. Add a new site note
      6. Navigate to Reports from user menu
      7. Create new report from Notes report source
        • Include default setup: Yes
      8. In report editor add the following columns:
        • Author > Full name
      9. Confirm the report lists the note details
        • Recipient > Full name columns shows the test user name
        • Author > Full name column shows the admin name
      10. Open the Debug panel under the report
      11. Confirm the alias for the two '{user}' tables differ (they'll look like LEFT JOIN {user} rbaliasX ON ... and LEFT JOIN {user} rbaliasY ON ... - where the actual values for X & Y differ)
      Show
      Automated tests will detect regressions Manual test Log in as admin Navigate to Development > Debugging in site administration Set Debug messages to DEVELOPER and save Course categories Create a new course in the default category Create a new cohort in the default category context Navigate to Reports from user menu Create new report from Course categories report source Include default setup: Yes In report editor add the following columns: Course > Course full name Cohort > Name Confirm the report lists the default category, and course/cohort you previously created Open the Debug panel under the report Confirm the alias for the '{ course }' and '{ cohort }' tables differ (they'll look like LEFT JOIN {course} rbaliasX ON ... and LEFT JOIN {cohort} rbaliasY ON ... - where the actual values for X & Y differ) Notes Create a new user Enrol user in the course you previously created From course participants page, click the new user to view their course profile Press Miscellaneous > Notes Add a new site note Navigate to Reports from user menu Create new report from Notes  report source Include default setup: Yes In report editor add the following columns: Author > Full name Confirm the report lists the note details Recipient > Full name columns shows the test user name Author > Full name column shows the admin name Open the Debug panel under the report Confirm the alias for the two '{ user }' tables differ (they'll look like LEFT JOIN {user} rbaliasX ON ... and LEFT JOIN {user} rbaliasY ON ... - where the actual values for X & Y differ)

      As our number of custom/system report entities has grown, so has the number of table aliases that are defined within them

      The current API requires each entity to define the tables it uses, plus the default alias each should have - while trying to ensure each is unique

      Take for example the 'context' table that is used by many entities, each trying to define a unique alias:

      1. https://github.com/moodle/moodle/blob/ecddfa6ccd8fa1390cf84a568baee78816b549aa/admin/roles/classes/reportbuilder/local/entities/role.php#L43
      2. https://github.com/moodle/moodle/blob/ecddfa6ccd8fa1390cf84a568baee78816b549aa/badges/classes/reportbuilder/local/entities/badge.php#L54
      3. https://github.com/moodle/moodle/blob/ecddfa6ccd8fa1390cf84a568baee78816b549aa/cohort/classes/reportbuilder/local/entities/cohort.php#L51
      4. The above is a sample of only 3 out of 12 instances, you get the idea...

      This also leads to developers having to manually resolve any duplicate aliases themselves:

      1. https://github.com/moodle/moodle/blob/ecddfa6ccd8fa1390cf84a568baee78816b549aa/blog/classes/reportbuilder/datasource/blogs.php#L91-L95
      2. https://github.com/moodle/moodle/blob/ecddfa6ccd8fa1390cf84a568baee78816b549aa/course/classes/reportbuilder/datasource/categories.php#L63-L69
      3. https://github.com/moodle/moodle/blob/ecddfa6ccd8fa1390cf84a568baee78816b549aa/notes/classes/reportbuilder/datasource/notes.php#L71-L78

      Simplify all of this by ensuring that all entity table aliases are auto-generated, so developers don't need to handle table alias uniqueness in their own entities, or duplication in their reports

      Make sure it's backwards-compatible with current API, emitting developer debugging when necessary

        1. MDL-79397-course category.png
          309 kB
          Ron Carl Alfon Yu
        2. MDL-79397-notes.png
          245 kB
          Ron Carl Alfon Yu

            pholden Paul Holden
            pholden Paul Holden
            David Carrillo David Carrillo
            Ilya Tregubov Ilya Tregubov
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours, 51 minutes
                4h 51m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.