Ejemplo n.º 1
0
 /**
  * Save a student submission for a single seplment
  *
  * @param int $seplmentid The id of the seplment
  * @param array $plugindata - The submitted data for plugins
  * @return array of warnings to indicate any errors
  * @since Moodle 2.6
  */
 public static function save_submission($seplmentid, $plugindata)
 {
     global $CFG, $USER;
     require_once "{$CFG->dirroot}/mod/sepl/locallib.php";
     $params = self::validate_parameters(self::save_submission_parameters(), array('seplmentid' => $seplmentid, 'plugindata' => $plugindata));
     $cm = get_coursemodule_from_instance('sepl', $params['seplmentid'], 0, false, MUST_EXIST);
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     $seplment = new sepl($context, $cm, null);
     $notices = array();
     $submissiondata = (object) $params['plugindata'];
     $seplment->save_submission($submissiondata, $notices);
     $warnings = array();
     foreach ($notices as $notice) {
         $warnings[] = self::generate_warning($params['seplmentid'], 'couldnotsavesubmission', $notice);
     }
     return $warnings;
 }
 /**
  * Test unlock_submissions
  */
 public function test_unlock_submissions()
 {
     global $DB, $USER;
     $this->resetAfterTest(true);
     // Create a course and seplment and users.
     $course = self::getDataGenerator()->create_course();
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_sepl');
     $params['course'] = $course->id;
     $params['seplsubmission_onlinetext_enabled'] = 1;
     $instance = $generator->create_instance($params);
     $cm = get_coursemodule_from_instance('sepl', $instance->id);
     $context = context_module::instance($cm->id);
     $sepl = new sepl($context, $cm, $course);
     $student1 = self::getDataGenerator()->create_user();
     $student2 = self::getDataGenerator()->create_user();
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $this->getDataGenerator()->enrol_user($student1->id, $course->id, $studentrole->id);
     $this->getDataGenerator()->enrol_user($student2->id, $course->id, $studentrole->id);
     $teacher = self::getDataGenerator()->create_user();
     $teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
     $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id);
     // Create a student1 with an online text submission.
     // Simulate a submission.
     $this->setUser($student1);
     $submission = $sepl->get_user_submission($student1->id, true);
     $data = new stdClass();
     $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_MOODLE);
     $plugin = $sepl->get_submission_plugin_by_type('onlinetext');
     $plugin->save($submission, $data);
     // Ready to test.
     $this->setUser($teacher);
     $students = array($student1->id, $student2->id);
     $result = mod_sepl_external::lock_submissions($instance->id, $students);
     $result = external_api::clean_returnvalue(mod_sepl_external::lock_submissions_returns(), $result);
     // Check for 0 warnings.
     $this->assertEquals(0, count($result));
     $result = mod_sepl_external::unlock_submissions($instance->id, $students);
     $result = external_api::clean_returnvalue(mod_sepl_external::unlock_submissions_returns(), $result);
     // Check for 0 warnings.
     $this->assertEquals(0, count($result));
     $this->setUser($student2);
     $submission = $sepl->get_user_submission($student2->id, true);
     $data = new stdClass();
     $data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_MOODLE);
     $notices = array();
     $sepl->save_submission($data, $notices);
 }