MDL-33952 Assignment - bon voyage!

mod_assignment has been replaced with a stub that only exists to support restoring and
auto upgrading to mod_assign. If you require mod_assignment for some old plugin, then
overwrite with the 2.6 version manually.
This commit is contained in:
Damyon Wiese 2013-12-19 13:04:28 +08:00
parent 33c6c949e5
commit 40cb48792a
46 changed files with 321 additions and 8630 deletions

View File

@ -575,32 +575,6 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve
continue;
}
}
if ($event->modulename == 'assignment'){
// create calendar_event to test edit_event capability
// this new event will also prevent double creation of calendar_event object
$checkevent = new calendar_event($event);
// TODO: rewrite this hack somehow
if (!calendar_edit_event_allowed($checkevent)){ // cannot manage entries, eg. student
if (!$assignment = $DB->get_record('assignment', array('id'=>$event->instance))) {
// print_error("invalidid", 'assignment');
continue;
}
// assign assignment to assignment object to use hidden_is_hidden method
require_once($CFG->dirroot.'/mod/assignment/lib.php');
if (!file_exists($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php')) {
continue;
}
require_once ($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php');
$assignmentclass = 'assignment_'.$assignment->assignmenttype;
$assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm);
if ($assignmentinstance->description_is_hidden()){//force not to show description before availability
$event->description = get_string('notavailableyet', 'assignment');
}
}
}
}
if ($processed >= $display->maxevents) {

View File

@ -900,13 +900,13 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$record = new stdClass();
$record->course = $course->id;
$module1 = self::getDataGenerator()->create_module('forum', $record);
$module2 = self::getDataGenerator()->create_module('assignment', $record);
$module2 = self::getDataGenerator()->create_module('assign', $record);
// Check the forum was correctly created.
$this->assertEquals(1, $DB->count_records('forum', array('id' => $module1->id)));
// Check the assignment was correctly created.
$this->assertEquals(1, $DB->count_records('assignment', array('id' => $module2->id)));
$this->assertEquals(1, $DB->count_records('assign', array('id' => $module2->id)));
// Check data exists in the course modules table.
$this->assertEquals(2, $DB->count_records_select('course_modules', 'id = :module1 OR id = :module2',
@ -939,7 +939,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$this->assertEquals(0, $DB->count_records('forum', array('id' => $module1->id)));
// Check the assignment was deleted.
$this->assertEquals(0, $DB->count_records('assignment', array('id' => $module2->id)));
$this->assertEquals(0, $DB->count_records('assign', array('id' => $module2->id)));
// Check we retrieve no data in the course modules table.
$this->assertEquals(0, $DB->count_records_select('course_modules', 'id = :module1 OR id = :module2',
@ -955,7 +955,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
// Create two modules.
$module1 = self::getDataGenerator()->create_module('forum', $record);
$module2 = self::getDataGenerator()->create_module('assignment', $record);
$module2 = self::getDataGenerator()->create_module('assign', $record);
// Since these modules were recreated the user will not have capabilities
// to delete them, ensure exception is thrown if they try.

View File

@ -81,11 +81,11 @@ abstract class grade_base_testcase extends advanced_testcase {
}
private function load_modules() {
$this->activities[0] = $this->getDataGenerator()->create_module('assignment', array('course'=>$this->course->id));
$this->course_module[0] = get_coursemodule_from_instance('assignment', $this->activities[0]->id);
$this->activities[0] = $this->getDataGenerator()->create_module('assign', array('course'=>$this->course->id));
$this->course_module[0] = get_coursemodule_from_instance('assign', $this->activities[0]->id);
$this->activities[1] = $this->getDataGenerator()->create_module('assignment', array('course'=>$this->course->id));
$this->course_module[1] = get_coursemodule_from_instance('assignment', $this->activities[1]->id);
$this->activities[1] = $this->getDataGenerator()->create_module('assign', array('course'=>$this->course->id));
$this->course_module[1] = get_coursemodule_from_instance('assign', $this->activities[1]->id);
$this->activities[2] = $this->getDataGenerator()->create_module('forum', array('course'=>$this->course->id));
$this->course_module[2] = get_coursemodule_from_instance('forum', $this->activities[2]->id);

View File

@ -53,15 +53,13 @@ class mod_assign_upgradelib_testcase extends mod_assign_base_testcase {
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
$params = array('course'=>$this->course->id,
'assignmenttype'=>'upload');
$record = $generator->create_instance($params);
$assignment = new assignment_base($record->cmid);
$assignment = $generator->create_instance($params);
$this->setAdminUser();
$log = '';
$upgrader = new assign_upgrade_manager();
$this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log));
$this->assertTrue($upgrader->upgrade_assignment($assignment->id, $log));
$record = $DB->get_record('assign', array('course'=>$this->course->id));
$cm = get_coursemodule_from_instance('assign', $record->id);
@ -99,15 +97,13 @@ class mod_assign_upgradelib_testcase extends mod_assign_base_testcase {
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
$params = array('course'=>$this->course->id,
'assignmenttype'=>'uploadsingle');
$record = $generator->create_instance($params);
$assignment = new assignment_base($record->cmid);
$assignment = $generator->create_instance($params);
$this->setAdminUser();
$log = '';
$upgrader = new assign_upgrade_manager();
$this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log));
$this->assertTrue($upgrader->upgrade_assignment($assignment->id, $log));
$record = $DB->get_record('assign', array('course'=>$this->course->id));
$cm = get_coursemodule_from_instance('assign', $record->id);
@ -145,15 +141,13 @@ class mod_assign_upgradelib_testcase extends mod_assign_base_testcase {
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
$params = array('course'=>$this->course->id,
'assignmenttype'=>'online');
$record = $generator->create_instance($params);
$assignment = new assignment_base($record->cmid);
$assignment = $generator->create_instance($params);
$this->setAdminUser();
$log = '';
$upgrader = new assign_upgrade_manager();
$this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log));
$this->assertTrue($upgrader->upgrade_assignment($assignment->id, $log));
$record = $DB->get_record('assign', array('course'=>$this->course->id));
$cm = get_coursemodule_from_instance('assign', $record->id);
@ -191,15 +185,13 @@ class mod_assign_upgradelib_testcase extends mod_assign_base_testcase {
$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);
$assignment = $generator->create_instance($params);
$this->setAdminUser();
$log = '';
$upgrader = new assign_upgrade_manager();
$this->assertTrue($upgrader->upgrade_assignment($assignment->assignment->id, $log));
$this->assertTrue($upgrader->upgrade_assignment($assignment->id, $log));
$record = $DB->get_record('assign', array('course'=>$this->course->id));
$cm = get_coursemodule_from_instance('assign', $record->id);

View File

@ -299,6 +299,15 @@ class assign_upgrade_manager {
$sql = 'UPDATE {grade_items} SET itemmodule = ?, iteminstance = ? WHERE itemmodule = ? AND iteminstance = ?';
$DB->execute($sql, $params);
// Create a mapping record to map urls from the old to the new assignment.
$mapping = new stdClass();
$mapping->oldcmid = $oldcoursemodule->id;
$mapping->oldinstance = $oldassignment->id;
$mapping->newcmid = $newcoursemodule->id;
$mapping->newinstance = $newassignment->get_instance()->id;
$mapping->timecreated = time();
$DB->insert_record('assignment_upgrade', $mapping);
$gradesdone = true;
} catch (Exception $exception) {

View File

@ -1,49 +0,0 @@
var assignment = {};
function setNext(){
document.getElementById('submitform').mode.value = 'next';
document.getElementById('submitform').userid.value = assignment.nextid;
}
function saveNext(){
document.getElementById('submitform').mode.value = 'saveandnext';
document.getElementById('submitform').userid.value = assignment.nextid;
document.getElementById('submitform').saveuserid.value = assignment.userid;
document.getElementById('submitform').menuindex.value = document.getElementById('submitform').grade.selectedIndex;
}
function initNext(nextid, usserid) {
assignment.nextid = nextid;
assignment.userid = userid;
}
M.mod_assignment = {};
M.mod_assignment.init_tree = function(Y, expand_all, htmlid) {
Y.use('yui2-treeview', function(Y) {
var tree = new Y.YUI2.widget.TreeView(htmlid);
tree.subscribe("clickEvent", function(node, event) {
// we want normal clicking which redirects to url
return false;
});
if (expand_all) {
tree.expandAll();
}
tree.render();
});
};
M.mod_assignment.init_grade_change = function(Y) {
var gradenode = Y.one('#id_grade');
if (gradenode) {
var originalvalue = gradenode.get('value');
gradenode.on('change', function() {
if (gradenode.get('value') != originalvalue) {
alert(M.str.mod_assignment.changegradewarning);
}
});
}
};

View File

@ -109,4 +109,13 @@ class restore_assignment_activity_task extends restore_activity_task {
return $rules;
}
/**
* Expose the restore mode so we can skip automatic upgrade for MODE_IMPORT (e.g. duplicate).
*
* @return int
*/
public function get_mode() {
return $this->plan->get_mode();
}
}

View File

@ -98,6 +98,46 @@ class restore_assignment_activity_structure_step extends restore_activity_struct
$this->set_mapping(restore_gradingform_plugin::itemid_mapping('submission'), $oldid, $newitemid);
}
/**
* This function will attempt to upgrade the newly restored assignment to an instance of mod_assign if
* mod_assignment is currently disabled and mod_assign is enabled and mod_assign says it can upgrade this assignment.
*
* @return none
*/
private function upgrade_mod_assign() {
global $DB, $CFG;
// The current module must exist.
$pluginmanager = core_plugin_manager::instance();
$plugininfo = $pluginmanager->get_plugin_info('mod_assign');
// Check that the assignment module is installed.
if ($plugininfo && $plugininfo->is_installed_and_upgraded()) {
// Include the required mod assign upgrade code.
require_once($CFG->dirroot . '/mod/assign/upgradelib.php');
require_once($CFG->dirroot . '/mod/assign/locallib.php');
// Get the id and type of this assignment.
$newinstance = $this->task->get_activityid();
$record = $DB->get_record('assignment', array('id'=>$newinstance), 'assignmenttype', MUST_EXIST);
$type = $record->assignmenttype;
$subplugininfo = $pluginmanager->get_plugin_info('assignment_' . $type);
// See if it is possible to upgrade.
if (assign::can_upgrade_assignment($type, $subplugininfo->versiondb)) {
$assignment_upgrader = new assign_upgrade_manager();
$log = '';
$success = $assignment_upgrader->upgrade_assignment($newinstance, $log);
if (!$success) {
throw new restore_step_exception('mod_assign_upgrade_failed', $log);
}
}
}
}
protected function after_execute() {
// Add assignment related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_assignment', 'intro', null);
@ -106,6 +146,17 @@ class restore_assignment_activity_structure_step extends restore_activity_struct
$this->add_related_files('mod_assignment', 'response', 'assignment_submission');
}
/**
* Hook to execute assignment upgrade after restore.
*/
protected function after_restore() {
if ($this->get_task()->get_mode() != backup::MODE_IMPORT) {
// Moodle 2.2 assignment upgrade
$this->upgrade_mod_assign();
}
}
/**
* Determine if a sub-plugin is supported or not
*

View File

@ -29,7 +29,17 @@ defined('MOODLE_INTERNAL') || die();
class assignment extends base {
public function is_uninstall_allowed() {
/**
* Returns the information about plugin availability
*
* True means that the plugin is enabled. False means that the plugin is
* disabled. Null means that the information is not available, or the
* plugin does not support configurable availability or the availability
* can not be changed.
*
* @return null|bool
*/
public function is_enabled() {
return false;
}
}

View File

@ -60,5 +60,22 @@
<INDEX NAME="timemarked" UNIQUE="false" FIELDS="timemarked"/>
</INDEXES>
</TABLE>
<TABLE NAME="assignment_upgrade" COMMENT="Info about upgraded assignments">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="oldcmid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="oldinstance" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="newcmid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="newinstance" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="oldcmid" UNIQUE="false" FIELDS="oldcmid"/>
<INDEX NAME="oldinstance" UNIQUE="false" FIELDS="oldinstance"/>
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>

View File

@ -23,8 +23,9 @@
function xmldb_assignment_upgrade($oldversion) {
global $CFG, $DB, $OUTPUT;
$dbman = $DB->get_manager();
require_once(__DIR__.'/upgradelib.php');
$dbman = $DB->get_manager();
// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this
@ -81,6 +82,55 @@ function xmldb_assignment_upgrade($oldversion) {
// Moodle v2.6.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2013121900) {
// Define table assignment_upgrade to be created.
$table = new xmldb_table('assignment_upgrade');
// Adding fields to table assignment_upgrade.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('oldcmid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('oldinstance', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('newcmid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('newinstance', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
// Adding keys to table assignment_upgrade.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
// Adding indexes to table assignment_upgrade.
$table->add_index('oldcmid', XMLDB_INDEX_NOTUNIQUE, array('oldcmid'));
$table->add_index('oldinstance', XMLDB_INDEX_NOTUNIQUE, array('oldinstance'));
// Conditionally launch create table for assignment_upgrade.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
if ($module = $DB->get_record("modules", array("name" => "assignment"))) {
$DB->set_field("modules", "visible", "0", array("id" => $module->id)); // Hide module.
// Hide all course modules.
$sql = "UPDATE {course_modules}
SET visibleold = visible, visible = 0
WHERE module = ?";
$DB->execute($sql, array($module->id));
// Increment course.cacherev for courses where we just made something invisible.
// This will force cache rebuilding on the next request.
increment_revision_number('course', 'cacherev',
"id IN (SELECT DISTINCT course
FROM {course_modules}
WHERE visibleold = 1 AND module = ?)",
array($module->id));
}
$count = $DB->count_records('assignment');
if ($count) {
mod_assignment_pending_upgrades_notification($count);
}
// Assignment savepoint reached.
upgrade_mod_savepoint(true, 2013121900, 'assignment');
}
return true;
}

View File

@ -0,0 +1,54 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Assignment upgrade script.
*
* @package mod_assignment
* @copyright 2013 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Inform admins about assignments that still need upgrading.
*/
function mod_assignment_pending_upgrades_notification($count) {
$admins = get_admins();
if (empty($admins)) {
return;
}
$a = new stdClass;
$a->count = $count;
$a->docsurl = get_docs_url('Assignment_upgrade_tool');
foreach ($admins as $admin) {
$message = new stdClass();
$message->component = 'moodle';
$message->name = 'notices';
$message->userfrom = \core_user::get_noreply_user();
$message->userto = $admin;
$message->smallmessage = get_string('pendingupgrades_message_small', 'mod_assignment');
$message->subject = get_string('pendingupgrades_message_subject', 'mod_assignment');
$message->fullmessage = get_string('pendingupgrades_message_content', 'mod_assignment', $a);
$message->fullmessagehtml = get_string('pendingupgrades_message_content', 'mod_assignment', $a);
$message->fullmessageformat = FORMAT_PLAIN;
$message->notification = 1;
message_send($message);
}
}

View File

