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

Modify the calendar events table to allow any component to create action events

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      Test 1
      1. Create a course, enrol a student
      2. Add two assignments, with the following settings:
        • Assign 1
          • Due date: Tomorrow
          • Submission type: Online text or File upload
        • Assing 2
          • Due date: The day after tomorrow
          • Submission type: Nothing checked
      3. Login as a student
      4. Check the timeline block on your dashboard.
      5. Confirm that you see "{{Assign 1}" with a link "Add submission"
      6. Go to the calendar.
      7. Confirm that you see both "Assign 1" and "Assign 2".
      8. Open "Assign 1"'s due date event, confirm that you see "Add submission".
      9. Close the event modal and open "Assign 2"'s due date event.
      10. Confirm that you see "Go to activity" instead.
      Test 2 (quick regression check)
      1. Manually create some events in the calendar (user, course, category, site).
      2. Make sure you can edit and delete them following "edit" and "delete" buttons.
      3. Make sure you can drag editable events to the different dates and they save
      4. Make sure (as a teacher) you can drag the "Assignment due date" event to a different date inside the calendar and it saves, even though it does not display the "Edit" button anywhere
      Test 3a (plugin support) - Standard event

      This is an example of creating an event from a plugin (block "Comments"), feel free to improvise to test.

      1. Open blocks/comments/block_comments.php and add to the get_content() function

                global $DB;
                $instanceid = 11;
                $ev = $DB->get_record('event', ['component' => 'block_comments', 'eventtype' => 'mytype', 'instance' => $instanceid]);
                if (!$ev) {
                    $event = new stdClass();
                    $event->eventtype = 'mytype';
                    $event->type = CALENDAR_EVENT_TYPE_STANDARD; // Change it to CALENDAR_EVENT_TYPE_ACTION in the next step.
                    $event->name = $event->description = 'Test event ' . $instanceid;
                    $event->instance = $instanceid;
                    $event->timestart = $event->timesort = time() + DAYSECS;
                    $event->visible = 1;
                    $event->timeduration = 0;
                    $event->context = context_system::instance();
                    $event->component = 'block_comments';
                    calendar_event::create($event, false);
                }
        

      2. Add an instance of block "Comments" to any course and view this course page. Now your event will be created.
      3. Go to your calendar.
      4. Confirm that you see "Test event 11" and its date is set for tomorrow.
      5. View this event in all possible view modes (monthly, daily, upcoming, clicking on the event so it opens in a popup, etc).
        • Make sure that it is always displayed consistently and there are no "Edit" and "Delete" buttons anywhere.
      6. Check your timeline on the dashboard.
      7. Confirm that this event will not be there (it is not an action event yet)
      Test 3b (plugin support) - Action event
      1. Turn your event into an action event by editing the code snippet in Test 3a:
        1. Set "$instanceid" to 12.
        2. Set "$event->type" from "CALENDAR_EVENT_TYPE_STANDARD" to "CALENDAR_EVENT_TYPE_ACTION"
      2. Refresh the page with the comments block to generate this action event.
      3. Go to the calendar.
      4. Confirm that you see "Test event 12" in the calendar.
      5. Add this callback to the blocks/comments/lib.php :

        function block_comments_core_calendar_provide_event_action(calendar_event $event,
                                                                 \core_calendar\action_factory $factory, $userid = 0) {
            return $factory->create_instance('My action', new \moodle_url('/my'), 5, true);
        }
        

      6. Check all possible views in the calendar and make sure that "Test event 12" is displayed with an action link "My action" in the bottom.
      7. Confirm that it can still not be edited or deleted.
      8. Go to your dashboard and check the timeline block.
      9. Confirm sure that "Test event 12" appears in the timeline
      10. Add this callback to the blocks/comments/lib.php :

        function block_comments_core_calendar_is_event_visible(calendar_event $event, $userid = 0) {
            return false;
        }
        

      11. Refresh the dashboard and check the timeline block.
      12. Confirm that "Test event 12" disappeared from the timeline block.
      13. Go to the calendar and confirm that it also disappeared from the calendar.
      14. Confirm that "Test event 12" also disappeared from the calendar.
      15. Confirm that "Test event 11" is still present in the calendar (The visibility callback does not affect standard type events)
      16. Edit "block_comments_core_calendar_is_event_visible" return from false to true so the action events are displayed again.
      17. Add this callback to the blocks/comments/lib.php :

        function block_comments_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) {
            return true;
        }
        

      18. Make sure that the item count (5) now shows in the timeline for the action event but it is not shown in the calendar itself
      Test 4 (even more)
      1. Revert code changes from Test 3.

        git reset --hard origin/master
        

      2. Remove the test events from the mdl_event table manually.
      3. Cherry-pick the following test commit.

        git fetch https://github.com/marinaglancy/moodle MDL-58866-master-test
        git cherry-pick FETCH_HEAD
        

      4. Purge the caches
      5. Refresh the page with the comments block to create the test events. This creates a different type of component event, it is visible not just for current user but for any user (you can test it).
      6. Confirm that you see Test event 13 (standard event) in the calendar but not on the timeline block events in the calendar.
      7. Confirm that you see the Test event 14 (action event) on both the timeline block and the calendar.
      8. Make sure the icon for this new event is custom and it has the alt-text from the language string ("My event type")
      9. After the test, make sure to revert the test commit with the git command on step 1.
      Show
      Test 1 Create a course, enrol a student Add two assignments, with the following settings: Assign 1 Due date: Tomorrow Submission type: Online text or File upload Assing 2 Due date: The day after tomorrow Submission type: Nothing checked Login as a student Check the timeline block on your dashboard. Confirm that you see "{{Assign 1}" with a link "Add submission" Go to the calendar. Confirm that you see both " Assign 1 " and " Assign 2 ". Open " Assign 1 "'s due date event, confirm that you see " Add submission ". Close the event modal and open " Assign 2 "'s due date event. Confirm that you see "Go to activity" instead. Test 2 (quick regression check) Manually create some events in the calendar (user, course, category, site). Make sure you can edit and delete them following "edit" and "delete" buttons. Make sure you can drag editable events to the different dates and they save Make sure (as a teacher) you can drag the "Assignment due date" event to a different date inside the calendar and it saves, even though it does not display the "Edit" button anywhere Test 3a (plugin support) - Standard event This is an example of creating an event from a plugin (block "Comments"), feel free to improvise to test. Open blocks/comments/block_comments.php and add to the get_content() function global $DB; $instanceid = 11; $ev = $DB->get_record('event', ['component' => 'block_comments', 'eventtype' => 'mytype', 'instance' => $instanceid]); if (!$ev) { $event = new stdClass(); $event->eventtype = 'mytype'; $event->type = CALENDAR_EVENT_TYPE_STANDARD; // Change it to CALENDAR_EVENT_TYPE_ACTION in the next step. $event->name = $event->description = 'Test event ' . $instanceid; $event->instance = $instanceid; $event->timestart = $event->timesort = time() + DAYSECS; $event->visible = 1; $event->timeduration = 0; $event->context = context_system::instance(); $event->component = 'block_comments'; calendar_event::create($event, false); } Add an instance of block "Comments" to any course and view this course page. Now your event will be created. Go to your calendar. Confirm that you see " Test event 11 " and its date is set for tomorrow. View this event in all possible view modes (monthly, daily, upcoming, clicking on the event so it opens in a popup, etc). Make sure that it is always displayed consistently and there are no "Edit" and "Delete" buttons anywhere. Check your timeline on the dashboard. Confirm that this event will not be there (it is not an action event yet) Test 3b (plugin support) - Action event Turn your event into an action event by editing the code snippet in Test 3a: Set " $instanceid " to 12. Set " $event->type " from " CALENDAR_EVENT_TYPE_STANDARD " to " CALENDAR_EVENT_TYPE_ACTION " Refresh the page with the comments block to generate this action event. Go to the calendar. Confirm that you see " Test event 12 " in the calendar. Add this callback to the blocks/comments/lib.php : function block_comments_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory, $userid = 0) { return $factory->create_instance('My action', new \moodle_url('/my'), 5, true); } Check all possible views in the calendar and make sure that " Test event 12 " is displayed with an action link " My action " in the bottom. Confirm that it can still not be edited or deleted. Go to your dashboard and check the timeline block. Confirm sure that " Test event 12 " appears in the timeline Add this callback to the blocks/comments/lib.php : function block_comments_core_calendar_is_event_visible(calendar_event $event, $userid = 0) { return false; } Refresh the dashboard and check the timeline block. Confirm that " Test event 12 " disappeared from the timeline block. Go to the calendar and confirm that it also disappeared from the calendar. Confirm that " Test event 12 " also disappeared from the calendar. Confirm that " Test event 11 " is still present in the calendar (The visibility callback does not affect standard type events) Edit " block_comments_core_calendar_is_event_visible " return from false to true so the action events are displayed again. Add this callback to the blocks/comments/lib.php : function block_comments_core_calendar_event_action_shows_item_count(calendar_event $event, $itemcount = 0) { return true; } Make sure that the item count (5) now shows in the timeline for the action event but it is not shown in the calendar itself Test 4 (even more) Revert code changes from Test 3. git reset --hard origin/master Remove the test events from the mdl_event table manually. Cherry-pick the following test commit. git fetch https://github.com/marinaglancy/moodle MDL-58866-master-test git cherry-pick FETCH_HEAD Purge the caches Refresh the page with the comments block to create the test events. This creates a different type of component event, it is visible not just for current user but for any user (you can test it). Confirm that you see Test event 13 (standard event) in the calendar but not on the timeline block events in the calendar. Confirm that you see the Test event 14 (action event) on both the timeline block and the calendar. Make sure the icon for this new event is custom and it has the alt-text from the language string ("My event type") After the test, make sure to revert the test commit with the git command on step 1.
    • Affected Branches:
      MOODLE_34_STABLE, MOODLE_39_STABLE
    • Fixed Branches:
      MOODLE_39_STABLE
    • Pull Master Branch:
      MDL-58866-master-2

      Description

      There are many components that should create events for the students dashboard that are not modules. We need to use the magic 4 columns instead of just modulename and instance.

      context, component, itemid and area.


      Comments about the implementation:

      • Added column "component"
      • The existing column "eventtype" can be used as "area"
      • The existing column "instanceid" can be used as "itemid"
      • The existing columns "courseid" and "categoryid" should be used as context, courseid=SITEID means system context, courseid=<courseid> means course context, categoryid=<categoryid> means course category context. If neither courseid nor categoryid is specified, the event is considered to be user event and has a user context. Important! In this case if userid is not passed when creating event, the id of the current user is taken and event is considered to be his personal event. This is the current implementation/limitation of the calendar API and it is very difficult to change it.

        Attachments

        1. MDL-58866.jpg
          MDL-58866.jpg
          38 kB
        2. MDL-58866 (2)-2.jpg
          MDL-58866 (2)-2.jpg
          33 kB
        3. MDL-58866 (3)-2.jpg
          MDL-58866 (3)-2.jpg
          52 kB
        4. MDL-58866 (4)-2.jpg
          MDL-58866 (4)-2.jpg
          41 kB
        5. MDL-58866 (5).jpg
          MDL-58866 (5).jpg
          32 kB
        6. MDL-58866 (6).jpg
          MDL-58866 (6).jpg
          34 kB
        7. plugin_event_with_action_in_timeline.png
          plugin_event_with_action_in_timeline.png
          15 kB
        8. plugin_event_with_action.png
          plugin_event_with_action.png
          14 kB
        9. plugin_event_without_action.png
          plugin_event_without_action.png
          12 kB
        10. plugin_events_in_calendar.png
          plugin_events_in_calendar.png
          36 kB

          Issue Links

            Activity

              People

              Assignee:
              marina Marina Glancy
              Reporter:
              damyon Damyon Wiese
              Peer reviewer:
              Paul Holden
              Integrator:
              Jun Pataleta
              Tester:
              Anna Carissa Sadia
              Participants:
              Component watchers:
              Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
              Votes:
              3 Vote for this issue
              Watchers:
              10 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                15/Jun/20

                  Time Tracking

                  Estimated:
                  Original Estimate - 3 weeks
                  3w
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 day, 3 hours, 30 minutes Time Not Required
                  1d 3h 30m