Exemple #1
0
             $params['other']['groupid'] = $fromform->groupid;
             $event = \mod_quiz\event\group_override_updated::create($params);
         }
         // Trigger the override updated event.
         $event->trigger();
     } else {
         unset($fromform->id);
         $fromform->id = $DB->insert_record('quiz_overrides', $fromform);
         // Determine which override created event to fire.
         $params['objectid'] = $fromform->id;
         if (!$groupmode) {
             $params['relateduserid'] = $fromform->userid;
             $event = \mod_quiz\event\user_override_created::create($params);
         } else {
             $params['other']['groupid'] = $fromform->groupid;
             $event = \mod_quiz\event\group_override_created::create($params);
         }
         // Trigger the override created event.
         $event->trigger();
     }
     quiz_update_open_attempts(array('quizid' => $quiz->id));
     quiz_update_events($quiz, $fromform);
     if (!empty($fromform->submitbutton)) {
         redirect($overridelisturl);
     }
     // The user pressed the 'again' button, so redirect back to this page.
     $url->remove_params('cmid');
     $url->param('action', 'duplicate');
     $url->param('id', $fromform->id);
     redirect($url);
 }
 /**
  * Test the group override created event.
  *
  * There is no external API for creating a group override, so the unit test will simply
  * create and trigger the event and ensure the event data is returned as expected.
  */
 public function test_group_override_created()
 {
     $this->resetAfterTest();
     $this->setAdminUser();
     $course = $this->getDataGenerator()->create_course();
     $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id));
     $params = array('objectid' => 1, 'context' => context_module::instance($quiz->cmid), 'other' => array('quizid' => $quiz->id, 'groupid' => 2));
     $event = \mod_quiz\event\group_override_created::create($params);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\mod_quiz\\event\\group_override_created', $event);
     $this->assertEquals(context_module::instance($quiz->cmid), $event->get_context());
     $this->assertEventContextNotUsed($event);
 }