@ -1,44 +0,0 @@
<?php
require_once('../../config.php');
require_once('lib.php');
$id = optional_param('id', 0, PARAM_INT); // Course module ID
$a = optional_param('a', 0, PARAM_INT); // Assignment ID
$url = new moodle_url('/mod/assignment/delete.php');
if ($id) {
if (! $cm = get_coursemodule_from_id('assignment', $id)) {
print_error('invalidcoursemodule');
}
if (! $assignment = $DB->get_record('assignment', array('id'=>$cm->instance))) {
print_error('invalidid', 'assignment');
}
if (! $course = $DB->get_record('course', array('id'=>$assignment->course))) {
print_error('coursemisconf', 'assignment');
}
$url->param('id', $id);
} else {
if (!$assignment = $DB->get_record('assignment', array('id'=>$a))) {
print_error('invalidcoursemodule');
}
if (! $course = $DB->get_record('course', array('id'=>$assignment->course))) {
print_error('coursemisconf', 'assignment');
}
if (! $cm = get_coursemodule_from_instance('assignment', $assignment->id, $course->id)) {
print_error('invalidcoursemodule');
}
$url->param('a', $a);
}
$PAGE->set_url($url);
require_login($course, false, $cm);
/// Load up the required assignment code
require($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php');
$assignmentclass = 'assignment_'.$assignment->assignmenttype;
$assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm, $course);
$assignmentinstance->delete(); // delete something

View File

@ -1,58 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Redirect the user to the appropriate submission related page within /mod/assignment
*
* Based on the supplied parameters and the user's capabilities the user will be redirected
* to either their own submission, a particular student's submission or a summary of all submissions
*
* @package mod_assignment
* @category grade
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
$id = required_param('id', PARAM_INT); // Course module ID
$userid = optional_param('userid', 0, PARAM_INT); // Graded user ID (optional)
$PAGE->set_url('/mod/assignment/grade.php', array('id'=>$id));
if (! $cm = get_coursemodule_from_id('assignment', $id)) {
print_error('invalidcoursemodule');
}
if (! $assignment = $DB->get_record("assignment", array("id"=>$cm->instance))) {
print_error('invalidid', 'assignment');
}
if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
print_error('coursemisconf', 'assignment');
}
require_login($course, false, $cm);
if (has_capability('mod/assignment:grade', context_module::instance($cm->id))) {
if ($userid) {
redirect('submissions.php?id='.$cm->id.'&userid='.$userid.'&mode=single&filter=0&offset=0');
} else {
redirect('submissions.php?id='.$cm->id);
}
} else {
// user will view his own submission, parameter $userid is ignored
redirect('view.php?id='.$cm->id);
}

View File

@ -23,204 +23,25 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['activityoverview'] = 'You have assignments that need attention';
$string['allowdeleting'] = 'Allow deleting';
$string['allowdeleting_help'] = 'If enabled, students may delete uploaded files at any time before submitting for grading.';
$string['allowmaxfiles'] = 'Maximum number of uploaded files';
$string['allowmaxfiles_help'] = 'The maximum number of files which may be uploaded. As this figure is not displayed anywhere, it is suggested that it is mentioned in the assignment description.';
$string['allownotes'] = 'Allow notes';
$string['allownotes_help'] = 'If enabled, students may enter notes into a text area, as in an online text assignment.';
$string['allowresubmit'] = 'Allow resubmitting';
$string['allowresubmit_help'] = 'If enabled, students will be allowed to resubmit assignments after they have been graded (for them to be re-graded).';
$string['alreadygraded'] = 'Your assignment has already been graded and resubmission is not allowed.';
$string['assignment:addinstance'] = 'Add a new assignment';
$string['assignmentdetails'] = 'Assignment details';
$string['assignment:exportownsubmission'] = 'Export own submission';
$string['assignment:exportsubmission'] = 'Export submission';
$string['assignment:grade'] = 'Grade assignment';
$string['assignmentmail'] = '{$a->teacher} has posted some feedback on your
assignment submission for \'{$a->assignment}\'
You can see it appended to your assignment submission:
{$a->url}';
$string['assignmentmailhtml'] = '{$a->teacher} has posted some feedback on your
assignment submission for \'<i>{$a->assignment}</i>\'<br /><br />
You can see it appended to your <a href="{$a->url}">assignment submission</a>.';
$string['assignmentmailsmall'] = '{$a->teacher} has posted some feedback on your
assignment submission for \'{$a->assignment}\' You can see it appended to your submission';
$string['assignmentname'] = 'Assignment name';
$string['assignment:submit'] = 'Submit assignment';
$string['assignmentsubmission'] = 'Assignment submissions';
$string['assignmenttype'] = 'Assignment type';
$string['assignment:view'] = 'View assignment';
$string['availabledate'] = 'Available from';
$string['cannotdeletefiles'] = 'An error occurred and files could not be deleted';
$string['cannotviewassignment'] = 'You can not view this assignment';
$string['changegradewarning'] = 'This assignment has graded submissions and changing the grade will not automatically re-calculate existing submission grades. You must re-grade all existing submissions, if you wish to change the grade.';
$string['closedassignment'] = 'This assignment is closed, as the submission deadline has passed.';
$string['comment'] = 'Comment';
$string['commentinline'] = 'Comment inline';
$string['commentinline_help'] = 'If enabled, the submission text will be copied into the feedback comment field during grading, making it easier to comment inline (using a different colour, perhaps) or to edit the original text.';
$string['configitemstocount'] = 'Nature of items to be counted for student submissions in online assignments.';
$string['configmaxbytes'] = 'Default maximum assignment size for all assignments on the site (subject to course limits and other local settings)';
$string['configshowrecentsubmissions'] = 'Everyone can see notifications of submissions in recent activity reports.';
$string['confirmdeletefile'] = 'Are you absolutely sure you want to delete this file?<br /><strong>{$a}</strong>';
$string['coursemisconf'] = 'Course is misconfigured';
$string['currentgrade'] = 'Current grade in gradebook';
$string['deleteallsubmissions'] = 'Delete all submissions';
$string['deletefilefailed'] = 'Deleting of file failed.';
$string['description'] = 'Description';
$string['downloadall'] = 'Download all assignments as a zip';
$string['draft'] = 'Draft';
$string['due'] = 'Assignment due';
$string['duedate'] = 'Due date';
$string['duedateno'] = 'No due date';
$string['early'] = '{$a} early';
$string['editmysubmission'] = 'Edit my submission';
$string['editthesefiles'] = 'Edit these files';
$string['editthisfile'] = 'Update this file';
$string['addsubmission'] = 'Add submission';
$string['emailstudents'] = 'Email alerts to students';
$string['emailteachermail'] = '{$a->username} has updated their assignment submission
for \'{$a->assignment}\' at {$a->timeupdated}
It is available here:
{$a->url}';
$string['emailteachermailhtml'] = '{$a->username} has updated their assignment submission
for <i>\'{$a->assignment}\' at {$a->timeupdated}</i><br /><br />
It is <a href="{$a->url}">available on the web site</a>.';
$string['emailteachers'] = 'Email alerts to teachers';
$string['emailteachers_help'] = 'If enabled, teachers receive email notification whenever students add or update an assignment submission.
Only teachers who are able to grade the particular assignment are notified. So, for example, if the course uses separate groups, teachers restricted to particular groups won\'t receive notification about students in other groups.';
$string['emptysubmission'] = 'You have not submitted anything yet';
$string['enablenotification'] = 'Send notifications';
$string['enablenotification_help'] = 'If enabled, students will be notified when their assignment submissions are graded.';
$string['errornosubmissions'] = 'There are no submissions to download';
$string['existingfiledeleted'] = 'Existing file has been deleted: {$a}';
$string['failedupdatefeedback'] = 'Failed to update submission feedback for user {$a}';
$string['feedback'] = 'Feedback';
$string['feedbackfromteacher'] = 'Feedback from {$a}';
$string['feedbackupdated'] = 'Submissions feedback updated for {$a} people';
$string['finalize'] = 'Prevent submission updates';
$string['finalizeerror'] = 'An error occurred and that submission could not be finalised';
$string['futureaassignment'] = 'This assignment is not yet available.';
$string['graded'] = 'Graded';
$string['guestnosubmit'] = 'Sorry, guests are not allowed to submit an assignment. You have to log in/ register before you can submit your answer.';
$string['guestnoupload'] = 'Sorry, guests are not allowed to upload';
$string['helpoffline'] = '<p>This is useful when the assignment is performed outside of Moodle. It could be
something elsewhere on the web or face-to-face.</p><p>Students can see a description of the assignment,
but can\'t upload files or anything. Grading works normally, and students will get notifications of
their grades.</p>';
$string['helponline'] = '<p>This assignment type asks users to edit a text, using the normal
editing tools. Teachers can grade them online, and even add inline comments or changes.</p>
<p>(If you are familiar with older versions of Moodle, this Assignment
type does the same thing as the old Journal module used to do.)</p>';
$string['helpupload'] = '<p>This type of assignment allows each participant to upload one or more files in any format.
These might be a Word processor documents, images, a zipped web site, or anything you ask them to submit.</p>
<p>This type also allows you to upload multiple response files. Response files can be also uploaded before submission which
can be used to give each participant different file to work with.</p>
<p>Participants may also enter notes describing the submitted files, progress status or any other text information.</p>
<p>Submission of this type of assignment must be manually finalised by the participant. You can review the current status
at any time, unfinished assignments are marked as Draft. You can revert any ungraded assignment back to draft status.</p>';
$string['helpuploadsingle'] = '<p>This type of assignment allows each participant to upload a
single file, of any type.</p> <p>This might be a Word processor document, an image,
a zipped web site, or anything you ask them to submit.</p>';
$string['hideintro'] = 'Hide description before available date';
$string['hideintro_help'] = 'If enabled, the assignment description is hidden before the "Available from" date. Only the assignment name is displayed.';
$string['invalidassignment'] = 'Invalid assignment';
$string['invalidfileandsubmissionid'] = 'Missing file or submission ID';
$string['invalidid'] = 'Invalid assignment ID';
$string['invalidsubmissionid'] = 'Invalid submission ID';
$string['invalidtype'] = 'Invalid assignment type';
$string['invaliduserid'] = 'Invalid user ID';
$string['itemstocount'] = 'Count';
$string['lastgrade'] = 'Last grade';
$string['late'] = '{$a} late';
$string['maximumgrade'] = 'Maximum grade';
$string['maximumsize'] = 'Maximum size';
$string['maxpublishstate'] = 'Maximum visibility for blog entry before due date';
$string['assignmentneedsupgrade'] = 'The legacy "Assignment 2.2" activity has been disabled. Please request that your site administrator runs the assignment upgrade tool for all legacy assignments in this site.';
$string['messageprovider:assignment_updates'] = 'Assignment (2.2) notifications';
$string['modulename'] = 'Assignment (2.2)';
$string['modulename_help'] = 'Assignments enable the teacher to specify a task either on or offline which can then be graded.';
$string['modulenameplural'] = 'Assignments (2.2)';
$string['newsubmissions'] = 'Assignments submitted';
$string['noassignments'] = 'There are no assignments yet';
$string['noattempts'] = 'No attempts have been made on this assignment';
$string['noblogs'] = 'You have no blog entries to submit!';
$string['nofiles'] = 'No files were submitted';
$string['nofilesyet'] = 'No files submitted yet';
$string['nomoresubmissions'] = 'No further submissions are allowed.';
$string['notavailableyet'] = 'Sorry, this assignment is not yet available.<br />Assignment instructions will be displayed here on the date given below.';
$string['notes'] = 'Notes';
$string['notesempty'] = 'No entry';
$string['notesupdateerror'] = 'Error when updating notes';
$string['notgradedyet'] = 'Not graded yet';
$string['norequiregrading'] = 'There are no assignments that require grading';
$string['nosubmisson'] = 'No assignments have been submit';
$string['notsubmittedyet'] = 'Not submitted yet';
$string['onceassignmentsent'] = 'Once the assignment is sent for marking, you will no longer be able to delete or attach file(s). Do you want to continue?';
$string['operation'] = 'Operation';
$string['optionalsettings'] = 'Optional settings';
$string['overwritewarning'] = 'Warning: uploading again will REPLACE your current submission';
$string['assignmentdisabled'] = 'The legacy "Assignment 2.2" activity is disabled.';
$string['modulename'] = 'Assignment 2.2 (Disabled)';
$string['modulename_help'] = 'Legacy activity module that has been removed from Moodle.';
$string['modulenameplural'] = 'Assignments 2.2 (Disabled)';
$string['page-mod-assignment-x'] = 'Any assignment module page';
$string['page-mod-assignment-view'] = 'Assignment module main page';
$string['page-mod-assignment-submissions'] = 'Assignment module submission page';
$string['pagesize'] = 'Submissions shown per page';
$string['popupinnewwindow'] = 'Open in a popup window';
$string['pluginadministration'] = 'Assignment administration';
$string['pluginname'] = 'Assignment (2.2)';
$string['preventlate'] = 'Prevent late submissions';
$string['quickgrade'] = 'Allow quick grading';
$string['quickgrade_help'] = 'If enabled, multiple assignments can be graded on one page. Add grades and comments then click the "Save all my feedback" button to save all changes for that page.';
$string['requiregrading'] = 'Require grading';
$string['responsefiles'] = 'Response files';
$string['reviewed'] = 'Reviewed';
$string['saveallfeedback'] = 'Save all my feedback';
$string['selectblog'] = 'Select which blog entry you wish to submit';
$string['sendformarking'] = 'Send for marking';
$string['showrecentsubmissions'] = 'Show recent submissions';
$string['submission'] = 'Submission';
$string['submissiondraft'] = 'Submission draft';
$string['submissionfeedback'] = 'Submission feedback';
$string['submissions'] = 'Submissions';
$string['submissionsaved'] = 'Your changes have been saved';
$string['submissionsnotgraded'] = '{$a} submissions not graded';
$string['submitassignment'] = 'Submit your assignment using this form';
$string['submitedformarking'] = 'Assignment was already submitted for marking and can not be updated';
$string['submitformarking'] = 'Final submission for assignment marking';
$string['submitted'] = 'Submitted';
$string['submittedfiles'] = 'Submitted files';
$string['subplugintype_assignment'] = 'Assignment type';
$string['subplugintype_assignment_plural'] = 'Assignment types';
$string['trackdrafts'] = 'Enable "Send for marking" button';
$string['trackdrafts_help'] = 'The "Send for marking" button allows students to indicate to the teacher that they have finished working on an assignment. The teacher may choose to revert the assignment to draft status (if it requires further work, for example).';
$string['typeblog'] = 'Blog post';
$string['typeoffline'] = 'Offline activity';
$string['typeonline'] = 'Online text';
$string['typeupload'] = 'Advanced uploading of files';
$string['typeuploadsingle'] = 'Upload a single file';
$string['unfinalize'] = 'Revert to draft';
$string['unfinalize_help'] = 'Reverting to draft enables the student to make further updates to their assignment';
$string['unfinalizeerror'] = 'An error occurred and that submission could not be reverted to draft';
$string['pluginname'] = 'Assignment 2.2 (Disabled)';
$string['upgradenotification'] = 'This activity is based on an older assignment module.';
$string['uploadafile'] = 'Upload a file';
$string['uploadfiles'] = 'Upload files';
$string['uploadbadname'] = 'This filename contained strange characters and couldn\'t be uploaded';
$string['uploadedfiles'] = 'uploaded files';
$string['uploaderror'] = 'An error happened while saving the file on the server';
$string['uploadfailnoupdate'] = 'File was uploaded OK but could not update your submission!';
$string['uploadfiletoobig'] = 'Sorry, but that file is too big (limit is {$a} bytes)';
$string['uploadnofilefound'] = 'No file was found - are you sure you selected one to upload?';
$string['uploadnotregistered'] = '\'{$a}\' was uploaded OK but submission did not register!';
$string['uploadsuccess'] = 'Uploaded \'{$a}\' successfully';
$string['usermisconf'] = 'User is misconfigured';
$string['usernosubmit'] = 'Sorry, you are not allowed to submit an assignment.';
$string['viewassignmentupgradetool'] = 'View the assignment upgrade tool';
$string['viewfeedback'] = 'View assignment grades and feedback';
$string['viewmysubmission'] = 'View my submission';
$string['viewsubmissions'] = 'View {$a} submitted assignments';
$string['yoursubmission'] = 'Your submission';
$string['unsupportedsubplugin'] = 'The assignment type of \'{$a}\' is not currently supported. You may wait until the assignment type is made available, or delete the assignment.';
$string['pendingupgrades_message_small'] = 'This plugin has been disabled. All remaining assignments must be upgraded to the new assignment module using the assignment upgrade tool.';
$string['pendingupgrades_message_subject'] = 'Important information regarding Assignment 2.2';
$string['pendingupgrades_message_content'] = 'As part of the upgrade to Moodle 2.7, the legacy Assignment 2.2 activity has been disabled. Backups from the legacy Assignment 2.2 activity will seamlessly restore to the newer Assignment activity. All remaining instances of the legacy Assignment 2.2 activity must be upgraded using the assignment upgrade tool {$a->docsurl}. There are {$a->count} instances of the legacy Assignment 2.2 activity on this site that require upgrading. Users will not be able to access the content of these activities until they have been upgraded.';
$string['pluginadministration'] = 'Assignment 2.2 (Disabled) administration';

