mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Another big dump with many changes.
The most notable one is the new online assignment type, which is a good example of how little code really needs to be written to make new assignment types now.
This commit is contained in:
parent
3014b4f4f4
commit
f77cfb73dd
@ -98,22 +98,13 @@ class assignment_base {
|
||||
|
||||
$this->view_header();
|
||||
|
||||
print_simple_box_start('center');
|
||||
echo format_text($this->assignment->description, $this->assignment->format);
|
||||
print_simple_box_end();
|
||||
$this->view_intro();
|
||||
|
||||
print_simple_box_start('center', '', '', '', 'time');
|
||||
echo '<table>';
|
||||
echo '<tr><td class="c0">'.get_string('availabledate','assignment').':</td>';
|
||||
echo ' <td class="c1">'.userdate($this->assignment->timeavailable).'</td></tr>';
|
||||
echo '<tr><td class="c0">'.get_string('duedate','assignment').':</td>';
|
||||
echo ' <td class="c1">'.userdate($this->assignment->timedue).'</td></tr>';
|
||||
echo '</table>';
|
||||
print_simple_box_end();
|
||||
$this->view_dates();
|
||||
|
||||
$this->view_feedback();
|
||||
|
||||
print_footer($this->course);
|
||||
$this->view_footer();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -138,6 +129,38 @@ class assignment_base {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Display the assignment intro
|
||||
*/
|
||||
function view_intro() {
|
||||
print_simple_box_start('center', '', '', '', 'generalbox', 'intro');
|
||||
echo format_text($this->assignment->description, $this->assignment->format);
|
||||
print_simple_box_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Display the assignment dates
|
||||
*/
|
||||
function view_dates() {
|
||||
if (!$this->assignment->timeavailable && !$this->assignment->timedue) {
|
||||
return;
|
||||
}
|
||||
|
||||
print_simple_box_start('center', '', '', '', 'generalbox', '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>';
|
||||
}
|
||||
echo '</table>';
|
||||
print_simple_box_end();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Display the bottom of the view.php page, this doesn't change much for submodules
|
||||
*/
|
||||
@ -235,9 +258,13 @@ class assignment_base {
|
||||
"<a href=\"$CFG->wwwroot/course/view.php?id={$this->course->id}\">{$this->course->shortname} </a> -> ".
|
||||
"<a href=\"$CFG->wwwroot/mod/assignment/index.php?id={$this->course->id}\">$strassignments</a> -> $strheading");
|
||||
|
||||
print_simple_box_start("center");
|
||||
print_heading(get_string("type$form->assignmenttype",'assignment'));
|
||||
print_simple_box_start('center', '70%');
|
||||
print_heading(get_string('type'.$form->assignmenttype,'assignment'));
|
||||
print_simple_box(get_string('help'.$form->assignmenttype, 'assignment'), 'center');
|
||||
include("$CFG->dirroot/mod/assignment/type/common.html");
|
||||
|
||||
include("$CFG->dirroot/mod/assignment/type/".$form->assignmenttype."/mod.html");
|
||||
$this->setup_end();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -459,15 +486,14 @@ class assignment_base {
|
||||
echo '<br />';
|
||||
print_textarea($this->usehtmleditor, 12, 58, 0, 0, 'comment', $submission->comment, $this->course->id);
|
||||
|
||||
echo '<div align="right" class="format">';
|
||||
if ($this->usehtmleditor) {
|
||||
print_string('formathtml');
|
||||
echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
|
||||
} else {
|
||||
echo '<div align="right" class="format">';
|
||||
choose_from_menu(format_text_menu(), "format", $submission->format, "");
|
||||
helpbutton("textformat", get_string("helpformatting"));
|
||||
echo '</div>';
|
||||
}
|
||||
helpbutton("textformat", get_string("helpformatting"));
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="buttons" align="center">';
|
||||
echo '<input type="submit" name="submit" value="'.get_string('savechanges').'" />';
|
||||
@ -635,11 +661,12 @@ class assignment_base {
|
||||
}
|
||||
if ($auser->timemarked > 0) {
|
||||
$teachermodified = '<div id="tt'.$auser->id.'">'.userdate($auser->timemarked).'</div>';
|
||||
$grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>';
|
||||
} else {
|
||||
$teachermodified = '<div id="tt'.$auser->id.'"> </div>';
|
||||
$grade = '<div id="g'.$auser->id.'"></div>';
|
||||
}
|
||||
|
||||
$grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>';
|
||||
$comment = '<div id="com'.$auser->id.'">'.shorten_text($auser->comment, 15).'</div>';
|
||||
|
||||
} else {
|
||||
@ -714,7 +741,13 @@ class assignment_base {
|
||||
}
|
||||
|
||||
|
||||
function get_submission($userid, $createnew=false) {
|
||||
function get_submission($userid=0, $createnew=false) {
|
||||
global $USER;
|
||||
|
||||
if (empty($userid)) {
|
||||
$userid = $USER->id;
|
||||
}
|
||||
|
||||
$submission = get_record('assignment_submissions', 'assignment', $this->assignment->id, 'userid', $userid);
|
||||
|
||||
if ($submission || !$createnew) {
|
||||
@ -904,6 +937,15 @@ class assignment_base {
|
||||
return make_upload_directory( $this->file_area_name($userid) );
|
||||
}
|
||||
|
||||
function isopen() {
|
||||
$time = time();
|
||||
if ($this->assignment->preventlate) {
|
||||
return ($this->assignment->timeavailable <= $time && $time <= $this->assignment->timedue);
|
||||
} else {
|
||||
return ($this->assignment->timeavailable <= $time);
|
||||
}
|
||||
}
|
||||
|
||||
function user_outline($user) {
|
||||
if ($submission = $this->get_submission($user->id)) {
|
||||
|
||||
|
@ -116,7 +116,7 @@
|
||||
<?php
|
||||
$ASSIGNMENT_TYPES = assignment_types();
|
||||
choose_from_menu($ASSIGNMENT_TYPES, "assignmenttype", $form->assignmenttype, "");
|
||||
helpbutton("assignmenttype", get_string("assignmenttype", "assignment"), "assignment");
|
||||
helpbutton("assignment/types", get_string("assignmenttype", "assignment"), "moodle");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
@ -132,7 +132,7 @@
|
||||
<input type="hidden" name="modulename" value="<?php p($form->modulename) ?>" />
|
||||
<input type="hidden" name="instance" value="<?php p($form->instance) ?>" />
|
||||
<input type="hidden" name="mode" value="<?php p($form->mode) ?>" />
|
||||
<input type="submit" value="<?php print_string('next') ?>" />
|
||||
<input type="submit" value="<?php print_string('next') ?> »" />
|
||||
<input type="submit" name=cancel value="<?php print_string('cancel') ?>" />
|
||||
</center>
|
||||
</form>
|
||||
|
@ -77,6 +77,20 @@
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#mod-assignment-view #online .singlebutton {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#mod-assignment-view #dates {
|
||||
font-size: 0.8em;
|
||||
margin-top: 30px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
#mod-assignment-view #dates .c0{
|
||||
text-align:right;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
#mod-assignment-view .feedback {
|
||||
border-width:1px;
|
||||
|
@ -10,14 +10,6 @@ class assignment_offline extends assignment_base {
|
||||
parent::assignment_base($cmid);
|
||||
}
|
||||
|
||||
function setup($form) {
|
||||
global $CFG, $usehtmleditor;
|
||||
|
||||
parent::setup($form);
|
||||
include("$CFG->dirroot/mod/assignment/type/offline/mod.html");
|
||||
parent::setup_end();
|
||||
}
|
||||
|
||||
function submittedlink() {
|
||||
global $USER;
|
||||
|
||||
|
205
mod/assignment/type/online/assignment.class.php
Normal file
205
mod/assignment/type/online/assignment.class.php
Normal file
@ -0,0 +1,205 @@
|
||||
<?php // $Id$
|
||||
|
||||
/**
|
||||
* Extend the base assignment class for assignments where you upload a single file
|
||||
*
|
||||
*/
|
||||
class assignment_online extends assignment_base {
|
||||
|
||||
function assignment_online($cmid=0) {
|
||||
parent::assignment_base($cmid);
|
||||
|
||||
}
|
||||
|
||||
function submittedlink() {
|
||||
global $USER;
|
||||
|
||||
$submitted = '';
|
||||
|
||||
if (isteacher($this->course->id)) {
|
||||
if ($this->currentgroup and isteacheredit($this->course->id)) {
|
||||
$group = get_record('groups', 'id', $this->currentgroup);
|
||||
$groupname = ' ('.$group->name.')';
|
||||
} else {
|
||||
$groupname = '';
|
||||
}
|
||||
$count = $this->count_real_submissions($this->currentgroup);
|
||||
$submitted = '<a href="submissions.php?id='.$this->cm->id.'">'.
|
||||
get_string('viewsubmissions', 'assignment', $count).'</a>'.$groupname;
|
||||
} else {
|
||||
if (isset($USER->id)) {
|
||||
if ($submission = $this->get_submission()) {
|
||||
if ($submission->timemodified <= $this->assignment->timedue) {
|
||||
$submitted = userdate($submission->timemodified);
|
||||
} else {
|
||||
$submitted = '<span class="late">'.userdate($submission->timemodified).'</span>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $submitted;
|
||||
}
|
||||
|
||||
function view() {
|
||||
|
||||
global $USER;
|
||||
|
||||
$editmode = ($this->isopen() && !empty($_GET['edit']));
|
||||
|
||||
if ($editmode) {
|
||||
$this->view_header(get_string('editmysubmission', 'assignment'));
|
||||
} else {
|
||||
$this->view_header();
|
||||
}
|
||||
|
||||
$this->view_intro();
|
||||
|
||||
$this->view_dates();
|
||||
|
||||
if ($data = data_submitted()) { // No incoming data?
|
||||
if ($this->update_submission($data)) {
|
||||
notify(get_string('submissionsaved', 'assignment'));
|
||||
}
|
||||
}
|
||||
|
||||
print_simple_box_start('center', '70%', '', '', 'generalbox', 'online');
|
||||
$submission = $this->get_submission();
|
||||
if ($editmode) {
|
||||
$this->view_edit_form($submission);
|
||||
} else {
|
||||
if ($submission) {
|
||||
echo format_text($submission->data1, $submission->data2);
|
||||
} else {
|
||||
print_string('emptysubmission', 'assignment');
|
||||
}
|
||||
if ($this->isopen()) {
|
||||
print_single_button('view.php', array('id'=>$this->cm->id,'edit'=>'1'),
|
||||
get_string('editmysubmission', 'assignment'));
|
||||
}
|
||||
}
|
||||
print_simple_box_end();
|
||||
|
||||
if ($editmode and $this->usehtmleditor) {
|
||||
use_html_editor(); // MUst be at the end of the page
|
||||
}
|
||||
|
||||
$this->view_feedback();
|
||||
|
||||
$this->view_footer();
|
||||
}
|
||||
|
||||
function view_edit_form($submission = NULL) {
|
||||
global $CFG;
|
||||
|
||||
$defaulttext = $submission ? $submission->data1 : '';
|
||||
$defaultformat = $submission ? $submission->data2 : $this->defaultformat;
|
||||
|
||||
echo '<form name="theform" action="view.php?id='.$this->cm->id.'" method="post">'; // do this so URLs look good
|
||||
|
||||
echo '<table cellspacing="0" class="editbox" align="center">';
|
||||
echo '<tr><td align="right">';
|
||||
helpbutton('reading', get_string('helpreading'), 'moodle', true, true);
|
||||
echo '<br />';
|
||||
helpbutton('writing', get_string('helpwriting'), 'moodle', true, true);
|
||||
echo '<br />';
|
||||
if ($this->usehtmleditor) {
|
||||
helpbutton('richtext', get_string('helprichtext'), 'moodle', true, true);
|
||||
} else {
|
||||
emoticonhelpbutton('theform', 'text');
|
||||
}
|
||||
echo '<br />';
|
||||
echo '</td></tr>';
|
||||
echo '<tr><td align="center">';
|
||||
print_textarea($this->usehtmleditor, 20, 60, 630, 400, 'text', $defaulttext);
|
||||
if (!$this->usehtmleditor) {
|
||||
echo '<div align="right" class="format">';
|
||||
print_string('formattexttype');
|
||||
echo ': ';
|
||||
choose_from_menu(format_text_menu(), 'format', $defaultformat, '');
|
||||
helpbutton('textformat', get_string('helpformatting'));
|
||||
echo '</div>';
|
||||
} else {
|
||||
echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
|
||||
}
|
||||
echo '</td></tr>';
|
||||
echo '<tr><td align="center">';
|
||||
echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />';
|
||||
echo '<input type="submit" value="'.get_string('savechanges').'" />';
|
||||
echo '<input type="reset" value="'.get_string('revert').'" />';
|
||||
echo '</td></tr></table>';
|
||||
|
||||
echo '</form>';
|
||||
|
||||
}
|
||||
|
||||
function update_submission($data) {
|
||||
global $CFG, $USER;
|
||||
|
||||
$submission = $this->get_submission($USER->id, true);
|
||||
|
||||
$submission->data1 = $data->text;
|
||||
$submission->format = $data->format;
|
||||
$submission->timemodified = time();
|
||||
|
||||
return update_record('assignment_submissions', $submission);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Display and process the submissions
|
||||
*/
|
||||
function process_feedback() {
|
||||
|
||||
global $USER;
|
||||
|
||||
if (!$feedback = data_submitted()) { // No incoming data?
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($feedback->cancel)) { // User hit cancel button
|
||||
return false;
|
||||
}
|
||||
|
||||
$newsubmission = $this->get_submission($feedback->userid, true); // Get or make one
|
||||
|
||||
$newsubmission->grade = $feedback->grade;
|
||||
$newsubmission->comment = $feedback->comment;
|
||||
$newsubmission->format = $feedback->format;
|
||||
$newsubmission->teacher = $USER->id;
|
||||
$newsubmission->mailed = 0; // Make sure mail goes out (again, even)
|
||||
$newsubmission->timemarked = time();
|
||||
|
||||
if (! update_record('assignment_submissions', $newsubmission)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
add_to_log($this->course->id, 'assignment', 'update grades',
|
||||
'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
|
||||
|
||||
return $newsubmission;
|
||||
|
||||
}
|
||||
|
||||
function print_user_files($userid, $return=false) {
|
||||
global $CFG;
|
||||
|
||||
if (!$submission = $this->get_submission($userid)) {
|
||||
return '';
|
||||
}
|
||||
$output = '<div class="files">'.
|
||||
'<img align="middle" src="'.$CFG->pixpath.'/f/html.gif" height="16" width="16" alt="html" />'.
|
||||
link_to_popup_window ('/mod/assignment/type/online/file.php?id='.$this->cm->id.'&userid='.
|
||||
$submission->userid, 'file'.$userid, shorten_text($submission->data1, 15), 450, 580,
|
||||
get_string('submission', 'assignment'), 'none', true).
|
||||
'</div>';
|
||||
|
||||
if ($return) {
|
||||
return $output;
|
||||
}
|
||||
echo $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
48
mod/assignment/type/online/file.php
Normal file
48
mod/assignment/type/online/file.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php // $Id$
|
||||
|
||||
require_once("../../../../config.php");
|
||||
require_once("../../lib.php");
|
||||
|
||||
$id = required_param('id', PARAM_INT); // Course Module ID
|
||||
$userid = required_param('userid', PARAM_INT); // Course Module ID
|
||||
|
||||
if (!empty($CFG->forcelogin)) {
|
||||
require_login();
|
||||
}
|
||||
|
||||
if (! $cm = get_record("course_modules", "id", $id)) {
|
||||
error("Course Module ID was incorrect");
|
||||
}
|
||||
|
||||
if (! $assignment = get_record("assignment", "id", $cm->instance)) {
|
||||
error("assignment ID was incorrect");
|
||||
}
|
||||
|
||||
if (! $course = get_record("course", "id", $assignment->course)) {
|
||||
error("Course is misconfigured");
|
||||
}
|
||||
|
||||
if (! $user = get_record("user", "id", $userid)) {
|
||||
error("User is misconfigured");
|
||||
}
|
||||
|
||||
require_login($course->id, false, $cm);
|
||||
|
||||
if (!isteacher($course->id)) {
|
||||
error("Only teachers can look at this page");
|
||||
}
|
||||
|
||||
require ("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php");
|
||||
$assignmentclass = "assignment_$assignment->assignmenttype";
|
||||
$assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm, $course);
|
||||
|
||||
if ($submission = $assignmentinstance->get_submission($userid)) {
|
||||
print_header(fullname($user,true).': '.$assignment->name);
|
||||
print_simple_box(format_text($submission->data1, $submission->data2), 'center', '100%');
|
||||
close_window_button();
|
||||
print_footer('none');
|
||||
} else {
|
||||
print_string('emptysubmission', 'assignment');
|
||||
}
|
||||
|
||||
?>
|
54
mod/assignment/type/online/mod.html
Normal file
54
mod/assignment/type/online/mod.html
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
if (!isset($form->resubmit)) {
|
||||
$form->resubmit = 1;
|
||||
}
|
||||
if (!isset($form->emailteachers)) {
|
||||
$form->emailteachers = 0;
|
||||
}
|
||||
if (!isset($form->var1)) {
|
||||
$form->var1 = 0;
|
||||
}
|
||||
?>
|
||||
|
||||
<table align="center" cellpadding="5" cellspacing="0">
|
||||
|
||||
<tr>
|
||||
<td align="right"><b><?php print_string("allowresubmit", "assignment") ?>:</b></td>
|
||||
<td>
|
||||
<?php
|
||||
$options[0] = get_string("no"); $options[1] = get_string("yes");
|
||||
choose_from_menu($options, "resubmit", $form->resubmit, "");
|
||||
helpbutton("resubmit", get_string("allowresubmit", "assignment"), "assignment");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td align="right"><b><?php print_string("emailteachers", "assignment") ?>:</b></td>
|
||||
<td>
|
||||
<?php
|
||||
$options[0] = get_string("no"); $options[1] = get_string("yes");
|
||||
choose_from_menu($options, "emailteachers", $form->emailteachers, "");
|
||||
helpbutton("emailteachers", get_string("emailteachers", "assignment"), "assignment");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td align="right"><b><?php print_string("commentinline", "assignment") ?>:</b></td>
|
||||
<td>
|
||||
<?php
|
||||
$options[0] = get_string("no"); $options[1] = get_string("yes");
|
||||
choose_from_menu($options, "var1", $form->var1, "");
|
||||
helpbutton("commentinline", get_string("commentinline", "assignment"), "assignment");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
<center>
|
||||
<br />
|
||||
<input type="submit" value="<?php print_string("continue") ?>" />
|
||||
</center>
|
@ -11,17 +11,6 @@ class assignment_uploadsingle extends assignment_base {
|
||||
|
||||
}
|
||||
|
||||
function setup($form) {
|
||||
global $CFG, $usehtmleditor;
|
||||
|
||||
parent::setup($form);
|
||||
|
||||
print_simple_box(get_string('', 'assignment'), 'center');
|
||||
|
||||
include("$CFG->dirroot/mod/assignment/type/uploadsingle/mod.html");
|
||||
parent::setup_end();
|
||||
}
|
||||
|
||||
function submittedlink() {
|
||||
global $USER;
|
||||
|
||||
@ -58,18 +47,9 @@ class assignment_uploadsingle extends assignment_base {
|
||||
|
||||
$this->view_header();
|
||||
|
||||
print_simple_box_start('center');
|
||||
echo format_text($this->assignment->description, $this->assignment->format);
|
||||
print_simple_box_end();
|
||||
$this->view_intro();
|
||||
|
||||
print_simple_box_start('center', '', '', '', 'time');
|
||||
echo '<table>';
|
||||
echo '<tr><td class="c0">'.get_string('availabledate','assignment').':</td>';
|
||||
echo ' <td class="c1">'.userdate($this->assignment->timeavailable).'</td></tr>';
|
||||
echo '<tr><td class="c0">'.get_string('duedate','assignment').':</td>';
|
||||
echo ' <td class="c1">'.userdate($this->assignment->timedue).'</td></tr>';
|
||||
echo '</table>';
|
||||
print_simple_box_end();
|
||||
$this->view_dates();
|
||||
|
||||
$this->view_feedback();
|
||||
|
||||
@ -164,6 +144,7 @@ class assignment_uploadsingle extends assignment_base {
|
||||
|
||||
$newsubmission->grade = $feedback->grade;
|
||||
$newsubmission->comment = $feedback->comment;
|
||||
$newsubmission->format = $feedback->format;
|
||||
$newsubmission->teacher = $USER->id;
|
||||
$newsubmission->mailed = 0; // Make sure mail goes out (again, even)
|
||||
$newsubmission->timemarked = time();
|
||||
|
@ -10,7 +10,7 @@
|
||||
}
|
||||
?>
|
||||
|
||||
<table cellpadding="5" cellspacing="0">
|
||||
<table align="center" cellpadding="5" cellspacing="0">
|
||||
|
||||
<tr valign="top">
|
||||
<td align="right"><b><?php print_string("maximumsize", "assignment") ?>:</b></td>
|
||||
|
Loading…
x
Reference in New Issue
Block a user