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

Return course generated image via the core_enrol_get_user_courses

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 4.2
    • 3.9.12
    • Web Services
    • MOODLE_39_STABLE
    • MOODLE_402_STABLE
    • MDL-73708-master
    • Hide
      1. As admin, enable WebServices and "Mobile services":
        Server ► Web services ► Overview
        Server ► Web Services ► Mobile
      2. Create a course without a summary image in it
      3. Create another course with a summary image in it
      4. Create a user and enroll the user as a student in the course
      5. Create a Token for the student user:
        • Click on Site administration ► Server ► Web services ► Manage tokens
      6. Next, you should do some CURL REST calling simulating a WS client with the student user.
        • You need to replace the wstoken, coursename is the name of the course without summary image, and the URL of your moodle instance

          curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_course_search_courses&wstoken=$wstoken&criterianame=search&criteriavalue=$coursename' --compressed

      7. Confirm that:
        • You receive the course object in the response
        • You have a param for courseimage that point to a URL similar to this: 

          $MOODLE_URL/pluginfile.php/$contextid/course/generated/course.svg

      8. Make the same request but now change the course to the course with a summary image
      9. Confirm that:
        • You receive the course object in the response
        • You have a param for courseimage that point to a URL similar to this: 

          $MOODLE_URL/pluginfile.php/$contextid/course/overviewfiles/$imagename

      10. Another CURL REST calling simulating a WS client with the student user.
        • You need to replace the wstoken, and the URL of your moodle instance

          curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_course_get_courses_by_field&wstoken=$wstoken' --compressed

      11. Confirm if both courses have courseimage following the same pattern inside the response
      12. Another CURL REST calling simulating a WS client with the student user.
        • You need to replace the wstoken, studentid, and the URL of your moodle instance

          curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_enrol_get_users_courses&wstoken=$wstoken&userid=$studentid' --compressed

      13. Confirm if both courses have courseimage following the same pattern inside the response
      14. Access and download the courseimages URLs in your browser
        • Check if you can access and see the image
        • Access your server logs and check if there are no warnings related to accessing images
      Show
      As admin, enable WebServices and "Mobile services": Server ► Web services ► Overview Server ► Web Services ► Mobile Create a course without a summary image in it Create another course with a summary image in it Create a user and enroll the user as a student in the course Create a Token for the student user: Click on Site administration ► Server ► Web services ► Manage tokens Next, you should do some CURL REST calling simulating a WS client with the student user. You need to replace the wstoken, coursename is the name of the course without summary image, and the URL of your moodle instance curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_course_search_courses&wstoken=$wstoken&criterianame=search&criteriavalue=$coursename' --compressed Confirm that: You receive the course object in the response You have a param for courseimage that point to a URL similar to this:  $MOODLE_URL/pluginfile.php/$contextid/course/generated/course.svg Make the same request but now change the course to the course with a summary image Confirm that: You receive the course object in the response You have a param for courseimage that point to a URL similar to this:  $MOODLE_URL/pluginfile.php/$contextid/course/overviewfiles/$imagename Another CURL REST calling simulating a WS client with the student user. You need to replace the wstoken, and the URL of your moodle instance curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_course_get_courses_by_field&wstoken=$wstoken' --compressed Confirm if both courses have courseimage following the same pattern inside the response Another CURL REST calling simulating a WS client with the student user. You need to replace the wstoken, studentid, and the URL of your moodle instance curl 'MOODLE_URL/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_enrol_get_users_courses&wstoken=$wstoken&userid=$studentid' --compressed Confirm if both courses have courseimage following the same pattern inside the response Access and download the courseimages URLs in your browser Check if you can access and see the image Access your server logs and check if there are no warnings related to accessing images

      The mobile app is not currently able to generate a matching image with web, this could be easily solved with this improvement.

      The images currently generated for web are base64 encoded and directly embedded in the HTML, while this is acceptable for a web app it creates some challenges for external system such as the Moodle app because the images have to be retrieved as a file from the server (is not feasible to just return base64 via Web Services JSON response payload)

      So, the proposed solution does the following:

      • It will use the pluginfile.php script to dynamically generate the geo-pattern course image when requested
      • It will return a new field in several course related WebSevices called courseimage with a URL for downloading the course image, pointing to the geo-pattern generaiton endpoint or a custom file if used
      • For the previous to happen we'd need a few minor API changes

       

       

        1. course.png
          course.png
          176 kB
        2. errorlog.gif
          errorlog.gif
          5.85 MB
        3. student id.png
          student id.png
          123 kB
        4. ws-student.png
          ws-student.png
          211 kB

            rodrigo.mady@moodle.com Rodrigo Mady
            jleyva Juan Leyva
            Juan Leyva Juan Leyva
            Paul Holden Paul Holden
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 4 hours, 43 minutes
                1d 4h 43m

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