File diff suppressed because it is too large Load Diff

View File

@ -1,179 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
//
// this file contains all the functions that aren't needed by core moodle
// but start becoming required once we're actually inside the assignment module.
require_once($CFG->dirroot . '/mod/assignment/lib.php');
require_once($CFG->libdir . '/portfolio/caller.php');
/**
* @package mod-assignment
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assignment_portfolio_caller extends portfolio_module_caller_base {
/**
* the assignment subclass
*/
private $assignment;
/**
* the file to include when waking up to load the assignment subclass def
*/
private $assignmentfile;
/** @var int callback arg - the id of submission we export */
protected $submissionid;
/**
* callback arg for a single file export
*/
protected $fileid;
public static function expected_callbackargs() {
return array(
'id' => true,
'submissionid' => false,
'fileid' => false,
);
}
/**
* Load data needed for the portfolio export
*
* If the assignment type implements portfolio_load_data(), the processing is delegated
* to it. Otherwise, the caller must provide either fileid (to export single file) or
* submissionid (to export all data attached to the given submission) via callback arguments.
*/
public function load_data() {
global $DB, $CFG;
if (! $this->cm = get_coursemodule_from_id('assignment', $this->id)) {
throw new portfolio_caller_exception('invalidcoursemodule');
}
if (! $assignment = $DB->get_record("assignment", array("id"=>$this->cm->instance))) {
throw new portfolio_caller_exception('invalidid', 'assignment');
}
$this->assignmentfile = '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php';
require_once($CFG->dirroot . $this->assignmentfile);
$assignmentclass = "assignment_$assignment->assignmenttype";
$this->assignment = new $assignmentclass($this->cm->id, $assignment, $this->cm);
if (!$this->assignment->portfolio_exportable()) {
throw new portfolio_caller_exception('notexportable', 'portfolio', $this->get_return_url());
}
if (is_callable(array($this->assignment, 'portfolio_load_data'))) {
return $this->assignment->portfolio_load_data($this);
}
if (empty($this->fileid)) {
if (empty($this->submissionid)) {
throw new portfolio_caller_exception('invalidfileandsubmissionid', 'mod_assignment');
}
if (! $submission = $DB->get_record('assignment_submissions', array('assignment'=>$assignment->id, 'id'=>$this->submissionid))) {
throw new portfolio_caller_exception('invalidsubmissionid', 'mod_assignment');
}
$submissionid = $submission->id;
} else {
// once we know the file id, we do not need the submission
$submissionid = null;
}
$this->set_file_and_format_data($this->fileid, $this->assignment->context->id, 'mod_assignment', 'submission', $submissionid, 'timemodified', false);
}
public function prepare_package() {
global $CFG, $DB;
if (is_callable(array($this->assignment, 'portfolio_prepare_package'))) {
return $this->assignment->portfolio_prepare_package($this->exporter, $this->user);
}
if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
$leapwriter = $this->exporter->get('format')->leap2a_writer();
$files = array();
if ($this->singlefile) {
$files[] = $this->singlefile;
} elseif ($this->multifiles) {
$files = $this->multifiles;
} else {
throw new portfolio_caller_exception('invalidpreparepackagefile', 'portfolio', $this->get_return_url());
}
$baseid = 'assignment' . $this->assignment->assignment->assignmenttype . $this->assignment->assignment->id . 'submission';
$entryids = array();
foreach ($files as $file) {
$entry = new portfolio_format_leap2a_file($file->get_filename(), $file);
$entry->author = $this->user;
$leapwriter->add_entry($entry);
$this->exporter->copy_existing_file($file);
$entryids[] = $entry->id;
}
if (count($files) > 1) {
// if we have multiple files, they should be grouped together into a folder
$entry = new portfolio_format_leap2a_entry($baseid . 'group', $this->assignment->assignment->name, 'selection');
$leapwriter->add_entry($entry);
$leapwriter->make_selection($entry, $entryids, 'Folder');
}
return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true);
}
return $this->prepare_package_file();
}
public function get_sha1() {
global $CFG;
if (is_callable(array($this->assignment, 'portfolio_get_sha1'))) {
return $this->assignment->portfolio_get_sha1($this);
}
return $this->get_sha1_file();
}
public function expected_time() {
if (is_callable(array($this->assignment, 'portfolio_get_expected_time'))) {
return $this->assignment->portfolio_get_expected_time();
}
return $this->expected_time_file();
}
public function check_permissions() {
$context = context_module::instance($this->assignment->cm->id);
return has_capability('mod/assignment:exportownsubmission', $context);
}
public function __wakeup() {
global $CFG;
if (empty($CFG)) {
return true; // too early yet
}
require_once($CFG->dirroot . $this->assignmentfile);
$this->assignment = unserialize(serialize($this->assignment));
}
public static function display_name() {
return get_string('modulename', 'assignment');
}
public static function base_supported_formats() {
return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_LEAP2A);
}
}

View File

@ -1,146 +1,48 @@
<?php
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
/**
* This file contains the forms to create and edit an instance of this module
*
* @package mod_assignment
* @copyright 2007 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->dirroot.'/course/moodleform_mod.php');
/**
* Disabled assignment settings form.
*
* @package mod_assignment
* @copyright 2013 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_assignment_mod_form extends moodleform_mod {
protected $_assignmentinstance = null;
function definition() {
global $CFG, $DB, $PAGE, $COURSE;
$mform =& $this->_form;
// this hack is needed for different settings of each subtype
if (!empty($this->_instance)) {
if($ass = $DB->get_record('assignment', array('id'=>$this->_instance))) {
$type = $ass->assignmenttype;
} else {
print_error('invalidassignment', 'assignment');
}
} else {
$type = required_param('type', PARAM_ALPHA);
}
$mform->addElement('hidden', 'assignmenttype', $type);
$mform->setType('assignmenttype', PARAM_ALPHA);
$mform->setDefault('assignmenttype', $type);
$mform->addElement('hidden', 'type', $type);
$mform->setType('type', PARAM_ALPHA);
$mform->setDefault('type', $type);
$classfile = $CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php';
if (!file_exists($classfile)) {
throw new moodle_exception('unsupportedsubplugin', 'assignment', new moodle_url('/course/view.php', array('id' => $COURSE->id)), $type);
}
require_once($classfile);
$assignmentclass = 'assignment_'.$type;
$assignmentinstance = new $assignmentclass();
//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
// $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment'));
$mform->addElement('text', 'name', get_string('assignmentname', 'assignment'), array('size'=>'64'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEANHTML);
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$this->add_intro_editor(true, get_string('description', 'assignment'));
$mform->addElement('date_time_selector', 'timeavailable', get_string('availabledate', 'assignment'), array('optional'=>true));
$mform->setDefault('timeavailable', time());
$mform->addElement('date_time_selector', 'timedue', get_string('duedate', 'assignment'), array('optional'=>true));
$mform->setDefault('timedue', time()+7*24*3600);
$ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
if ($assignmentinstance->supports_lateness()) {
$mform->addElement('select', 'preventlate', get_string('preventlate', 'assignment'), $ynoptions);
$mform->setDefault('preventlate', 0);
}
// hack to support pluggable assignment type titles
if (get_string_manager()->string_exists('type'.$type, 'assignment')) {
$typetitle = get_string('type'.$type, 'assignment');
} else {
$typetitle = get_string('type'.$type, 'assignment_'.$type);
}
$this->standard_grading_coursemodule_elements();
$mform->addElement('header', 'typedesc', $typetitle);
$assignmentinstance->setup_elements($mform);
$this->standard_coursemodule_elements();
$this->add_action_buttons();
// Add warning popup/noscript tag, if grades are changed by user.
if ($mform->elementExists('grade') && !empty($this->_instance) && $DB->record_exists_select('assignment_submissions', 'assignment = ? AND grade <> -1', array($this->_instance))) {
$module = array(
'name' => 'mod_assignment',
'fullpath' => '/mod/assignment/assignment.js',
'requires' => array('node', 'event'),
'strings' => array(array('changegradewarning', 'mod_assignment'))
);
$PAGE->requires->js_init_call('M.mod_assignment.init_grade_change', null, false, $module);
// Add noscript tag in case
$noscriptwarning = $mform->createElement('static', 'warning', null, html_writer::tag('noscript', get_string('changegradewarning', 'mod_assignment')));
$mform->insertElementBefore($noscriptwarning, 'grade');
}
}
// Needed by plugin assignment types if they include a filemanager element in the settings form
function has_instance() {
return ($this->_instance != NULL);
}
// Needed by plugin assignment types if they include a filemanager element in the settings form
function get_context() {
return $this->context;
}
protected function get_assignment_instance() {
global $CFG, $DB;
if ($this->_assignmentinstance) {
return $this->_assignmentinstance;
}
if (!empty($this->_instance)) {
if($ass = $DB->get_record('assignment', array('id'=>$this->_instance))) {
$type = $ass->assignmenttype;
} else {
print_error('invalidassignment', 'assignment');
}
} else {
$type = required_param('type', PARAM_ALPHA);
}
require_once($CFG->dirroot.'/mod/assignment/type/'.$type.'/assignment.class.php');
$assignmentclass = 'assignment_'.$type;
$this->assignmentinstance = new $assignmentclass();
return $this->assignmentinstance;
/**
* Called to define this moodle form
*
* @return void
*/
public function definition() {
print_error('assignmentdisabled', 'assignment');
}
function data_preprocessing(&$default_values) {
// Allow plugin assignment types to preprocess form data (needed if they include any filemanager elements)
$this->get_assignment_instance()->form_data_preprocessing($default_values, $this);
}
function validation($data, $files) {
// Allow plugin assignment types to do any extra validation after the form has been submitted
$errors = parent::validation($data, $files);
$errors = array_merge($errors, $this->get_assignment_instance()->form_validation($data, $files));
return $errors;
}
}

View File

@ -1,130 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* A custom renderer class that extends the plugin_renderer_base and
* is used by the assignment module.
*
* @package mod-assignment
* @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
**/
class mod_assignment_renderer extends plugin_renderer_base {
/**
* @return string
*/
public function assignment_files($context, $itemid, $filearea='submission') {
return $this->render(new assignment_files($context, $itemid, $filearea));
}
public function render_assignment_files(assignment_files $tree) {
$module = array('name'=>'mod_assignment_files', 'fullpath'=>'/mod/assignment/assignment.js', 'requires'=>array('yui2-treeview'));
$this->htmlid = 'assignment_files_tree_'.uniqid();
$this->page->requires->js_init_call('M.mod_assignment.init_tree', array(true, $this->htmlid));
$html = '<div id="'.$this->htmlid.'">';
$html .= $this->htmllize_tree($tree, $tree->dir);
$html .= '</div>';
if ($tree->portfolioform) {
$html .= $tree->portfolioform;
}
return $html;
}
/**
* Internal function - creates htmls structure suitable for YUI tree.
*/
protected function htmllize_tree($tree, $dir) {
global $CFG;
$yuiconfig = array();
$yuiconfig['type'] = 'html';
if (empty($dir['subdirs']) and empty($dir['files'])) {
return '';
}
$result = '<ul>';
foreach ($dir['subdirs'] as $subdir) {
$image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
}
foreach ($dir['files'] as $file) {
$filename = $file->get_filename();
if ($CFG->enableplagiarism) {
require_once($CFG->libdir.'/plagiarismlib.php');
$plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
} else {
$plagiarsmlinks = '';
}
$image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
}
$result .= '</ul>';
return $result;
}
}
class assignment_files implements renderable {
public $context;
public $dir;
public $portfolioform;
public $cm;
public $course;
public function __construct($context, $itemid, $filearea='submission') {
global $USER, $CFG;
$this->context = $context;
list($context, $course, $cm) = get_context_info_array($context->id);
$this->cm = $cm;
$this->course = $course;
$fs = get_file_storage();
$this->dir = $fs->get_area_tree($this->context->id, 'mod_assignment', $filearea, $itemid);
if (!empty($CFG->enableportfolios)) {
require_once($CFG->libdir . '/portfoliolib.php');
$files = $fs->get_area_files($this->context->id, 'mod_assignment', $filearea, $itemid, "timemodified", false);
if (count($files) >= 1 && has_capability('mod/assignment:exportownsubmission', $this->context)) {
$button = new portfolio_add_button();
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'submissionid' => $itemid), 'mod_assignment');
$button->reset_formats();
$this->portfolioform = $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
}
}
$this->preprocess($this->dir, $filearea);
}
public function preprocess($dir, $filearea) {
global $CFG;
foreach ($dir['subdirs'] as $subdir) {
$this->preprocess($subdir, $filearea);
}
foreach ($dir['files'] as $file) {
$file->portfoliobutton = '';
if (!empty($CFG->enableportfolios)) {
$button = new portfolio_add_button();
if (has_capability('mod/assignment:exportownsubmission', $this->context)) {
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), 'mod_assignment');
$button->set_format_by_file($file);
$file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
}
}
$url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$this->context->id.'/mod_assignment/'.$filearea.'/'.$file->get_itemid(). $file->get_filepath().$file->get_filename(), true);
$filename = $file->get_filename();
$file->fileurl = html_writer::link($url, $filename);
}
}
}

View File

