本文整理汇总了PHP中assign::get_submission_plugins方法的典型用法代码示例。如果您正苦于以下问题:PHP assign::get_submission_plugins方法的具体用法?PHP assign::get_submission_plugins怎么用?PHP assign::get_submission_plugins使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类assign
的用法示例。
在下文中一共展示了assign::get_submission_plugins方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
//.........这里部分代码省略.........
$columns[] = 'allocatedmarker';
$headers[] = get_string('marker', 'assign');
}
// Grade.
$columns[] = 'grade';
$headers[] = get_string('grade');
if ($this->is_downloading()) {
if ($this->assignment->get_instance()->grade >= 0) {
$columns[] = 'grademax';
$headers[] = get_string('maxgrade', 'assign');
} else {
// This is a custom scale.
$columns[] = 'scale';
$headers[] = get_string('scale', 'assign');
}
if ($this->assignment->get_instance()->markingworkflow) {
// Add a column for the marking workflow state.
$columns[] = 'workflowstate';
$headers[] = get_string('markingworkflowstate', 'assign');
}
// Add a column for the list of valid marking workflow states.
$columns[] = 'gradecanbechanged';
$headers[] = get_string('gradecanbechanged', 'assign');
}
if (!$this->is_downloading() && $this->hasgrade) {
// We have to call this column userid so we can use userid as a default sortable column.
$columns[] = 'userid';
$headers[] = get_string('edit');
}
// Submission plugins.
if ($assignment->is_any_submission_plugin_enabled()) {
$columns[] = 'timesubmitted';
$headers[] = get_string('lastmodifiedsubmission', 'assign');
foreach ($this->assignment->get_submission_plugins() as $plugin) {
if ($this->is_downloading()) {
if ($plugin->is_visible() && $plugin->is_enabled()) {
foreach ($plugin->get_editor_fields() as $field => $description) {
$index = 'plugin' . count($this->plugincache);
$this->plugincache[$index] = array($plugin, $field);
$columns[] = $index;
$headers[] = $plugin->get_name();
}
}
} else {
if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
$index = 'plugin' . count($this->plugincache);
$this->plugincache[$index] = array($plugin);
$columns[] = $index;
$headers[] = $plugin->get_name();
}
}
}
}
// Time marked.
$columns[] = 'timemarked';
$headers[] = get_string('lastmodifiedgrade', 'assign');
// Feedback plugins.
foreach ($this->assignment->get_feedback_plugins() as $plugin) {
if ($this->is_downloading()) {
if ($plugin->is_visible() && $plugin->is_enabled()) {
foreach ($plugin->get_editor_fields() as $field => $description) {
$index = 'plugin' . count($this->plugincache);
$this->plugincache[$index] = array($plugin, $field);
$columns[] = $index;
$headers[] = $description;
}
示例2: __construct
//.........这里部分代码省略.........
if ($assignment->is_any_submission_plugin_enabled()) {
$columns[] = 'status';
$headers[] = get_string('status');
}
// Team submission columns
if ($assignment->get_instance()->teamsubmission) {
$columns[] = 'team';
$headers[] = get_string('submissionteam', 'assign');
$columns[] = 'teamstatus';
$headers[] = get_string('teamsubmissionstatus', 'assign');
}
// Grade
$columns[] = 'grade';
$headers[] = get_string('grade');
if ($this->is_downloading()) {
if ($this->assignment->get_instance()->grade >= 0) {
$columns[] = 'grademax';
$headers[] = get_string('maxgrade', 'assign');
} else {
// This is a custom scale.
$columns[] = 'scale';
$headers[] = get_string('scale', 'assign');
}
}
if (!$this->is_downloading()) {
// We have to call this column userid so we can use userid as a default sortable column.
$columns[] = 'userid';
$headers[] = get_string('edit');
}
// Submission plugins
if ($assignment->is_any_submission_plugin_enabled()) {
$columns[] = 'timesubmitted';
$headers[] = get_string('lastmodifiedsubmission', 'assign');
foreach ($this->assignment->get_submission_plugins() as $plugin) {
if ($this->is_downloading()) {
if ($plugin->is_visible() && $plugin->is_enabled()) {
foreach ($plugin->get_editor_fields() as $field => $description) {
$index = 'plugin' . count($this->plugincache);
$this->plugincache[$index] = array($plugin, $field);
$columns[] = $index;
$headers[] = $plugin->get_name();
}
}
} else {
if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
$index = 'plugin' . count($this->plugincache);
$this->plugincache[$index] = array($plugin);
$columns[] = $index;
$headers[] = $plugin->get_name();
}
}
}
}
// time marked
$columns[] = 'timemarked';
$headers[] = get_string('lastmodifiedgrade', 'assign');
// Feedback plugins
foreach ($this->assignment->get_feedback_plugins() as $plugin) {
if ($this->is_downloading()) {
if ($plugin->is_visible() && $plugin->is_enabled()) {
foreach ($plugin->get_editor_fields() as $field => $description) {
$index = 'plugin' . count($this->plugincache);
$this->plugincache[$index] = array($plugin, $field);
$columns[] = $index;
$headers[] = $description;
}
示例3: assign_get_file_info
/**
* File browsing support for assign module.
*
* @param file_browser $browser
* @param object $areas
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return object file_info instance or null if not found
*/
function assign_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename)
{
global $CFG;
require_once $CFG->dirroot . '/mod/assign/locallib.php';
if ($context->contextlevel != CONTEXT_MODULE) {
return null;
}
$fs = get_file_storage();
$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;
// need to find the plugin this belongs to
$assignment = new assign($context, $cm, $course);
$pluginowner = null;
foreach ($assignment->get_submission_plugins() as $plugin) {
if ($plugin->is_visible()) {
$pluginareas = $plugin->get_file_areas();
if (array_key_exists($filearea, $pluginareas)) {
$pluginowner = $plugin;
break;
}
}
}
if (!$pluginowner) {
foreach ($assignment->get_feedback_plugins() as $plugin) {
if ($plugin->is_visible()) {
$pluginareas = $plugin->get_file_areas();
if (array_key_exists($filearea, $pluginareas)) {
$pluginowner = $plugin;
break;
}
}
}
}
if (!$pluginowner) {
return null;
}
$result = $pluginowner->get_file_info($browser, $filearea, $itemid, $filepath, $filename);
return $result;
}
示例4: assign_get_file_info
/**
* File browsing support for assign module.
*
* @param file_browser $browser
* @param object $areas
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return object file_info instance or null if not found
*/
function assign_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename)
{
global $CFG;
require_once $CFG->dirroot . '/mod/assign/locallib.php';
if ($context->contextlevel != CONTEXT_MODULE) {
return null;
}
$urlbase = $CFG->wwwroot . '/pluginfile.php';
$fs = get_file_storage();
$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;
// Need to find where this belongs to.
$assignment = new assign($context, $cm, $course);
if ($filearea === ASSIGN_INTROATTACHMENT_FILEAREA) {
if (!has_capability('moodle/course:managefiles', $context)) {
// Students can not peak here!
return null;
}
if (!($storedfile = $fs->get_file($assignment->get_context()->id, 'mod_assign', $filearea, 0, $filepath, $filename))) {
return null;
}
return new file_info_stored($browser, $assignment->get_context(), $storedfile, $urlbase, $filearea, $itemid, true, true, false);
}
$pluginowner = null;
foreach ($assignment->get_submission_plugins() as $plugin) {
if ($plugin->is_visible()) {
$pluginareas = $plugin->get_file_areas();
if (array_key_exists($filearea, $pluginareas)) {
$pluginowner = $plugin;
break;
}
}
}
if (!$pluginowner) {
foreach ($assignment->get_feedback_plugins() as $plugin) {
if ($plugin->is_visible()) {
$pluginareas = $plugin->get_file_areas();
if (array_key_exists($filearea, $pluginareas)) {
$pluginowner = $plugin;
break;
}
}
}
}
if (!$pluginowner) {
return null;
}
$result = $pluginowner->get_file_info($browser, $filearea, $itemid, $filepath, $filename);
return $result;
}
示例5: save_submission_parameters
/**
* Describes the parameters for save_submission
* @return external_external_function_parameters
* @since Moodle 2.6
*/
public static function save_submission_parameters()
{
global $CFG;
$instance = new assign(null, null, null);
$pluginsubmissionparams = array();
foreach ($instance->get_submission_plugins() as $plugin) {
if ($plugin->is_visible()) {
$pluginparams = $plugin->get_external_parameters();
if (!empty($pluginparams)) {
$pluginsubmissionparams = array_merge($pluginsubmissionparams, $pluginparams);
}
}
}
return new external_function_parameters(array('assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on'), 'plugindata' => new external_single_structure($pluginsubmissionparams)));
}
示例6: array
//.........这里部分代码省略.........
if ($filter == ASSIGN_FILTER_REQUIRE_GRADING) {
$where .= ' AND (s.timemodified > g.timemodified OR (s.timemodified IS NOT NULL AND g.timemodified IS NULL))';
}
if (strpos($filter, ASSIGN_FILTER_SINGLE_USER) === 0) {
$userfilter = (int) array_pop(explode('=', $filter));
$where .= ' AND (u.id = :userid)';
$params['userid'] = $userfilter;
}
$this->set_sql($fields, $from, $where, $params);
$columns = array();
$headers = array();
// Select
$columns[] = 'select';
$headers[] = get_string('select') . '<div class="selectall"><input type="checkbox" name="selectall" title="' . get_string('selectall') . '"/></div>';
// Edit links
if (!$this->is_downloading()) {
$columns[] = 'edit';
$headers[] = get_string('edit');
}
// User picture
$columns[] = 'picture';
$headers[] = get_string('pictureofuser');
// Fullname
$columns[] = 'fullname';
$headers[] = get_string('fullname');
// Submission status
if ($assignment->is_any_submission_plugin_enabled()) {
$columns[] = 'status';
$headers[] = get_string('status');
}
// Grade
$columns[] = 'grade';
$headers[] = get_string('grade');
// Submission plugins
if ($assignment->is_any_submission_plugin_enabled()) {
$columns[] = 'timesubmitted';
$headers[] = get_string('lastmodifiedsubmission', 'assign');
foreach ($this->assignment->get_submission_plugins() as $plugin) {
if ($plugin->is_visible() && $plugin->is_enabled()) {
$columns[] = 'assignsubmission_' . $plugin->get_type();
$headers[] = $plugin->get_name();
}
}
}
// time marked
$columns[] = 'timemarked';
$headers[] = get_string('lastmodifiedgrade', 'assign');
// Feedback plugins
foreach ($this->assignment->get_feedback_plugins() as $plugin) {
if ($plugin->is_visible() && $plugin->is_enabled()) {
$columns[] = 'assignfeedback_' . $plugin->get_type();
$headers[] = $plugin->get_name();
}
}
// final grade
$columns[] = 'finalgrade';
$headers[] = get_string('finalgrade', 'grades');
// load the grading info for all users
$this->gradinginfo = grade_get_grades($this->assignment->get_course()->id, 'mod', 'assign', $this->assignment->get_instance()->id, $users);
if (!empty($CFG->enableoutcomes) && !empty($this->gradinginfo->outcomes)) {
$columns[] = 'outcomes';
$headers[] = get_string('outcomes', 'grades');
}
// set the columns
$this->define_columns($columns);
$this->define_headers($headers);
$this->no_sorting('finalgrade');
$this->no_sorting('edit');
$this->no_sorting('select');
$this->no_sorting('outcomes');
foreach ($this->assignment->get_submission_plugins() as $plugin) {
if ($plugin->is_visible() && $plugin->is_enabled()) {
$this->no_sorting('assignsubmission_' . $plugin->get_type());
}
}
foreach ($this->assignment->get_feedback_plugins() as $plugin) {
if ($plugin->is_visible() && $plugin->is_enabled()) {
$this->no_sorting('assignfeedback_' . $plugin->get_type());
}
}
}
示例7: upgrade_assignment
/**
* This function converts all of the base settings for an instance of
* the old assignment to the new format. Then it calls each of the plugins
* to see if they can help upgrade this assignment.
* @param int $oldassignmentid (don't rely on the old assignment type even being installed)
* @param string $log This string gets appended to during the conversion process
* @return bool true or false
*/
public function upgrade_assignment($oldassignmentid, &$log)
{
global $DB, $CFG, $USER;
// Steps to upgrade an assignment.
// Is the user the admin? admin check goes here.
if (!is_siteadmin($USER->id)) {
return false;
}
core_php_time_limit::raise(ASSIGN_MAX_UPGRADE_TIME_SECS);
// Get the module details.
$oldmodule = $DB->get_record('modules', array('name' => 'assignment'), '*', MUST_EXIST);
$params = array('module' => $oldmodule->id, 'instance' => $oldassignmentid);
$oldcoursemodule = $DB->get_record('course_modules', $params, '*', MUST_EXIST);
$oldcontext = context_module::instance($oldcoursemodule->id);
// First insert an assign instance to get the id.
$oldassignment = $DB->get_record('assignment', array('id' => $oldassignmentid), '*', MUST_EXIST);
$oldversion = get_config('assignment_' . $oldassignment->assignmenttype, 'version');
$data = new stdClass();
$data->course = $oldassignment->course;
$data->name = $oldassignment->name;
$data->intro = $oldassignment->intro;
$data->introformat = $oldassignment->introformat;
$data->alwaysshowdescription = 1;
$data->sendnotifications = $oldassignment->emailteachers;
$data->sendlatenotifications = $oldassignment->emailteachers;
$data->duedate = $oldassignment->timedue;
$data->allowsubmissionsfromdate = $oldassignment->timeavailable;
$data->grade = $oldassignment->grade;
$data->submissiondrafts = $oldassignment->resubmit;
$data->requiresubmissionstatement = 0;
$data->markingworkflow = 0;
$data->markingallocation = 0;
$data->cutoffdate = 0;
// New way to specify no late submissions.
if ($oldassignment->preventlate) {
$data->cutoffdate = $data->duedate;
}
$data->teamsubmission = 0;
$data->requireallteammemberssubmit = 0;
$data->teamsubmissiongroupingid = 0;
$data->blindmarking = 0;
$data->attemptreopenmethod = 'none';
$data->maxattempts = ASSIGN_UNLIMITED_ATTEMPTS;
$newassignment = new assign(null, null, null);
if (!$newassignment->add_instance($data, false)) {
$log = get_string('couldnotcreatenewassignmentinstance', 'mod_assign');
return false;
}
// Now create a new coursemodule from the old one.
$newmodule = $DB->get_record('modules', array('name' => 'assign'), '*', MUST_EXIST);
$newcoursemodule = $this->duplicate_course_module($oldcoursemodule, $newmodule->id, $newassignment->get_instance()->id);
if (!$newcoursemodule) {
$log = get_string('couldnotcreatenewcoursemodule', 'mod_assign');
return false;
}
// Convert the base database tables (assignment, submission, grade).
// These are used to store information in case a rollback is required.
$gradingarea = null;
$gradingdefinitions = null;
$gradeidmap = array();
$completiondone = false;
$gradesdone = false;
// From this point we want to rollback on failure.
$rollback = false;
try {
$newassignment->set_context(context_module::instance($newcoursemodule->id));
// The course module has now been created - time to update the core tables.
// Copy intro files.
$newassignment->copy_area_files_for_upgrade($oldcontext->id, 'mod_assignment', 'intro', 0, $newassignment->get_context()->id, 'mod_assign', 'intro', 0);
// Get the plugins to do their bit.
foreach ($newassignment->get_submission_plugins() as $plugin) {
if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) {
$plugin->enable();
if (!$plugin->upgrade_settings($oldcontext, $oldassignment, $log)) {
$rollback = true;
}
} else {
$plugin->disable();
}
}
foreach ($newassignment->get_feedback_plugins() as $plugin) {
if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) {
$plugin->enable();
if (!$plugin->upgrade_settings($oldcontext, $oldassignment, $log)) {
$rollback = true;
}
} else {
$plugin->disable();
}
}
// See if there is advanced grading upgrades required.
$gradingarea = $DB->get_record('grading_areas', array('contextid' => $oldcontext->id, 'areaname' => 'submission'), '*', IGNORE_MISSING);
//.........这里部分代码省略.........
示例8: get_submissions
/**
* Returns submissions for the requested assignment ids
*
* @param array of ints $assignmentids
* @param string $status only return submissions with this status
* @param int $since only return submissions with timemodified >= since
* @param int $before only return submissions with timemodified <= before
* @return array of submissions for each requested assignment
* @since Moodle 2.5
*/
public static function get_submissions($assignmentids, $status = '', $since = 0, $before = 0) {
global $DB, $CFG;
require_once("$CFG->dirroot/mod/assign/locallib.php");
$params = self::validate_parameters(self::get_submissions_parameters(),
array('assignmentids' => $assignmentids,
'status' => $status,
'since' => $since,
'before' => $before));
$warnings = array();
$assignments = array();
// Check the user is allowed to get the submissions for the assignments requested.
$placeholders = array();
list($inorequalsql, $placeholders) = $DB->get_in_or_equal($params['assignmentids'], SQL_PARAMS_NAMED);
$sql = "SELECT cm.id, cm.instance FROM {course_modules} cm JOIN {modules} md ON md.id = cm.module ".
"WHERE md.name = :modname AND cm.instance ".$inorequalsql;
$placeholders['modname'] = 'assign';
$cms = $DB->get_records_sql($sql, $placeholders);
$assigns = array();
foreach ($cms as $cm) {
try {
$context = context_module::instance($cm->id);
self::validate_context($context);
require_capability('mod/assign:grade', $context);
$assign = new assign($context, null, null);
$assigns[] = $assign;
} catch (Exception $e) {
$warnings[] = array(
'item' => 'assignment',
'itemid' => $cm->instance,
'warningcode' => '1',
'message' => 'No access rights in module context'
);
}
}
foreach ($assigns as $assign) {
$submissions = array();
$submissionplugins = $assign->get_submission_plugins();
$placeholders = array('assignid1' => $assign->get_instance()->id,
'assignid2' => $assign->get_instance()->id);
$submissionmaxattempt = 'SELECT mxs.userid, MAX(mxs.attemptnumber) AS maxattempt
FROM {assign_submission} mxs
WHERE mxs.assignment = :assignid1 GROUP BY mxs.userid';
$sql = "SELECT mas.id, mas.assignment,mas.userid,".
"mas.timecreated,mas.timemodified,mas.status,mas.groupid ".
"FROM {assign_submission} mas ".
"JOIN ( " . $submissionmaxattempt . " ) smx ON mas.userid = smx.userid ".
"WHERE mas.assignment = :assignid2 AND mas.attemptnumber = smx.maxattempt";
if (!empty($params['status'])) {
$placeholders['status'] = $params['status'];
$sql = $sql." AND mas.status = :status";
}
if (!empty($params['before'])) {
$placeholders['since'] = $params['since'];
$placeholders['before'] = $params['before'];
$sql = $sql." AND mas.timemodified BETWEEN :since AND :before";
} else {
$placeholders['since'] = $params['since'];
$sql = $sql." AND mas.timemodified >= :since";
}
$submissionrecords = $DB->get_records_sql($sql, $placeholders);
if (!empty($submissionrecords)) {
$fs = get_file_storage();
foreach ($submissionrecords as $submissionrecord) {
$submission = array(
'id' => $submissionrecord->id,
'userid' => $submissionrecord->userid,
'timecreated' => $submissionrecord->timecreated,
'timemodified' => $submissionrecord->timemodified,
'status' => $submissionrecord->status,
'groupid' => $submissionrecord->groupid
);
foreach ($submissionplugins as $submissionplugin) {
$plugin = array(
'name' => $submissionplugin->get_name(),
'type' => $submissionplugin->get_type()
);
// Subtype is 'assignsubmission', type is currently 'file' or 'onlinetext'.
$component = $submissionplugin->get_subtype().'_'.$submissionplugin->get_type();
$fileareas = $submissionplugin->get_file_areas();
foreach ($fileareas as $filearea => $name) {
$fileareainfo = array('area' => $filearea);
//.........这里部分代码省略.........
示例9: save_submission_parameters
/**
* Describes the parameters for save_submission
* @return external_external_function_parameters
* @since Moodle 2.6
*/
public static function save_submission_parameters()
{
global $CFG;
require_once "{$CFG->dirroot}/mod/assign/locallib.php";
$instance = new assign(null, null, null);
$pluginsubmissionparams = array();
foreach ($instance->get_submission_plugins() as $plugin) {
$pluginparams = $plugin->get_external_parameters();
if (!empty($pluginparams)) {
$pluginsubmissionparams = array_merge($pluginsubmissionparams, $pluginparams);
}
}
return new external_function_parameters(array('assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on'), 'plugindata' => new external_single_structure($pluginsubmissionparams)));
}
示例10: upgrade_assignment
/**
* This function converts all of the base settings for an instance of
* the old assignment to the new format. Then it calls each of the plugins
* to see if they can help upgrade this assignment.
* @param int $oldassignmentid (don't rely on the old assignment type even being installed)
* @param string $log This string gets appended to during the conversion process
* @return bool true or false
*/
public function upgrade_assignment($oldassignmentid, &$log)
{
// steps to upgrade an assignment
global $DB, $CFG, $USER;
// steps to upgrade an assignment
// is the user the admin? admin check goes here
if (!is_siteadmin($USER->id)) {
return false;
}
// should we use a shutdown handler to rollback on timeout?
@set_time_limit(ASSIGN_MAX_UPGRADE_TIME_SECS);
// get the module details
$oldmodule = $DB->get_record('modules', array('name' => 'assignment'), '*', MUST_EXIST);
$oldcoursemodule = $DB->get_record('course_modules', array('module' => $oldmodule->id, 'instance' => $oldassignmentid), '*', MUST_EXIST);
$oldcontext = context_module::instance($oldcoursemodule->id);
// first insert an assign instance to get the id
$oldassignment = $DB->get_record('assignment', array('id' => $oldassignmentid), '*', MUST_EXIST);
$oldversion = get_config('assignment_' . $oldassignment->assignmenttype, 'version');
$data = new stdClass();
$data->course = $oldassignment->course;
$data->name = $oldassignment->name;
$data->intro = $oldassignment->intro;
$data->introformat = $oldassignment->introformat;
$data->alwaysshowdescription = 1;
$data->sendnotifications = $oldassignment->emailteachers;
$data->sendlatenotifications = $oldassignment->emailteachers;
$data->duedate = $oldassignment->timedue;
$data->allowsubmissionsfromdate = $oldassignment->timeavailable;
$data->grade = $oldassignment->grade;
$data->submissiondrafts = $oldassignment->resubmit;
$data->preventlatesubmissions = $oldassignment->preventlate;
$newassignment = new assign(null, null, null);
if (!$newassignment->add_instance($data, false)) {
$log = get_string('couldnotcreatenewassignmentinstance', 'mod_assign');
return false;
}
// now create a new coursemodule from the old one
$newmodule = $DB->get_record('modules', array('name' => 'assign'), '*', MUST_EXIST);
$newcoursemodule = $this->duplicate_course_module($oldcoursemodule, $newmodule->id, $newassignment->get_instance()->id);
if (!$newcoursemodule) {
$log = get_string('couldnotcreatenewcoursemodule', 'mod_assign');
return false;
}
// convert the base database tables (assignment, submission, grade)
// these are used to store information in case a rollback is required
$gradingarea = null;
$gradingdefinitions = null;
$gradeidmap = array();
$completiondone = false;
$gradesdone = false;
// from this point we want to rollback on failure
$rollback = false;
try {
$newassignment->set_context(context_module::instance($newcoursemodule->id));
// the course module has now been created - time to update the core tables
// copy intro files
$newassignment->copy_area_files_for_upgrade($oldcontext->id, 'mod_assignment', 'intro', 0, $newassignment->get_context()->id, 'mod_assign', 'intro', 0);
// get the plugins to do their bit
foreach ($newassignment->get_submission_plugins() as $plugin) {
if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) {
$plugin->enable();
if (!$plugin->upgrade_settings($oldcontext, $oldassignment, $log)) {
$rollback = true;
}
} else {
$plugin->disable();
}
}
foreach ($newassignment->get_feedback_plugins() as $plugin) {
if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) {
$plugin->enable();
if (!$plugin->upgrade_settings($oldcontext, $oldassignment, $log)) {
$rollback = true;
}
} else {
$plugin->disable();
}
}
// see if there is advanced grading upgrades required
$gradingarea = $DB->get_record('grading_areas', array('contextid' => $oldcontext->id, 'areaname' => 'submission'), '*', IGNORE_MISSING);
if ($gradingarea) {
$DB->update_record('grading_areas', array('id' => $gradingarea->id, 'contextid' => $newassignment->get_context()->id, 'component' => 'mod_assign', 'areaname' => 'submissions'));
$gradingdefinitions = $DB->get_records('grading_definitions', array('areaid' => $gradingarea->id));
}
// upgrade completion data
$DB->set_field('course_modules_completion', 'coursemoduleid', $newcoursemodule->id, array('coursemoduleid' => $oldcoursemodule->id));
$allcriteria = $DB->get_records('course_completion_criteria', array('moduleinstance' => $oldcoursemodule->id));
foreach ($allcriteria as $criteria) {
$criteria->module = 'assign';
$criteria->moduleinstance = $newcoursemodule->id;
$DB->update_record('course_completion_criteria', $criteria);
}
//.........这里部分代码省略.........
示例11: get_submission_status
/**
* Returns information about an assignment submission status for a given user.
*
* @param int $assignid assignment instance id
* @param int $userid user id (empty for current user)
* @return array of warnings and grading, status, feedback and previous attempts information
* @since Moodle 3.1
* @throws required_capability_exception
*/
public static function get_submission_status($assignid, $userid = 0)
{
global $USER, $DB;
$warnings = array();
$params = array('assignid' => $assignid, 'userid' => $userid);
$params = self::validate_parameters(self::get_submission_status_parameters(), $params);
// Request and permission validation.
$assign = $DB->get_record('assign', array('id' => $params['assignid']), 'id', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($assign, 'assign');
$context = context_module::instance($cm->id);
self::validate_context($context);
$assign = new assign($context, $cm, $course);
// Default value for userid.
if (empty($params['userid'])) {
$params['userid'] = $USER->id;
}
$user = core_user::get_user($params['userid'], '*', MUST_EXIST);
core_user::require_active_user($user);
if (!$assign->can_view_submission($user->id)) {
throw new required_capability_exception($context, 'mod/assign:viewgrades', 'nopermission', '');
}
$gradingsummary = $lastattempt = $feedback = $previousattempts = null;
// Get the renderable since it contais all the info we need.
if ($assign->can_view_grades()) {
$gradingsummary = $assign->get_assign_grading_summary_renderable();
}
// Retrieve the rest of the renderable objects.
if (has_capability('mod/assign:submit', $assign->get_context(), $user)) {
$lastattempt = $assign->get_assign_submission_status_renderable($user, true);
}
$feedback = $assign->get_assign_feedback_status_renderable($user);
$previousattempts = $assign->get_assign_attempt_history_renderable($user);
// Now, build the result.
$result = array();
// First of all, grading summary, this is suitable for teachers/managers.
if ($gradingsummary) {
$result['gradingsummary'] = $gradingsummary;
}
// Did we submit anything?
if ($lastattempt) {
$submissionplugins = $assign->get_submission_plugins();
if (empty($lastattempt->submission)) {
unset($lastattempt->submission);
} else {
$lastattempt->submission->plugins = self::get_plugins_data($assign, $submissionplugins, $lastattempt->submission);
}
if (empty($lastattempt->teamsubmission)) {
unset($lastattempt->teamsubmission);
} else {
$lastattempt->teamsubmission->plugins = self::get_plugins_data($assign, $submissionplugins, $lastattempt->teamsubmission);
}
// We need to change the type of some of the structures retrieved from the renderable.
if (!empty($lastattempt->submissiongroup)) {
$lastattempt->submissiongroup = $lastattempt->submissiongroup->id;
} else {
unset($lastattempt->submissiongroup);
}
if (!empty($lastattempt->usergroups)) {
$lastattempt->usergroups = array_keys($lastattempt->usergroups);
}
// We cannot use array_keys here.
if (!empty($lastattempt->submissiongroupmemberswhoneedtosubmit)) {
$lastattempt->submissiongroupmemberswhoneedtosubmit = array_map(function ($e) {
return $e->id;
}, $lastattempt->submissiongroupmemberswhoneedtosubmit);
}
$result['lastattempt'] = $lastattempt;
}
// The feedback for our latest submission.
if ($feedback) {
if ($feedback->grade) {
$feedbackplugins = $assign->get_feedback_plugins();
$feedback->plugins = self::get_plugins_data($assign, $feedbackplugins, $feedback->grade);
} else {
unset($feedback->plugins);
unset($feedback->grade);
}
$result['feedback'] = $feedback;
}
// Retrieve only previous attempts.
if ($previousattempts and count($previousattempts->submissions) > 1) {
// Don't show the last one because it is the current submission.
array_pop($previousattempts->submissions);
// Show newest to oldest.
$previousattempts->submissions = array_reverse($previousattempts->submissions);
foreach ($previousattempts->submissions as $i => $submission) {
$attempt = array();
$grade = null;
foreach ($previousattempts->grades as $onegrade) {
if ($onegrade->attemptnumber == $submission->attemptnumber) {
$grade = $onegrade;
//.........这里部分代码省略.........
示例12: plagiarism_urkund_get_file_object
function plagiarism_urkund_get_file_object($plagiarismfile)
{
global $CFG, $DB;
if (strpos($plagiarismfile->identifier, $CFG->tempdir) === true) {
// This is a stored text file in temp dir.
$file = new stdclass();
if (file_exists($plagiarismfile->identifier)) {
$file->type = "tempurkund";
$file->filename = basename($plagiarismfile->identifier);
$file->timestamp = time();
$file->identifier = sha1(file_get_contents($plagiarismfile->identifier));
$file->filepath = $plagiarismfile->identifier;
// Sanity check to see if the Sha1 for this file has already been sent to urkund using a different record.
if ($DB->record_exists('plagiarism_urkund_files', array('identifier' => $file->identifier, 'cm' => $plagiarismfile->cm, 'userid' => $plagiarismfile->userid))) {
// This file has already been sent and multiple records for this file were created
// Delete plagiarism record and file.
$DB->delete_records('plagiarism_urkund_files', array('id' => $plagiarismfile->id));
debugging("This file has been duplicated, deleting the duplicate record. Identifier:" . $file->identifier);
unlink($plagiarismfile->identifier);
// Delete temp file as we don't need it anymore.
return false;
}
return $file;
} else {
debugging("The local version of this file has been deleted, and this file cannot be sent");
return false;
}
} else {
$cm = get_coursemodule_from_id('', $plagiarismfile->cm);
$modulecontext = context_module::instance($plagiarismfile->cm);
$fs = get_file_storage();
if ($cm->modname == 'assign') {
require_once $CFG->dirroot . '/mod/assign/locallib.php';
$assign = new assign($modulecontext, null, null);
if ($assign->get_instance()->teamsubmission) {
$submission = $assign->get_group_submission($plagiarismfile->userid, 0, false);
} else {
$submission = $assign->get_user_submission($plagiarismfile->userid, false);
}
$submissionplugins = $assign->get_submission_plugins();
foreach ($submissionplugins as $submissionplugin) {
$component = $submissionplugin->get_subtype() . '_' . $submissionplugin->get_type();
$fileareas = $submissionplugin->get_file_areas();
foreach ($fileareas as $filearea => $name) {
$files = $fs->get_area_files($assign->get_context()->id, $component, $filearea, $submission->id, "timemodified", false);
foreach ($files as $file) {
if ($file->get_contenthash() == $plagiarismfile->identifier) {
return $file;
}
}
}
}
} else {
if ($cm->modname == 'workshop') {
require_once $CFG->dirroot . '/mod/workshop/locallib.php';
$cm = get_coursemodule_from_id('workshop', $plagiarismfile->cm, 0, false, MUST_EXIST);
$workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$workshop = new workshop($workshop, $cm, $course);
$submissions = $workshop->get_submissions($plagiarismfile->userid);
foreach ($submissions as $submission) {
$files = $fs->get_area_files($workshop->context->id, 'mod_workshop', 'submission_attachment', $submission->id);
foreach ($files as $file) {
if ($file->get_contenthash() == $plagiarismfile->identifier) {
return $file;
}
}
}
} else {
if ($cm->modname == 'forum') {
require_once $CFG->dirroot . '/mod/forum/lib.php';
$cm = get_coursemodule_from_id('forum', $plagiarismfile->cm, 0, false, MUST_EXIST);
$posts = forum_get_user_posts($cm->instance, $plagiarismfile->userid);
foreach ($posts as $post) {
$files = $fs->get_area_files($modulecontext->id, 'mod_forum', 'attachment', $post->id, "timemodified", false);
foreach ($files as $file) {
if ($file->get_contenthash() == $plagiarismfile->identifier) {
return $file;
}
}
}
}
}
}
}
}
示例13: urkund_reset_file
function urkund_reset_file($id)
{
global $DB, $CFG;
$plagiarismfile = $DB->get_record('plagiarism_urkund_files', array('id' => $id), '*', MUST_EXIST);
if ($plagiarismfile->statuscode == 'Analyzed' || $plagiarismfile->statuscode == URKUND_STATUSCODE_ACCEPTED) {
// Sanity Check.
return true;
}
// Set some new values.
$plagiarismfile->statuscode = 'pending';
$plagiarismfile->attempt = 0;
$plagiarismfile->timesubmitted = time();
$cm = get_coursemodule_from_id('', $plagiarismfile->cm);
$modulecontext = context_module::instance($plagiarismfile->cm);
$fs = get_file_storage();
if ($cm->modname == 'assignment') {
$submission = $DB->get_record('assignment_submissions', array('assignment' => $cm->instance, 'userid' => $plagiarismfile->userid));
$files = $fs->get_area_files($modulecontext->id, 'mod_assignment', 'submission', $submission->id);
foreach ($files as $file) {
if ($file->get_contenthash() == $plagiarismfile->identifier) {
$DB->update_record('plagiarism_urkund_files', $plagiarismfile);
// Update before trying to send again.
return urkund_send_file($plagiarismfile->cm, $plagiarismfile->userid, $file, plagiarism_plugin_urkund::get_settings());
}
}
} else {
if ($cm->modname == 'assign') {
require_once $CFG->dirroot . '/mod/assign/locallib.php';
$assign = new assign($modulecontext, null, null);
$submissionplugins = $assign->get_submission_plugins();
$dbparams = array('assignment' => $assign->get_instance()->id, 'userid' => $plagiarismfile->userid);
$submissions = $DB->get_records('assign_submission', $dbparams);
foreach ($submissions as $submission) {
foreach ($submissionplugins as $submissionplugin) {
$component = $submissionplugin->get_subtype() . '_' . $submissionplugin->get_type();
$fileareas = $submissionplugin->get_file_areas();
foreach ($fileareas as $filearea => $name) {
$files = $fs->get_area_files($assign->get_context()->id, $component, $filearea, $submission->id, "timemodified", false);
foreach ($files as $file) {
if ($file->get_contenthash() == $plagiarismfile->identifier) {
$DB->update_record('plagiarism_urkund_files', $plagiarismfile);
// Update before trying to send again.
return urkund_send_file($plagiarismfile->cm, $plagiarismfile->userid, $file, plagiarism_plugin_urkund::get_settings());
}
}
}
}
}
} else {
if ($cm->modname == 'workshop') {
require_once $CFG->dirroot . '/mod/workshop/locallib.php';
$cm = get_coursemodule_from_id('workshop', $plagiarismfile->cm, 0, false, MUST_EXIST);
$workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$workshop = new workshop($workshop, $cm, $course);
$submissions = $workshop->get_submissions($plagiarismfile->userid);
foreach ($submissions as $submission) {
$files = $fs->get_area_files($workshop->context->id, 'mod_workshop', 'submission_attachment', $submission->id);
foreach ($files as $file) {
if ($file->get_contenthash() == $plagiarismfile->identifier) {
$DB->update_record('plagiarism_urkund_files', $plagiarismfile);
// Update before trying to send again.
return urkund_send_file($plagiarismfile->cm, $plagiarismfile->userid, $file, plagiarism_plugin_urkund::get_settings());
}
}
}
} else {
if ($cm->modname == 'forum') {
require_once $CFG->dirroot . '/mod/forum/lib.php';
$cm = get_coursemodule_from_id('forum', $plagiarismfile->cm, 0, false, MUST_EXIST);
$posts = forum_get_user_posts($cm->instance, $plagiarismfile->userid);
foreach ($posts as $post) {
$files = $fs->get_area_files($modulecontext->id, 'mod_forum', 'attachment', $post->id, "timemodified", false);
foreach ($files as $file) {
if ($file->get_contenthash() == $plagiarismfile->identifier) {
$DB->update_record('plagiarism_urkund_files', $plagiarismfile);
// Update before trying to send again.
return urkund_send_file($plagiarismfile->cm, $plagiarismfile->userid, $file, plagiarism_plugin_urkund::get_settings());
}
}
}
}
}
}
}
}
示例14: grading_popup
/**
* Makes the grading interface for the pop up. Robbed from /mod/assign/locallib.php
* line 1583ish - view_single_grade_page().
*
* @param array $params From $_GET
* @param object $coursemodule The coursemodule object that the user has been authenticated
* against
* @param bool $data
* @throws coding_exception
* @global $PAGE
* @global stdClass $CFG
* @global moodle_database $DB
* @global $OUTPUT
* @global stdClass $USER
* @return string
*/
public function grading_popup($params, $coursemodule, $data = false)
{
global $PAGE, $CFG, $DB;
$modulecontext = context_module::instance($coursemodule->id);
$course = $DB->get_record('course', array('id' => $coursemodule->course));
$coursecontext = context_course::instance($course->id);
$assign = new assign($modulecontext, $coursemodule, $course);
/* @var mod_assign_renderer $renderer */
$renderer = $PAGE->get_renderer('mod_assign');
$output = '';
// Include grade form.
require_once $CFG->dirroot . '/mod/assign/gradeform.php';
// Need submit permission to submit an assignment.
require_capability('mod/assign:grade', $modulecontext);
/* Pinched from private method assign::get_grading_userid_list() */
$filter = get_user_preferences('assign_filter', '');
$table = new assign_grading_table($assign, 0, $filter, 0, false);
$useridlist = $table->get_column_data('userid');
$userid = $params['userid'];
$rownum = 0;
foreach ($useridlist as $key => $useridinlist) {
if ($useridinlist == $userid) {
$rownum = $key;
reset($useridlist);
// Just in case.
break;
}
}
$last = false;
if ($rownum == count($useridlist) - 1) {
$last = true;
}
$user = $DB->get_record('user', array('id' => $userid));
if ($user) {
$output .= $renderer->render(new assign_user_summary($user, $course->id, has_capability('moodle/site:viewfullnames', $coursecontext)));
}
$submission = $DB->get_record('assign_submission', array('assignment' => $assign->get_instance()->id, 'userid' => $userid));
// Get the current grade. Pinched from assign::get_user_grade().
$grade = $DB->get_record('assign_grades', array('assignment' => $assign->get_instance()->id, 'userid' => $userid));
// Pinched from assign::is_graded().
$isgraded = !empty($grade) && $grade->grade !== null && $grade->grade >= 0;
if ($assign->can_view_submission($userid)) {
$gradelocked = $grade && $grade->locked || $assign->grading_disabled($userid);
$widget = new assign_submission_status($assign->get_instance()->allowsubmissionsfromdate, $assign->get_instance()->alwaysshowdescription, $submission, $assign->is_any_submission_plugin_enabled(), $gradelocked, $isgraded, $assign->get_instance()->duedate, $assign->get_submission_plugins(), $assign->get_return_action(), $assign->get_return_params(), $assign->get_course_module()->id, assign_submission_status::GRADER_VIEW, false, false);
$output .= $renderer->render($widget);
}
if ($grade) {
$data = new stdClass();
if ($grade->grade !== null && $grade->grade >= 0) {
$data->grade = format_float($grade->grade, 2);
}
} else {
$data = new stdClass();
$data->grade = '';
}
// Now show the grading form.
$customdata = array('useridlist' => $useridlist, 'rownum' => $rownum, 'last' => $last);
$mform = new mod_assign_grade_form(block_ajax_marking_form_url($params), array($assign, $data, $customdata), 'post', '', array('class' => 'gradeform'));
$output .= $renderer->render(new assign_form('gradingform', $mform));
$assign->add_to_log('view grading form', get_string('viewgradingformforstudent', 'assign', array('id' => $user->id, 'fullname' => fullname($user))));
return $output;
}