本文整理汇总了PHP中assign::get_context方法的典型用法代码示例。如果您正苦于以下问题:PHP assign::get_context方法的具体用法?PHP assign::get_context怎么用?PHP assign::get_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类assign
的用法示例。
在下文中一共展示了assign::get_context方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_file_info
/**
* Default implementation of file_get_info for plugins.
* This is used by the filebrowser to browse a plugins file areas.
*
* This implementation should work for most plugins but can be overridden if required.
* @param file_browser $browser
* @param string $filearea
* @param int $itemid
* @param string $filepath
* @param string $filename
* @return file_info_stored
*/
public function get_file_info($browser, $filearea, $itemid, $filepath, $filename)
{
global $CFG, $DB, $USER;
$urlbase = $CFG->wwwroot . '/pluginfile.php';
// Permission check on the itemid.
if ($this->get_subtype() == 'assignsubmission') {
if ($itemid) {
$record = $DB->get_record('assign_submission', array('id' => $itemid), 'userid', IGNORE_MISSING);
if (!$record) {
return null;
}
if (!$this->assignment->can_view_submission($record->userid)) {
return null;
}
}
} else {
// Not supported for feedback plugins.
return null;
}
$fs = get_file_storage();
$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;
if (!($storedfile = $fs->get_file($this->assignment->get_context()->id, $this->get_subtype() . '_' . $this->get_type(), $filearea, $itemid, $filepath, $filename))) {
return null;
}
return new file_info_stored($browser, $this->assignment->get_context(), $storedfile, $urlbase, $filearea, $itemid, true, true, false);
}
示例2: col_allocatedmarker
/**
* list current marker
*
* @param stdClass $row - The row of data
* @return id the user->id of the marker.
*/
public function col_allocatedmarker(stdClass $row) {
static $markers = null;
static $markerlist = array();
if ($markers === null) {
$markers = get_users_by_capability($this->assignment->get_context(), 'mod/assign:grade');
$markerlist[0] = get_string('choosemarker', 'assign');
foreach ($markers as $marker) {
$markerlist[$marker->id] = fullname($marker);
}
}
if (empty($markerlist)) {
// TODO: add some form of notification here that no markers are available.
return '';
}
if ($this->is_downloading()) {
return $markers[$row->allocatedmarker];
}
if ($this->quickgrading && has_capability('mod/assign:manageallocations', $this->assignment->get_context()) &&
(empty($row->workflowstate) ||
$row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_INMARKING ||
$row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED)) {
$name = 'quickgrade_' . $row->id . '_allocatedmarker';
return html_writer::select($markerlist, $name, $row->allocatedmarker, false);
} else if (!empty($row->allocatedmarker)) {
$output = '';
if ($this->quickgrading) { // Add hidden field for quickgrading page.
$name = 'quickgrade_' . $row->id . '_allocatedmarker';
$output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$name, 'value'=>$row->allocatedmarker));
}
$output .= $markerlist[$row->allocatedmarker];
return $output;
}
}
示例3: create_from_submission
/**
* Create instance of event.
*
* @param \assign $assign
* @param \stdClass $submission
* @return submission_viewed
*/
public static function create_from_submission(\assign $assign, \stdClass $submission)
{
$data = array('objectid' => $submission->id, 'relateduserid' => $submission->userid, 'context' => $assign->get_context(), 'other' => array('assignid' => $assign->get_instance()->id));
/** @var submission_viewed $event */
$event = self::create($data);
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
示例4: create_from_assign
/**
* Create instance of event.
*
* @param \assign $assign
* @return batch_set_marker_allocation_viewed
*/
public static function create_from_assign(\assign $assign)
{
$data = array('context' => $assign->get_context(), 'other' => array('assignid' => $assign->get_instance()->id));
self::$preventcreatecall = false;
/** @var batch_set_marker_allocation_viewed $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
示例5: create_from_assign
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @return all_submissions_downloaded
*/
public static function create_from_assign(\assign $assign)
{
$data = array('context' => $assign->get_context(), 'objectid' => $assign->get_instance()->id);
self::$preventcreatecall = false;
/** @var submission_graded $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
return $event;
}
示例6: set_assign
/**
* Set assign instance for this event.
* @param \assign $assign
* @throws \coding_exception
*/
public function set_assign(\assign $assign)
{
if ($this->is_triggered()) {
throw new \coding_exception('set_assign() must be done before triggerring of event');
}
if ($assign->get_context()->id != $this->get_context()->id) {
throw new \coding_exception('Invalid assign isntance supplied!');
}
$this->assign = $assign;
}
示例7: create_from_grade
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $grade
* @return submission_graded
*/
public static function create_from_grade(\assign $assign, \stdClass $grade)
{
$data = array('context' => $assign->get_context(), 'objectid' => $grade->id, 'relateduserid' => $grade->userid);
self::$preventcreatecall = false;
/** @var submission_graded $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('assign_grades', $grade);
return $event;
}
示例8: create_from_submission
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $submission
* @return statement_accepted
*/
public static function create_from_submission(\assign $assign, \stdClass $submission)
{
$data = array('context' => $assign->get_context(), 'objectid' => $submission->id);
self::$preventcreatecall = false;
/** @var statement_accepted $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
示例9: create_from_user
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $user
* @return submission_locked
*/
public static function create_from_user(\assign $assign, \stdClass $user)
{
$data = array('context' => $assign->get_context(), 'objectid' => $assign->get_instance()->id, 'relateduserid' => $user->id);
self::$preventcreatecall = false;
/** @var submission_locked $event */
$event = self::create($data);
self::$preventcreatecall = true;
$event->set_assign($assign);
$event->add_record_snapshot('user', $user);
return $event;
}
示例10: create_from_submission
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \assign $assign
* @param \stdClass $submission
* @param bool $editable
* @return assessable_submitted
*/
public static function create_from_submission(\assign $assign, \stdClass $submission, $editable)
{
global $USER;
$data = array('context' => $assign->get_context(), 'objectid' => $submission->id, 'other' => array('submission_editable' => $editable));
if (!empty($submission->userid) && $submission->userid != $USER->id) {
$data['relateduserid'] = $submission->userid;
}
/** @var assessable_submitted $event */
$event = self::create($data);
$event->set_assign($assign);
$event->add_record_snapshot('assign_submission', $submission);
return $event;
}
示例11: 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;
}
示例12: copy_drafts_from_to
/**
* This function copies annotations and comments from the source user
* to the current group member being processed when using applytoall.
* @param int|\assign $assignment
* @param stdClass $grade
* @param int $sourceuserid
* @return bool
*/
public static function copy_drafts_from_to($assignment, $grade, $sourceuserid)
{
global $DB;
// Delete any existing annotations and comments from current user.
$DB->delete_records('assignfeedback_editpdf_annot', array('gradeid' => $grade->id));
$DB->delete_records('assignfeedback_editpdf_cmnt', array('gradeid' => $grade->id));
// Get gradeid, annotations and comments from sourceuserid.
$sourceusergrade = $assignment->get_user_grade($sourceuserid, true, $grade->attemptnumber);
$annotations = $DB->get_records('assignfeedback_editpdf_annot', array('gradeid' => $sourceusergrade->id, 'draft' => 1));
$comments = $DB->get_records('assignfeedback_editpdf_cmnt', array('gradeid' => $sourceusergrade->id, 'draft' => 1));
// Add annotations and comments to current user to generate feedback file.
foreach ($annotations as $annotation) {
$annotation->gradeid = $grade->id;
$DB->insert_record('assignfeedback_editpdf_annot', $annotation);
}
foreach ($comments as $comment) {
$comment->gradeid = $grade->id;
$DB->insert_record('assignfeedback_editpdf_cmnt', $comment);
}
// Delete the existing stamps and copy the source ones.
$fs = get_file_storage();
$fs->delete_area_files($assignment->get_context()->id, 'assignfeedback_editpdf', 'stamps', $grade->id);
if ($files = $fs->get_area_files($assignment->get_context()->id, 'assignfeedback_editpdf', 'stamps', $sourceusergrade->id, "filename", false)) {
foreach ($files as $file) {
$newrecord = new \stdClass();
$newrecord->contextid = $assignment->get_context()->id;
$newrecord->itemid = $grade->id;
$fs->create_file_from_storedfile($newrecord, $file);
}
}
return true;
}
示例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: 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);
//.........这里部分代码省略.........
示例15: import_zip_files
/**
* Process an uploaded zip file
*
* @param assign $assignment - The assignment instance
* @param assign_feedback_file $fileplugin - The file feedback plugin
* @return string - The html response
*/
public function import_zip_files($assignment, $fileplugin) {
global $USER, $CFG, $PAGE, $DB;
@set_time_limit(ASSIGNFEEDBACK_FILE_MAXFILEUNZIPTIME);
$packer = get_file_packer('application/zip');
$feedbackfilesupdated = 0;
$feedbackfilesadded = 0;
$userswithnewfeedback = array();
$contextid = $assignment->get_context()->id;
$fs = get_file_storage();
$files = $fs->get_directory_files($contextid,
'assignfeedback_file',
ASSIGNFEEDBACK_FILE_IMPORT_FILEAREA,
$USER->id,
'/import/');
$currentgroup = groups_get_activity_group($assignment->get_course_module(), true);
$allusers = $assignment->list_participants($currentgroup, false);
$participants = array();
foreach ($allusers as $user) {
$participants[$assignment->get_uniqueid_for_user($user->id)] = $user;
}
foreach ($files as $unzippedfile) {
// Set the timeout for unzipping each file.
$user = null;
$plugin = null;
$filename = '';
if ($this->is_valid_filename_for_import($assignment, $unzippedfile, $participants, $user, $plugin, $filename)) {
if ($this->is_file_modified($assignment, $user, $plugin, $filename, $unzippedfile)) {
$grade = $assignment->get_user_grade($user->id, true);
if ($oldfile = $fs->get_file($contextid,
'assignfeedback_file',
ASSIGNFEEDBACK_FILE_FILEAREA,
$grade->id,
'/',
$filename)) {
// Update existing feedback file.
$oldfile->replace_content_with($unzippedfile);
$feedbackfilesupdated++;
} else {
// Create a new feedback file.
$newfilerecord = new stdClass();
$newfilerecord->contextid = $contextid;
$newfilerecord->component = 'assignfeedback_file';
$newfilerecord->filearea = ASSIGNFEEDBACK_FILE_FILEAREA;
$newfilerecord->filename = $filename;
$newfilerecord->filepath = '/';
$newfilerecord->itemid = $grade->id;
$fs->create_file_from_storedfile($newfilerecord, $unzippedfile);
$feedbackfilesadded++;
}
$userswithnewfeedback[$user->id] = 1;
// Update the number of feedback files for this user.
$fileplugin->update_file_count($grade);
// Update the last modified time on the grade which will trigger student notifications.
$assignment->notify_grade_modified($grade);
}
}
}
require_once($CFG->dirroot . '/mod/assign/feedback/file/renderable.php');
$importsummary = new assignfeedback_file_import_summary($assignment->get_course_module()->id,
count($userswithnewfeedback),
$feedbackfilesadded,
$feedbackfilesupdated);
$assignrenderer = $assignment->get_renderer();
$renderer = $PAGE->get_renderer('assignfeedback_file');
$o = '';
$o .= $assignrenderer->render(new assign_header($assignment->get_instance(),
$assignment->get_context(),
false,
$assignment->get_course_module()->id,
get_string('uploadzipsummary', 'assignfeedback_file')));
$o .= $renderer->render($importsummary);
$o .= $assignrenderer->render_footer();
return $o;
}