@ -1,24 +0,0 @@
<?php
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
require_once($CFG->dirroot.'/mod/assignment/lib.php');
if (isset($CFG->maxbytes)) {
$maxbytes = 0;
if (isset($CFG->assignment_maxbytes)) {
$maxbytes = $CFG->assignment_maxbytes;
}
$settings->add(new admin_setting_configselect('assignment_maxbytes', get_string('maximumsize', 'assignment'),
get_string('configmaxbytes', 'assignment'), 1048576, get_max_upload_sizes($CFG->maxbytes, 0, 0, $maxbytes)));
}
$options = array(ASSIGNMENT_COUNT_WORDS => trim(get_string('numwords', '', '?')),
ASSIGNMENT_COUNT_LETTERS => trim(get_string('numletters', '', '?')));
$settings->add(new admin_setting_configselect('assignment_itemstocount', get_string('itemstocount', 'assignment'),
get_string('configitemstocount', 'assignment'), ASSIGNMENT_COUNT_WORDS, $options));
$settings->add(new admin_setting_configcheckbox('assignment_showrecentsubmissions', get_string('showrecentsubmissions', 'assignment'),
get_string('configshowrecentsubmissions', 'assignment'), 1));
}

View File

@ -1,47 +0,0 @@
/** General Styles **/
.path-mod-assignment .userpicture,
.path-mod-assignment .picture.user,
.path-mod-assignment .picture.teacher {width:35px;height: 35px;vertical-align:top;}
.path-mod-assignment .feedback .files,
.path-mod-assignment .feedback .grade,
.path-mod-assignment .feedback .outcome,
.path-mod-assignment .feedback .finalgrade {float: right;}
.path-mod-assignment .feedback .disabledfeedback {width: 500px;height: 250px;}
.path-mod-assignment .feedback .from {float: left;}
.path-mod-assignment .files img {margin-right: 4px;}
.path-mod-assignment .files a {white-space:nowrap;}
.path-mod-assignment .late {color: red;}
/** Styles for submissions.php **/
#page-mod-assignment-submissions fieldset.felement {margin-left: 16%;}
#page-mod-assignment-submissions form#options div {text-align:right;margin-left:auto;margin-right:20px;}
#page-mod-assignment-submissions .header .commands {display: inline;}
#page-mod-assignment-submissions .picture {width: 35px;}
#page-mod-assignment-submissions .fullname,
#page-mod-assignment-submissions .timemodified,
#page-mod-assignment-submissions .timemarked {text-align: left;}
#page-mod-assignment-submissions .submissions .grade,
#page-mod-assignment-submissions .submissions .outcome,
#page-mod-assignment-submissions .submissions .finalgrade {text-align: right;}
#page-mod-assignment-submissions .submissions .header.noheader {display:none;}
#page-mod-assignment-submissions .qgprefs #optiontable {text-align:right;margin-left:auto;}
/** Styles for view.php **/
#page-mod-assignment-view .feedback {margin:10px auto;}
#page-mod-assignment-view .feedback .grade {text-align: right;}
#page-mod-assignment-view #online .singlebutton {text-align: center;}
#page-mod-assignment-view #dates .c0 {text-align:right;font-weight:bold;}
#page-mod-assignment-submissions .mform.optionspref .fitem .fitemtitle {width:50%;}
#page-mod-assignment-submissions .mform.optionspref .fitem .felement {width: 30%; margin-left: 51%;}
#page-mod-assignment-submissions .optionspref {width: 50%;}
#page-mod-assignment-submissions .fastgbutton {text-align: center;}
#page-mod-assignment-submissions.dir-rtl .fullname,
#page-mod-assignment-submissions.dir-rtl .timemodified,
#page-mod-assignment-submissions.dir-rtl .timemarked {text-align:right;}
#page-mod-assignment-submissions.dir-rtl .mform.optionspref .fitem .fitemtitle {text-align:left;}
#page-mod-assignment-type-uploadsingle-upload.dir-rtl .mdl-left {text-align:right;}
.mod-assignment-download-link {text-align:right;}

View File

@ -1,58 +0,0 @@
<?php
require_once("../../config.php");
require_once("lib.php");
require_once($CFG->libdir.'/plagiarismlib.php');
$id = optional_param('id', 0, PARAM_INT); // Course module ID
$a = optional_param('a', 0, PARAM_INT); // Assignment ID
$mode = optional_param('mode', 'all', PARAM_ALPHA); // What mode are we in?
$download = optional_param('download' , 'none', PARAM_ALPHA); //ZIP download asked for?
$url = new moodle_url('/mod/assignment/submissions.php');
if ($id) {
if (! $cm = get_coursemodule_from_id('assignment', $id)) {
print_error('invalidcoursemodule');
}
if (! $assignment = $DB->get_record("assignment", array("id"=>$cm->instance))) {
print_error('invalidid', 'assignment');
}
if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
print_error('coursemisconf', 'assignment');
}
$url->param('id', $id);
} else {
if (!$assignment = $DB->get_record("assignment", array("id"=>$a))) {
print_error('invalidcoursemodule');
}
if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
print_error('coursemisconf', 'assignment');
}
if (! $cm = get_coursemodule_from_instance("assignment", $assignment->id, $course->id)) {
print_error('invalidcoursemodule');
}
$url->param('a', $a);
}
if ($mode !== 'all') {
$url->param('mode', $mode);
}
$PAGE->set_url($url);
require_login($course, false, $cm);
require_capability('mod/assignment:grade', context_module::instance($cm->id));
$PAGE->requires->js('/mod/assignment/assignment.js');
/// Load up the required assignment code
require($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php');
$assignmentclass = 'assignment_'.$assignment->assignmenttype;
$assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm, $course);
if($download == "zip") {
$assignmentinstance->download_submissions();
} else {
$assignmentinstance->submissions($mode); // Display or process the submissions
}

View File

