本文整理汇总了PHP中assign::save_submission方法的典型用法代码示例。如果您正苦于以下问题:PHP assign::save_submission方法的具体用法?PHP assign::save_submission怎么用?PHP assign::save_submission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类assign
的用法示例。
在下文中一共展示了assign::save_submission方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save_submission
/**
* Save a student submission for a single assignment
*
* @param int $assignmentid The id of the assignment
* @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($assignmentid, $plugindata)
{
global $CFG, $USER;
require_once "{$CFG->dirroot}/mod/assign/locallib.php";
$params = self::validate_parameters(self::save_submission_parameters(), array('assignmentid' => $assignmentid, 'plugindata' => $plugindata));
$cm = get_coursemodule_from_instance('assign', $params['assignmentid'], 0, false, MUST_EXIST);
$context = context_module::instance($cm->id);
self::validate_context($context);
$assignment = new assign($context, $cm, null);
$notices = array();
if (!$assignment->submissions_open($USER->id)) {
$notices[] = get_string('duedatereached', 'assign');
} else {
$submissiondata = (object) $params['plugindata'];
$assignment->save_submission($submissiondata, $notices);
}
$warnings = array();
foreach ($notices as $notice) {
$warnings[] = self::generate_warning($params['assignmentid'], 'couldnotsavesubmission', $notice);
}
return $warnings;
}
示例2: test_get_participant_no_user
/**
* get_participant should return a summarised list of details if requested.
*/
public function test_get_participant_no_user()
{
global $DB;
$this->resetAfterTest(true);
$result = $this->create_assign_with_student_and_teacher();
$assignmodule = $result['assign'];
$student = $result['student'];
$teacher = $result['teacher'];
$course = $result['course'];
$context = context_course::instance($course->id);
$teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
// Create an assign instance to save a submission.
set_config('submissionreceipts', 0, 'assign');
$cm = get_coursemodule_from_instance('assign', $assignmodule->id);
$context = context_module::instance($cm->id);
$assign = new assign($context, $cm, $course);
$this->setUser($student);
// Simulate a submission.
$data = new stdClass();
$data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Student submission text', 'format' => FORMAT_MOODLE);
$notices = array();
$assign->save_submission($data, $notices);
$data = new stdClass();
$data->userid = $student->id;
$assign->submit_for_grading($data, array());
$this->setUser($teacher);
$result = mod_assign_external::get_participant($assignmodule->id, $student->id, false);
$this->assertEquals($student->id, $result['id']);
$this->assertEquals(fullname($student), $result['fullname']);
$this->assertTrue($result['submitted']);
$this->assertTrue($result['requiregrading']);
$this->assertFalse($result['blindmarking']);
// Make sure we don't get any additional info.
$this->assertTrue(empty($result['user']));
}
示例3: test_unlock_submissions
/**
* Test unlock_submissions
*/
public function test_unlock_submissions()
{
global $DB, $USER;
$this->resetAfterTest(true);
// Create a course and assignment and users.
$course = self::getDataGenerator()->create_course();
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$params['course'] = $course->id;
$params['assignsubmission_onlinetext_enabled'] = 1;
$instance = $generator->create_instance($params);
$cm = get_coursemodule_from_instance('assign', $instance->id);
$context = context_module::instance($cm->id);
$assign = new assign($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 = $assign->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 = $assign->get_submission_plugin_by_type('onlinetext');
$plugin->save($submission, $data);
// Ready to test.
$this->setUser($teacher);
$students = array($student1->id, $student2->id);
$result = mod_assign_external::lock_submissions($instance->id, $students);
// Check for 0 warnings.
$this->assertEquals(0, count($result));
$result = mod_assign_external::unlock_submissions($instance->id, $students);
// Check for 0 warnings.
$this->assertEquals(0, count($result));
$this->setUser($student2);
$submission = $assign->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();
$assign->save_submission($data, $notices);
}