public function initiate() { $assign = new assign($this->application); if ($assign->host()->dir($this->configuration)) { $module = new module(); $module->loader(); if (module::request(support\configuration::class)->configuration()) { $rewrite = avail::configuration($this->rewrite)->request('rewrite'); if ($assign->rewrite($rewrite)) { if ($route = $module->route()) { module::request(support\validation::class)->extension('ASV'); module::request(support\authorization::class)->extension('ASA'); module::request(support\mail::class)->extension('ASM'); $ase = $module->environment(); if ($ase) { if (isset($ase['database'])) { if ($assign->database(array_merge(avail::$database, $ase['database']))) { return true; } else { unset($ase['database']); } } avail::configuration($ase)->merge(); } avail::authorization()->subscribe(); avail::directory()->set(avail::configuration($this->directory)->request('directory')); new verse(); $verso = new verso($route->page); $verso->set(); $verso->execute(); } } } } }
/** * Permission control method for submission plugin ---- required method for AJAXmoodle based comment API * * @param stdClass $options * @return array */ function assignsubmission_comments_comment_permissions(stdClass $options) { global $USER, $CFG, $DB; if ($options->commentarea != 'submission_comments' && $options->commentarea != 'submission_comments_upgrade') { throw new comment_exception('invalidcommentarea'); } if (!$submission = $DB->get_record('assign_submission', array('id'=>$options->itemid))) { throw new comment_exception('invalidcommentitemid'); } $context = $options->context; require_once($CFG->dirroot . '/mod/assign/locallib.php'); $assignment = new assign($context, null, null); if ($assignment->get_instance()->id != $submission->assignment) { throw new comment_exception('invalidcontext'); } if (!has_capability('mod/assign:grade', $context)) { if (!has_capability('mod/assign:submit', $context)) { return array('post' => false, 'view' => false); } else if ($submission->userid != $USER->id) { return array('post' => false, 'view' => false); } } return array('post' => true, 'view' => true); }
public function __construct(\mod_mediagallery\collection $collection, array $galleries) { global $CFG, $DB; $this->collection = $collection; $this->galleries = $galleries; if ($collection->user_can_add_children()) { $this->maxreached = false; } if ($this->isassessable = $collection->is_assessable()) { $this->hassubmitted = $collection->has_submitted(); if ($this->linkedassigncmid = $collection->get_linked_assignid()) { require_once $CFG->dirroot . '/mod/assign/locallib.php'; $context = \context_module::instance($this->linkedassigncmid); $cm = get_coursemodule_from_id('assign', $this->linkedassigncmid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $assign = new \assign($context, $cm, $course); $this->submissionsopen = $assign->submissions_open(); } } $this->readonly = $collection->is_read_only(); $this->tags = $collection->get_tags(); $mygalleries = $collection->get_my_galleries(); $this->userorgrouphasgallery = !empty($mygalleries); foreach (array('id', 'mode', 'thumbnailsperrow', 'thumbnailsperpage') as $opt) { if (isset($collection->{$opt})) { $this->{$opt} = $collection->{$opt}; } } }
/** * 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; }
/** * 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; }
/** * Constructor for this renderable. * * @param int $userid The user we will open the grading app too. * @param int $groupid If groups are enabled this is the current course group. * @param assign $assignment The assignment class */ public function __construct($userid, $groupid, $assignment) { $this->userid = $userid; $this->groupid = $groupid; $this->assignment = $assignment; $this->participants = $assignment->list_participants_with_filter_status_and_group($groupid); if (!$this->userid && count($this->participants)) { $this->userid = reset($this->participants)->id; } }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * Annotate files from plugin configuration * @param backup_nested_element $assign the backup structure of the activity * @param string $subtype the plugin type to handle * @return void */ protected function annotate_plugin_config_files(backup_nested_element $assign, $subtype) { $dummyassign = new assign(null, null, null); $plugins = $dummyassign->load_plugins($subtype); foreach ($plugins as $plugin) { $component = $plugin->get_subtype() . '_' . $plugin->get_type(); $areas = $plugin->get_config_file_areas(); foreach ($areas as $area) { $assign->annotate_files($component, $area, null); } } }
/** * 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; }
public function save_dates(cm_info $cm, array $dates) { global $DB, $COURSE; $update = new stdClass(); $update->id = $cm->instance; $update->duedate = $dates['duedate']; $update->allowsubmissionsfromdate = $dates['allowsubmissionsfromdate']; $update->cutoffdate = $dates['cutoffdate']; $result = $DB->update_record('assign', $update); $module = new assign(context_module::instance($cm->id), null, null); // Update the calendar and grades. $module->update_calendar($cm->id); $module->update_gradebook(false, $cm->id); }
/** * 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); }
public function execute() { $Id = $this->executeArrange(); $versoObject = $Id[avail::$config['APC']]; $versoMethod = $Id[avail::$config['APM']]; if ($Obj = module::request($versoObject)->map()) { if (method_exists($Obj, $versoMethod) && is_callable(array($Obj, $versoMethod))) { avail::$contextId = call_user_func(array($Obj, $versoMethod)); avail::$contextResponse = avail::$contextType; $currentSupport = array($Obj, $versoMethod . avail::$config['AHS']); if (is_callable($currentSupport)) { call_user_func($currentSupport); } $finalSupport = array($Obj, avail::$config['AHF'] . avail::$config['AHS']); if (is_callable($finalSupport)) { call_user_func($finalSupport); } } else { // avail::assist(14)->log('is_not_callable'); assign::template('method')->error(array('class' => avail::$config['ARO'] . avail::$config['ASP'] . avail::SlA . $versoObject, 'method' => $versoMethod)); } } else { // TODO: disable initial()->error() on live application // avail::assist(14)->log('is_not_callable'); assign::template('class')->error(array('class' => $versoObject, 'root' => avail::$config['ARO'] . avail::$config['ASP'] . avail::SlA)); } }
/** * Always return a valid sort - even if the userid column is missing. * @return array column name => SORT_... constant. */ public function get_sort_columns() { $result = parent::get_sort_columns(); $assignment = $this->assignment->get_instance(); if (empty($assignment->blindmarking)) { $result = array_merge($result, array('userid' => SORT_ASC)); } else { $result = array_merge($result, ['COALESCE(s.timecreated, ' . time() . ')' => SORT_ASC, 'COALESCE(s.id, ' . PHP_INT_MAX . ')' => SORT_ASC, 'um.id' => SORT_ASC]); } return $result; }
public function test_grade_edit_tree_column_range_get_item_cell() { global $DB, $CFG; $this->resetAfterTest(true); // Make some things we need. $scale = $this->getDataGenerator()->create_scale(); $course = $this->getDataGenerator()->create_course(); $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id)); $modulecontext = context_module::instance($assign->id); // The generator returns a dummy object, lets get the real assign object. $assign = new assign($modulecontext, false, false); $cm = $assign->get_course_module(); // Get range column. $column = grade_edit_tree_column::factory('range'); $gradeitemparams = array('itemtype' => 'mod', 'itemmodule' => $cm->modname, 'iteminstance' => $cm->instance, 'courseid' => $cm->course, 'itemnumber' => 0); // Lets set the grade to something we know. $instance = $assign->get_instance(); $instance->grade = 70; $instance->instance = $instance->id; $assign->update_instance($instance); $gradeitem = grade_item::fetch($gradeitemparams); $cell = $column->get_item_cell($gradeitem, array()); $this->assertEquals(GRADE_TYPE_VALUE, $gradeitem->gradetype); $this->assertEquals(null, $gradeitem->scaleid); $this->assertEquals(70.0, (double) $cell->text, "Grade text is 70", 0.01); // Now change it to a scale. $instance = $assign->get_instance(); $instance->grade = -$scale->id; $instance->instance = $instance->id; $assign->update_instance($instance); $gradeitem = grade_item::fetch($gradeitemparams); $cell = $column->get_item_cell($gradeitem, array()); // Make the expected scale text. $scaleitems = null; $scaleitems = explode(',', $scale->scale); $scalestring = end($scaleitems) . ' (' . count($scaleitems) . ')'; $this->assertEquals(GRADE_TYPE_SCALE, $gradeitem->gradetype); $this->assertEquals($scale->id, $gradeitem->scaleid); $this->assertEquals($scalestring, $cell->text, "Grade text matches scale"); // Now change it to no grade. $instance = $assign->get_instance(); $instance->grade = 0; $instance->instance = $instance->id; $assign->update_instance($instance); $gradeitem = grade_item::fetch($gradeitemparams); $cell = $column->get_item_cell($gradeitem, array()); $this->assertEquals(GRADE_TYPE_TEXT, $gradeitem->gradetype); $this->assertEquals(null, $gradeitem->scaleid); $this->assertEquals(' - ', $cell->text, 'Grade text matches empty value of " - "'); }
/** * Serves assignment submissions and other files. * * @param mixed $course course or id of the course * @param mixed $cm course module or id of the course module * @param context $context * @param string $filearea * @param array $args * @param bool $forcedownload * @return bool false if file not found, does not return if found - just send the file */ function assignsubmission_onenote_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload) { global $DB, $CFG; if ($context->contextlevel != CONTEXT_MODULE) { return false; } require_login($course, false, $cm); $itemid = (int) array_shift($args); $record = $DB->get_record('assign_submission', array('id' => $itemid), 'userid, assignment, groupid', MUST_EXIST); $userid = $record->userid; $groupid = $record->groupid; require_once $CFG->dirroot . '/mod/assign/locallib.php'; $assign = new assign($context, $cm, $course); if ($assign->get_instance()->id != $record->assignment) { return false; } if ($assign->get_instance()->teamsubmission && !$assign->can_view_group_submission($groupid)) { return false; } if (!$assign->get_instance()->teamsubmission && !$assign->can_view_submission($userid)) { return false; } $relativepath = implode('/', $args); $fullpath = "/{$context->id}/assignsubmission_onenote/{$filearea}/{$itemid}/{$relativepath}"; $fs = get_file_storage(); if (!($file = $fs->get_file_by_hash(sha1($fullpath))) || $file->is_directory()) { return false; } // Download MUST be forced - security! send_stored_file($file, 0, 0, true); }
/** * This function is a static wrapper around can_upgrade * * @param string $type The plugin type * @param int $version The plugin version * @return bool */ public static function can_upgrade_assignment($type, $version) { $assignment = new assign(null, null, null); return $assignment->can_upgrade($type, $version); }
/** * Tests the backup and restore of single activity to same course (duplicate) * when it contains availability conditions that depend on other items in * course. */ public function test_duplicate_availability() { global $DB, $CFG; $this->resetAfterTest(true); $this->setAdminUser(); $CFG->enableavailability = true; $CFG->enablecompletion = true; // Create a course with completion enabled and 2 forums. $generator = $this->getDataGenerator(); $course = $generator->create_course(array('format' => 'topics', 'enablecompletion' => COMPLETION_ENABLED)); $forum = $generator->create_module('forum', array('course' => $course->id)); $forum2 = $generator->create_module('forum', array('course' => $course->id, 'completion' => COMPLETION_TRACKING_MANUAL)); // We need a grade, easiest is to add an assignment. $assignrow = $generator->create_module('assign', array('course' => $course->id)); $assign = new assign(context_module::instance($assignrow->cmid), false, false); $item = $assign->get_grade_item(); // Make a test group and grouping as well. $group = $generator->create_group(array('courseid' => $course->id, 'name' => 'Group!')); $grouping = $generator->create_grouping(array('courseid' => $course->id, 'name' => 'Grouping!')); // Set the forum to have availability conditions on all those things, // plus some that don't exist or are special values. $availability = '{"op":"|","show":false,"c":[' . '{"type":"completion","cm":' . $forum2->cmid . ',"e":1},' . '{"type":"completion","cm":99999999,"e":1},' . '{"type":"grade","id":' . $item->id . ',"min":4,"max":94},' . '{"type":"grade","id":99999998,"min":4,"max":94},' . '{"type":"grouping","id":' . $grouping->id . '},' . '{"type":"grouping","id":99999997},' . '{"type":"group","id":' . $group->id . '},' . '{"type":"group"},' . '{"type":"group","id":99999996}' . ']}'; $DB->set_field('course_modules', 'availability', $availability, array('id' => $forum->cmid)); // Duplicate it. $newcmid = $this->duplicate($course, $forum->cmid); // For those which still exist on the course we expect it to keep using // the real ID. For those which do not exist on the course any more // (e.g. simulating backup/restore of single activity between 2 courses) // we expect the IDs to be replaced with marker value: 0 for cmid // and grade, -1 for group/grouping. $expected = str_replace(array('99999999', '99999998', '99999997', '99999996'), array(0, 0, -1, -1), $availability); // Check settings in new activity. $actual = $DB->get_field('course_modules', 'availability', array('id' => $newcmid)); $this->assertEquals($expected, $actual); }
/** * Describes the parameters for save_grades * @return external_external_function_parameters * @since Moodle 2.7 */ public static function save_grades_parameters() { global $CFG; require_once "{$CFG->dirroot}/grade/grading/lib.php"; $instance = new assign(null, null, null); $pluginfeedbackparams = array(); foreach ($instance->get_feedback_plugins() as $plugin) { if ($plugin->is_visible()) { $pluginparams = $plugin->get_external_parameters(); if (!empty($pluginparams)) { $pluginfeedbackparams = array_merge($pluginfeedbackparams, $pluginparams); } } } $advancedgradingdata = array(); $methods = array_keys(grading_manager::available_methods(false)); foreach ($methods as $method) { require_once $CFG->dirroot . '/grade/grading/form/' . $method . '/lib.php'; $details = call_user_func('gradingform_' . $method . '_controller::get_external_instance_filling_details'); if (!empty($details)) { $items = array(); foreach ($details as $key => $value) { $value->required = VALUE_OPTIONAL; unset($value->content->keys['id']); $items[$key] = new external_multiple_structure(new external_single_structure(array('criterionid' => new external_value(PARAM_INT, 'criterion id'), 'fillings' => $value))); } $advancedgradingdata[$method] = new external_single_structure($items, 'items', VALUE_OPTIONAL); } } return new external_function_parameters(array('assignmentid' => new external_value(PARAM_INT, 'The assignment id to operate on'), 'applytoall' => new external_value(PARAM_BOOL, 'If true, this grade will be applied ' . 'to all members ' . 'of the group (for group assignments).'), 'grades' => new external_multiple_structure(new external_single_structure(array('userid' => new external_value(PARAM_INT, 'The student id to operate on'), 'grade' => new external_value(PARAM_FLOAT, 'The new grade for this user. ' . 'Ignored if advanced grading used'), 'attemptnumber' => new external_value(PARAM_INT, 'The attempt number (-1 means latest attempt)'), 'addattempt' => new external_value(PARAM_BOOL, 'Allow another attempt if manual attempt reopen method'), 'workflowstate' => new external_value(PARAM_ALPHA, 'The next marking workflow state'), 'plugindata' => new external_single_structure($pluginfeedbackparams, 'plugin data', VALUE_DEFAULT, array()), 'advancedgradingdata' => new external_single_structure($advancedgradingdata, 'advanced grading data', VALUE_DEFAULT, array())))))); }
/** * Serve the grading panel as a fragment. * * @param array $args List of named arguments for the fragment loader. * @return string */ function mod_assign_output_fragment_gradingpanel($args) { global $CFG; $context = $args['context']; if ($context->contextlevel != CONTEXT_MODULE) { return null; } require_once $CFG->dirroot . '/mod/assign/locallib.php'; $assign = new assign($context, null, null); $userid = clean_param($args['userid'], PARAM_INT); $attemptnumber = clean_param($args['attemptnumber'], PARAM_INT); $formdata = array(); if (!empty($args['jsonformdata'])) { $serialiseddata = json_decode($args['jsonformdata']); parse_str($serialiseddata, $formdata); } $viewargs = array('userid' => $userid, 'attemptnumber' => $attemptnumber, 'formdata' => $formdata); return $assign->view('gradingpanel', $viewargs); }
*/ use assignfeedback_editpdf\document_services; use assignfeedback_editpdf\page_editor; use assignfeedback_editpdf\comments_quick_list; define('AJAX_SCRIPT', true); require '../../../../config.php'; require_once $CFG->dirroot . '/mod/assign/locallib.php'; require_sesskey(); $action = optional_param('action', '', PARAM_ALPHANUM); $assignmentid = required_param('assignmentid', PARAM_INT); $userid = required_param('userid', PARAM_INT); $attemptnumber = required_param('attemptnumber', PARAM_INT); $readonly = optional_param('readonly', false, PARAM_BOOL); $cm = \get_coursemodule_from_instance('assign', $assignmentid, 0, false, MUST_EXIST); $context = \context_module::instance($cm->id); $assignment = new \assign($context, null, null); require_login($assignment->get_course(), false, $cm); if (!$assignment->can_view_submission($userid)) { print_error('nopermission'); } if ($action == 'loadallpages') { $draft = true; if (!has_capability('mod/assign:grade', $context)) { $draft = false; $readonly = true; // A student always sees the readonly version. require_capability('mod/assign:submit', $context); } // Whoever is viewing the readonly version should not use the drafts, but the actual annotations. if ($readonly) { $draft = false;
public function test_cron() { // First run cron so there are no messages waiting to be sent (from other tests). cron_setup_user(); assign::cron(); // Now create an assignment and add some feedback. $this->setUser($this->editingteachers[0]); $assign = $this->create_instance(array('sendstudentnotifications' => 1)); // Simulate adding a grade. $this->setUser($this->teachers[0]); $data = new stdClass(); $data->grade = '50.0'; $assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0); $assign->testable_apply_grade_to_user($data, $this->students[1]->id, 0); $data->sendstudentnotifications = false; $assign->testable_apply_grade_to_user($data, $this->students[2]->id, 0); // Now run cron and see that one message was sent. $this->preventResetByRollback(); $sink = $this->redirectMessages(); cron_setup_user(); $this->expectOutputRegex('/Done processing 2 assignment submissions/'); assign::cron(); $messages = $sink->get_messages(); // The sent count should be 2, because the 3rd one was marked as do not send notifications. $this->assertEquals(2, count($messages)); $this->assertEquals(1, $messages[0]->notification); $this->assertEquals($assign->get_instance()->name, $messages[0]->contexturlname); }
/** * Obtains the automatic completion state for this module based on any conditions * in assign settings. * * @param object $course Course * @param object $cm Course-module * @param int $userid User ID * @param bool $type Type of comparison (or/and; can be used as return value if no conditions) * @return bool True if completed, false if not, $type if conditions not set. */ function assign_get_completion_state($course, $cm, $userid, $type) { global $CFG, $DB; require_once $CFG->dirroot . '/mod/assign/locallib.php'; $assign = new assign(null, $cm, $course); // If completion option is enabled, evaluate it and return true/false. if ($assign->get_instance()->completionsubmit) { $submission = $DB->get_record('assign_submission', array('assignment' => $assign->get_instance()->id, 'userid' => $userid), '*', IGNORE_MISSING); return $submission && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED; } else { // Completion option is not enabled so just return $type. return $type; } }
/** * Fetch the plugin by its type. * * @return assign_submission_plugin */ protected function get_submission_plugin() { global $CFG; if (!$this->plugin || !$this->cmid) { return null; } require_once $CFG->dirroot . '/mod/assign/locallib.php'; $context = context_module::instance($this->cmid); $assignment = new assign($context, null, null); return $assignment->get_submission_plugin_by_type($this->plugin); }
die; } // Check if we need the closing date header $table = new html_table(); $table->head = array($strplural, get_string('duedate', 'assign'), get_string('submissions', 'assign')); $table->align = array('left', 'left', 'center'); $table->data = array(); foreach ($assignments as $assignment) { $cm = get_coursemodule_from_instance('assign', $assignment->id, 0, false, MUST_EXIST); $link = html_writer::link(new moodle_url('/mod/assign/view.php', array('id' => $cm->id)), $assignment->name); $date = '-'; if (!empty($assignment->duedate)) { $date = userdate($assignment->duedate); } $context = context_module::instance($cm->id); $instance = new assign($context, $cm, $course); $submitted = ''; if (has_capability('mod/assign:grade', $context)) { $submitted = $instance->count_submissions_with_status(ASSIGN_SUBMISSION_STATUS_SUBMITTED); } else { if (has_capability('mod/assign:submit', $context)) { $submission = $DB->get_record('assign_submission', array('assignment' => $assignment->id, 'userid' => $USER->id)); if (!empty($submission->status)) { $submitted = get_string('submissionstatus_' . $submission->status, 'assign'); } else { $submitted = get_string('submissionstatus_', 'assign'); } } } $row = array($link, $date, $submitted); $table->data[] = $row;
/** * Return things to the renderer. * * @return bool Can this user view all grades (the gradebook) */ public function can_view_all_grades() { $context = $this->assignment->get_course_context(); return has_capability('gradereport/grader:view', $context) && has_capability('moodle/grade:viewall', $context); }
public function test_upgrade_offline_assignment() { global $DB; $this->setUser($this->editingteachers[0]); $generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment'); $params = array('course'=>$this->course->id, 'assignmenttype'=>'offline'); $record = $generator->create_instance($params); $assignment = new assignment_base($record->cmid); $this->setAdminUser(); $log = ''; $upgrader = new assign_upgrade_manager(); $this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log)); $record = $DB->get_record('assign', array('course'=>$this->course->id)); $cm = get_coursemodule_from_instance('assign', $record->id); $context = context_module::instance($cm->id); $assign = new assign($context, $cm, $this->course); $plugin = $assign->get_submission_plugin_by_type('onlinetext'); $this->assertEmpty($plugin->is_enabled()); $plugin = $assign->get_submission_plugin_by_type('comments'); $this->assertEmpty($plugin->is_enabled()); $plugin = $assign->get_submission_plugin_by_type('file'); $this->assertEmpty($plugin->is_enabled()); $plugin = $assign->get_feedback_plugin_by_type('comments'); $this->assertNotEmpty($plugin->is_enabled()); $plugin = $assign->get_feedback_plugin_by_type('file'); $this->assertEmpty($plugin->is_enabled()); $plugin = $assign->get_feedback_plugin_by_type('offline'); $this->assertEmpty($plugin->is_enabled()); course_delete_module($cm->id); }