@ -1,77 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* PHPUnit data generator tests
*
* @package mod_assignment
* @category phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* PHPUnit data generator testcase
*
* @package mod_assignment
* @category phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_assignment_generator_testcase extends advanced_testcase {
public function test_generator() {
global $DB;
$this->resetAfterTest(true);
$this->assertEquals(0, $DB->count_records('assignment'));
$course = $this->getDataGenerator()->create_course();
/** @var mod_assignment_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
$this->assertInstanceOf('mod_assignment_generator', $generator);
$this->assertEquals('assignment', $generator->get_modulename());
$generator->create_instance(array('course'=>$course->id, 'grade'=>0));
$generator->create_instance(array('course'=>$course->id, 'grade'=>0));
$assignment = $generator->create_instance(array('course'=>$course->id, 'grade'=>100));
$this->assertEquals(3, $DB->count_records('assignment'));
$cm = get_coursemodule_from_instance('assignment', $assignment->id);
$this->assertEquals($assignment->id, $cm->instance);
$this->assertEquals('assignment', $cm->modname);
$this->assertEquals($course->id, $cm->course);
$context = context_module::instance($cm->id);
$this->assertEquals($assignment->cmid, $context->instanceid);
// test gradebook integration using low level DB access - DO NOT USE IN PLUGIN CODE!
$gitem = $DB->get_record('grade_items', array('courseid'=>$course->id, 'itemtype'=>'mod', 'itemmodule'=>'assignment', 'iteminstance'=>$assignment->id));
$this->assertNotEmpty($gitem);
$this->assertEquals(100, $gitem->grademax);
$this->assertEquals(0, $gitem->grademin);
$this->assertEquals(GRADE_TYPE_VALUE, $gitem->gradetype);
// test eventslib integration
$this->setAdminUser();
$generator->create_instance(array('course'=>$course->id, 'timedue'=>(time()+60*60+24)));
$this->setUser(null);
}
}

View File

@ -1,106 +0,0 @@
<?php
/**
* Extend the base assignment class for offline assignments
*
*/
class assignment_offline extends assignment_base {
function assignment_offline($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
parent::assignment_base($cmid, $assignment, $cm, $course);
$this->type = 'offline';
}
function supports_lateness() {
return false;
}
function display_lateness($timesubmitted) {
return '';
}
function print_student_answer($studentid){
return '';//does nothing!
}
function prepare_new_submission($userid, $teachermodified=false) {
$submission = new stdClass();
$submission->assignment = $this->assignment->id;
$submission->userid = $userid;
$submission->timecreated = time(); // needed for offline assignments
$submission->timemodified = $submission->timecreated;
$submission->numfiles = 0;
$submission->data1 = '';
$submission->data2 = '';
$submission->grade = -1;
$submission->submissioncomment = '';
$submission->format = 0;
$submission->teacher = 0;
$submission->timemarked = 0;
$submission->mailed = 0;
return $submission;
}
// needed for the timemodified override
function process_feedback($formdata=null) {
global $CFG, $USER, $DB;
require_once($CFG->libdir.'/gradelib.php');
if (!$feedback = data_submitted() or !confirm_sesskey()) { // No incoming data?
return false;
}
///For save and next, we need to know the userid to save, and the userid to go
///We use a new hidden field in the form, and set it to -1. If it's set, we use this
///as the userid to store
if ((int)$feedback->saveuserid !== -1){
$feedback->userid = $feedback->saveuserid;
}
if (!empty($feedback->cancel)) { // User hit cancel button
return false;
}
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $feedback->userid);
// store outcomes if needed
$this->process_outcomes($feedback->userid);
$submission = $this->get_submission($feedback->userid, true); // Get or make one
if (!$grading_info->items[0]->grades[$feedback->userid]->locked and
!$grading_info->items[0]->grades[$feedback->userid]->overridden) {
$submission->grade = $feedback->xgrade;
$submission->submissioncomment = $feedback->submissioncomment_editor['text'];
$submission->teacher = $USER->id;
$mailinfo = get_user_preferences('assignment_mailinfo', 0);
if (!$mailinfo) {
$submission->mailed = 1; // treat as already mailed
} else {
$submission->mailed = 0; // Make sure mail goes out (again, even)
}
$submission->timemarked = time();
unset($submission->data1); // Don't need to update this.
unset($submission->data2); // Don't need to update this.
if (empty($submission->timemodified)) { // eg for offline assignments
$submission->timemodified = time();
}
$DB->update_record('assignment_submissions', $submission);
// trigger grade event
$this->update_grade($submission);
add_to_log($this->course->id, 'assignment', 'update grades',
'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
}
return $submission;
}
}

View File

@ -1,145 +0,0 @@
<?php
//===================================================
// all.php
//
// Displays a complete list of online assignments
// for the course. Rather like what happened in
// the old Journal activity.
// Howard Miller 2008
// See MDL-14045
//===================================================
require_once("../../../../config.php");
require_once("{$CFG->dirroot}/mod/assignment/lib.php");
require_once($CFG->libdir.'/gradelib.php');
require_once('assignment.class.php');
// get parameter
$id = required_param('id', PARAM_INT); // course
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourse');
}
$PAGE->set_url('/mod/assignment/type/online/all.php', array('id'=>$id));
require_course_login($course);
// check for view capability at course level
$context = context_course::instance($course->id);
require_capability('mod/assignment:view',$context);
// various strings
$str = new stdClass;
$str->assignments = get_string("modulenameplural", "assignment");
$str->duedate = get_string('duedate','assignment');
$str->duedateno = get_string('duedateno','assignment');
$str->editmysubmission = get_string('editmysubmission','assignment');
$str->emptysubmission = get_string('emptysubmission','assignment');
$str->noassignments = get_string('noassignments','assignment');
$str->onlinetext = get_string('typeonline','assignment');
$str->submitted = get_string('submitted','assignment');
$PAGE->navbar->add($str->assignments, new moodle_url('/mod/assignment/index.php', array('id'=>$id)));
$PAGE->navbar->add($str->onlinetext);
// get all the assignments in the course
$assignments = get_all_instances_in_course('assignment',$course, $USER->id );
// array to hold display data
$views = array();
// loop over assignments finding online ones
foreach( $assignments as $assignment ) {
// only interested in online assignments
if ($assignment->assignmenttype != 'online') {
continue;
}
// check we are allowed to view this
$context = context_module::instance($assignment->coursemodule);
if (!has_capability('mod/assignment:view',$context)) {
continue;
}
// create instance of assignment class to get
// submitted assignments
$onlineinstance = new assignment_online( $assignment->coursemodule );
$submitted = $onlineinstance->submittedlink(true);
$submission = $onlineinstance->get_submission();
// submission (if there is one)
if (empty($submission)) {
$submissiontext = $str->emptysubmission;
if (!empty($assignment->timedue)) {
$submissiondate = "{$str->duedate} ".userdate( $assignment->timedue );
} else {
$submissiondate = $str->duedateno;
}
} else {
$submissiontext = format_text( $submission->data1, $submission->data2 );
$submissiondate = "{$str->submitted} ".userdate( $submission->timemodified );
}
// edit link
$editlink = "<a href=\"{$CFG->wwwroot}/mod/assignment/view.php?".
"id={$assignment->coursemodule}&amp;edit=1\">{$str->editmysubmission}</a>";
// format options for description
$formatoptions = new stdClass;
$formatoptions->noclean = true;
// object to hold display data for assignment
$view = new stdClass;
// start to build view object
$view->section = get_section_name($course, $assignment->section);
$view->name = $assignment->name;
$view->submitted = $submitted;
$view->description = format_module_intro('assignment', $assignment, $assignment->coursemodule);
$view->editlink = $editlink;
$view->submissiontext = $submissiontext;
$view->submissiondate = $submissiondate;
$view->cm = $assignment->coursemodule;
$views[] = $view;
}
//===================
// DISPLAY
//===================
$PAGE->set_title($str->assignments);
echo $OUTPUT->header();
foreach ($views as $view) {
echo $OUTPUT->container_start('clearfix generalbox assignment');
// info bit
echo $OUTPUT->heading("$view->section - $view->name", 3, 'mdl-left');
if (!empty($view->submitted)) {
echo '<div class="reportlink">'.$view->submitted.'</div>';
}
// description part
echo '<div class="description">'.$view->description.'</div>';
//submission part
echo $OUTPUT->container_start('generalbox submission');
echo '<div class="submissiondate">'.$view->submissiondate.'</div>';
echo "<p class='no-overflow'>$view->submissiontext</p>\n";
echo "<p>$view->editlink</p>\n";
echo $OUTPUT->container_end();
// feedback part
$onlineinstance = new assignment_online( $view->cm );
$onlineinstance->view_feedback();
echo $OUTPUT->container_end();
}
echo $OUTPUT->footer();

View File

@ -1,502 +0,0 @@
<?php
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->libdir . '/portfoliolib.php');
require_once($CFG->dirroot . '/mod/assignment/lib.php');
require_once($CFG->libdir . '/filelib.php');
/**
* Extend the base assignment class for assignments where you upload a single file
*
*/
class assignment_online extends assignment_base {
var $filearea = 'submission';
function assignment_online($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
parent::assignment_base($cmid, $assignment, $cm, $course);
$this->type = 'online';
}
function view() {
global $OUTPUT, $CFG, $USER, $PAGE;
$edit = optional_param('edit', 0, PARAM_BOOL);
$saved = optional_param('saved', 0, PARAM_BOOL);
$context = context_module::instance($this->cm->id);
require_capability('mod/assignment:view', $context);
$submission = $this->get_submission($USER->id, false);
//Guest can not submit nor edit an assignment (bug: 4604)
if (!is_enrolled($this->context, $USER, 'mod/assignment:submit')) {
$editable = false;
} else {
$editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked);
}
$editmode = ($editable and $edit);
if ($editmode) {
// Loading the constants FILE_INTERNAL and FILE_EXTERNAL.
require_once($CFG->dirroot . '/repository/lib.php');
// prepare form and process submitted data
$editoroptions = array(
'noclean' => false,
'maxfiles' => EDITOR_UNLIMITED_FILES,
'maxbytes' => $this->course->maxbytes,
'context' => $this->context,
'return_types' => FILE_INTERNAL | FILE_EXTERNAL
);
$data = new stdClass();
$data->id = $this->cm->id;
$data->edit = 1;
if ($submission) {
$data->sid = $submission->id;
$data->text = $submission->data1;
$data->textformat = $submission->data2;
} else {
$data->sid = NULL;
$data->text = '';
$data->textformat = NULL;
}
$data = file_prepare_standard_editor($data, 'text', $editoroptions, $this->context, 'mod_assignment', $this->filearea, $data->sid);
$mform = new mod_assignment_online_edit_form(null, array($data, $editoroptions));
if ($mform->is_cancelled()) {
redirect($PAGE->url);
}
if ($data = $mform->get_data()) {
$submission = $this->get_submission($USER->id, true); //create the submission if needed & its id
$data = file_postupdate_standard_editor($data, 'text', $editoroptions, $this->context, 'mod_assignment', $this->filearea, $submission->id);
$submission = $this->update_submission($data);
//TODO fix log actions - needs db upgrade
add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
$this->email_teachers($submission);
//redirect to get updated submission date and word count
redirect(new moodle_url($PAGE->url, array('saved'=>1)));
}
}
add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id);
/// print header, etc. and display form if needed
if ($editmode) {
$this->view_header(get_string('editmysubmission', 'assignment'));
} else {
$this->view_header();
}
$this->view_intro();
$this->view_dates();
if ($saved) {
echo $OUTPUT->notification(get_string('submissionsaved', 'assignment'), 'notifysuccess');
}
if (is_enrolled($this->context, $USER)) {
if ($editmode) {
echo $OUTPUT->box_start('generalbox', 'onlineenter');
$mform->display();
} else {
echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter', 'online');
if ($submission && has_capability('mod/assignment:exportownsubmission', $this->context)) {
echo plagiarism_get_links(array('userid' => $USER->id,
'content' => trim(format_text($submission->data1, $submission->data2, array('context' => $context))),
'cmid' => $this->cm->id,
'course' => $this->course,
'assignment' => $this->assignment));
$text = file_rewrite_pluginfile_urls($submission->data1, 'pluginfile.php', $this->context->id, 'mod_assignment', $this->filearea, $submission->id);
echo format_text($text, $submission->data2, array('overflowdiv'=>true));
if ($CFG->enableportfolios) {
require_once($CFG->libdir . '/portfoliolib.php');
$button = new portfolio_add_button();
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), 'mod_assignment');
$fs = get_file_storage();
if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', $this->filearea, $submission->id, "timemodified", false)) {
$button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
} else {
$button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
}
$button->render();
}
} else if ($this->isopen()){ //fix for #4206
echo '<div style="text-align:center">'.get_string('emptysubmission', 'assignment').'</div>';
}
}
echo $OUTPUT->box_end();
if (!$editmode && $editable) {
if (!empty($submission)) {
$submitbutton = "editmysubmission";
} else {
$submitbutton = "addsubmission";
}
echo "<div style='text-align:center'>";
echo $OUTPUT->single_button(new moodle_url('view.php', array('id'=>$this->cm->id, 'edit'=>'1')), get_string($submitbutton, 'assignment'));
echo "</div>";
}
}
$this->view_feedback();
$this->view_footer();
}
/*
* Display the assignment dates
*/
function view_dates() {
global $USER, $CFG, $OUTPUT;
if (!$this->assignment->timeavailable && !$this->assignment->timedue) {
return;
}
echo $OUTPUT->box_start('generalbox boxaligncenter', 'dates');
echo '<table>';
if ($this->assignment->timeavailable) {
echo '<tr><td class="c0">'.get_string('availabledate','assignment').':</td>';
echo ' <td class="c1">'.userdate($this->assignment->timeavailable).'</td></tr>';
}
if ($this->assignment->timedue) {
echo '<tr><td class="c0">'.get_string('duedate','assignment').':</td>';
echo ' <td class="c1">'.userdate($this->assignment->timedue).'</td></tr>';
}
$submission = $this->get_submission($USER->id);
if ($submission) {
echo '<tr><td class="c0">'.get_string('lastedited').':</td>';
echo ' <td class="c1">'.userdate($submission->timemodified);
/// Decide what to count
if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_WORDS) {
echo ' ('.get_string('numwords', '', count_words(format_text($submission->data1, $submission->data2))).')</td></tr>';
} else if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_LETTERS) {
echo ' ('.get_string('numletters', '', count_letters(format_text($submission->data1, $submission->data2))).')</td></tr>';
}
}
echo '</table>';
echo $OUTPUT->box_end();
}
function update_submission($data) {
global $CFG, $USER, $DB;
$submission = $this->get_submission($USER->id, true);
$update = new stdClass();
$update->id = $submission->id;
$update->data1 = $data->text;
$update->data2 = $data->textformat;
$update->timemodified = time();
$DB->update_record('assignment_submissions', $update);
$submission = $this->get_submission($USER->id);
$this->update_grade($submission);
$fs = get_file_storage();
$files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id);
// Let Moodle know that an assessable content was uploaded (eg for plagiarism detection)
$params = array(
'context' => $this->context,
'objectid' => $submission->id,
'other' => array(
'content' => trim(format_text($update->data1, $update->data2)),
'pathnamehashes' => array_keys($files),
'triggeredfrom' => 'update_submission'
)
);
$event = \assignment_online\event\assessable_uploaded::create($params);
$event->trigger();
return $submission;
}
function print_student_answer($userid, $return=false){
global $OUTPUT;
if (!$submission = $this->get_submission($userid)) {
return '';
}
$link = new moodle_url("/mod/assignment/type/online/file.php?id={$this->cm->id}&userid={$submission->userid}");
$action = new popup_action('click', $link, 'file'.$userid, array('height' => 450, 'width' => 580));
$popup = $OUTPUT->action_link($link, shorten_text(trim(strip_tags(format_text($submission->data1,$submission->data2))), 15), $action, array('title'=>get_string('submission', 'assignment')));
$output = '<div class="files">'.
$OUTPUT->pix_icon(file_extension_icon('.htm'), 'html', 'moodle', array('class' => 'icon')).
$popup .
plagiarism_get_links(array('userid' => $userid,
'content' => trim(format_text($submission->data1, $submission->data2)),
'cmid' => $this->cm->id,
'course' => $this->course,
'assignment' => $this->assignment)) .
'</div>';
return $output;
}
function print_user_files($userid=0, $return=false) {
global $OUTPUT, $CFG, $USER;
if (!$userid) {
if (!isloggedin()) {
return '';
}
$userid = $USER->id;
}
if (!$submission = $this->get_submission($userid)) {
return '';
}
$link = new moodle_url("/mod/assignment/type/online/file.php?id={$this->cm->id}&userid={$submission->userid}");
$action = new popup_action('click', $link, 'file'.$userid, array('height' => 450, 'width' => 580));
$popup = $OUTPUT->action_link($link, get_string('popupinnewwindow','assignment'), $action, array('title'=>get_string('submission', 'assignment')));
$output = '<div class="files">'.
$OUTPUT->pix_icon(file_extension_icon('.htm'), 'html', 'moodle', array('height' => 16, 'width' => 16)).
$popup .
'</div>';
$wordcount = '<p id="wordcount">'. $popup . '&nbsp;';
/// Decide what to count
if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_WORDS) {
$wordcount .= '('.get_string('numwords', '', count_words(format_text($submission->data1, $submission->data2))).')';
} else if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_LETTERS) {
$wordcount .= '('.get_string('numletters', '', count_letters(format_text($submission->data1, $submission->data2))).')';
}
$wordcount .= '</p>';
$text = file_rewrite_pluginfile_urls($submission->data1, 'pluginfile.php', $this->context->id, 'mod_assignment', $this->filearea, $submission->id);
return $wordcount . format_text($text, $submission->data2, array('overflowdiv'=>true));
}
function preprocess_submission(&$submission) {
if ($this->assignment->var1 && empty($submission->submissioncomment)) { // comment inline
// Convert to html, clean & copy student data to teacher
$submission->submissioncomment = format_text($submission->data1, $submission->data2);
$submission->format = FORMAT_HTML;
}
}
function setup_elements(&$mform) {
global $CFG, $COURSE;
$ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
$mform->addElement('select', 'resubmit', get_string('allowresubmit', 'assignment'), $ynoptions);
$mform->addHelpButton('resubmit', 'allowresubmit', 'assignment');
$mform->setDefault('resubmit', 0);
$mform->addElement('select', 'emailteachers', get_string('emailteachers', 'assignment'), $ynoptions);
$mform->addHelpButton('emailteachers', 'emailteachers', 'assignment');
$mform->setDefault('emailteachers', 0);
$mform->addElement('select', 'var1', get_string('commentinline', 'assignment'), $ynoptions);
$mform->addHelpButton('var1', 'commentinline', 'assignment');
$mform->setDefault('var1', 0);
$coursecontext = context_course::instance($COURSE->id);
plagiarism_get_form_elements_module($mform, $coursecontext, 'mod_assignment');
}
function portfolio_exportable() {
return true;
}
function portfolio_load_data($caller) {
$submission = $this->get_submission();
$fs = get_file_storage();
if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', $this->filearea, $submission->id, "timemodified", false)) {
$caller->set('multifiles', $files);
}
}
function portfolio_get_sha1($caller) {
$submission = $this->get_submission();
$textsha1 = sha1(format_text($submission->data1, $submission->data2));
$filesha1 = '';
try {
$filesha1 = $caller->get_sha1_file();
} catch (portfolio_caller_exception $e) {} // no files
return sha1($textsha1 . $filesha1);
}
function portfolio_prepare_package($exporter, $user) {
$submission = $this->get_submission($user->id);
$options = portfolio_format_text_options();
$html = format_text($submission->data1, $submission->data2, $options);
$html = portfolio_rewrite_pluginfile_urls($html, $this->context->id, 'mod_assignment', $this->filearea, $submission->id, $exporter->get('format'));
if (in_array($exporter->get('formatclass'), array(PORTFOLIO_FORMAT_PLAINHTML, PORTFOLIO_FORMAT_RICHHTML))) {
if ($files = $exporter->get('caller')->get('multifiles')) {
foreach ($files as $f) {
$exporter->copy_existing_file($f);
}
}
return $exporter->write_new_file($html, 'assignment.html', !empty($files));
} else if ($exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
$leapwriter = $exporter->get('format')->leap2a_writer();
$entry = new portfolio_format_leap2a_entry('assignmentonline' . $this->assignment->id, $this->assignment->name, 'resource', $html);
$entry->add_category('web', 'resource_type');
$entry->published = $submission->timecreated;
$entry->updated = $submission->timemodified;
$entry->author = $user;
$leapwriter->add_entry($entry);
if ($files = $exporter->get('caller')->get('multifiles')) {
$leapwriter->link_files($entry, $files, 'assignmentonline' . $this->assignment->id . 'file');
foreach ($files as $f) {
$exporter->copy_existing_file($f);
}
}
$exporter->write_new_file($leapwriter->to_xml(), $exporter->get('format')->manifest_name(), true);
} else {
debugging('invalid format class: ' . $exporter->get('formatclass'));
}
}
function extend_settings_navigation($node) {
global $PAGE, $CFG, $USER;
// get users submission if there is one
$submission = $this->get_submission();
if (is_enrolled($PAGE->cm->context, $USER, 'mod/assignment:submit')) {
$editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked);
} else {
$editable = false;
}
// If the user has submitted something add a bit more stuff
if ($submission) {
// Add a view link to the settings nav
$link = new moodle_url('/mod/assignment/view.php', array('id'=>$PAGE->cm->id));
$node->add(get_string('viewmysubmission', 'assignment'), $link, navigation_node::TYPE_SETTING);
if (!empty($submission->timemodified)) {
$submittednode = $node->add(get_string('submitted', 'assignment') . ' ' . userdate($submission->timemodified));
$submittednode->text = preg_replace('#([^,])\s#', '$1&nbsp;', $submittednode->text);
$submittednode->add_class('note');
if ($submission->timemodified <= $this->assignment->timedue || empty($this->assignment->timedue)) {
$submittednode->add_class('early');
} else {
$submittednode->add_class('late');
}
}
}
if (!$submission || $editable) {
// If this assignment is editable once submitted add an edit link to the settings nav
$link = new moodle_url('/mod/assignment/view.php', array('id'=>$PAGE->cm->id, 'edit'=>1, 'sesskey'=>sesskey()));
$node->add(get_string('editmysubmission', 'assignment'), $link, navigation_node::TYPE_SETTING);
}
}
public function send_file($filearea, $args, $forcedownload, array $options=array()) {
global $USER, $CFG;
require_capability('mod/assignment:view', $this->context);
$fullpath = "/{$this->context->id}/mod_assignment/$filearea/".implode('/', $args);
$fs = get_file_storage();
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
send_file_not_found();
}
if (($USER->id != $file->get_userid()) && !has_capability('mod/assignment:grade', $this->context)) {
send_file_not_found();
}
\core\session\manager::write_close(); // Unlock session during file serving.
// Make the lifetime significantly shorter,
// it would be better to have file revision numbers.
$lifetime = $CFG->filelifetime;
if ($lifetime > 60*6) {
$lifetime = 60*6;
}
send_stored_file($file, $lifetime, 0, true, $options);
}
/**
* creates a zip of all assignment submissions and sends a zip to the browser
*/
public function download_submissions() {
global $CFG, $DB;
raise_memory_limit(MEMORY_EXTRA);
$submissions = $this->get_submissions('','');
if (empty($submissions)) {
print_error('errornosubmissions', 'assignment');
}
$filesforzipping = array();
//NOTE: do not create any stuff in temp directories, we now support unicode file names and that would not work, sorry
//online assignment can use html
$filextn=".html";
$groupmode = groups_get_activity_groupmode($this->cm);
$groupid = 0; // All users
$groupname = '';
if ($groupmode) {
$groupid = groups_get_activity_group($this->cm, true);
$groupname = groups_get_group_name($groupid).'-';
}
$filename = str_replace(' ', '_', clean_filename($this->course->shortname.'-'.$this->assignment->name.'-'.$groupname.$this->assignment->id.".zip")); //name of new zip file.
foreach ($submissions as $submission) {
$a_userid = $submission->userid; //get userid
if ((groups_is_member($groupid,$a_userid)or !$groupmode or !$groupid)) {
$a_assignid = $submission->assignment; //get name of this assignment for use in the file names.
$a_user = $DB->get_record("user", array("id"=>$a_userid),'id,username,firstname,lastname'); //get user firstname/lastname
$submissioncontent = "<html><body>". format_text($submission->data1, $submission->data2). "</body></html>"; //fetched from database
//get file name.html
$fileforzipname = clean_filename(fullname($a_user) . "_" .$a_userid.$filextn);
$filesforzipping[$fileforzipname] = array($submissioncontent);
}
} //end of foreach
if ($zipfile = assignment_pack_files($filesforzipping)) {
send_temp_file($zipfile, $filename); //send file and delete after sending.
}
}
}
class mod_assignment_online_edit_form extends moodleform {
function definition() {
$mform = $this->_form;
list($data, $editoroptions) = $this->_customdata;
// visible elements
$mform->addElement('editor', 'text_editor', get_string('submission', 'assignment'), null, $editoroptions);
$mform->setType('text_editor', PARAM_RAW); // to be cleaned before display
$mform->addRule('text_editor', get_string('required'), 'required', null, 'client');
// hidden params
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'edit');
$mform->setType('edit', PARAM_INT);
// buttons
$this->add_action_buttons();
$this->set_data($data);
}
}

View File

@ -1,124 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* assignment_online assessable uploaded event.
*
* @package assignment_online
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignment_online\event;
defined('MOODLE_INTERNAL') || die();
/**
* assignment_online assessable uploaded event class.
*
* @property-read array $other {
* Extra information about event.
*
* @type array pathnamehashes uploaded files path name hashes.
* @type string content submission text.
* @type string triggeredfrom name of the function from which it is triggred.
* }
*
* @package assignment_online
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assessable_uploaded extends \core\event\assessable_uploaded {
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "User {$this->userid} has saved an online text in submission {$this->objectid}.";
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
*
* @return stdClass
*/
protected function get_legacy_eventdata() {
$eventdata = new \stdClass();
$eventdata->modulename = 'assignment';
$eventdata->name = $this->other['triggeredfrom'];
$eventdata->cmid = $this->context->instanceid;
$eventdata->itemid = $this->objectid;
$eventdata->courseid = $this->courseid;
$eventdata->userid = $this->userid;
$eventdata->content = $this->other['content'];
if ($this->other['pathnamehashes']) {
$eventdata->pathnamehashes = $this->other['pathnamehashes'];
}
return $eventdata;
}
/**
* Return the legacy event name.
*
* @return string
*/
public static function get_legacy_eventname() {
return 'assessable_content_uploaded';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_assessable_uploaded', 'assignment_online');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assignment/view.php', array('id' => $this->context->instanceid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
parent::init();
$this->data['objecttable'] = 'assignment_submissions';
}
/**
* Custom validation
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['triggeredfrom'])) {
throw new \coding_exception('triggeredfrom must be set in $other');
}
}
}

View File

@ -1,68 +0,0 @@
<?php
require("../../../../config.php");
require("../../lib.php");
require("assignment.class.php");
$id = required_param('id', PARAM_INT); // Course Module ID
$userid = required_param('userid', PARAM_INT); // User ID
$PAGE->set_url('/mod/assignment/type/online/file.php', array('id'=>$id, 'userid'=>$userid));
if (! $cm = get_coursemodule_from_id('assignment', $id)) {
print_error('invalidcoursemodule');
}
if (! $assignment = $DB->get_record("assignment", array("id"=>$cm->instance))) {
print_error('invalidid', 'assignment');
}
if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
print_error('coursemisconf', 'assignment');
}
if (! $user = $DB->get_record("user", array("id"=>$userid))) {
print_error('usermisconf', 'assignment');
}
require_login($course, false, $cm);
$context = context_module::instance($cm->id);
if (($USER->id != $user->id) && !has_capability('mod/assignment:grade', $context)) {
print_error('cannotviewassignment', 'assignment');
}
if ($assignment->assignmenttype != 'online') {
print_error('invalidtype', 'assignment');
}
$assignmentinstance = new assignment_online($cm->id, $assignment, $cm, $course);
if ($submission = $assignmentinstance->get_submission($user->id)) {
$PAGE->set_pagelayout('popup');
$PAGE->set_title(fullname($user,true).': '.$assignment->name);
echo $OUTPUT->header();
echo $OUTPUT->box_start('generalbox boxaligcenter', 'dates');
echo '<table>';
if ($assignment->timedue) {
echo '<tr><td class="c0">'.get_string('duedate','assignment').':</td>';
echo ' <td class="c1">'.userdate($assignment->timedue).'</td></tr>';
}
echo '<tr><td class="c0">'.get_string('lastedited').':</td>';
echo ' <td class="c1">'.userdate($submission->timemodified);
/// Decide what to count
if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_WORDS) {
echo ' ('.get_string('numwords', '', count_words(format_text($submission->data1, $submission->data2))).')</td></tr>';
} else if ($CFG->assignment_itemstocount == ASSIGNMENT_COUNT_LETTERS) {
echo ' ('.get_string('numletters', '', count_letters(format_text($submission->data1, $submission->data2))).')</td></tr>';
}
echo '</table>';
echo $OUTPUT->box_end();
$text = file_rewrite_pluginfile_urls($submission->data1, 'pluginfile.php', $context->id, 'mod_assignment', $assignmentinstance->filearea, $submission->id);
echo $OUTPUT->box(format_text($text, $submission->data2, array('overflowdiv'=>true)), 'generalbox boxaligncenter boxwidthwide');
echo $OUTPUT->close_window_button();
echo $OUTPUT->footer();
} else {
print_string('emptysubmission', 'assignment');
}

View File

@ -1,7 +1,6 @@
This file describes changes in the assignment type API and DB structures.
Information provided here is intended especially for developers.
=== 2.3 ===
=== 2.7 ===
API changes:
* send_file() methods now accept $forcedownload and $options parameters
mod_assignment has been deleted. Do not use it.

File diff suppressed because it is too large Load Diff

View File

@ -1,131 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* assignment_submitted assessable uploaded event.
*
* @package assignment_submitted
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignment_upload\event;
defined('MOODLE_INTERNAL') || die();
/**
* assignment_submitted assessable uploaded event class.
*
* @property-read array $other {
* Extra information about event.
*
* @type int assignmentid assignment id.
* @type bool submission_editable is submission editable.
* }
*
* @package assignment_submitted
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assessable_submitted extends \core\event\assessable_submitted {
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "User {$this->userid} has submitted the upload submission {$this->objectid}.";
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
*
* @return stdClass
*/
protected function get_legacy_eventdata() {
$eventdata = new \stdClass();
$eventdata->modulename = 'assignment';
$eventdata->cmid = $this->context->instanceid;
$eventdata->itemid = $this->objectid;
$eventdata->courseid = $this->courseid;
$eventdata->userid = $this->userid;
return $eventdata;
}
/**
* Return the legacy event name.
*
* @return string
*/
public static function get_legacy_eventname() {
return 'assessable_files_done';
}
/**
* Get legacy log data.
*
* @return array
*/
protected function get_legacy_logdata() {
return array($this->courseid, 'assignment', 'upload', 'view.php?a='.$this->other['assignmentid'],
$this->other['assignmentid'], $this->context->instanceid);
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_assessable_submitted', 'assignment_submitted');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assignment/view.php', array('id' => $this->context->instanceid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
parent::init();
$this->data['objecttable'] = 'assignment_submissions';
}
/**
* Custom validation
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['submission_editable'])) {
throw new \coding_exception('Other must contain the key submission_editable.');
}
if (!isset($this->other['assignmentid'])) {
throw new \coding_exception('Other must contain the key assignmentid.');
}
}
}

View File

@ -1,138 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* assignment_upload assessable uploaded event.
*
* @package assignment_upload
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignment_upload\event;
defined('MOODLE_INTERNAL') || die();
/**
* assignment_upload assessable uploaded event class.
*
* @property-read array $other {
* Extra information about event.
*
* @type array pathnamehashes uploaded files path name hashes.
* @type string content empty string.
* @type int assignmentid assignment id.
* }
*
* @package assignment_upload
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assessable_uploaded extends \core\event\assessable_uploaded {
/**
* Legacy files.
*
* @var array
*/
protected $legacyfiles;
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "User {$this->userid} has uploaded a file in submission {$this->objectid}.";
}
/**
* Legacy event data if get_legacy_eventname() is not empty.
*
* @return stdClass
*/
protected function get_legacy_eventdata() {
$eventdata = new \stdClass();
$eventdata->modulename = 'assignment';
$eventdata->cmid = $this->context->instanceid;
$eventdata->itemid = $this->objectid;
$eventdata->courseid = $this->courseid;
$eventdata->userid = $this->userid;
if ($this->legacyfiles) {
$eventdata->files = $this->legacyfiles; // This is depreceated - please use pathnamehashes instead!
}
$eventdata->pathnamehashes = $this->other['pathnamehashes'];
return $eventdata;
}
/**
* Return the legacy event name.
*
* @return string
*/
public static function get_legacy_eventname() {
return 'assessable_file_uploaded';
}
/**
* Get legacy log data.
*
* @return array
*/
protected function get_legacy_logdata() {
return array($this->courseid, 'assignment', 'upload', 'view.php?a=' . $this->other['assignmentid'],
$this->other['assignmentid'], $this->context->id);
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_assessable_uploaded', 'assignment_upload');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assignment/view.php', array('id' => $this->context->instanceid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
parent::init();
$this->data['objecttable'] = 'assignment_submissions';
}
/**
* Set legacy files.
*
* @param array $files
* @return void
*/
public function set_legacy_files($files) {
$this->legacyfiles = $files;
}
}

View File

@ -1,74 +0,0 @@
<?php
require('../../../../config.php');
require('../../lib.php');
require('assignment.class.php');
$id = required_param('id', PARAM_INT); // Course Module ID
$userid = required_param('userid', PARAM_INT); // User ID
$offset = optional_param('offset', 0, PARAM_INT);
$mode = optional_param('mode', '', PARAM_ALPHA);
$url = new moodle_url('/mod/assignment/type/online/file.php', array('id'=>$id, 'userid'=>$userid));
if ($offset !== 0) {
$url->param('offset',$offset);
}
if ($mode !== 0) {
$url->param('mode',$mode);
}
$PAGE->set_url($url);
if (! $cm = get_coursemodule_from_id('assignment', $id)) {
print_error('invalidcoursemodule');
}
if (! $assignment = $DB->get_record('assignment', array('id'=>$cm->instance))) {
print_error('invalidid', 'assignment');
}
if (! $course = $DB->get_record('course', array('id'=>$assignment->course))) {
print_error('coursemisconf', 'assignment');
}
if (! $user = $DB->get_record('user', array('id'=>$userid))) {
print_error("invaliduserid");
}
require_login($course, false, $cm);
if (!has_capability('mod/assignment:grade', context_module::instance($cm->id))) {
print_error('cannotviewassignment', 'assignment');
}
if ($assignment->assignmenttype != 'upload') {
print_error('invalidtype', 'assignment');
}
$assignmentinstance = new assignment_upload($cm->id, $assignment, $cm, $course);
$returnurl = "../../submissions.php?id={$assignmentinstance->cm->id}&amp;userid=$userid&amp;offset=$offset&amp;mode=single";
if ($submission = $assignmentinstance->get_submission($user->id)
and !empty($submission->data1)) {
$PAGE->set_title(fullname($user,true).': '.$assignment->name);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('notes', 'assignment').' - '.fullname($user,true));
echo $OUTPUT->box(format_text($submission->data1, FORMAT_HTML, array('overflowdiv'=>true)), 'generalbox boxaligncenter boxwidthwide');
if ($mode != 'single') {
echo $OUTPUT->close_window_button();
} else {
echo $OUTPUT->continue_button($returnurl);
}
echo $OUTPUT->footer();
} else {
$PAGE->set_title(fullname($user,true).': '.$assignment->name);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('notes', 'assignment').' - '.fullname($user,true));
echo $OUTPUT->box(get_string('notesempty', 'assignment'), 'generalbox boxaligncenter boxwidthwide');
if ($mode != 'single') {
echo $OUTPUT->close_window_button();
} else {
echo $OUTPUT->continue_button($returnurl);
}
echo $OUTPUT->footer();
}

View File

@ -1,95 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
*
* @package mod-assignment
* @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/config.php');
require_once(dirname(__FILE__).'/upload_form.php');
require_once(dirname(__FILE__).'/assignment.class.php');
require_once("$CFG->dirroot/repository/lib.php");
$contextid = required_param('contextid', PARAM_INT);
$id = optional_param('id', null, PARAM_INT);
$formdata = new stdClass();
$formdata->userid = required_param('userid', PARAM_INT);
$formdata->offset = optional_param('offset', null, PARAM_INT);
$formdata->forcerefresh = optional_param('forcerefresh', null, PARAM_INT);
$formdata->mode = optional_param('mode', null, PARAM_ALPHA);
$url = new moodle_url('/mod/assignment/type/upload/upload.php', array('contextid'=>$contextid,
'id'=>$id,'offset'=>$formdata->offset,'forcerefresh'=>$formdata->forcerefresh,'userid'=>$formdata->userid,'mode'=>$formdata->mode));
list($context, $course, $cm) = get_context_info_array($contextid);
require_login($course, true, $cm);
if (isguestuser()) {
die();
}
if (!$assignment = $DB->get_record('assignment', array('id'=>$cm->instance))) {
print_error('invalidid', 'assignment');
}
$fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
$PAGE->set_url($url);
$PAGE->set_context($context);
$title = strip_tags($fullname.': '.get_string('modulename', 'assignment').': '.format_string($assignment->name,true));
$PAGE->set_title($title);
$PAGE->set_heading($title);
$instance = new assignment_upload($cm->id, $assignment, $cm, $course);
$submission = $instance->get_submission($formdata->userid, false);
$filemanager_options = array('subdirs'=>1, 'maxbytes'=>$assignment->maxbytes, 'maxfiles'=>$assignment->var1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
$mform = new mod_assignment_upload_form(null, array('contextid'=>$contextid, 'userid'=>$formdata->userid, 'options'=>$filemanager_options));
if ($mform->is_cancelled()) {
redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
} else if ($formdata = $mform->get_data()) {
$instance->upload($mform, $filemanager_options);
die;
}
echo $OUTPUT->header();
echo $OUTPUT->box_start('generalbox');
if ($instance->can_upload_file($submission) && ($id==null)) {
$data = new stdClass();
$submissionid = null;
if (is_object($submission) && isset($submission->id)) {
$submissionid = $submission->id;
}
// move submission files to user draft area
$data = file_prepare_standard_filemanager($data, 'files', $filemanager_options, $context, 'mod_assignment', 'submission', $submissionid);
// set file manager itemid, so it will find the files in draft area
$mform->set_data($data);
$mform->display();
}else {
echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
echo $OUTPUT->continue_button(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
}
echo $OUTPUT->box_end();
echo $OUTPUT->footer();

View File

@ -1,44 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->libdir.'/formslib.php');//putting this is as a safety as i got a class not found error.
/**
* @package mod-assignment
* @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_assignment_upload_form extends moodleform {
function definition() {
$mform = $this->_form;
$instance = $this->_customdata;
// visible elements
$mform->addElement('filemanager', 'files_filemanager', get_string('uploadafile'), null, $instance['options']);
$mform->addRule('files_filemanager', get_string('uploadnofilefound'), 'required', null, 'client');
// hidden params
$mform->addElement('hidden', 'contextid', $instance['contextid']);
$mform->setType('contextid', PARAM_INT);
$mform->addElement('hidden', 'userid', $instance['userid']);
$mform->setType('userid', PARAM_INT);
$mform->addElement('hidden', 'action', 'uploadfile');
$mform->setType('action', PARAM_ALPHA);
// buttons
$this->add_action_buttons(true, get_string('savechanges', 'admin'));
}
}

View File

@ -1,472 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Extend the base assignment class for assignments where you upload a single file
*
* @package mod-assignment
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot.'/mod/assignment/lib.php');
require_once(dirname(__FILE__).'/upload_form.php');
class assignment_uploadsingle extends assignment_base {
function print_student_answer($userid, $return=false){
global $CFG, $USER, $OUTPUT;
$fs = get_file_storage();
$browser = get_file_browser();
$output = '';
if ($submission = $this->get_submission($userid)) {
if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) {
foreach ($files as $file) {
$filename = $file->get_filename();
$found = true;
$mimetype = $file->get_mimetype();
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename);
$output .= '<a href="'.$path.'" >'.$OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')).s($filename).'</a><br />';
$output .= plagiarism_get_links(array('userid'=>$userid, 'file'=>$file, 'cmid'=>$this->cm->id, 'course'=>$this->course, 'assignment'=>$this->assignment));
$output .='<br/>';
}
}
}
$output = '<div class="files">'.$output.'</div>';
return $output;
}
function assignment_uploadsingle($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
parent::assignment_base($cmid, $assignment, $cm, $course);
$this->type = 'uploadsingle';
}
function view() {
global $USER, $OUTPUT;
$context = context_module::instance($this->cm->id);
require_capability('mod/assignment:view', $context);
add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id);
$this->view_header();
$this->view_intro();
$this->view_dates();
$filecount = false;
if ($submission = $this->get_submission($USER->id)) {
$filecount = $this->count_user_files($submission->id);
if ($submission->timemarked) {
$this->view_feedback($submission);
}
if ($filecount) {
echo $OUTPUT->box($this->print_user_files($USER->id, true), 'generalbox boxaligncenter');
}
}
if (is_enrolled($this->context, $USER, 'mod/assignment:submit') && $this->isopen() && (!$filecount || $this->assignment->resubmit || !$submission->timemarked)) {
$this->view_upload_form();
}
$this->view_footer();
}
/**
* Display the response file to the student
*
* This default method prints the response file
*
* @param object $submission The submission object
*/
function view_responsefile($submission) {
$fs = get_file_storage();
$noresponsefiles = $fs->is_area_empty($this->context->id, 'mod_assignment', 'response', $submission->id);
if (!$noresponsefiles) {
echo '<tr>';
echo '<td class="left side">&nbsp;</td>';
echo '<td class="content">';
echo $this->print_responsefiles($submission->userid);
echo '</td></tr>';
}
}
function process_feedback($formdata=null) {
if (!$feedback = data_submitted() or !confirm_sesskey()) { // No incoming data?
return false;
}
$userid = required_param('userid', PARAM_INT);
$offset = required_param('offset', PARAM_INT);
$mform = $this->display_submission($offset, $userid, false);
parent::process_feedback($mform);
}
/**
* Counts all complete (real) assignment submissions by enrolled students. This overrides assignment_base::count_real_submissions().
* This is necessary for simple file uploads where we need to check that the numfiles field is greater than zero to determine if a
* submission is complete.
*
* @param int $groupid (optional) If nonzero then count is restricted to this group
* @return int The number of submissions
*/
function count_real_submissions($groupid=0) {
global $DB;
// Grab the context assocated with our course module
$context = context_module::instance($this->cm->id);
// Get ids of users enrolled in the given course.
list($enroledsql, $params) = get_enrolled_sql($context, 'mod/assignment:submit', $groupid);
$params['assignmentid'] = $this->cm->instance;
// Get ids of users enrolled in the given course.
return $DB->count_records_sql("SELECT COUNT('x')
FROM {assignment_submissions} s
LEFT JOIN {assignment} a ON a.id = s.assignment
INNER JOIN ($enroledsql) u ON u.id = s.userid
WHERE s.assignment = :assignmentid AND
s.numfiles > 0", $params);
}
function print_responsefiles($userid, $return=false) {
global $OUTPUT, $PAGE;
$output = $OUTPUT->box_start('responsefiles');
if ($submission = $this->get_submission($userid)) {
$renderer = $PAGE->get_renderer('mod_assignment');
$output .= $renderer->assignment_files($this->context, $submission->id, 'response');
}
$output .= $OUTPUT->box_end();
if ($return) {
return $output;
}
echo $output;
}
function can_manage_responsefiles() {
if (has_capability('mod/assignment:grade', $this->context)) {
return true;
} else {
return false;
}
}
function view_upload_form() {
global $OUTPUT, $USER;
echo $OUTPUT->box_start('uploadbox');
$fs = get_file_storage();
// edit files in another page
if ($submission = $this->get_submission($USER->id)) {
if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) {
$str = get_string('editthisfile', 'assignment');
} else {
$str = get_string('uploadafile', 'assignment');
}
} else {
$str = get_string('uploadafile', 'assignment');
}
echo $OUTPUT->single_button(new moodle_url('/mod/assignment/type/uploadsingle/upload.php', array('contextid'=>$this->context->id, 'userid'=>$USER->id)), $str, 'get');
echo $OUTPUT->box_end();
}
function upload($mform) {
$action = required_param('action', PARAM_ALPHA);
switch ($action) {
case 'uploadresponse':
$this->upload_responsefile($mform);
break;
case 'uploadfile':
$this->upload_file($mform);
}
}
function upload_file($mform) {
global $CFG, $USER, $DB, $OUTPUT;
$viewurl = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id));
if (!is_enrolled($this->context, $USER, 'mod/assignment:submit')) {
redirect($viewurl);
}
$submission = $this->get_submission($USER->id);
$filecount = 0;
if ($submission) {
$filecount = $this->count_user_files($submission->id);
}
if ($this->isopen() && (!$filecount || $this->assignment->resubmit || !$submission->timemarked)) {
if ($submission = $this->get_submission($USER->id)) {
//TODO: change later to ">= 0", to prevent resubmission when graded 0
if (($submission->grade > 0) and !$this->assignment->resubmit) {
redirect($viewurl, get_string('alreadygraded', 'assignment'));
}
}
if ($formdata = $mform->get_data()) {
$fs = get_file_storage();
$submission = $this->get_submission($USER->id, true); //create new submission if needed
$fs->delete_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id);
if ($newfilename = $mform->get_new_filename('assignment_file')) {
$file = $mform->save_stored_file('assignment_file', $this->context->id, 'mod_assignment', 'submission',
$submission->id, '/', $newfilename);
$updates = new stdClass(); //just enough data for updating the submission
$updates->timemodified = time();
$updates->numfiles = 1;
$updates->id = $submission->id;
$DB->update_record('assignment_submissions', $updates);
add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
$this->update_grade($submission);
$this->email_teachers($submission);
// Let Moodle know that an assessable file was uploaded (eg for plagiarism detection)
$eventdata = new stdClass();
$eventdata->modulename = 'assignment';
$eventdata->cmid = $this->cm->id;
$eventdata->itemid = $submission->id;
$eventdata->courseid = $this->course->id;
$eventdata->userid = $USER->id;
$eventdata->file = $file; // This is depreceated - please use pathnamehashes instead!
$eventdata->pathnamehashes = array($file->get_pathnamehash());
events_trigger('assessable_file_uploaded', $eventdata);
}
redirect($viewurl, get_string('uploadedfile'));
} else {
redirect($viewurl, get_string('uploaderror', 'assignment')); //submitting not allowed!
}
}
redirect($viewurl);
}
function upload_responsefile($mform) {
global $CFG, $USER, $OUTPUT, $PAGE;
$userid = required_param('userid', PARAM_INT);
$mode = required_param('mode', PARAM_ALPHA);
$offset = required_param('offset', PARAM_INT);
$returnurl = new moodle_url("/mod/assignment/submissions.php", array('id'=>$this->cm->id,'userid'=>$userid,'mode'=>$mode,'offset'=>$offset)); //not xhtml, just url.
if ($formdata = $mform->get_data() and $this->can_manage_responsefiles()) {
$fs = get_file_storage();
$submission = $this->get_submission($userid, true); //create new submission if needed
$fs->delete_area_files($this->context->id, 'mod_assignment', 'response', $submission->id);
if ($newfilename = $mform->get_new_filename('assignment_file')) {
$file = $mform->save_stored_file('assignment_file', $this->context->id,
'mod_assignment', 'response',$submission->id, '/', $newfilename);
}
redirect($returnurl, get_string('uploadedfile'));
} else {
redirect($returnurl, get_string('uploaderror', 'assignment')); //submitting not allowed!
}
}
function setup_elements(&$mform) {
global $CFG, $COURSE;
$ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
$mform->addElement('select', 'resubmit', get_string('allowresubmit', 'assignment'), $ynoptions);
$mform->addHelpButton('resubmit', 'allowresubmit', 'assignment');
$mform->setDefault('resubmit', 0);
$mform->addElement('select', 'emailteachers', get_string('emailteachers', 'assignment'), $ynoptions);
$mform->addHelpButton('emailteachers', 'emailteachers', 'assignment');
$mform->setDefault('emailteachers', 0);
$choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
$mform->addElement('select', 'maxbytes', get_string('maximumsize', 'assignment'), $choices);
$mform->setDefault('maxbytes', $CFG->assignment_maxbytes);
$course_context = context_course::instance($COURSE->id);
plagiarism_get_form_elements_module($mform, $course_context, 'mod_assignment');
}
function portfolio_exportable() {
return true;
}
function send_file($filearea, $args, $forcedownload, array $options=array()) {
global $CFG, $DB, $USER;
require_once($CFG->libdir.'/filelib.php');
require_login($this->course, false, $this->cm);
if ($filearea !== 'submission' && $filearea !== 'response') {
return false;
}
$submissionid = (int)array_shift($args);
if (!$submission = $DB->get_record('assignment_submissions', array('assignment'=>$this->assignment->id, 'id'=>$submissionid))) {
return false;
}
if ($USER->id != $submission->userid and !has_capability('mod/assignment:grade', $this->context)) {
return false;
}
$relativepath = implode('/', $args);
$fullpath = '/'.$this->context->id.'/mod_assignment/'.$filearea.'/'.$submissionid.'/'.$relativepath;
$fs = get_file_storage();
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
return false;
}
send_stored_file($file, 0, 0, true, $options); // download MUST be forced - security!
}
function extend_settings_navigation($node) {
global $CFG, $USER, $OUTPUT;
// get users submission if there is one
$submission = $this->get_submission();
if (is_enrolled($this->context, $USER, 'mod/assignment:submit')) {
$editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked);
} else {
$editable = false;
}
// If the user has submitted something add some related links and data
if (isset($submission->numfiles) AND $submission->numfiles) {
// Add a view link to the settings nav
$link = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id));
$node->add(get_string('viewmysubmission', 'assignment'), $link, navigation_node::TYPE_SETTING);
if (!empty($submission->timemodified)) {
$submissionnode = $node->add(get_string('submitted', 'assignment') . ' ' . userdate($submission->timemodified));
$submissionnode->text = preg_replace('#([^,])\s#', '$1&nbsp;', $submissionnode->text);
$submissionnode->add_class('note');
if ($submission->timemodified <= $this->assignment->timedue || empty($this->assignment->timedue)) {
$submissionnode->add_class('early');
} else {
$submissionnode->add_class('late');
}
}
}
// Check if the user has uploaded any files, if so we can add some more stuff to the settings nav
if ($submission && is_enrolled($this->context, $USER, 'mod/assignment:submit') && $this->count_user_files($submission->id)) {
$fs = get_file_storage();
if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) {
$filenode = $node->add(get_string('submission', 'assignment'));
foreach ($files as $file) {
$filename = $file->get_filename();
$mimetype = $file->get_mimetype();
$link = moodle_url::make_pluginfile_url($this->context->id, 'mod_assignment', 'submission', $submission->id, $file->get_filepath(), $filename);
$filenode->add($filename, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon(file_file_icon($file), ''));
}
}
}
}
/**
* creates a zip of all assignment submissions and sends a zip to the browser
*/
function download_submissions() {
global $CFG,$DB;
require_once($CFG->libdir.'/filelib.php');
$submissions = $this->get_submissions('','');
if (empty($submissions)) {
print_error('errornosubmissions', 'assignment');
}
$filesforzipping = array();
$fs = get_file_storage();
$groupmode = groups_get_activity_groupmode($this->cm);
$groupid = 0; // All users
$groupname = '';
if ($groupmode) {
$groupid = groups_get_activity_group($this->cm, true);
$groupname = groups_get_group_name($groupid).'-';
}
$filename = str_replace(' ', '_', clean_filename($this->course->shortname.'-'.$this->assignment->name.'-'.$groupname.$this->assignment->id.".zip")); //name of new zip file.
foreach ($submissions as $submission) {
$a_userid = $submission->userid; //get userid
if ((groups_is_member($groupid,$a_userid)or !$groupmode or !$groupid)) {
$a_assignid = $submission->assignment; //get name of this assignment for use in the file names.
$a_user = $DB->get_record("user", array("id"=>$a_userid),'id,username,firstname,lastname'); //get user firstname/lastname
$files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false);
foreach ($files as $file) {
//get files new name.
$fileext = strstr($file->get_filename(), '.');
$fileoriginal = str_replace($fileext, '', $file->get_filename());
$fileforzipname = clean_filename(fullname($a_user) . "_" . $fileoriginal."_".$a_userid.$fileext);
//save file name to array for zipping.
$filesforzipping[$fileforzipname] = $file;
}
}
} // End of foreach
if ($zipfile = assignment_pack_files($filesforzipping)) {
send_temp_file($zipfile, $filename); //send file and delete after sending.
}
}
/**
* Check the given submission is complete. Preliminary rows are often created in the assignment_submissions
* table before a submission actually takes place. This function checks to see if the given submission has actually
* been submitted.
*
* @param stdClass $submission The submission we want to check for completion
* @return bool Indicates if the submission was found to be complete
*/
public function is_submitted_with_required_data($submission) {
return ($submission->timemodified AND $submission->numfiles > 0);
}
}
class mod_assignment_uploadsingle_response_form extends moodleform {
function definition() {
$mform = $this->_form;
$instance = $this->_customdata;
// visible elements
$mform->addElement('filepicker', 'assignment_file', get_string('uploadafile'), null, $instance->options);
// hidden params
$mform->addElement('hidden', 'id', $instance->cm->id);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'contextid', $instance->contextid);
$mform->setType('contextid', PARAM_INT);
$mform->addElement('hidden', 'action', 'uploadresponse');
$mform->setType('action', PARAM_ALPHA);
$mform->addElement('hidden', 'mode', $instance->mode);
$mform->setType('mode', PARAM_ALPHA);
$mform->addElement('hidden', 'offset', $instance->offset);
$mform->setType('offset', PARAM_INT);
$mform->addElement('hidden', 'forcerefresh' , $instance->forcerefresh);
$mform->setType('forcerefresh', PARAM_INT);
$mform->addElement('hidden', 'userid', $instance->userid);
$mform->setType('userid', PARAM_INT);
// buttons
$this->add_action_buttons(false, get_string('uploadthisfile'));
}
}

View File

@ -1,78 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
*
* @package mod-assignment
* @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/config.php');
require_once(dirname(__FILE__).'/upload_form.php');
require_once(dirname(__FILE__).'/assignment.class.php');
require_once("$CFG->dirroot/repository/lib.php");
$contextid = required_param('contextid', PARAM_INT);
$id = optional_param('id', null, PARAM_INT);
$formdata = new stdClass();
$formdata->userid = required_param('userid', PARAM_INT);
$formdata->offset = optional_param('offset', null, PARAM_INT);
$formdata->forcerefresh = optional_param('forcerefresh', null, PARAM_INT);
$formdata->mode = optional_param('mode', null, PARAM_ALPHA);
$url = new moodle_url('/mod/assignment/type/uploadsingle/upload.php', array('contextid'=>$contextid,
'id'=>$id,'offset'=>$formdata->offset,'forcerefresh'=>$formdata->forcerefresh,'userid'=>$formdata->userid,'mode'=>$formdata->mode));
list($context, $course, $cm) = get_context_info_array($contextid);
if (!$assignment = $DB->get_record('assignment', array('id'=>$cm->instance))) {
print_error('invalidid', 'assignment');
}
require_login($course, true, $cm);
if (isguestuser()) {
die();
}
$instance = new assignment_uploadsingle($cm->id, $assignment, $cm, $course);
$fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
$PAGE->set_url($url);
$PAGE->set_context($context);
$title = strip_tags($fullname.': '.get_string('modulename', 'assignment').': '.format_string($assignment->name,true));
$PAGE->set_title($title);
$PAGE->set_heading($title);
$options = array('subdirs'=>0, 'maxbytes'=>get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $assignment->maxbytes), 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
$mform = new mod_assignment_uploadsingle_form(null, array('contextid'=>$contextid, 'userid'=>$formdata->userid, 'options'=>$options));
if ($mform->is_cancelled()) {
redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
} else if ($mform->get_data()) {
$instance->upload($mform);
die();
// redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
}
echo $OUTPUT->header();
echo $OUTPUT->box_start('generalbox');
$mform->display();
echo $OUTPUT->box_end();
echo $OUTPUT->footer();

View File

@ -1,46 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once($CFG->libdir.'/formslib.php');//putting this is as a safety as i got a class not found error.
/**
* @package mod-assignment
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_assignment_uploadsingle_form extends moodleform {
function definition() {
$mform = $this->_form;
$instance = $this->_customdata;
// visible elements
//$mform->addElement('filemanager', 'newfile', get_string('uploadafile'));
//$mform->addElement('filemanager', 'files_filemanager', get_string('uploadafile'), null, $instance['options']);
$mform->addElement('filepicker', 'assignment_file', get_string('uploadafile'), null, $instance['options']);
$mform->addRule('assignment_file', get_string('uploadnofilefound'), 'required', null, 'client');
// hidden params
$mform->addElement('hidden', 'contextid', $instance['contextid']);
$mform->setType('contextid', PARAM_INT);
$mform->addElement('hidden', 'userid', $instance['userid']);
$mform->setType('userid', PARAM_INT);
$mform->addElement('hidden', 'action', 'uploadfile');
$mform->setType('action', PARAM_ALPHA);
// buttons
$this->add_action_buttons(true, get_string('savechanges', 'admin'));
}
}

View File

@ -1,44 +0,0 @@
<?php
require_once("../../config.php");
require_once("lib.php");
$id = optional_param('id', 0, PARAM_INT); // Course module ID
$a = optional_param('a', 0, PARAM_INT); // Assignment ID
$url = new moodle_url('/mod/assignment/upload.php');
if ($id) {
if (! $cm = get_coursemodule_from_id('assignment', $id)) {
print_error('invalidcoursemodule');
}
if (! $assignment = $DB->get_record("assignment", array("id"=>$cm->instance))) {
print_error('invalidid', 'assignment');
}
if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
print_error('coursemisconf', 'assignment');
}
$url->param('id', $id);
} else {
if (!$assignment = $DB->get_record("assignment", array("id"=>$a))) {
print_error('invalidcoursemodule');
}
if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
print_error('invalidid', 'assignment');
}
if (! $cm = get_coursemodule_from_instance("assignment", $assignment->id, $course->id)) {
print_error('invalidcoursemodule', 'assignment');
}
$url->param('a', $a);
}
$PAGE->set_url($url);
require_login($course, false, $cm);
/// Load up the required assignment code
require_once($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php');
$assignmentclass = 'assignment_'.$assignment->assignmenttype;
$assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm, $course);
$assignmentinstance->upload(); // Upload files

View File

@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
$module->version = 2013110500; // The current module version (Date: YYYYMMDDXX)
$module->version = 2013121900; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2013110500; // Requires this Moodle version
$module->component = 'mod_assignment'; // Full name of the plugin (used for diagnostics)
$module->cron = 60;

View File

@ -1,55 +1,31 @@
<?php
require_once("../../config.php");
require_once("lib.php");
require_once($CFG->libdir . '/completionlib.php');
require_once($CFG->libdir . '/plagiarismlib.php');
$id = optional_param('id', 0, PARAM_INT); // Course Module ID
$a = optional_param('a', 0, PARAM_INT); // Assignment ID
$id = optional_param('id', 0, PARAM_INT); // Course Module ID.
$a = optional_param('a', 0, PARAM_INT); // Assignment ID.
$url = new moodle_url('/mod/assignment/view.php');
require_login();
$PAGE->set_context(context_system::instance());
if (!$id && !$a) {
print_error('invalidcoursemodule');
}
$mapping = null;
if ($id) {
if (! $cm = get_coursemodule_from_id('assignment', $id)) {
print_error('invalidcoursemodule');
}
if (! $assignment = $DB->get_record("assignment", array("id"=>$cm->instance))) {
print_error('invalidid', 'assignment');
}
if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
print_error('coursemisconf', 'assignment');
}
$url->param('id', $id);
$mapping = $DB->get_record('assignment_upgrade', array('oldcmid' => $id), '*', IGNORE_MISSING);
} else {
if (!$assignment = $DB->get_record("assignment", array("id"=>$a))) {
print_error('invalidid', 'assignment');
}
if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
print_error('coursemisconf', 'assignment');
}
if (! $cm = get_coursemodule_from_instance("assignment", $assignment->id, $course->id)) {
print_error('invalidcoursemodule');
}
$url->param('a', $a);
$mapping = $DB->get_record('assignment_upgrade', array('oldinstance' => $a), '*', IGNORE_MISSING);
}
$PAGE->set_url($url);
require_login($course, true, $cm);
$PAGE->requires->js('/mod/assignment/assignment.js');
$classfile = "$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php";
if (!file_exists($classfile)) {
throw new moodle_exception('unsupportedsubplugin', 'assignment', new moodle_url('/course/view.php', array('id' => $course->id)), $assignment->assignmenttype);
if (!$mapping) {
$url = '';
if (has_capability('moodle/site:config', context_system::instance())) {
$url = new moodle_url('/admin/tool/assignmentupgrade/listnotupgraded.php');
}
print_error('assignmentneedsupgrade', 'assignment', $url);
}
require_once($classfile);
$assignmentclass = "assignment_$assignment->assignmenttype";
$assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm, $course);
/// Mark as viewed
$completion=new completion_info($course);
$completion->set_module_viewed($cm);
$assignmentinstance->view(); // Actually display the assignment!
$url = new moodle_url('/mod/assign/view.php', array('id' => $mapping->newcmid));
redirect($url);

View File

@ -750,20 +750,6 @@ td.eventskey {
margin-bottom: 0;
}
/* Assignment */
#page-mod-assignment-view .reportlink a {
background-color: #fcffd8;
}
#page-mod-assignment-view .generalbox {
border-color: #e5e5e5;
}
#page-mod-assignment-submissions .mform fieldset legend {
margin-top: 0.5em;
}
/* Choice */
#page-mod-choice-view #notice {

View File

@ -82,183 +82,6 @@
width: 100%;
}
/* Assignment
------------------------*/
.path-mod-assignment .reportlink {
font-size: 0.9em;
}
.path-mod-assignment #dates {
margin: 1em auto;
border: none;
}
.path-mod-assignment #dates .c0 {
background: #f6f6f6;
}
.path-mod-assignment #dates table {
margin: 0 auto;
}
.path-mod-assignment #dates table td {
border: 1px solid #ddd;
}
.path-mod-assignment .generalbox {
border: none;
}
.path-mod-assignment #intro {
border: 1px solid #ddd;
}
.path-mod-assignment .generalbox .files {
width:35%;
margin: 2em auto;
border-bottom: 1px solid #eee;
padding: 10px;
}
.path-mod-assignment #userfiles {
width: 50%;
margin: 0 auto;
padding: 10px;
}
.path-mod-assignment #userfiles .files {
width:100%;
}
.path-mod-assignment .nofiles {
text-align: center;
color: #f00;
}
.path-mod-assignment #notice {
padding: 10px 10px 0;
width: 50%;
margin: 0 auto;
}
.path-mod-assignment #notice .buttons {
margin: 0;
}
#page-mod-assignment-view .uploadbox .mform {
margin: 1em 22%;
}
#page-mod-assignment-view .uploadbox .mform .ffile {
margin-left: 27%;
width: 100%;
}
#page-mod-assignment-view .uploadbox .mform .fitemtitle {
width: 24%;
}
#page-mod-assignment-view .mform .fsubmit {
text-align: center;
}
#page-mod-assignment-view h3 {
padding-top: 1em;
}
#page-mod-assignment-view #online {
padding: 10px;
width: 90%;
}
#online,
#onlineenter {
border: none;
margin-top: 1em;
}
#page-mod-assignment-view #onlineenter .mform {
margin: 0;
}
#page-mod-assignment-view #onlineenter .fgroup {
text-align: center;
width: 90%;
}
#page-mod-assignment-submissions .firstinitial {
margin-top: 1em;
}
#page-mod-assignment-submissions .lastinitial {
margin-bottom: 0.5em;
}
#page-mod-assignment-submissions #attempts {
font-size: 0.95em;
}
#page-mod-assignment-submissions #attempts td {
vertical-align: middle;
}
#page-mod-assignment-submissions #attempts .status .s0 {
background: #ffc;
}
#page-mod-assignment-submissions #optiontable .iconhelp {
margin-left: 3px;
}
#page-mod-assignment-submissions #optiontable #perpage {
width: 50px;
}
#page-mod-assignment-submissions .feedback .finalgrade {
margin: 5px 0;
}
#page-mod-assignment-submissions .feedback #edit-submissioncomment_tbl {
margin-bottom: 5px;
}
#page-mod-assignment-submissions .feedback .buttons input {
margin: 0 5px 10px;
}
#page-mod-assignment-submissions .feedback .mform {
width: 75%;
margin: 10px auto;
}
#page-mod-assignment-submissions .feedback .mform .fitemtitle {
width: 27%;
}
#page-mod-assignment-submissions .feedback .mform .ffile {
margin-left: 29%;
}
#page-mod-assignment-submissions .feedback .mform .fsubmit {
text-align: center;
}
#page-mod-assignment-submissions .feedback .user,
#page-mod-assignment-submissions .feedback .topic {
border-top: 1px solid #ddd;
}
#page-mod-assignment-submissions .feedback .topic .time {
font-size: 0.9em;
font-style: italic;
color: #555;
}
#page-mod-assignment-submissions .feedback .topic .singlebutton {
margin-top: 5px;
}
/* Chat
------------------------*/
@ -468,4 +291,4 @@
/* SCORM Player
-------------------------*/
#page-mod-scorm-player div.singleselect {margin: -20px 0 0;}
#page-mod-scorm-player div.singleselect {margin: -20px 0 0;}

View File

@ -35,9 +35,3 @@
.forumpost .options {
border-bottom: 5px solid #aaa;
}
/* Assignments
--------------------------*/
.path-mod-assignment #dates table .c0 {
background-color: #f5f5f5;
}

View File

@ -410,15 +410,6 @@ margin: 0;
background-position:0 0;
}
#page-mod-assignment-submissions #wrapper {
padding: 0 1%;
}
#page-mod-assignment-submissions #attempts td,
#page-mod-assignment-submissions #attempts th.header {
font-size: 80%;
}
.course-content ul.topics,
.course-content ul.weeks {
clear: both;

View File

@ -4,7 +4,6 @@
**********************************************************/
/** General **/
#page-mod-assignment-index .cell,
#page-mod-chat-index .cell,
#page-mod-choice-index .cell,
#page-mod-forum-index .generalbox .cell,
@ -16,35 +15,6 @@
.mod_introbox {width:90%;margin:1em auto;}
table.mod_index {width:90%;margin:1em auto;}
/** Assignment **/
.path-mod-assignment .feedback .files {background-color: #EFEFEF;padding:5px;}
.path-mod-assignment .feedback .time,
#page-mod-assignment-view .feedback .date {font-size: 0.8em;}
.path-mod-assignment #wordcount {font-size: 0.8em;text-align: right;}
#page-mod-assignment-submissions .feedback .content,
#page-mod-assignment-submissions .feedback .topic,
#page-mod-assignment-submissions .feedback .picture {padding: 10px;border:1px solid #DDD;}
#page-mod-assignment-submissions .generaltable .r1 {background-color: #FFFFFF;}
#page-mod-assignment-submissions .s0 {background: #FFD991;}
#page-mod-assignment-submissions table.submissions td.cell,
#page-mod-assignment-submissions table.submissions th{border:1px solid #DDD;vertical-align: middle;padding-left: 5px;padding-right: 5px;}
#page-mod-assignment-submissions .timemodified,
#page-mod-assignment-submissions .timemarked {font-size: 0.9em;}
#page-mod-assignment-submissions .fgcontrols {margin-top: 1em;text-align:center;}
#page-mod-assignment-submissions .fgcontrols .fastgbutton{margin-top: 0.5em;}
#page-mod-assignment-view #dates {font-size: 0.8em;margin:30px auto;}
#page-mod-assignment-view #dates .c0 {text-align:right;font-weight:bold;}
#page-mod-assignment-view .feedback {border:1px solid #DDD;}
#page-mod-assignment-view .feedback .topic {padding: 4px;border:0px solid #DDD;border-bottom-width: 1px;}
#page-mod-assignment-view .feedback .content {padding: 4px;}
#page-mod-assignment-view .feedback .left {width: 35px;padding: 4px;text-align: center;vertical-align: top;}
#page-mod-assignment-view #dates {font-size: 0.8em;margin:30px auto;}
#page-mod-assignment-submissions .status,
#page-mod-assignment-view #online .singlebutton {text-align: center;}
#page-mod-assignment-submissions .submissions .grade,
#page-mod-assignment-view .feedback .fullname,
#page-mod-assignment-view .feedback .grade {font-weight:bold;}
/** Chat **/
.path-mod-chat .time {font-weight: bold;}
.path-mod-chat .user {color:blue;}