2006-02-16 21:56:57 +00:00
|
|
|
<?PHP // $Id$
|
2005-04-14 13:24:40 +00:00
|
|
|
/**
|
|
|
|
* assignment_base is the base class for assignment types
|
|
|
|
*
|
|
|
|
* This class provides all the functionality for an assignment
|
|
|
|
*/
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2006-01-05 16:27:20 +00:00
|
|
|
DEFINE ('ASSIGNMENT_COUNT_WORDS', 1);
|
|
|
|
DEFINE ('ASSIGNMENT_COUNT_LETTERS', 2);
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
2005-04-14 13:24:40 +00:00
|
|
|
* Standard base class for all assignment submodules (assignment types).
|
|
|
|
*/
|
|
|
|
class assignment_base {
|
|
|
|
|
|
|
|
var $cm;
|
|
|
|
var $course;
|
|
|
|
var $assignment;
|
2006-02-19 13:26:58 +00:00
|
|
|
var $strassignment;
|
|
|
|
var $strassignments;
|
|
|
|
var $strsubmissions;
|
|
|
|
var $strlastmodified;
|
|
|
|
var $pagetitle;
|
|
|
|
var $currentgroup;
|
|
|
|
var $usehtmleditor;
|
|
|
|
var $defaultformat;
|
2006-09-30 15:41:20 +00:00
|
|
|
var $context;
|
2007-11-29 14:43:04 +00:00
|
|
|
var $type;
|
2005-04-14 13:24:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for the base assignment class
|
|
|
|
*
|
|
|
|
* Constructor for the base assignment class.
|
|
|
|
* If cmid is set create the cm, course, assignment objects.
|
2006-02-19 13:26:58 +00:00
|
|
|
* If the assignment is hidden and the user is not a teacher then
|
|
|
|
* this prints a page header and notice.
|
2005-04-14 13:24:40 +00:00
|
|
|
*
|
|
|
|
* @param cmid integer, the current course module id - not set for new assignments
|
2005-04-17 15:38:02 +00:00
|
|
|
* @param assignment object, usually null, but if we have it we pass it to save db access
|
2006-02-19 13:26:58 +00:00
|
|
|
* @param cm object, usually null, but if we have it we pass it to save db access
|
|
|
|
* @param course object, usually null, but if we have it we pass it to save db access
|
2005-04-14 13:24:40 +00:00
|
|
|
*/
|
2007-05-28 08:55:15 +00:00
|
|
|
function assignment_base($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
|
2008-01-24 20:33:50 +00:00
|
|
|
global $COURSE;
|
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
if ($cmid == 'staticonly') {
|
|
|
|
//use static functions only!
|
|
|
|
return;
|
|
|
|
}
|
2005-04-14 13:24:40 +00:00
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
if ($cm) {
|
|
|
|
$this->cm = $cm;
|
|
|
|
} else if (! $this->cm = get_coursemodule_from_id('assignment', $cmid)) {
|
|
|
|
error('Course Module ID was incorrect');
|
|
|
|
}
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
|
2006-09-30 15:41:20 +00:00
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
if ($course) {
|
|
|
|
$this->course = $course;
|
2008-01-24 20:33:50 +00:00
|
|
|
} else if ($this->cm->course == $COURSE->id) {
|
|
|
|
$this->course = $COURSE;
|
2007-05-28 08:55:15 +00:00
|
|
|
} else if (! $this->course = get_record('course', 'id', $this->cm->course)) {
|
|
|
|
error('Course is misconfigured');
|
|
|
|
}
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
if ($assignment) {
|
|
|
|
$this->assignment = $assignment;
|
|
|
|
} else if (! $this->assignment = get_record('assignment', 'id', $this->cm->instance)) {
|
|
|
|
error('assignment ID was incorrect');
|
|
|
|
}
|
|
|
|
|
2007-05-31 20:34:41 +00:00
|
|
|
$this->assignment->cmidnumber = $this->cm->id; // compatibility with modedit assignment obj
|
|
|
|
$this->assignment->courseid = $this->course->id; // compatibility with modedit assignment obj
|
2004-04-01 15:40:39 +00:00
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
$this->strassignment = get_string('modulename', 'assignment');
|
|
|
|
$this->strassignments = get_string('modulenameplural', 'assignment');
|
|
|
|
$this->strsubmissions = get_string('submissions', 'assignment');
|
|
|
|
$this->strlastmodified = get_string('lastmodified');
|
|
|
|
$this->pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment.': '.format_string($this->assignment->name,true));
|
|
|
|
|
|
|
|
// visibility
|
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cmid);
|
|
|
|
if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
|
|
|
|
$pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment);
|
2007-10-12 15:55:49 +00:00
|
|
|
$navigation = build_navigation('', $this->cm);
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2007-10-12 15:55:49 +00:00
|
|
|
print_header($pagetitle, $this->course->fullname, $navigation,
|
2007-05-28 08:55:15 +00:00
|
|
|
"", "", true, '', navmenu($this->course, $this->cm));
|
|
|
|
notice(get_string("activityiscurrentlyhidden"), "$CFG->wwwroot/course/view.php?id={$this->course->id}");
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
2007-08-26 23:50:08 +00:00
|
|
|
$this->currentgroup = groups_get_activity_group($this->cm);
|
2004-04-01 15:40:39 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
/// Set up things for a HTML editor if it's needed
|
|
|
|
if ($this->usehtmleditor = can_use_html_editor()) {
|
|
|
|
$this->defaultformat = FORMAT_HTML;
|
|
|
|
} else {
|
|
|
|
$this->defaultformat = FORMAT_MOODLE;
|
2004-04-01 15:40:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Display the assignment, used by view.php
|
|
|
|
*
|
|
|
|
* This in turn calls the methods producing individual parts of the page
|
2005-04-14 13:24:40 +00:00
|
|
|
*/
|
|
|
|
function view() {
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2006-08-09 13:45:49 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE,$this->cm->id);
|
2006-08-14 05:55:40 +00:00
|
|
|
require_capability('mod/assignment:view', $context);
|
2007-06-03 09:10:52 +00:00
|
|
|
|
|
|
|
add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}",
|
2005-04-14 13:24:40 +00:00
|
|
|
$this->assignment->id, $this->cm->id);
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
$this->view_header();
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2005-04-18 09:29:09 +00:00
|
|
|
$this->view_intro();
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2005-04-18 09:29:09 +00:00
|
|
|
$this->view_dates();
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
$this->view_feedback();
|
|
|
|
|
2005-04-18 09:29:09 +00:00
|
|
|
$this->view_footer();
|
2004-05-17 16:24:19 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Display the header and top of a page
|
|
|
|
*
|
|
|
|
* (this doesn't change much for assignment types)
|
|
|
|
* This is used by the view() method to print the header of view.php but
|
|
|
|
* it can be used on other pages in which case the string to denote the
|
|
|
|
* page in the navigation trail should be passed as an argument
|
|
|
|
*
|
|
|
|
* @param $subpage string Description of subpage to be used in navigation trail
|
2005-04-17 15:38:02 +00:00
|
|
|
*/
|
|
|
|
function view_header($subpage='') {
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
if ($subpage) {
|
2007-10-12 15:55:49 +00:00
|
|
|
$navigation = build_navigation($subpage, $this->cm);
|
2005-04-17 15:38:02 +00:00
|
|
|
} else {
|
2007-10-12 15:55:49 +00:00
|
|
|
$navigation = build_navigation('', $this->cm);
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
|
|
|
print_header($this->pagetitle, $this->course->fullname, $navigation, '', '',
|
|
|
|
true, update_module_button($this->cm->id, $this->course->id, $this->strassignment),
|
2005-04-17 15:38:02 +00:00
|
|
|
navmenu($this->course, $this->cm));
|
|
|
|
|
2007-08-26 23:50:08 +00:00
|
|
|
$groupmode = groups_get_activity_groupmode($this->cm);
|
|
|
|
groups_print_activity_menu($this->cm, 'view.php?id=' . $this->cm->id);
|
2008-01-24 20:33:50 +00:00
|
|
|
$this->currentgroup = groups_get_activity_group($this->cm); // must be done after the printing!
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
echo '<div class="reportlink">'.$this->submittedlink().'</div>';
|
2007-05-28 08:55:15 +00:00
|
|
|
echo '<div class="clearer"></div>';
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
2005-04-18 09:29:09 +00:00
|
|
|
* Display the assignment intro
|
2006-02-19 13:26:58 +00:00
|
|
|
*
|
|
|
|
* This will most likely be extended by assignment type plug-ins
|
|
|
|
* The default implementation prints the assignment description in a box
|
2005-04-18 09:29:09 +00:00
|
|
|
*/
|
|
|
|
function view_intro() {
|
2006-11-30 09:50:01 +00:00
|
|
|
print_simple_box_start('center', '', '', 0, 'generalbox', 'intro');
|
2005-07-05 06:03:04 +00:00
|
|
|
$formatoptions = new stdClass;
|
|
|
|
$formatoptions->noclean = true;
|
|
|
|
echo format_text($this->assignment->description, $this->assignment->format, $formatoptions);
|
2005-04-18 09:29:09 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
2005-04-18 09:29:09 +00:00
|
|
|
* Display the assignment dates
|
2006-02-19 13:26:58 +00:00
|
|
|
*
|
|
|
|
* Prints the assignment start and end dates in a box.
|
|
|
|
* This will be suitable for most assignment types
|
2005-04-18 09:29:09 +00:00
|
|
|
*/
|
|
|
|
function view_dates() {
|
|
|
|
if (!$this->assignment->timeavailable && !$this->assignment->timedue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-11-30 09:50:01 +00:00
|
|
|
print_simple_box_start('center', '', '', 0, 'generalbox', 'dates');
|
2005-04-18 09:29:09 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Display the bottom and footer of a page
|
|
|
|
*
|
|
|
|
* This default method just prints the footer.
|
|
|
|
* This will be suitable for most assignment types
|
2005-04-17 15:38:02 +00:00
|
|
|
*/
|
|
|
|
function view_footer() {
|
|
|
|
print_footer($this->course);
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Display the feedback to the student
|
|
|
|
*
|
|
|
|
* This default method prints the teacher picture and name, date when marked,
|
2006-09-21 09:35:20 +00:00
|
|
|
* grade and teacher submissioncomment.
|
2006-02-19 13:26:58 +00:00
|
|
|
*
|
|
|
|
* @param $submission object The submission object or NULL in which case it will be loaded
|
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
function view_feedback($submission=NULL) {
|
2007-09-23 16:05:41 +00:00
|
|
|
global $USER, $CFG;
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
|
|
|
|
if (!has_capability('mod/assignment:submit', $this->context, $USER->id, false)) {
|
|
|
|
// can not submit assignments -> no feedback
|
|
|
|
return;
|
|
|
|
}
|
2004-04-01 15:40:39 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
if (!$submission) { /// Get submission for this assignment
|
|
|
|
$submission = $this->get_submission($USER->id);
|
2005-04-17 17:11:41 +00:00
|
|
|
}
|
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $USER->id);
|
|
|
|
$item = $grading_info->items[0];
|
|
|
|
$grade = $item->grades[$USER->id];
|
|
|
|
|
|
|
|
if ($grade->hidden or $grade->grade === false) { // hidden or error
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-18 15:36:45 +00:00
|
|
|
if ($grade->grade === null and empty($grade->str_feedback)) { /// Nothing to show yet
|
2005-04-17 17:11:41 +00:00
|
|
|
return;
|
2004-04-09 23:55:02 +00:00
|
|
|
}
|
2004-04-01 15:40:39 +00:00
|
|
|
|
2007-11-01 08:25:05 +00:00
|
|
|
$graded_date = $grade->dategraded;
|
2007-11-16 02:52:48 +00:00
|
|
|
$graded_by = $grade->usermodified;
|
2004-04-01 15:40:39 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
/// We need the teacher info
|
|
|
|
$teacher = get_record('user', 'id', $graded_by);
|
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
/// Print the feedback
|
2007-09-23 16:05:41 +00:00
|
|
|
print_heading(get_string('feedbackfromteacher', 'assignment', $this->course->teacher)); // TODO: fix teacher string
|
2005-04-15 14:19:24 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
echo '<table cellspacing="0" class="feedback">';
|
|
|
|
|
|
|
|
echo '<tr>';
|
|
|
|
echo '<td class="left picture">';
|
2007-09-23 16:05:41 +00:00
|
|
|
if ($teacher) {
|
|
|
|
print_user_picture($teacher->id, $this->course->id, $teacher->picture);
|
|
|
|
}
|
2005-04-14 13:24:40 +00:00
|
|
|
echo '</td>';
|
2005-04-15 14:19:24 +00:00
|
|
|
echo '<td class="topic">';
|
2005-04-17 17:11:41 +00:00
|
|
|
echo '<div class="from">';
|
2007-09-23 16:05:41 +00:00
|
|
|
if ($teacher) {
|
|
|
|
echo '<div class="fullname">'.fullname($teacher).'</div>';
|
|
|
|
}
|
|
|
|
echo '<div class="time">'.userdate($graded_date).'</div>';
|
2005-04-17 17:11:41 +00:00
|
|
|
echo '</div>';
|
2005-04-14 13:24:40 +00:00
|
|
|
echo '</td>';
|
|
|
|
echo '</tr>';
|
|
|
|
|
|
|
|
echo '<tr>';
|
|
|
|
echo '<td class="left side"> </td>';
|
2005-04-15 14:19:24 +00:00
|
|
|
echo '<td class="content">';
|
2007-09-23 16:05:41 +00:00
|
|
|
echo '<div class="grade">';
|
2008-01-21 18:46:31 +00:00
|
|
|
echo get_string("grade").': '.$grade->str_long_grade;
|
2007-09-23 16:05:41 +00:00
|
|
|
echo '</div>';
|
|
|
|
echo '<div class="clearer"></div>';
|
2004-05-05 07:07:56 +00:00
|
|
|
|
2005-04-15 14:19:24 +00:00
|
|
|
echo '<div class="comment">';
|
2007-09-23 16:05:41 +00:00
|
|
|
echo $grade->str_feedback;
|
2005-04-15 14:19:24 +00:00
|
|
|
echo '</div>';
|
2005-04-14 13:24:40 +00:00
|
|
|
echo '</tr>';
|
|
|
|
|
|
|
|
echo '</table>';
|
2004-04-01 15:40:39 +00:00
|
|
|
}
|
|
|
|
|
2007-06-03 09:10:52 +00:00
|
|
|
/**
|
2005-04-20 06:49:49 +00:00
|
|
|
* Returns a link with info about the state of the assignment submissions
|
2006-02-19 13:26:58 +00:00
|
|
|
*
|
|
|
|
* This is used by view_header to put this link at the top right of the page.
|
|
|
|
* For teachers it gives the number of submitted assignments with a link
|
|
|
|
* For students it gives the time of their submission.
|
|
|
|
* This will be suitable for most assignment types.
|
2008-01-24 20:33:50 +00:00
|
|
|
* @param bool $allgroup print all groups info if user can access all groups, suitable for index.php
|
2006-02-19 13:26:58 +00:00
|
|
|
* @return string
|
2005-04-20 06:49:49 +00:00
|
|
|
*/
|
2008-01-24 20:33:50 +00:00
|
|
|
function submittedlink($allgroups=false) {
|
2005-04-20 06:49:49 +00:00
|
|
|
global $USER;
|
|
|
|
|
|
|
|
$submitted = '';
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE,$this->cm->id);
|
2006-08-28 08:42:30 +00:00
|
|
|
if (has_capability('mod/assignment:grade', $context)) {
|
2008-01-24 20:33:50 +00:00
|
|
|
if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) {
|
|
|
|
$group = 0;
|
2005-04-20 06:49:49 +00:00
|
|
|
} else {
|
2008-01-24 20:33:50 +00:00
|
|
|
$group = $this->currentgroup;
|
|
|
|
}
|
|
|
|
if ($count = $this->count_real_submissions($group)) {
|
|
|
|
$submitted = '<a href="submissions.php?id='.$this->cm->id.'">'.
|
|
|
|
get_string('viewsubmissions', 'assignment', $count).'</a>';
|
|
|
|
} else {
|
|
|
|
$submitted = '<a href="submissions.php?id='.$this->cm->id.'">'.
|
|
|
|
get_string('noattempts', 'assignment').'</a>';
|
2005-04-20 06:49:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-09-02 11:44:04 +00:00
|
|
|
if (!empty($USER->id)) {
|
2005-04-20 06:49:49 +00:00
|
|
|
if ($submission = $this->get_submission($USER->id)) {
|
|
|
|
if ($submission->timemodified) {
|
2005-07-05 06:03:04 +00:00
|
|
|
if ($submission->timemodified <= $this->assignment->timedue || empty($this->assignment->timedue)) {
|
2005-04-20 06:49:49 +00:00
|
|
|
$submitted = '<span class="early">'.userdate($submission->timemodified).'</span>';
|
|
|
|
} else {
|
|
|
|
$submitted = '<span class="late">'.userdate($submission->timemodified).'</span>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $submitted;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-10 13:38:04 +00:00
|
|
|
function setup_elements(&$mform) {
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2007-01-10 13:38:04 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Create a new assignment activity
|
|
|
|
*
|
|
|
|
* Given an object containing all the necessary data,
|
|
|
|
* (defined by the form in mod.html) this function
|
|
|
|
* will create a new instance and return the id number
|
|
|
|
* of the new instance.
|
|
|
|
* The due data is added to the calendar
|
|
|
|
* This is common to all assignment types.
|
|
|
|
*
|
|
|
|
* @param $assignment object The data from the form on mod.html
|
|
|
|
* @return int The id of the assignment
|
|
|
|
*/
|
2005-04-14 13:24:40 +00:00
|
|
|
function add_instance($assignment) {
|
2007-05-28 08:55:15 +00:00
|
|
|
global $COURSE;
|
2005-04-14 13:24:40 +00:00
|
|
|
|
|
|
|
$assignment->timemodified = time();
|
2007-05-28 08:55:15 +00:00
|
|
|
$assignment->courseid = $assignment->course;
|
2005-04-27 09:37:52 +00:00
|
|
|
|
2005-05-31 23:00:20 +00:00
|
|
|
if ($returnid = insert_record("assignment", $assignment)) {
|
2007-05-28 08:55:15 +00:00
|
|
|
$assignment->id = $returnid;
|
2005-05-31 23:00:20 +00:00
|
|
|
|
2005-07-05 06:03:04 +00:00
|
|
|
if ($assignment->timedue) {
|
2007-05-28 08:55:15 +00:00
|
|
|
$event = new object();
|
2005-07-05 06:03:04 +00:00
|
|
|
$event->name = $assignment->name;
|
|
|
|
$event->description = $assignment->description;
|
|
|
|
$event->courseid = $assignment->course;
|
|
|
|
$event->groupid = 0;
|
|
|
|
$event->userid = 0;
|
|
|
|
$event->modulename = 'assignment';
|
|
|
|
$event->instance = $returnid;
|
|
|
|
$event->eventtype = 'due';
|
|
|
|
$event->timestart = $assignment->timedue;
|
|
|
|
$event->timeduration = 0;
|
2005-05-31 23:00:20 +00:00
|
|
|
|
2005-07-05 06:03:04 +00:00
|
|
|
add_event($event);
|
|
|
|
}
|
2007-05-28 08:55:15 +00:00
|
|
|
|
|
|
|
$assignment = stripslashes_recursive($assignment);
|
2007-06-05 22:58:37 +00:00
|
|
|
assignment_grade_item_update($assignment);
|
2007-05-28 08:55:15 +00:00
|
|
|
|
2005-05-31 23:00:20 +00:00
|
|
|
}
|
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
|
2005-05-31 23:00:20 +00:00
|
|
|
return $returnid;
|
2005-04-14 13:24:40 +00:00
|
|
|
}
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Deletes an assignment activity
|
|
|
|
*
|
2006-10-18 11:14:48 +00:00
|
|
|
* Deletes all database records, files and calendar events for this assignment.
|
2006-02-19 13:26:58 +00:00
|
|
|
* @param $assignment object The assignment to be deleted
|
|
|
|
* @return boolean False indicates error
|
|
|
|
*/
|
2005-04-14 13:24:40 +00:00
|
|
|
function delete_instance($assignment) {
|
2006-10-18 11:14:48 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2007-06-01 15:13:36 +00:00
|
|
|
$assignment->courseid = $assignment->course;
|
|
|
|
|
2005-05-31 23:00:20 +00:00
|
|
|
$result = true;
|
|
|
|
|
|
|
|
if (! delete_records('assignment_submissions', 'assignment', $assignment->id)) {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! delete_records('assignment', 'id', $assignment->id)) {
|
|
|
|
$result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! delete_records('event', 'modulename', 'assignment', 'instance', $assignment->id)) {
|
|
|
|
$result = false;
|
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2006-10-18 11:14:48 +00:00
|
|
|
// delete file area with all attachments - ignore errors
|
|
|
|
require_once($CFG->libdir.'/filelib.php');
|
|
|
|
fulldelete($CFG->dataroot.'/'.$assignment->course.'/'.$CFG->moddata.'/assignment/'.$assignment->id);
|
|
|
|
|
2007-06-03 09:10:52 +00:00
|
|
|
assignment_grade_item_delete($assignment);
|
2007-06-01 15:13:36 +00:00
|
|
|
|
2005-05-31 23:00:20 +00:00
|
|
|
return $result;
|
2005-04-14 13:24:40 +00:00
|
|
|
}
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Updates a new assignment activity
|
|
|
|
*
|
|
|
|
* Given an object containing all the necessary data,
|
|
|
|
* (defined by the form in mod.html) this function
|
|
|
|
* will update the assignment instance and return the id number
|
|
|
|
* The due date is updated in the calendar
|
|
|
|
* This is common to all assignment types.
|
|
|
|
*
|
|
|
|
* @param $assignment object The data from the form on mod.html
|
|
|
|
* @return int The assignment id
|
|
|
|
*/
|
2005-04-14 13:24:40 +00:00
|
|
|
function update_instance($assignment) {
|
2007-05-28 08:55:15 +00:00
|
|
|
global $COURSE;
|
2005-04-14 13:24:40 +00:00
|
|
|
|
2005-04-27 09:37:52 +00:00
|
|
|
$assignment->timemodified = time();
|
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
$assignment->id = $assignment->instance;
|
2007-05-28 08:55:15 +00:00
|
|
|
$assignment->courseid = $assignment->course;
|
2005-05-31 23:00:20 +00:00
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
if (!update_record('assignment', $assignment)) {
|
|
|
|
return false;
|
|
|
|
}
|
2005-05-31 23:00:20 +00:00
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
if ($assignment->timedue) {
|
|
|
|
$event = new object();
|
2005-05-31 23:00:20 +00:00
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
if ($event->id = get_field('event', 'id', 'modulename', 'assignment', 'instance', $assignment->id)) {
|
2005-05-31 23:00:20 +00:00
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
$event->name = $assignment->name;
|
|
|
|
$event->description = $assignment->description;
|
|
|
|
$event->timestart = $assignment->timedue;
|
2005-05-31 23:00:20 +00:00
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
update_event($event);
|
2005-07-05 06:30:07 +00:00
|
|
|
} else {
|
2007-05-28 08:55:15 +00:00
|
|
|
$event = new object();
|
|
|
|
$event->name = $assignment->name;
|
|
|
|
$event->description = $assignment->description;
|
|
|
|
$event->courseid = $assignment->course;
|
|
|
|
$event->groupid = 0;
|
|
|
|
$event->userid = 0;
|
|
|
|
$event->modulename = 'assignment';
|
|
|
|
$event->instance = $assignment->id;
|
|
|
|
$event->eventtype = 'due';
|
|
|
|
$event->timestart = $assignment->timedue;
|
|
|
|
$event->timeduration = 0;
|
|
|
|
|
|
|
|
add_event($event);
|
2005-05-31 23:00:20 +00:00
|
|
|
}
|
2007-05-28 08:55:15 +00:00
|
|
|
} else {
|
|
|
|
delete_records('event', 'modulename', 'assignment', 'instance', $assignment->id);
|
2005-05-31 23:00:20 +00:00
|
|
|
}
|
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
// get existing grade item
|
|
|
|
$assignment = stripslashes_recursive($assignment);
|
2007-05-29 00:56:44 +00:00
|
|
|
|
2007-06-03 09:10:52 +00:00
|
|
|
assignment_grade_item_update($assignment);
|
2007-05-28 08:55:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-06-03 09:10:52 +00:00
|
|
|
* Update grade item for this submission.
|
2007-05-28 08:55:15 +00:00
|
|
|
*/
|
2007-06-03 09:10:52 +00:00
|
|
|
function update_grade($submission) {
|
2007-06-05 22:58:37 +00:00
|
|
|
assignment_update_grades($this->assignment, $submission->userid);
|
2005-04-14 13:24:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
2005-04-14 13:24:40 +00:00
|
|
|
* Top-level function for handling of submissions called by submissions.php
|
2006-02-19 13:26:58 +00:00
|
|
|
*
|
|
|
|
* This is for handling the teacher interaction with the grading interface
|
|
|
|
* This should be suitable for most assignment types.
|
|
|
|
*
|
|
|
|
* @param $mode string Specifies the kind of teacher interaction taking place
|
2005-04-14 13:24:40 +00:00
|
|
|
*/
|
|
|
|
function submissions($mode) {
|
2005-11-03 06:25:00 +00:00
|
|
|
///The main switch is changed to facilitate
|
|
|
|
///1) Batch fast grading
|
|
|
|
///2) Skip to the next one on the popup
|
|
|
|
///3) Save and Skip to the next one on the popup
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
//make user global so we can use the id
|
|
|
|
global $USER;
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
switch ($mode) {
|
|
|
|
case 'grade': // We are in a popup window grading
|
|
|
|
if ($submission = $this->process_feedback()) {
|
2005-11-16 22:57:44 +00:00
|
|
|
//IE needs proper header with encoding
|
|
|
|
print_header(get_string('feedback', 'assignment').':'.format_string($this->assignment->name));
|
2005-04-14 13:24:40 +00:00
|
|
|
print_heading(get_string('changessaved'));
|
2006-04-27 04:12:58 +00:00
|
|
|
print $this->update_main_listing($submission);
|
2005-04-14 13:24:40 +00:00
|
|
|
}
|
2006-06-05 12:18:13 +00:00
|
|
|
close_window();
|
2005-04-14 13:24:40 +00:00
|
|
|
break;
|
2004-11-07 15:27:19 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
case 'single': // We are in a popup window displaying submission
|
|
|
|
$this->display_submission();
|
|
|
|
break;
|
2004-06-09 07:05:16 +00:00
|
|
|
|
2006-08-28 08:42:30 +00:00
|
|
|
case 'all': // Main window, display everything
|
2005-04-14 13:24:40 +00:00
|
|
|
$this->display_submissions();
|
|
|
|
break;
|
2005-11-04 06:50:30 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
case 'fastgrade':
|
2005-11-04 06:50:30 +00:00
|
|
|
///do the fast grading stuff - this process should work for all 3 subclasses
|
2005-11-18 10:31:46 +00:00
|
|
|
$grading = false;
|
2005-11-15 23:48:04 +00:00
|
|
|
$commenting = false;
|
2005-11-18 10:31:46 +00:00
|
|
|
$col = false;
|
2006-09-21 09:35:20 +00:00
|
|
|
if (isset($_POST['submissioncomment'])) {
|
|
|
|
$col = 'submissioncomment';
|
2005-11-15 23:48:04 +00:00
|
|
|
$commenting = true;
|
|
|
|
}
|
|
|
|
if (isset($_POST['menu'])) {
|
2005-11-18 10:31:46 +00:00
|
|
|
$col = 'menu';
|
2005-11-15 23:48:04 +00:00
|
|
|
$grading = true;
|
|
|
|
}
|
2005-11-18 10:31:46 +00:00
|
|
|
if (!$col) {
|
2006-09-21 09:35:20 +00:00
|
|
|
//both submissioncomment and grade columns collapsed..
|
2007-06-03 09:10:52 +00:00
|
|
|
$this->display_submissions();
|
2005-11-15 23:48:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-11-18 10:31:46 +00:00
|
|
|
foreach ($_POST[$col] as $id => $unusedvalue){
|
2005-11-16 15:22:21 +00:00
|
|
|
|
|
|
|
$id = (int)$id; //clean parameter name
|
2007-08-02 22:38:52 +00:00
|
|
|
|
|
|
|
$this->process_outcomes($id);
|
|
|
|
|
2005-11-18 10:31:46 +00:00
|
|
|
if (!$submission = $this->get_submission($id)) {
|
|
|
|
$submission = $this->prepare_new_submission($id);
|
|
|
|
$newsubmission = true;
|
|
|
|
} else {
|
|
|
|
$newsubmission = false;
|
|
|
|
}
|
|
|
|
unset($submission->data1); // Don't need to update this.
|
|
|
|
unset($submission->data2); // Don't need to update this.
|
2005-11-15 23:48:04 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
//for fast grade, we need to check if any changes take place
|
2005-11-15 23:48:04 +00:00
|
|
|
$updatedb = false;
|
|
|
|
|
|
|
|
if ($grading) {
|
|
|
|
$grade = $_POST['menu'][$id];
|
2005-11-18 10:31:46 +00:00
|
|
|
$updatedb = $updatedb || ($submission->grade != $grade);
|
|
|
|
$submission->grade = $grade;
|
2005-11-15 23:48:04 +00:00
|
|
|
} else {
|
2005-11-18 10:31:46 +00:00
|
|
|
if (!$newsubmission) {
|
|
|
|
unset($submission->grade); // Don't need to update this.
|
|
|
|
}
|
2005-11-15 23:48:04 +00:00
|
|
|
}
|
|
|
|
if ($commenting) {
|
2006-09-21 09:35:20 +00:00
|
|
|
$commentvalue = trim($_POST['submissioncomment'][$id]);
|
|
|
|
$updatedb = $updatedb || ($submission->submissioncomment != stripslashes($commentvalue));
|
|
|
|
$submission->submissioncomment = $commentvalue;
|
2005-11-15 23:48:04 +00:00
|
|
|
} else {
|
2006-09-21 09:35:20 +00:00
|
|
|
unset($submission->submissioncomment); // Don't need to update this.
|
2005-11-03 06:25:00 +00:00
|
|
|
}
|
|
|
|
|
2005-11-18 10:31:46 +00:00
|
|
|
$submission->teacher = $USER->id;
|
|
|
|
$submission->mailed = $updatedb?0:$submission->mailed;//only change if it's an update
|
|
|
|
$submission->timemarked = time();
|
|
|
|
|
|
|
|
//if it is not an update, we don't change the last modified time etc.
|
2006-09-21 09:35:20 +00:00
|
|
|
//this will also not write into database if no submissioncomment and grade is entered.
|
2005-11-18 10:31:46 +00:00
|
|
|
|
2005-11-15 23:48:04 +00:00
|
|
|
if ($updatedb){
|
2005-11-18 10:31:46 +00:00
|
|
|
if ($newsubmission) {
|
2007-05-28 08:55:15 +00:00
|
|
|
if (!$sid = insert_record('assignment_submissions', $submission)) {
|
2005-11-18 10:31:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-05-28 08:55:15 +00:00
|
|
|
$submission->id = $sid;
|
2005-11-18 10:31:46 +00:00
|
|
|
} else {
|
|
|
|
if (!update_record('assignment_submissions', $submission)) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-05-28 08:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// triger grade event
|
2007-06-03 09:10:52 +00:00
|
|
|
$this->update_grade($submission);
|
2007-05-28 08:55:15 +00:00
|
|
|
|
2005-11-18 10:31:46 +00:00
|
|
|
//add to log only if updating
|
2007-06-03 09:10:52 +00:00
|
|
|
add_to_log($this->course->id, 'assignment', 'update grades',
|
|
|
|
'submissions.php?id='.$this->assignment->id.'&user='.$submission->userid,
|
|
|
|
$submission->userid, $this->cm->id);
|
2005-11-03 06:25:00 +00:00
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
|
|
|
}
|
2007-08-02 22:38:52 +00:00
|
|
|
|
2007-09-04 05:50:04 +00:00
|
|
|
$message = notify(get_string('changessaved'), 'notifysuccess', 'center', true);
|
|
|
|
|
|
|
|
$this->display_submissions($message);
|
2005-11-03 06:25:00 +00:00
|
|
|
break;
|
2005-11-18 10:31:46 +00:00
|
|
|
|
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
case 'next':
|
|
|
|
/// We are currently in pop up, but we want to skip to next one without saving.
|
|
|
|
/// This turns out to be similar to a single case
|
|
|
|
/// The URL used is for the next submission.
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
$this->display_submission();
|
|
|
|
break;
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
case 'saveandnext':
|
|
|
|
///We are in pop up. save the current one and go to the next one.
|
|
|
|
//first we save the current changes
|
|
|
|
if ($submission = $this->process_feedback()) {
|
|
|
|
//print_heading(get_string('changessaved'));
|
2006-04-27 04:12:58 +00:00
|
|
|
$extra_javascript = $this->update_main_listing($submission);
|
2005-11-03 06:25:00 +00:00
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
//then we display the next submission
|
2006-04-27 04:12:58 +00:00
|
|
|
$this->display_submission($extra_javascript);
|
2005-11-03 06:25:00 +00:00
|
|
|
break;
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
default:
|
|
|
|
echo "something seriously is wrong!!";
|
2007-06-03 09:10:52 +00:00
|
|
|
break;
|
2004-06-09 07:05:16 +00:00
|
|
|
}
|
2005-04-14 13:24:40 +00:00
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Helper method updating the listing on the main script from popup using javascript
|
|
|
|
*
|
|
|
|
* @param $submission object The submission whose data is to be updated on the main page
|
|
|
|
*/
|
2005-04-14 17:56:03 +00:00
|
|
|
function update_main_listing($submission) {
|
2007-08-03 13:22:31 +00:00
|
|
|
global $SESSION, $CFG;
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2006-04-27 04:12:58 +00:00
|
|
|
$output = '';
|
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
$perpage = get_user_preferences('assignment_perpage', 10);
|
2005-04-14 17:56:03 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
$quickgrade = get_user_preferences('assignment_quickgrade', 0);
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-14 17:56:03 +00:00
|
|
|
/// Run some Javascript to try and update the parent page
|
2006-04-27 04:12:58 +00:00
|
|
|
$output .= '<script type="text/javascript">'."\n<!--\n";
|
2006-09-21 09:35:20 +00:00
|
|
|
if (empty($SESSION->flextable['mod-assignment-submissions']->collapse['submissioncomment'])) {
|
2005-11-03 06:25:00 +00:00
|
|
|
if ($quickgrade){
|
2007-02-15 08:16:54 +00:00
|
|
|
$output.= 'opener.document.getElementById("submissioncomment'.$submission->userid.'").value="'
|
2006-09-21 09:35:20 +00:00
|
|
|
.trim($submission->submissioncomment).'";'."\n";
|
2005-11-03 06:25:00 +00:00
|
|
|
} else {
|
2006-04-27 04:12:58 +00:00
|
|
|
$output.= 'opener.document.getElementById("com'.$submission->userid.
|
2006-09-21 09:35:20 +00:00
|
|
|
'").innerHTML="'.shorten_text(trim(strip_tags($submission->submissioncomment)), 15)."\";\n";
|
2005-11-03 06:25:00 +00:00
|
|
|
}
|
2005-04-14 17:56:03 +00:00
|
|
|
}
|
2005-11-03 06:25:00 +00:00
|
|
|
|
|
|
|
if (empty($SESSION->flextable['mod-assignment-submissions']->collapse['grade'])) {
|
|
|
|
//echo optional_param('menuindex');
|
|
|
|
if ($quickgrade){
|
2007-02-15 08:16:54 +00:00
|
|
|
$output.= 'opener.document.getElementById("menumenu'.$submission->userid.
|
|
|
|
'").selectedIndex="'.optional_param('menuindex', 0, PARAM_INT).'";'."\n";
|
2005-11-03 06:25:00 +00:00
|
|
|
} else {
|
2006-04-27 04:12:58 +00:00
|
|
|
$output.= 'opener.document.getElementById("g'.$submission->userid.'").innerHTML="'.
|
2005-11-03 06:25:00 +00:00
|
|
|
$this->display_grade($submission->grade)."\";\n";
|
2007-06-03 09:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
2005-11-03 06:25:00 +00:00
|
|
|
//need to add student's assignments in there too.
|
2005-04-17 15:38:02 +00:00
|
|
|
if (empty($SESSION->flextable['mod-assignment-submissions']->collapse['timemodified']) &&
|
|
|
|
$submission->timemodified) {
|
2006-04-27 04:12:58 +00:00
|
|
|
$output.= 'opener.document.getElementById("ts'.$submission->userid.
|
2007-07-18 18:42:45 +00:00
|
|
|
'").innerHTML="'.addslashes_js($this->print_student_answer($submission->userid)).userdate($submission->timemodified)."\";\n";
|
2005-04-14 17:56:03 +00:00
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
if (empty($SESSION->flextable['mod-assignment-submissions']->collapse['timemarked']) &&
|
|
|
|
$submission->timemarked) {
|
2006-04-27 04:12:58 +00:00
|
|
|
$output.= 'opener.document.getElementById("tt'.$submission->userid.
|
2005-04-14 17:56:03 +00:00
|
|
|
'").innerHTML="'.userdate($submission->timemarked)."\";\n";
|
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-14 17:56:03 +00:00
|
|
|
if (empty($SESSION->flextable['mod-assignment-submissions']->collapse['status'])) {
|
2006-04-27 04:12:58 +00:00
|
|
|
$output.= 'opener.document.getElementById("up'.$submission->userid.'").className="s1";';
|
2005-11-03 06:25:00 +00:00
|
|
|
$buttontext = get_string('update');
|
2007-06-03 09:10:52 +00:00
|
|
|
$button = link_to_popup_window ('/mod/assignment/submissions.php?id='.$this->cm->id.'&userid='.$submission->userid.'&mode=single'.'&offset='.(optional_param('offset', '', PARAM_INT)-1),
|
2005-11-03 06:25:00 +00:00
|
|
|
'grade'.$submission->userid, $buttontext, 450, 700, $buttontext, 'none', true, 'button'.$submission->userid);
|
2007-07-18 18:42:45 +00:00
|
|
|
$output.= 'opener.document.getElementById("up'.$submission->userid.'").innerHTML="'.addslashes_js($button).'";';
|
2007-06-03 09:10:52 +00:00
|
|
|
}
|
2007-08-17 07:25:47 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $submission->userid);
|
|
|
|
|
|
|
|
if (empty($SESSION->flextable['mod-assignment-submissions']->collapse['finalgrade'])) {
|
|
|
|
$output.= 'opener.document.getElementById("finalgrade_'.$submission->userid.
|
|
|
|
'").innerHTML="'.$grading_info->items[0]->grades[$submission->userid]->str_grade.'";'."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($CFG->enableoutcomes) and empty($SESSION->flextable['mod-assignment-submissions']->collapse['outcome'])) {
|
2007-09-22 20:21:44 +00:00
|
|
|
|
|
|
|
if (!empty($grading_info->outcomes)) {
|
|
|
|
foreach($grading_info->outcomes as $n=>$outcome) {
|
2007-09-23 16:05:41 +00:00
|
|
|
if ($outcome->grades[$submission->userid]->locked) {
|
2007-08-02 22:38:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($quickgrade){
|
|
|
|
$output.= 'opener.document.getElementById("outcome_'.$n.'_'.$submission->userid.
|
2007-09-22 20:21:44 +00:00
|
|
|
'").selectedIndex="'.$outcome->grades[$submission->userid]->grade.'";'."\n";
|
|
|
|
|
2007-08-02 22:38:52 +00:00
|
|
|
} else {
|
2007-09-22 20:21:44 +00:00
|
|
|
$options = make_grades_menu(-$outcome->scaleid);
|
2007-08-02 22:38:52 +00:00
|
|
|
$options[0] = get_string('nooutcome', 'grades');
|
2007-09-22 20:21:44 +00:00
|
|
|
$output.= 'opener.document.getElementById("outcome_'.$n.'_'.$submission->userid.'").innerHTML="'.$options[$outcome->grades[$submission->userid]->grade]."\";\n";
|
2007-08-02 22:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-27 04:12:58 +00:00
|
|
|
$output .= "\n-->\n</script>";
|
|
|
|
return $output;
|
2005-04-14 17:56:03 +00:00
|
|
|
}
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Return a grade in user-friendly form, whether it's a scale or not
|
2007-06-03 09:10:52 +00:00
|
|
|
*
|
2006-02-19 13:26:58 +00:00
|
|
|
* @param $grade
|
|
|
|
* @return string User-friendly representation of grade
|
2005-04-14 15:23:48 +00:00
|
|
|
*/
|
|
|
|
function display_grade($grade) {
|
|
|
|
|
2005-11-09 22:25:38 +00:00
|
|
|
static $scalegrades = array(); // Cache scales for each assignment - they might have different scales!!
|
2005-04-14 15:23:48 +00:00
|
|
|
|
|
|
|
if ($this->assignment->grade >= 0) { // Normal number
|
2005-11-04 06:50:30 +00:00
|
|
|
if ($grade == -1) {
|
|
|
|
return '-';
|
|
|
|
} else {
|
|
|
|
return $grade.' / '.$this->assignment->grade;
|
|
|
|
}
|
2005-04-14 15:23:48 +00:00
|
|
|
|
|
|
|
} else { // Scale
|
2005-11-09 22:25:38 +00:00
|
|
|
if (empty($scalegrades[$this->assignment->id])) {
|
2005-04-14 15:23:48 +00:00
|
|
|
if ($scale = get_record('scale', 'id', -($this->assignment->grade))) {
|
2005-11-09 22:25:38 +00:00
|
|
|
$scalegrades[$this->assignment->id] = make_menu_from_list($scale->scale);
|
2005-04-14 15:23:48 +00:00
|
|
|
} else {
|
|
|
|
return '-';
|
|
|
|
}
|
|
|
|
}
|
2005-11-09 22:25:38 +00:00
|
|
|
if (isset($scalegrades[$this->assignment->id][$grade])) {
|
|
|
|
return $scalegrades[$this->assignment->id][$grade];
|
2005-04-15 13:41:57 +00:00
|
|
|
}
|
2005-11-18 10:31:46 +00:00
|
|
|
return '-';
|
2005-04-14 15:23:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
2005-04-14 13:24:40 +00:00
|
|
|
* Display a single submission, ready for grading on a popup window
|
2006-02-19 13:26:58 +00:00
|
|
|
*
|
2006-09-21 09:35:20 +00:00
|
|
|
* This default method prints the teacher info and submissioncomment box at the top and
|
2006-02-19 13:26:58 +00:00
|
|
|
* the student info and submission at the bottom.
|
|
|
|
* This method also fetches the necessary data in order to be able to
|
|
|
|
* provide a "Next submission" button.
|
|
|
|
* Calls preprocess_submission() to give assignment type plug-ins a chance
|
|
|
|
* to process submissions before they are graded
|
|
|
|
* This method gets its arguments from the page parameters userid and offset
|
2005-04-14 13:24:40 +00:00
|
|
|
*/
|
2006-04-27 04:12:58 +00:00
|
|
|
function display_submission($extra_javascript = '') {
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-04 06:50:30 +00:00
|
|
|
global $CFG;
|
2007-08-02 22:38:52 +00:00
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
2008-01-24 20:33:50 +00:00
|
|
|
require_once($CFG->libdir.'/tablelib.php');
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-12 03:04:11 +00:00
|
|
|
$userid = required_param('userid', PARAM_INT);
|
|
|
|
$offset = required_param('offset', PARAM_INT);//offset for where to start looking for student.
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
if (!$user = get_record('user', 'id', $userid)) {
|
|
|
|
error('No such user!');
|
|
|
|
}
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2005-11-18 10:31:46 +00:00
|
|
|
if (!$submission = $this->get_submission($user->id)) {
|
|
|
|
$submission = $this->prepare_new_submission($userid);
|
2005-04-14 13:24:40 +00:00
|
|
|
}
|
|
|
|
if ($submission->timemodified > $submission->timemarked) {
|
|
|
|
$subtype = 'assignmentnew';
|
|
|
|
} else {
|
|
|
|
$subtype = 'assignmentold';
|
|
|
|
}
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array($user->id));
|
|
|
|
$disabled = $grading_info->items[0]->grades[$userid]->locked || $grading_info->items[0]->grades[$userid]->overridden;
|
|
|
|
|
2006-09-27 08:29:24 +00:00
|
|
|
/// construct SQL, using current offset to find the data of the next student
|
2005-11-03 06:25:00 +00:00
|
|
|
$course = $this->course;
|
|
|
|
$assignment = $this->assignment;
|
|
|
|
$cm = $this->cm;
|
2007-02-15 08:16:54 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
/// Get all ppl that can submit assignments
|
2006-09-27 08:29:24 +00:00
|
|
|
|
2007-08-26 23:50:08 +00:00
|
|
|
$currentgroup = groups_get_activity_group($cm);
|
2008-01-24 20:33:50 +00:00
|
|
|
if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
|
|
|
|
$users = array_keys($users);
|
|
|
|
}
|
2006-09-27 08:29:24 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
// if groupmembersonly used, remove users who are not in any group
|
|
|
|
if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
|
|
|
|
if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
|
|
|
|
$users = array_intersect($users, array_keys($groupingusers));
|
|
|
|
}
|
2005-11-13 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
2005-11-04 06:50:30 +00:00
|
|
|
$nextid = 0;
|
2008-01-24 20:33:50 +00:00
|
|
|
|
|
|
|
if ($users) {
|
|
|
|
$select = 'SELECT u.id, u.firstname, u.lastname, u.picture,
|
|
|
|
s.id AS submissionid, s.grade, s.submissioncomment,
|
|
|
|
s.timemodified, s.timemarked,
|
|
|
|
COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ';
|
|
|
|
$sql = 'FROM '.$CFG->prefix.'user u '.
|
|
|
|
'LEFT JOIN '.$CFG->prefix.'assignment_submissions s ON u.id = s.userid
|
|
|
|
AND s.assignment = '.$this->assignment->id.' '.
|
|
|
|
'WHERE u.id IN ('.implode(',', $users).') ';
|
|
|
|
|
|
|
|
if ($sort = flexible_table::get_sql_sort('mod-assignment-submissions')) {
|
|
|
|
$sort = 'ORDER BY '.$sort.' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($auser = get_records_sql($select.$sql.$sort, $offset+1, 1)) !== false) {
|
|
|
|
$nextuser = array_shift($auser);
|
|
|
|
/// Calculate user status
|
|
|
|
$nextuser->status = ($nextuser->timemarked > 0) && ($nextuser->timemarked >= $nextuser->timemodified);
|
|
|
|
$nextid = $nextuser->id;
|
|
|
|
}
|
2005-11-03 06:25:00 +00:00
|
|
|
}
|
2005-11-19 15:39:31 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
print_header(get_string('feedback', 'assignment').':'.fullname($user, true).':'.format_string($this->assignment->name));
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2006-04-27 04:12:58 +00:00
|
|
|
/// Print any extra javascript needed for saveandnext
|
|
|
|
echo $extra_javascript;
|
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
///SOme javascript to help with setting up >.>
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-13 02:50:46 +00:00
|
|
|
echo '<script type="text/javascript">'."\n";
|
2005-11-03 06:25:00 +00:00
|
|
|
echo 'function setNext(){'."\n";
|
2007-02-15 08:16:54 +00:00
|
|
|
echo 'document.getElementById(\'submitform\').mode.value=\'next\';'."\n";
|
|
|
|
echo 'document.getElementById(\'submitform\').userid.value="'.$nextid.'";'."\n";
|
2005-11-03 06:25:00 +00:00
|
|
|
echo '}'."\n";
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
echo 'function saveNext(){'."\n";
|
2007-02-15 08:16:54 +00:00
|
|
|
echo 'document.getElementById(\'submitform\').mode.value=\'saveandnext\';'."\n";
|
|
|
|
echo 'document.getElementById(\'submitform\').userid.value="'.$nextid.'";'."\n";
|
|
|
|
echo 'document.getElementById(\'submitform\').saveuserid.value="'.$userid.'";'."\n";
|
|
|
|
echo 'document.getElementById(\'submitform\').menuindex.value = document.getElementById(\'submitform\').grade.selectedIndex;'."\n";
|
2005-11-03 06:25:00 +00:00
|
|
|
echo '}'."\n";
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
echo '</script>'."\n";
|
2005-04-17 17:51:25 +00:00
|
|
|
echo '<table cellspacing="0" class="feedback '.$subtype.'" >';
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
///Start of teacher info row
|
2004-04-24 04:51:56 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
echo '<tr>';
|
2007-01-08 03:34:44 +00:00
|
|
|
echo '<td class="picture teacher">';
|
2005-04-14 13:24:40 +00:00
|
|
|
if ($submission->teacher) {
|
|
|
|
$teacher = get_record('user', 'id', $submission->teacher);
|
|
|
|
} else {
|
|
|
|
global $USER;
|
|
|
|
$teacher = $USER;
|
|
|
|
}
|
|
|
|
print_user_picture($teacher->id, $this->course->id, $teacher->picture);
|
|
|
|
echo '</td>';
|
|
|
|
echo '<td class="content">';
|
2007-01-04 21:32:36 +00:00
|
|
|
echo '<form id="submitform" action="submissions.php" method="post">';
|
2007-08-03 14:56:32 +00:00
|
|
|
echo '<div>'; // xhtml compatibility - invisiblefieldset was breaking layout here
|
2007-02-15 08:16:54 +00:00
|
|
|
echo '<input type="hidden" name="offset" value="'.($offset+1).'" />';
|
2005-11-13 02:50:46 +00:00
|
|
|
echo '<input type="hidden" name="userid" value="'.$userid.'" />';
|
|
|
|
echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />';
|
|
|
|
echo '<input type="hidden" name="mode" value="grade" />';
|
|
|
|
echo '<input type="hidden" name="menuindex" value="0" />';//selected menu index
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
//new hidden field, initialized to -1.
|
2005-11-13 02:50:46 +00:00
|
|
|
echo '<input type="hidden" name="saveuserid" value="-1" />';
|
2007-08-03 14:03:32 +00:00
|
|
|
|
2005-04-17 17:51:25 +00:00
|
|
|
if ($submission->timemarked) {
|
|
|
|
echo '<div class="from">';
|
|
|
|
echo '<div class="fullname">'.fullname($teacher, true).'</div>';
|
|
|
|
echo '<div class="time">'.userdate($submission->timemarked).'</div>';
|
|
|
|
echo '</div>';
|
|
|
|
}
|
2007-08-03 14:03:32 +00:00
|
|
|
echo '<div class="grade"><label for="menugrade">'.get_string('grade').'</label> ';
|
2007-09-23 16:05:41 +00:00
|
|
|
choose_from_menu(make_grades_menu($this->assignment->grade), 'grade', $submission->grade, get_string('nograde'), '', -1, false, $disabled);
|
2005-04-17 17:51:25 +00:00
|
|
|
echo '</div>';
|
2007-07-31 22:56:29 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
echo '<div class="clearer"></div>';
|
|
|
|
echo '<div class="finalgrade">'.get_string('finalgrade', 'grades').': '.$grading_info->items[0]->grades[$userid]->str_grade.'</div>';
|
2007-08-03 14:32:26 +00:00
|
|
|
echo '<div class="clearer"></div>';
|
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
if (!empty($CFG->enableoutcomes)) {
|
|
|
|
foreach($grading_info->outcomes as $n=>$outcome) {
|
|
|
|
echo '<div class="outcome"><label for="menuoutcome_'.$n.'">'.$outcome->name.'</label> ';
|
|
|
|
$options = make_grades_menu(-$outcome->scaleid);
|
|
|
|
if ($outcome->grades[$submission->userid]->locked) {
|
2007-08-02 22:38:52 +00:00
|
|
|
$options[0] = get_string('nooutcome', 'grades');
|
2007-09-22 20:21:44 +00:00
|
|
|
echo $options[$outcome->grades[$submission->userid]->grade];
|
2007-07-31 22:56:29 +00:00
|
|
|
} else {
|
2007-09-22 20:21:44 +00:00
|
|
|
choose_from_menu($options, 'outcome_'.$n.'['.$userid.']', $outcome->grades[$submission->userid]->grade, get_string('nooutcome', 'grades'), '', 0, false, false, 0, 'menuoutcome_'.$n);
|
2007-07-31 22:56:29 +00:00
|
|
|
}
|
2007-08-02 22:38:52 +00:00
|
|
|
echo '</div>';
|
2007-08-03 14:32:26 +00:00
|
|
|
echo '<div class="clearer"></div>';
|
2007-07-31 22:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
|
2005-04-20 07:48:11 +00:00
|
|
|
$this->preprocess_submission($submission);
|
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
if ($disabled) {
|
|
|
|
echo '<div class="disabledfeedback">'.$grading_info->items[0]->grades[$userid]->str_feedback.'</div>';
|
2005-04-17 17:58:51 +00:00
|
|
|
|
|
|
|
} else {
|
2007-09-23 16:05:41 +00:00
|
|
|
print_textarea($this->usehtmleditor, 14, 58, 0, 0, 'submissioncomment', $submission->submissioncomment, $this->course->id);
|
|
|
|
if ($this->usehtmleditor) {
|
|
|
|
echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
|
|
|
|
} else {
|
|
|
|
echo '<div class="format">';
|
|
|
|
choose_from_menu(format_text_menu(), "format", $submission->format, "");
|
|
|
|
helpbutton("textformat", get_string("helpformatting"));
|
|
|
|
echo '</div>';
|
|
|
|
}
|
2005-04-17 17:58:51 +00:00
|
|
|
}
|
2005-04-14 13:24:40 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
///Print Buttons in Single View
|
2007-01-08 03:34:44 +00:00
|
|
|
echo '<div class="buttons">';
|
2007-02-15 08:16:54 +00:00
|
|
|
echo '<input type="submit" name="submit" value="'.get_string('savechanges').'" onclick = "document.getElementById(\'submitform\').menuindex.value = document.getElementById(\'submitform\').grade.selectedIndex" />';
|
2005-04-14 13:24:40 +00:00
|
|
|
echo '<input type="submit" name="cancel" value="'.get_string('cancel').'" />';
|
2005-11-03 06:25:00 +00:00
|
|
|
//if there are more to be graded.
|
2005-11-04 06:50:30 +00:00
|
|
|
if ($nextid) {
|
2005-11-13 03:20:35 +00:00
|
|
|
echo '<input type="submit" name="saveandnext" value="'.get_string('saveandnext').'" onclick="saveNext()" />';
|
|
|
|
echo '<input type="submit" name="next" value="'.get_string('next').'" onclick="setNext();" />';
|
2005-11-03 06:25:00 +00:00
|
|
|
}
|
2005-04-17 15:38:02 +00:00
|
|
|
echo '</div>';
|
2007-08-03 14:56:32 +00:00
|
|
|
echo '</div></form>';
|
2006-09-30 15:41:20 +00:00
|
|
|
|
|
|
|
$customfeedback = $this->custom_feedbackform($submission, true);
|
|
|
|
if (!empty($customfeedback)) {
|
2007-06-03 09:10:52 +00:00
|
|
|
echo $customfeedback;
|
2006-09-30 15:41:20 +00:00
|
|
|
}
|
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
echo '</td></tr>';
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
///End of teacher info row, Start of student info row
|
|
|
|
echo '<tr>';
|
2007-01-08 03:34:44 +00:00
|
|
|
echo '<td class="picture user">';
|
2005-11-03 06:25:00 +00:00
|
|
|
print_user_picture($user->id, $this->course->id, $user->picture);
|
|
|
|
echo '</td>';
|
|
|
|
echo '<td class="topic">';
|
|
|
|
echo '<div class="from">';
|
|
|
|
echo '<div class="fullname">'.fullname($user, true).'</div>';
|
|
|
|
if ($submission->timemodified) {
|
|
|
|
echo '<div class="time">'.userdate($submission->timemodified).
|
|
|
|
$this->display_lateness($submission->timemodified).'</div>';
|
|
|
|
}
|
|
|
|
echo '</div>';
|
|
|
|
$this->print_user_files($user->id);
|
|
|
|
echo '</td>';
|
|
|
|
echo '</tr>';
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
///End of student info row
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
echo '</table>';
|
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
if (!$disabled and $this->usehtmleditor) {
|
2005-04-17 15:38:02 +00:00
|
|
|
use_html_editor();
|
|
|
|
}
|
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
print_footer('none');
|
2002-08-04 16:19:37 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
2005-04-20 07:48:11 +00:00
|
|
|
* Preprocess submission before grading
|
2006-02-19 13:26:58 +00:00
|
|
|
*
|
|
|
|
* Called by display_submission()
|
|
|
|
* The default type does nothing here.
|
|
|
|
* @param $submission object The submission object
|
2005-04-20 07:48:11 +00:00
|
|
|
*/
|
|
|
|
function preprocess_submission(&$submission) {
|
|
|
|
}
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
2005-04-14 13:24:40 +00:00
|
|
|
* Display all the submissions ready for grading
|
|
|
|
*/
|
2007-09-04 05:50:04 +00:00
|
|
|
function display_submissions($message='') {
|
2005-11-03 06:25:00 +00:00
|
|
|
global $CFG, $db, $USER;
|
2007-08-02 22:38:52 +00:00
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
2002-09-22 06:41:56 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
/* first we check to see if the form has just been submitted
|
|
|
|
* to request user_preference updates
|
|
|
|
*/
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
if (isset($_POST['updatepref'])){
|
2005-11-15 23:48:04 +00:00
|
|
|
$perpage = optional_param('perpage', 10, PARAM_INT);
|
2005-11-03 06:25:00 +00:00
|
|
|
$perpage = ($perpage <= 0) ? 10 : $perpage ;
|
|
|
|
set_user_preference('assignment_perpage', $perpage);
|
2005-11-15 23:48:04 +00:00
|
|
|
set_user_preference('assignment_quickgrade', optional_param('quickgrade',0, PARAM_BOOL));
|
2005-11-03 06:25:00 +00:00
|
|
|
}
|
2003-04-26 15:08:34 +00:00
|
|
|
|
2007-06-03 09:10:52 +00:00
|
|
|
/* next we get perpage and quickgrade (allow quick grade) params
|
2005-11-03 06:25:00 +00:00
|
|
|
* from database
|
|
|
|
*/
|
|
|
|
$perpage = get_user_preferences('assignment_perpage', 10);
|
2007-06-10 20:34:07 +00:00
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
$quickgrade = get_user_preferences('assignment_quickgrade', 0);
|
|
|
|
|
|
|
|
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {
|
2007-08-07 07:25:06 +00:00
|
|
|
$uses_outcomes = true;
|
|
|
|
} else {
|
|
|
|
$uses_outcomes = false;
|
|
|
|
}
|
|
|
|
|
2005-11-15 23:48:04 +00:00
|
|
|
$page = optional_param('page', 0, PARAM_INT);
|
2005-04-14 13:24:40 +00:00
|
|
|
$strsaveallfeedback = get_string('saveallfeedback', 'assignment');
|
2002-10-17 07:23:51 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
/// Some shortcuts to make the code read better
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
$course = $this->course;
|
|
|
|
$assignment = $this->assignment;
|
|
|
|
$cm = $this->cm;
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
$tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet
|
2003-08-17 12:45:13 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->assignment->id, $this->assignment->id, $this->cm->id);
|
2007-08-03 11:55:28 +00:00
|
|
|
|
2008-01-21 13:40:47 +00:00
|
|
|
$navigation = build_navigation($this->strsubmissions, $this->cm);
|
2007-08-03 11:55:28 +00:00
|
|
|
print_header_simple(format_string($this->assignment->name,true), "", $navigation,
|
|
|
|
'', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm));
|
2007-05-28 08:55:15 +00:00
|
|
|
|
2007-09-04 05:50:04 +00:00
|
|
|
if (!empty($message)) {
|
|
|
|
echo $message; // display messages here if any
|
|
|
|
}
|
|
|
|
|
2007-04-04 04:05:53 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2007-05-28 08:55:15 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
/// Check to see if groups are being used in this assignment
|
|
|
|
|
2007-05-28 08:55:15 +00:00
|
|
|
/// find out current groups mode
|
2007-08-26 23:50:08 +00:00
|
|
|
$groupmode = groups_get_activity_groupmode($cm);
|
|
|
|
$currentgroup = groups_get_activity_group($cm, true);
|
|
|
|
groups_print_activity_menu($cm, 'submissions.php?id=' . $this->cm->id);
|
2007-05-28 08:55:15 +00:00
|
|
|
|
|
|
|
/// Get all ppl that are allowed to submit assignments
|
2008-01-24 20:33:50 +00:00
|
|
|
if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
|
2007-11-16 04:24:57 +00:00
|
|
|
$users = array_keys($users);
|
|
|
|
}
|
2007-08-26 23:50:08 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
// if groupmembersonly used, remove users who are not in any group
|
|
|
|
if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
|
|
|
|
if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
|
|
|
|
$users = array_intersect($users, array_keys($groupingusers));
|
|
|
|
}
|
2007-08-26 23:50:08 +00:00
|
|
|
}
|
2003-08-17 12:45:13 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
$tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
|
2007-08-07 07:25:06 +00:00
|
|
|
if ($uses_outcomes) {
|
2007-09-23 16:05:41 +00:00
|
|
|
$tablecolumns[] = 'outcome'; // no sorting based on outcomes column
|
2007-08-03 13:22:31 +00:00
|
|
|
}
|
|
|
|
|
2007-08-03 11:55:28 +00:00
|
|
|
$tableheaders = array('',
|
|
|
|
get_string('fullname'),
|
|
|
|
get_string('grade'),
|
|
|
|
get_string('comment', 'assignment'),
|
|
|
|
get_string('lastmodified').' ('.$course->student.')',
|
|
|
|
get_string('lastmodified').' ('.$course->teacher.')',
|
2007-09-23 16:05:41 +00:00
|
|
|
get_string('status'),
|
|
|
|
get_string('finalgrade', 'grades'));
|
2007-08-07 07:25:06 +00:00
|
|
|
if ($uses_outcomes) {
|
2007-09-23 16:05:41 +00:00
|
|
|
$tableheaders[] = get_string('outcome', 'grades');
|
2007-08-03 13:22:31 +00:00
|
|
|
}
|
2003-08-17 12:45:13 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
require_once($CFG->libdir.'/tablelib.php');
|
|
|
|
$table = new flexible_table('mod-assignment-submissions');
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
$table->define_columns($tablecolumns);
|
|
|
|
$table->define_headers($tableheaders);
|
2005-11-08 07:19:27 +00:00
|
|
|
$table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id.'&currentgroup='.$currentgroup);
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2006-07-06 09:47:48 +00:00
|
|
|
$table->sortable(true, 'lastname');//sorted by lastname by default
|
2005-04-14 13:24:40 +00:00
|
|
|
$table->collapsible(true);
|
|
|
|
$table->initialbars(true);
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
$table->column_suppress('picture');
|
|
|
|
$table->column_suppress('fullname');
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
$table->column_class('picture', 'picture');
|
2005-04-14 17:10:40 +00:00
|
|
|
$table->column_class('fullname', 'fullname');
|
|
|
|
$table->column_class('grade', 'grade');
|
2006-09-21 09:35:20 +00:00
|
|
|
$table->column_class('submissioncomment', 'comment');
|
2005-04-14 17:10:40 +00:00
|
|
|
$table->column_class('timemodified', 'timemodified');
|
|
|
|
$table->column_class('timemarked', 'timemarked');
|
|
|
|
$table->column_class('status', 'status');
|
2007-09-23 16:05:41 +00:00
|
|
|
$table->column_class('finalgrade', 'finalgrade');
|
2007-08-07 07:25:06 +00:00
|
|
|
if ($uses_outcomes) {
|
2007-09-23 16:05:41 +00:00
|
|
|
$table->column_class('outcome', 'outcome');
|
2007-08-03 13:22:31 +00:00
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
$table->set_attribute('cellspacing', '0');
|
|
|
|
$table->set_attribute('id', 'attempts');
|
2005-04-14 17:10:40 +00:00
|
|
|
$table->set_attribute('class', 'submissions');
|
2005-04-14 13:24:40 +00:00
|
|
|
$table->set_attribute('width', '90%');
|
2007-01-05 04:57:58 +00:00
|
|
|
//$table->set_attribute('align', 'center');
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
$table->no_sorting('finalgrade');
|
|
|
|
$table->no_sorting('outcome');
|
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
// Start working -- this is necessary as soon as the niceties are over
|
|
|
|
$table->setup();
|
|
|
|
|
|
|
|
if (empty($users)) {
|
2008-01-24 20:33:50 +00:00
|
|
|
print_heading(get_string('nosubmitusers','assignment'));
|
2005-04-14 13:24:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-05-15 23:18:24 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
/// Construct the SQL
|
2004-05-15 23:18:24 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
if ($where = $table->get_sql_where()) {
|
|
|
|
$where .= ' AND ';
|
|
|
|
}
|
2004-05-15 23:18:24 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
if ($sort = $table->get_sql_sort()) {
|
2005-11-13 04:01:41 +00:00
|
|
|
$sort = ' ORDER BY '.$sort;
|
2005-04-14 13:24:40 +00:00
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2008-01-16 14:45:24 +00:00
|
|
|
$select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt,
|
2007-06-03 09:10:52 +00:00
|
|
|
s.id AS submissionid, s.grade, s.submissioncomment,
|
2007-09-13 17:51:48 +00:00
|
|
|
s.timemodified, s.timemarked,
|
|
|
|
COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ';
|
2005-04-14 13:24:40 +00:00
|
|
|
$sql = 'FROM '.$CFG->prefix.'user u '.
|
2007-06-03 09:10:52 +00:00
|
|
|
'LEFT JOIN '.$CFG->prefix.'assignment_submissions s ON u.id = s.userid
|
2007-02-01 23:55:05 +00:00
|
|
|
AND s.assignment = '.$this->assignment->id.' '.
|
2007-08-26 23:50:08 +00:00
|
|
|
'WHERE '.$where.'u.id IN ('.implode(',',$users).') ';
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-05-22 01:51:03 +00:00
|
|
|
$table->pagesize($perpage, count($users));
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
|
|
|
|
$offset = $page * $perpage;
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
$strupdate = get_string('update');
|
2005-04-14 17:10:40 +00:00
|
|
|
$strgrade = get_string('grade');
|
2005-04-14 13:24:40 +00:00
|
|
|
$grademenu = make_grades_menu($this->assignment->grade);
|
|
|
|
|
2006-10-23 23:00:18 +00:00
|
|
|
if (($ausers = get_records_sql($select.$sql.$sort, $table->get_page_start(), $table->get_page_size())) !== false) {
|
2007-09-22 20:21:44 +00:00
|
|
|
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers));
|
2005-04-14 15:23:48 +00:00
|
|
|
foreach ($ausers as $auser) {
|
2007-09-23 16:05:41 +00:00
|
|
|
$final_grade = $grading_info->items[0]->grades[$auser->id];
|
2007-02-01 23:55:05 +00:00
|
|
|
/// Calculate user status
|
2007-08-20 22:21:46 +00:00
|
|
|
$auser->status = ($auser->timemarked > 0) && ($auser->timemarked >= $auser->timemodified);
|
2008-01-16 14:45:24 +00:00
|
|
|
$picture = print_user_picture($auser, $course->id, $auser->picture, false, true);
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-18 10:31:46 +00:00
|
|
|
if (empty($auser->submissionid)) {
|
|
|
|
$auser->grade = -1; //no submission yet
|
2005-11-03 06:25:00 +00:00
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-14 15:23:48 +00:00
|
|
|
if (!empty($auser->submissionid)) {
|
2005-11-03 06:25:00 +00:00
|
|
|
///Prints student answer and student modified date
|
|
|
|
///attach file or print link to student answer, depending on the type of the assignment.
|
2007-06-03 09:10:52 +00:00
|
|
|
///Refer to print_student_answer in inherited classes.
|
|
|
|
if ($auser->timemodified > 0) {
|
2007-08-03 11:55:28 +00:00
|
|
|
$studentmodified = '<div id="ts'.$auser->id.'">'.$this->print_student_answer($auser->id)
|
|
|
|
. userdate($auser->timemodified).'</div>';
|
2005-04-14 15:23:48 +00:00
|
|
|
} else {
|
2005-04-14 17:10:40 +00:00
|
|
|
$studentmodified = '<div id="ts'.$auser->id.'"> </div>';
|
2005-04-14 15:23:48 +00:00
|
|
|
}
|
2005-11-03 06:25:00 +00:00
|
|
|
///Print grade, dropdown or text
|
2005-04-14 15:23:48 +00:00
|
|
|
if ($auser->timemarked > 0) {
|
|
|
|
$teachermodified = '<div id="tt'.$auser->id.'">'.userdate($auser->timemarked).'</div>';
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
if ($final_grade->locked or $final_grade->overridden) {
|
|
|
|
$grade = '<div id="g'.$auser->id.'">'.$final_grade->str_grade.'</div>';
|
|
|
|
} else if ($quickgrade) {
|
2007-08-03 11:55:28 +00:00
|
|
|
$menu = choose_from_menu(make_grades_menu($this->assignment->grade),
|
|
|
|
'menu['.$auser->id.']', $auser->grade,
|
|
|
|
get_string('nograde'),'',-1,true,false,$tabindex++);
|
|
|
|
$grade = '<div id="g'.$auser->id.'">'. $menu .'</div>';
|
2005-11-03 06:25:00 +00:00
|
|
|
} else {
|
|
|
|
$grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>';
|
|
|
|
}
|
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
} else {
|
2005-04-14 17:10:40 +00:00
|
|
|
$teachermodified = '<div id="tt'.$auser->id.'"> </div>';
|
2007-09-23 16:05:41 +00:00
|
|
|
if ($final_grade->locked or $final_grade->overridden) {
|
|
|
|
$grade = '<div id="g'.$auser->id.'">'.$final_grade->str_grade.'</div>';
|
|
|
|
} else if ($quickgrade) {
|
2007-08-03 11:55:28 +00:00
|
|
|
$menu = choose_from_menu(make_grades_menu($this->assignment->grade),
|
|
|
|
'menu['.$auser->id.']', $auser->grade,
|
|
|
|
get_string('nograde'),'',-1,true,false,$tabindex++);
|
|
|
|
$grade = '<div id="g'.$auser->id.'">'.$menu.'</div>';
|
2005-11-03 06:25:00 +00:00
|
|
|
} else {
|
|
|
|
$grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
///Print Comment
|
2007-09-23 16:05:41 +00:00
|
|
|
if ($final_grade->locked or $final_grade->overridden) {
|
|
|
|
$comment = '<div id="com'.$auser->id.'">'.shorten_text(strip_tags($final_grade->str_feedback),15).'</div>';
|
|
|
|
|
|
|
|
} else if ($quickgrade) {
|
2007-08-03 11:55:28 +00:00
|
|
|
$comment = '<div id="com'.$auser->id.'">'
|
|
|
|
. '<textarea tabindex="'.$tabindex++.'" name="submissioncomment['.$auser->id.']" id="submissioncomment'
|
|
|
|
. $auser->id.'" rows="2" cols="20">'.($auser->submissioncomment).'</textarea></div>';
|
2005-11-03 06:25:00 +00:00
|
|
|
} else {
|
2006-09-21 09:35:20 +00:00
|
|
|
$comment = '<div id="com'.$auser->id.'">'.shorten_text(strip_tags($auser->submissioncomment),15).'</div>';
|
2005-04-14 13:24:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
2005-04-14 17:10:40 +00:00
|
|
|
$studentmodified = '<div id="ts'.$auser->id.'"> </div>';
|
|
|
|
$teachermodified = '<div id="tt'.$auser->id.'"> </div>';
|
2005-11-03 06:25:00 +00:00
|
|
|
$status = '<div id="st'.$auser->id.'"> </div>';
|
2007-08-03 11:55:28 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
if ($final_grade->locked or $final_grade->overridden) {
|
|
|
|
$grade = '<div id="g'.$auser->id.'">'.$final_grade->str_grade.'</div>';
|
|
|
|
} else if ($quickgrade) { // allow editing
|
2007-08-03 11:55:28 +00:00
|
|
|
$menu = choose_from_menu(make_grades_menu($this->assignment->grade),
|
|
|
|
'menu['.$auser->id.']', $auser->grade,
|
|
|
|
get_string('nograde'),'',-1,true,false,$tabindex++);
|
|
|
|
$grade = '<div id="g'.$auser->id.'">'.$menu.'</div>';
|
2005-11-03 06:25:00 +00:00
|
|
|
} else {
|
2005-11-18 10:31:46 +00:00
|
|
|
$grade = '<div id="g'.$auser->id.'">-</div>';
|
2005-11-03 06:25:00 +00:00
|
|
|
}
|
2007-08-03 11:55:28 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
if ($final_grade->locked or $final_grade->overridden) {
|
|
|
|
$comment = '<div id="com'.$auser->id.'">'.$final_grade->str_feedback.'</div>';
|
|
|
|
} else if ($quickgrade) {
|
2007-08-03 11:55:28 +00:00
|
|
|
$comment = '<div id="com'.$auser->id.'">'
|
|
|
|
. '<textarea tabindex="'.$tabindex++.'" name="submissioncomment['.$auser->id.']" id="submissioncomment'
|
|
|
|
. $auser->id.'" rows="2" cols="20">'.($auser->submissioncomment).'</textarea></div>';
|
2005-11-03 06:25:00 +00:00
|
|
|
} else {
|
|
|
|
$comment = '<div id="com'.$auser->id.'"> </div>';
|
|
|
|
}
|
2005-04-14 13:24:40 +00:00
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2007-02-01 23:55:05 +00:00
|
|
|
if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1
|
2005-04-15 13:41:57 +00:00
|
|
|
$auser->status = 0;
|
2007-02-01 23:55:05 +00:00
|
|
|
} else {
|
|
|
|
$auser->status = 1;
|
2005-04-15 13:41:57 +00:00
|
|
|
}
|
|
|
|
|
2005-04-14 17:10:40 +00:00
|
|
|
$buttontext = ($auser->status == 1) ? $strupdate : $strgrade;
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
///No more buttons, we use popups ;-).
|
|
|
|
$popup_url = '/mod/assignment/submissions.php?id='.$this->cm->id
|
|
|
|
. '&userid='.$auser->id.'&mode=single'.'&offset='.$offset++;
|
|
|
|
$button = link_to_popup_window ($popup_url, 'grade'.$auser->id, $buttontext, 600, 780,
|
|
|
|
$buttontext, 'none', true, 'button'.$auser->id);
|
2007-08-03 11:55:28 +00:00
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
$status = '<div id="up'.$auser->id.'" class="s'.$auser->status.'">'.$button.'</div>';
|
2007-08-02 22:38:52 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
$finalgrade = '<span id="finalgrade_'.$auser->id.'">'.$final_grade->str_grade.'</span>';
|
|
|
|
|
2007-08-02 22:38:52 +00:00
|
|
|
$outcomes = '';
|
2007-08-03 11:55:28 +00:00
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
if ($uses_outcomes) {
|
2007-08-03 11:55:28 +00:00
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
foreach($grading_info->outcomes as $n=>$outcome) {
|
|
|
|
$outcomes .= '<div class="outcome"><label>'.$outcome->name.'</label>';
|
|
|
|
$options = make_grades_menu(-$outcome->scaleid);
|
2007-08-03 11:55:28 +00:00
|
|
|
|
2007-09-22 20:21:44 +00:00
|
|
|
if ($outcome->grades[$auser->id]->locked or !$quickgrade) {
|
2007-08-02 22:38:52 +00:00
|
|
|
$options[0] = get_string('nooutcome', 'grades');
|
2007-09-22 20:21:44 +00:00
|
|
|
$outcomes .= ': <span id="outcome_'.$n.'_'.$auser->id.'">'.$options[$outcome->grades[$auser->id]->grade].'</span>';
|
2007-08-02 22:38:52 +00:00
|
|
|
} else {
|
2007-08-07 07:25:06 +00:00
|
|
|
$outcomes .= ' ';
|
2007-08-03 11:55:28 +00:00
|
|
|
$outcomes .= choose_from_menu($options, 'outcome_'.$n.'['.$auser->id.']',
|
2007-09-22 20:21:44 +00:00
|
|
|
$outcome->grades[$auser->id]->grade, get_string('nooutcome', 'grades'), '', 0, true, false, 0, 'outcome_'.$n.'_'.$auser->id);
|
2007-08-02 22:38:52 +00:00
|
|
|
}
|
2007-08-03 11:55:28 +00:00
|
|
|
$outcomes .= '</div>';
|
2007-08-02 22:38:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
$row = array($picture, fullname($auser), $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade);
|
2007-08-07 07:25:06 +00:00
|
|
|
if ($uses_outcomes) {
|
2007-08-03 13:22:31 +00:00
|
|
|
$row[] = $outcomes;
|
|
|
|
}
|
|
|
|
|
2005-04-14 15:23:48 +00:00
|
|
|
$table->add_data($row);
|
|
|
|
}
|
2005-04-14 13:24:40 +00:00
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-04 06:50:30 +00:00
|
|
|
/// Print quickgrade form around the table
|
|
|
|
if ($quickgrade){
|
2007-01-04 21:32:36 +00:00
|
|
|
echo '<form action="submissions.php" id="fastg" method="post">';
|
2007-03-01 07:28:11 +00:00
|
|
|
echo '<div>';
|
2007-01-05 05:56:19 +00:00
|
|
|
echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />';
|
|
|
|
echo '<input type="hidden" name="mode" value="fastgrade" />';
|
|
|
|
echo '<input type="hidden" name="page" value="'.$page.'" />';
|
2007-03-01 07:28:11 +00:00
|
|
|
echo '</div>';
|
2007-09-04 05:50:04 +00:00
|
|
|
//echo '<div style="text-align:center"><input type="submit" name="fastg" value="'.get_string('saveallfeedback', 'assignment').'" /></div>';
|
2005-11-04 06:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$table->print_html(); /// Print the whole table
|
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
if ($quickgrade){
|
2007-01-05 04:57:58 +00:00
|
|
|
echo '<div style="text-align:center"><input type="submit" name="fastg" value="'.get_string('saveallfeedback', 'assignment').'" /></div>';
|
2005-11-04 06:50:30 +00:00
|
|
|
echo '</form>';
|
2005-11-03 06:25:00 +00:00
|
|
|
}
|
2005-11-04 06:50:30 +00:00
|
|
|
/// End of fast grading form
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-11-04 06:50:30 +00:00
|
|
|
/// Mini form for setting user preference
|
2005-11-03 06:25:00 +00:00
|
|
|
echo '<br />';
|
2007-01-04 21:32:36 +00:00
|
|
|
echo '<form id="options" action="submissions.php?id='.$this->cm->id.'" method="post">';
|
2007-09-26 11:42:36 +00:00
|
|
|
echo '<div>';
|
2005-11-13 02:50:46 +00:00
|
|
|
echo '<input type="hidden" id="updatepref" name="updatepref" value="1" />';
|
2007-09-26 11:42:36 +00:00
|
|
|
echo '<table id="optiontable" align="right">';
|
2005-11-03 06:25:00 +00:00
|
|
|
echo '<tr align="right"><td>';
|
|
|
|
echo '<label for="perpage">'.get_string('pagesize','assignment').'</label>';
|
|
|
|
echo ':</td>';
|
2007-09-26 11:42:36 +00:00
|
|
|
echo '<td>';
|
2005-11-03 06:25:00 +00:00
|
|
|
echo '<input type="text" id="perpage" name="perpage" size="1" value="'.$perpage.'" />';
|
|
|
|
helpbutton('pagesize', get_string('pagesize','assignment'), 'assignment');
|
|
|
|
echo '</td></tr>';
|
2007-09-22 20:21:44 +00:00
|
|
|
echo '<tr align="right">';
|
|
|
|
echo '<td>';
|
|
|
|
print_string('quickgrade','assignment');
|
|
|
|
echo ':</td>';
|
2007-09-26 11:42:36 +00:00
|
|
|
echo '<td>';
|
2007-09-22 20:21:44 +00:00
|
|
|
if ($quickgrade){
|
|
|
|
echo '<input type="checkbox" name="quickgrade" value="1" checked="checked" />';
|
|
|
|
} else {
|
|
|
|
echo '<input type="checkbox" name="quickgrade" value="1" />';
|
2005-11-03 06:25:00 +00:00
|
|
|
}
|
2007-09-22 20:21:44 +00:00
|
|
|
helpbutton('quickgrade', get_string('quickgrade', 'assignment'), 'assignment').'</p></div>';
|
|
|
|
echo '</td></tr>';
|
2005-11-03 06:25:00 +00:00
|
|
|
echo '<tr>';
|
|
|
|
echo '<td colspan="2" align="right">';
|
|
|
|
echo '<input type="submit" value="'.get_string('savepreferences').'" />';
|
|
|
|
echo '</td></tr></table>';
|
2007-09-26 11:42:36 +00:00
|
|
|
echo '</div>';
|
2005-11-03 06:25:00 +00:00
|
|
|
echo '</form>';
|
|
|
|
///End of mini form
|
2005-04-14 13:24:40 +00:00
|
|
|
print_footer($this->course);
|
2003-06-07 06:23:31 +00:00
|
|
|
}
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Process teacher feedback submission
|
|
|
|
*
|
|
|
|
* This is called by submissions() when a grading even has taken place.
|
|
|
|
* It gets its data from the submitted form.
|
|
|
|
* @return object The updated submission object
|
2005-04-14 13:24:40 +00:00
|
|
|
*/
|
|
|
|
function process_feedback() {
|
2007-09-23 16:05:41 +00:00
|
|
|
global $CFG, $USER;
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2005-11-13 03:37:40 +00:00
|
|
|
if (!$feedback = data_submitted()) { // No incoming data?
|
2005-04-14 13:24:40 +00:00
|
|
|
return false;
|
2002-08-04 16:19:37 +00:00
|
|
|
}
|
2002-11-06 08:12:06 +00:00
|
|
|
|
2005-11-03 06:25:00 +00:00
|
|
|
///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;
|
|
|
|
}
|
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
if (!empty($feedback->cancel)) { // User hit cancel button
|
|
|
|
return false;
|
|
|
|
}
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $feedback->userid);
|
|
|
|
|
2007-08-02 22:38:52 +00:00
|
|
|
// store outcomes if needed
|
|
|
|
$this->process_outcomes($feedback->userid);
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
$submission = $this->get_submission($feedback->userid, true); // Get or make one
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
if (!$grading_info->items[0]->grades[$feedback->userid]->locked and
|
|
|
|
!$grading_info->items[0]->grades[$feedback->userid]->overridden) {
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
$submission->grade = $feedback->grade;
|
|
|
|
$submission->submissioncomment = $feedback->submissioncomment;
|
|
|
|
$submission->format = $feedback->format;
|
|
|
|
$submission->teacher = $USER->id;
|
|
|
|
$submission->mailed = 0; // Make sure mail goes out (again, even)
|
|
|
|
$submission->timemarked = time();
|
2005-07-12 13:12:24 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
unset($submission->data1); // Don't need to update this.
|
|
|
|
unset($submission->data2); // Don't need to update this.
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
if (empty($submission->timemodified)) { // eg for offline assignments
|
|
|
|
// $submission->timemodified = time();
|
|
|
|
}
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
if (! update_record('assignment_submissions', $submission)) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-05-28 08:55:15 +00:00
|
|
|
|
2007-09-23 16:05:41 +00:00
|
|
|
// triger 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);
|
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
return $submission;
|
2002-08-04 16:19:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-08-02 22:38:52 +00:00
|
|
|
function process_outcomes($userid) {
|
|
|
|
global $CFG, $USER;
|
2007-08-03 13:22:31 +00:00
|
|
|
|
|
|
|
if (empty($CFG->enableoutcomes)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-02 22:38:52 +00:00
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
|
|
|
|
if (!$formdata = data_submitted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = array();
|
2007-09-22 20:21:44 +00:00
|
|
|
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $userid);
|
|
|
|
|
|
|
|
if (!empty($grading_info->outcomes)) {
|
|
|
|
foreach($grading_info->outcomes as $n=>$old) {
|
2007-08-02 22:38:52 +00:00
|
|
|
$name = 'outcome_'.$n;
|
2007-09-22 20:21:44 +00:00
|
|
|
if (isset($formdata->{$name}[$userid]) and $old->grades[$userid]->grade != $formdata->{$name}[$userid]) {
|
2007-08-02 22:38:52 +00:00
|
|
|
$data[$n] = $formdata->{$name}[$userid];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count($data) > 0) {
|
|
|
|
grade_update_outcomes('mod/assignment', $this->course->id, 'mod', 'assignment', $this->assignment->id, $userid, $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Load the submission object for a particular user
|
|
|
|
*
|
|
|
|
* @param $userid int The id of the user whose submission we want or 0 in which case USER->id is used
|
|
|
|
* @param $createnew boolean optional Defaults to false. If set to true a new submission object will be created in the database
|
|
|
|
* @return object The submission
|
|
|
|
*/
|
2005-04-18 09:29:09 +00:00
|
|
|
function get_submission($userid=0, $createnew=false) {
|
|
|
|
global $USER;
|
|
|
|
|
|
|
|
if (empty($userid)) {
|
|
|
|
$userid = $USER->id;
|
|
|
|
}
|
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
$submission = get_record('assignment_submissions', 'assignment', $this->assignment->id, 'userid', $userid);
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
if ($submission || !$createnew) {
|
|
|
|
return $submission;
|
|
|
|
}
|
2005-11-18 10:31:46 +00:00
|
|
|
$newsubmission = $this->prepare_new_submission($userid);
|
2005-04-14 13:24:40 +00:00
|
|
|
if (!insert_record("assignment_submissions", $newsubmission)) {
|
|
|
|
error("Could not insert a new empty submission");
|
|
|
|
}
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
return get_record('assignment_submissions', 'assignment', $this->assignment->id, 'userid', $userid);
|
|
|
|
}
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Instantiates a new submission object for a given user
|
|
|
|
*
|
|
|
|
* Sets the assignment, userid and times, everything else is set to default values.
|
|
|
|
* @param $userid int The userid for which we want a submission object
|
|
|
|
* @return object The submission
|
|
|
|
*/
|
2005-11-18 10:31:46 +00:00
|
|
|
function prepare_new_submission($userid) {
|
2007-06-03 09:10:52 +00:00
|
|
|
$submission = new Object;
|
2005-11-18 10:31:46 +00:00
|
|
|
$submission->assignment = $this->assignment->id;
|
|
|
|
$submission->userid = $userid;
|
2007-06-03 09:10:52 +00:00
|
|
|
//$submission->timecreated = time();
|
2007-02-15 08:16:54 +00:00
|
|
|
$submission->timecreated = '';
|
|
|
|
// teachers should not be modifying modified date, except offline assignments
|
2005-11-18 10:31:46 +00:00
|
|
|
$submission->timemodified = $submission->timecreated;
|
|
|
|
$submission->numfiles = 0;
|
|
|
|
$submission->data1 = '';
|
|
|
|
$submission->data2 = '';
|
|
|
|
$submission->grade = -1;
|
2006-09-21 09:35:20 +00:00
|
|
|
$submission->submissioncomment = '';
|
2005-11-18 10:31:46 +00:00
|
|
|
$submission->format = 0;
|
|
|
|
$submission->teacher = 0;
|
|
|
|
$submission->timemarked = 0;
|
|
|
|
$submission->mailed = 0;
|
|
|
|
return $submission;
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Return all assignment submissions by ENROLLED students (even empty)
|
|
|
|
*
|
|
|
|
* @param $sort string optional field names for the ORDER BY in the sql query
|
|
|
|
* @param $dir string optional specifying the sort direction, defaults to DESC
|
|
|
|
* @return array The submission objects indexed by id
|
|
|
|
*/
|
2005-04-14 13:24:40 +00:00
|
|
|
function get_submissions($sort='', $dir='DESC') {
|
2006-02-19 13:26:58 +00:00
|
|
|
return assignment_get_all_submissions($this->assignment, $sort, $dir);
|
2005-04-14 13:24:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Counts all real assignment submissions by ENROLLED students (not empty ones)
|
|
|
|
*
|
|
|
|
* @param $groupid int optional If nonzero then count is restricted to this group
|
|
|
|
* @return int The number of submissions
|
|
|
|
*/
|
2005-04-14 13:24:40 +00:00
|
|
|
function count_real_submissions($groupid=0) {
|
2008-01-24 20:33:50 +00:00
|
|
|
return assignment_count_real_submissions($this->cm, $groupid);
|
2005-04-14 15:23:48 +00:00
|
|
|
}
|
2002-08-04 16:19:37 +00:00
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Alerts teachers by email of new or changed assignments that need grading
|
|
|
|
*
|
|
|
|
* First checks whether the option to email teachers is set for this assignment.
|
|
|
|
* Sends an email to ALL teachers in the course (or in the group if using separate groups).
|
|
|
|
* Uses the methods email_teachers_text() and email_teachers_html() to construct the content.
|
|
|
|
* @param $submission object The submission that has changed
|
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
function email_teachers($submission) {
|
|
|
|
global $CFG;
|
|
|
|
|
2005-04-18 16:01:02 +00:00
|
|
|
if (empty($this->assignment->emailteachers)) { // No need to do anything
|
2005-04-17 15:38:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = get_record('user', 'id', $submission->userid);
|
|
|
|
|
2007-04-10 14:51:34 +00:00
|
|
|
if ($teachers = $this->get_graders($user)) {
|
2005-04-17 15:38:02 +00:00
|
|
|
|
|
|
|
$strassignments = get_string('modulenameplural', 'assignment');
|
|
|
|
$strassignment = get_string('modulename', 'assignment');
|
|
|
|
$strsubmitted = get_string('submitted', 'assignment');
|
|
|
|
|
|
|
|
foreach ($teachers as $teacher) {
|
2007-02-13 08:54:06 +00:00
|
|
|
$info = new object();
|
2007-04-10 14:51:34 +00:00
|
|
|
$info->username = fullname($user, true);
|
2005-04-18 16:01:02 +00:00
|
|
|
$info->assignment = format_string($this->assignment->name,true);
|
|
|
|
$info->url = $CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id;
|
|
|
|
|
|
|
|
$postsubject = $strsubmitted.': '.$info->username.' -> '.$this->assignment->name;
|
|
|
|
$posttext = $this->email_teachers_text($info);
|
|
|
|
$posthtml = ($teacher->mailformat == 1) ? $this->email_teachers_html($info) : '';
|
2005-04-17 15:38:02 +00:00
|
|
|
|
|
|
|
@email_to_user($teacher, $user, $postsubject, $posttext, $posthtml); // If it fails, oh well, too bad.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-10 14:51:34 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of teachers that should be grading given submission
|
|
|
|
*/
|
|
|
|
function get_graders($user) {
|
|
|
|
//potential graders
|
2007-05-28 08:55:15 +00:00
|
|
|
$potgraders = get_users_by_capability($this->context, 'mod/assignment:grade', '', '', '', '', '', '', false, false);
|
|
|
|
|
2007-04-10 14:51:34 +00:00
|
|
|
$graders = array();
|
2007-08-26 23:50:08 +00:00
|
|
|
if (groups_get_activity_groupmode($this->cm) == SEPARATEGROUPS) { // Separate groups are being used
|
2007-08-15 20:21:01 +00:00
|
|
|
if ($groups = groups_get_all_groups($this->course->id, $user->id)) { // Try to find all groups
|
2007-04-10 14:51:34 +00:00
|
|
|
foreach ($groups as $group) {
|
|
|
|
foreach ($potgraders as $t) {
|
|
|
|
if ($t->id == $user->id) {
|
|
|
|
continue; // do not send self
|
|
|
|
}
|
|
|
|
if (groups_is_member($group->id, $t->id)) {
|
|
|
|
$graders[$t->id] = $t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// user not in group, try to find graders without group
|
|
|
|
foreach ($potgraders as $t) {
|
|
|
|
if ($t->id == $user->id) {
|
|
|
|
continue; // do not send self
|
|
|
|
}
|
2007-08-15 20:21:01 +00:00
|
|
|
if (!groups_get_all_groups($this->course->id, $t->id)) { //ugly hack
|
2007-04-10 14:51:34 +00:00
|
|
|
$graders[$t->id] = $t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
foreach ($potgraders as $t) {
|
|
|
|
if ($t->id == $user->id) {
|
|
|
|
continue; // do not send self
|
|
|
|
}
|
|
|
|
$graders[$t->id] = $t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $graders;
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Creates the text content for emails to teachers
|
|
|
|
*
|
|
|
|
* @param $info object The info used by the 'emailteachermail' language string
|
|
|
|
* @return string
|
|
|
|
*/
|
2005-04-18 16:01:02 +00:00
|
|
|
function email_teachers_text($info) {
|
2007-04-10 14:51:34 +00:00
|
|
|
$posttext = format_string($this->course->shortname).' -> '.$this->strassignments.' -> '.
|
|
|
|
format_string($this->assignment->name)."\n";
|
2005-04-18 16:01:02 +00:00
|
|
|
$posttext .= '---------------------------------------------------------------------'."\n";
|
|
|
|
$posttext .= get_string("emailteachermail", "assignment", $info)."\n";
|
2006-04-27 04:12:58 +00:00
|
|
|
$posttext .= "\n---------------------------------------------------------------------\n";
|
2005-04-18 16:01:02 +00:00
|
|
|
return $posttext;
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Creates the html content for emails to teachers
|
|
|
|
*
|
|
|
|
* @param $info object The info used by the 'emailteachermailhtml' language string
|
|
|
|
* @return string
|
|
|
|
*/
|
2005-04-18 16:01:02 +00:00
|
|
|
function email_teachers_html($info) {
|
2005-07-12 14:37:34 +00:00
|
|
|
global $CFG;
|
2005-04-18 16:01:02 +00:00
|
|
|
$posthtml = '<p><font face="sans-serif">'.
|
2007-04-10 14:51:34 +00:00
|
|
|
'<a href="'.$CFG->wwwroot.'/course/view.php?id='.$this->course->id.'">'.format_string($this->course->shortname).'</a> ->'.
|
2005-04-18 16:01:02 +00:00
|
|
|
'<a href="'.$CFG->wwwroot.'/mod/assignment/index.php?id='.$this->course->id.'">'.$this->strassignments.'</a> ->'.
|
2007-04-10 14:51:34 +00:00
|
|
|
'<a href="'.$CFG->wwwroot.'/mod/assignment/view.php?id='.$this->cm->id.'">'.format_string($this->assignment->name).'</a></font></p>';
|
2005-04-18 16:01:02 +00:00
|
|
|
$posthtml .= '<hr /><font face="sans-serif">';
|
|
|
|
$posthtml .= '<p>'.get_string('emailteachermailhtml', 'assignment', $info).'</p>';
|
|
|
|
$posthtml .= '</font><hr />';
|
2005-07-09 13:37:36 +00:00
|
|
|
return $posthtml;
|
2005-04-18 16:01:02 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Produces a list of links to the files uploaded by a user
|
|
|
|
*
|
|
|
|
* @param $userid int optional id of the user. If 0 then $USER->id is used.
|
|
|
|
* @param $return boolean optional defaults to false. If true the list is returned rather than printed
|
|
|
|
* @return string optional
|
|
|
|
*/
|
2005-04-18 16:01:02 +00:00
|
|
|
function print_user_files($userid=0, $return=false) {
|
|
|
|
global $CFG, $USER;
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-18 16:01:02 +00:00
|
|
|
if (!$userid) {
|
|
|
|
if (!isloggedin()) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
$userid = $USER->id;
|
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 17:11:41 +00:00
|
|
|
$filearea = $this->file_area_name($userid);
|
2005-04-17 15:38:02 +00:00
|
|
|
|
|
|
|
$output = '';
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 17:11:41 +00:00
|
|
|
if ($basedir = $this->file_area($userid)) {
|
2005-04-17 15:38:02 +00:00
|
|
|
if ($files = get_directory_list($basedir)) {
|
2006-02-18 21:19:04 +00:00
|
|
|
require_once($CFG->libdir.'/filelib.php');
|
2005-04-17 15:38:02 +00:00
|
|
|
foreach ($files as $key => $file) {
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
$icon = mimeinfo('icon', $file);
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
if ($CFG->slasharguments) {
|
2005-07-12 13:12:24 +00:00
|
|
|
$ffurl = "$CFG->wwwroot/file.php/$filearea/$file";
|
2005-04-17 15:38:02 +00:00
|
|
|
} else {
|
2005-07-12 13:12:24 +00:00
|
|
|
$ffurl = "$CFG->wwwroot/file.php?file=/$filearea/$file";
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2007-01-08 09:14:05 +00:00
|
|
|
$output .= '<img align="middle" src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'.
|
2005-11-03 06:25:00 +00:00
|
|
|
'<a href="'.$ffurl.'" >'.$file.'</a><br />';
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = '<div class="files">'.$output.'</div>';
|
|
|
|
|
|
|
|
if ($return) {
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Count the files uploaded by a given user
|
|
|
|
*
|
|
|
|
* @param $userid int The user id
|
|
|
|
* @return int
|
|
|
|
*/
|
2005-04-17 17:11:41 +00:00
|
|
|
function count_user_files($userid) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$filearea = $this->file_area_name($userid);
|
|
|
|
|
2006-08-09 18:36:54 +00:00
|
|
|
if ( is_dir($CFG->dataroot.'/'.$filearea) && $basedir = $this->file_area($userid)) {
|
2005-04-17 17:11:41 +00:00
|
|
|
if ($files = get_directory_list($basedir)) {
|
|
|
|
return count($files);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Creates a directory file name, suitable for make_upload_directory()
|
|
|
|
*
|
|
|
|
* @param $userid int The user id
|
|
|
|
* @return string path to file area
|
|
|
|
*/
|
2005-04-17 17:11:41 +00:00
|
|
|
function file_area_name($userid) {
|
2005-04-17 15:38:02 +00:00
|
|
|
global $CFG;
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 17:11:41 +00:00
|
|
|
return $this->course->id.'/'.$CFG->moddata.'/assignment/'.$this->assignment->id.'/'.$userid;
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
2006-02-19 13:26:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes an upload directory
|
|
|
|
*
|
|
|
|
* @param $userid int The user id
|
|
|
|
* @return string path to file area.
|
|
|
|
*/
|
2005-04-17 17:11:41 +00:00
|
|
|
function file_area($userid) {
|
|
|
|
return make_upload_directory( $this->file_area_name($userid) );
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the student is allowed to submit
|
|
|
|
*
|
|
|
|
* Checks that the assignment has started and, if the option to prevent late
|
|
|
|
* submissions is set, also checks that the assignment has not yet closed.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2005-04-18 09:29:09 +00:00
|
|
|
function isopen() {
|
|
|
|
$time = time();
|
2005-07-05 06:03:04 +00:00
|
|
|
if ($this->assignment->preventlate && $this->assignment->timedue) {
|
2005-04-18 09:29:09 +00:00
|
|
|
return ($this->assignment->timeavailable <= $time && $time <= $this->assignment->timedue);
|
|
|
|
} else {
|
|
|
|
return ($this->assignment->timeavailable <= $time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
|
|
|
|
/**
|
2007-11-16 02:52:48 +00:00
|
|
|
* Return true if is set description is hidden till available date
|
|
|
|
*
|
2007-11-29 14:43:04 +00:00
|
|
|
* This is needed by calendar so that hidden descriptions do not
|
2007-11-16 02:52:48 +00:00
|
|
|
* come up in upcoming events.
|
|
|
|
*
|
2007-11-29 14:43:04 +00:00
|
|
|
* Check that description is hidden till available date
|
2007-11-16 02:52:48 +00:00
|
|
|
* By default return false
|
|
|
|
* Assignments types should implement this method if needed
|
|
|
|
* @return boolen
|
2007-11-29 14:43:04 +00:00
|
|
|
*/
|
2007-11-16 02:52:48 +00:00
|
|
|
function description_is_hidden() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Return an outline of the user's interaction with the assignment
|
|
|
|
*
|
|
|
|
* The default method prints the grade and timemodified
|
|
|
|
* @param $user object
|
|
|
|
* @return object with properties ->info and ->time
|
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
function user_outline($user) {
|
|
|
|
if ($submission = $this->get_submission($user->id)) {
|
2005-11-18 10:31:46 +00:00
|
|
|
|
2007-02-13 08:54:06 +00:00
|
|
|
$result = new object();
|
2005-11-18 10:31:46 +00:00
|
|
|
$result->info = get_string('grade').': '.$this->display_grade($submission->grade);
|
2005-04-17 15:38:02 +00:00
|
|
|
$result->time = $submission->timemodified;
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-02-19 13:26:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Print complete information about the user's interaction with the assignment
|
|
|
|
*
|
|
|
|
* @param $user object
|
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
function user_complete($user) {
|
|
|
|
if ($submission = $this->get_submission($user->id)) {
|
2005-04-17 17:11:41 +00:00
|
|
|
if ($basedir = $this->file_area($user->id)) {
|
2005-04-17 15:38:02 +00:00
|
|
|
if ($files = get_directory_list($basedir)) {
|
|
|
|
$countfiles = count($files)." ".get_string("uploadedfiles", "assignment");
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$countfiles .= "; $file";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
print_simple_box_start();
|
|
|
|
echo get_string("lastmodified").": ";
|
2005-11-03 06:25:00 +00:00
|
|
|
echo userdate($submission->timemodified);
|
|
|
|
echo $this->display_lateness($submission->timemodified);
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 17:11:41 +00:00
|
|
|
$this->print_user_files($user->id);
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
echo '<br />';
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
if (empty($submission->timemarked)) {
|
|
|
|
print_string("notgradedyet", "assignment");
|
|
|
|
} else {
|
|
|
|
$this->view_feedback($submission);
|
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
print_simple_box_end();
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
} else {
|
|
|
|
print_string("notsubmittedyet", "assignment");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Return a string indicating how late a submission is
|
|
|
|
*
|
2007-06-03 09:10:52 +00:00
|
|
|
* @param $timesubmitted int
|
2006-02-19 13:26:58 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2005-04-17 17:11:41 +00:00
|
|
|
function display_lateness($timesubmitted) {
|
2006-03-15 03:36:33 +00:00
|
|
|
return assignment_display_lateness($timesubmitted, $this->assignment->timedue);
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
2006-09-30 15:41:20 +00:00
|
|
|
/**
|
|
|
|
* Empty method stub for all delete actions.
|
|
|
|
*/
|
|
|
|
function delete() {
|
|
|
|
//nothing by default
|
|
|
|
redirect('view.php?id='.$this->cm->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Empty custom feedback grading form.
|
|
|
|
*/
|
|
|
|
function custom_feedbackform($submission, $return=false) {
|
|
|
|
//nothing by default
|
|
|
|
return '';
|
|
|
|
}
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2007-07-19 16:59:51 +00:00
|
|
|
/**
|
|
|
|
* Add a get_coursemodule_info function in case any assignment type wants to add 'extra' information
|
|
|
|
* for the course (see resource).
|
|
|
|
*
|
2007-08-03 11:55:28 +00:00
|
|
|
* Given a course_module object, this function returns any "extra" information that may be needed
|
2007-07-19 16:59:51 +00:00
|
|
|
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
|
2007-08-03 11:55:28 +00:00
|
|
|
*
|
2007-07-19 16:59:51 +00:00
|
|
|
* @param $coursemodule object The coursemodule object (record).
|
|
|
|
* @return object An object on information that the coures will know about (most noticeably, an icon).
|
2007-08-03 11:55:28 +00:00
|
|
|
*
|
2007-07-19 16:59:51 +00:00
|
|
|
*/
|
|
|
|
function get_coursemodule_info($coursemodule) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-08-21 09:53:35 +00:00
|
|
|
/**
|
|
|
|
* Plugin cron method - do not use $this here, create new assignment instances if needed.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function cron() {
|
|
|
|
//no plugin cron by default - override if needed
|
|
|
|
}
|
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
/**
|
|
|
|
* Reset all submissions
|
|
|
|
*/
|
|
|
|
function reset_userdata($data) {
|
|
|
|
global $CFG;
|
|
|
|
require_once($CFG->libdir.'/filelib.php');
|
|
|
|
|
|
|
|
if (!count_records('assignment', 'course', $data->courseid, 'assignmenttype', $this->type)) {
|
|
|
|
return array(); // no assignments of this type present
|
|
|
|
}
|
|
|
|
|
|
|
|
$componentstr = get_string('modulenameplural', 'assignment');
|
|
|
|
$status = array();
|
|
|
|
|
|
|
|
$typestr = get_string('type'.$this->type, 'assignment');
|
|
|
|
|
|
|
|
if (!empty($data->reset_assignment_submissions)) {
|
|
|
|
$assignmentssql = "SELECT a.id
|
|
|
|
FROM {$CFG->prefix}assignment a
|
|
|
|
WHERE a.course={$data->courseid} AND a.assignmenttype='{$this->type}'";
|
|
|
|
|
|
|
|
delete_records_select('assignment_submissions', "assignment IN ($assignmentssql)");
|
|
|
|
|
|
|
|
if ($assignments = get_records_sql($assignmentssql)) {
|
|
|
|
foreach ($assignments as $assignmentid=>$unused) {
|
|
|
|
fulldelete($CFG->dataroot.'/'.$data->courseid.'/moddata/assignment/'.$assignmentid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallsubmissions','assignment').': '.$typestr, 'error'=>false);
|
2008-01-24 20:33:50 +00:00
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
if (empty($data->reset_gradebook_grades)) {
|
|
|
|
// remove all grades from gradebook
|
|
|
|
assignment_reset_gradebook($data->courseid, $this->type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// updating dates - shift may be negative too
|
|
|
|
if ($data->timeshift) {
|
|
|
|
shift_course_mod_dates('assignment', array('timedue', 'timeavailable'), $data->timeshift, $data->courseid);
|
|
|
|
$status[] = array('component'=>$componentstr, 'item'=>get_string('datechanged').': '.$typestr, 'error'=>false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
}
|
2005-04-14 13:24:40 +00:00
|
|
|
} ////// End of the assignment_base class
|
2002-08-04 16:19:37 +00:00
|
|
|
|
Centralised file upload code, integration with clam AV, integration with some modules: assignment, exercise, forum, glossaryt, resource, scorm (more to come soon).
These patches are maintained in an publicly accessible Arch repository, see: http://lists.eduforge.org/cgi-bin/archzoom.cgi/arch-eduforge@catalyst.net.nz--2004-MIRROR/moodle--eduforge--1.3.3
Index of arch patches in this commit:
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-15
final touches to sears stuff until testing can begin, beginning of magical uploadey wrappery function goodness
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-18
Virus scanning on upload
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-19
made emacs use spaces instead of tabs and fixed lib/moodlelib.php where it was bad in the new functions; few wording changes, added in support for clamdscan
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-20
handlevirus.php = new script to handle output of clamscan (designed for cron clamscan), changes to strings for emailing out virus notifications, changes to moodlelib - slightly different notice reporting in handle_infected_file and new function for replacing file with message
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-21
refactor to filter out invalid lines in input to handlevirus
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-22
modified assignment to use hande_file_upload
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-25
bug fix for handle_file_upload
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-26
Small fix for non thinking brain doing something silly
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-35
small fix to switch order of items in drop down to allow sensible defaults
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-36
small changes to strings file
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-38
taken stuff out of moodlelib to put in upload class
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-39
new upload class -in a changeset by itself just in case - not quite finished
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-40
tweaks to upload class - clam_scan_file can now take a path as an argument, not just an entry from _FILES, there is better handling of failure and notification, more allowance for module writers to keep control in general. Also slightly nicer strings entries for a few things
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-41
upload class integration with assignment module, bug fix, slight tweak
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-42
small changes to uploadlib, integration with assessment and assignment
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-44
tweaks for assessment and assignment for uploading
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-48
integration with exercise module
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-49
integration of virus stuff with forum module
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-50
integration of upload class and glossary module
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-51
just in case glossary_move_attachments is ever used, we change the log entries before we move the files. also moved clam_log_upload out of the class
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-52
virus scanning for imports for glossary
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-53
relog entries when moving files attached to forum posts
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-54
resource module integration with virus scanning
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-55
scorm integration with upload/virus class
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-56
fix for handlevirus.php since upload class changes
Full logs:
Revision: moodle--eduforge--1.3.3--patch-15
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Wed Sep 1 17:28:13 NZST 2004
Standard-date: 2004-09-01 05:28:13 GMT
Modified-files: lang/en/moodle.php lib/moodlelib.php
mod/assessment/sears.php mod/assessment/upload.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-15
Summary: final touches to sears stuff until testing can begin, beginning of magical uploadey wrappery function goodness
Keywords:
Revision: moodle--eduforge--1.3.3--patch-18
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Thu Sep 2 15:49:54 NZST 2004
Standard-date: 2004-09-02 03:49:54 GMT
Modified-files: admin/config.html lang/en/moodle.php
lib/moodlelib.php mod/assessment/upload.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-18
Summary: Virus scanning on upload
Keywords:
Revision: moodle--eduforge--1.3.3--patch-19
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Thu Sep 2 17:06:14 NZST 2004
Standard-date: 2004-09-02 05:06:14 GMT
Modified-files: lang/en/moodle.php lib/moodlelib.php
mod/assessment/upload.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-19
Summary: made emacs use spaces instead of tabs and fixed lib/moodlelib.php where it was bad in the new functions; few wording changes, added in support for clamdscan
Keywords:
Revision: moodle--eduforge--1.3.3--patch-20
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Fri Sep 3 16:06:05 NZST 2004
Standard-date: 2004-09-03 04:06:05 GMT
New-files: admin/.arch-ids/handlevirus.php.id
admin/handlevirus.php
Modified-files: lang/en/moodle.php lib/moodlelib.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-20
Summary: handlevirus.php = new script to handle output of clamscan (designed for cron clamscan), changes to strings for emailing out virus notifications, changes to moodlelib - slightly different notice reporting in handle_infected_file and new function for replacing file with message
Keywords:
Revision: moodle--eduforge--1.3.3--patch-21
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Mon Sep 6 11:37:31 NZST 2004
Standard-date: 2004-09-05 23:37:31 GMT
Modified-files: admin/handlevirus.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-21
Summary: refactor to filter out invalid lines in input to handlevirus
Keywords:
Revision: moodle--eduforge--1.3.3--patch-22
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Mon Sep 6 13:07:48 NZST 2004
Standard-date: 2004-09-06 01:07:48 GMT
Modified-files: mod/assignment/upload.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-22
Summary: modified assignment to use hande_file_upload
Keywords:
Revision: moodle--eduforge--1.3.3--patch-25
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Mon Sep 6 16:32:11 NZST 2004
Standard-date: 2004-09-06 04:32:11 GMT
Modified-files: lib/moodlelib.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-25
Summary: bug fix for handle_file_upload
Keywords:
Revision: moodle--eduforge--1.3.3--patch-26
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Mon Sep 6 16:51:50 NZST 2004
Standard-date: 2004-09-06 04:51:50 GMT
Modified-files: lib/moodlelib.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-26
Summary: Small fix for non thinking brain doing something silly
Keywords:
Revision: moodle--eduforge--1.3.3--patch-35
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Fri Sep 10 10:09:53 NZST 2004
Standard-date: 2004-09-09 22:09:53 GMT
Modified-files: admin/config.html
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-35
Summary: small fix to switch order of items in drop down to allow sensible defaults
Keywords:
Revision: moodle--eduforge--1.3.3--patch-36
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Fri Sep 10 10:11:29 NZST 2004
Standard-date: 2004-09-09 22:11:29 GMT
Modified-files: lang/en/moodle.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-36
Summary: small changes to strings file
Keywords:
Revision: moodle--eduforge--1.3.3--patch-38
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Fri Sep 10 10:17:24 NZST 2004
Standard-date: 2004-09-09 22:17:24 GMT
Modified-files: lib/moodlelib.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-38
Summary: taken stuff out of moodlelib to put in upload class
Keywords:
Revision: moodle--eduforge--1.3.3--patch-39
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Fri Sep 10 10:21:21 NZST 2004
Standard-date: 2004-09-09 22:21:21 GMT
New-files: lib/.arch-ids/uploadlib.php.id lib/uploadlib.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-39
Summary: new upload class -in a changeset by itself just in case - not quite finished
Keywords:
Revision: moodle--eduforge--1.3.3--patch-40
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Fri Sep 10 11:58:24 NZST 2004
Standard-date: 2004-09-09 23:58:24 GMT
Modified-files: lang/en/moodle.php lib/uploadlib.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-40
Summary: tweaks to upload class - clam_scan_file can now take a path as an argument, not just an entry from _FILES, there is better handling of failure and notification, more allowance for module writers to keep control in general. Also slightly nicer strings entries for a few things
Keywords:
Revision: moodle--eduforge--1.3.3--patch-41
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Fri Sep 10 12:38:02 NZST 2004
Standard-date: 2004-09-10 00:38:02 GMT
Modified-files: lib/uploadlib.php mod/assignment/upload.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-41
Summary: upload class integration with assignment module, bug fix, slight tweak
Keywords:
Revision: moodle--eduforge--1.3.3--patch-42
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Fri Sep 10 15:30:20 NZST 2004
Standard-date: 2004-09-10 03:30:20 GMT
Modified-files: lib/uploadlib.php mod/assessment/upload.php
mod/assessment/view.php mod/assignment/upload.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-42
Summary: small changes to uploadlib, integration with assessment and assignment
Keywords:
Revision: moodle--eduforge--1.3.3--patch-44
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Fri Sep 10 16:54:40 NZST 2004
Standard-date: 2004-09-10 04:54:40 GMT
Modified-files: mod/assessment/lib.php
mod/assignment/lib.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-44
Summary: tweaks for assessment and assignment for uploading
Keywords:
Revision: moodle--eduforge--1.3.3--patch-48
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Mon Sep 13 09:57:03 NZST 2004
Standard-date: 2004-09-12 21:57:03 GMT
Modified-files: lang/en/moodle.php
mod/exercise/locallib.php mod/exercise/upload.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-48
Summary: integration with exercise module
Keywords:
Revision: moodle--eduforge--1.3.3--patch-49
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Mon Sep 13 11:35:46 NZST 2004
Standard-date: 2004-09-12 23:35:46 GMT
Modified-files: mod/forum/lib.php mod/forum/post.html
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-49
Summary: integration of virus stuff with forum module
Keywords:
Revision: moodle--eduforge--1.3.3--patch-50
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Mon Sep 13 14:00:29 NZST 2004
Standard-date: 2004-09-13 02:00:29 GMT
Modified-files: lang/en/glossary.php mod/glossary/edit.html
mod/glossary/edit.php mod/glossary/lib.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-50
Summary: integration of upload class and glossary module
Keywords:
Revision: moodle--eduforge--1.3.3--patch-51
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Mon Sep 13 15:13:02 NZST 2004
Standard-date: 2004-09-13 03:13:02 GMT
Modified-files: lib/uploadlib.php mod/glossary/lib.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-51
Summary: just in case glossary_move_attachments is ever used, we change the log entries before we move the files. also moved clam_log_upload out of the class
Keywords:
Revision: moodle--eduforge--1.3.3--patch-52
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Mon Sep 13 15:26:56 NZST 2004
Standard-date: 2004-09-13 03:26:56 GMT
Modified-files: mod/glossary/import.html
mod/glossary/import.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-52
Summary: virus scanning for imports for glossary
Keywords:
Revision: moodle--eduforge--1.3.3--patch-53
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Mon Sep 13 16:02:22 NZST 2004
Standard-date: 2004-09-13 04:02:22 GMT
Modified-files: mod/forum/lib.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-53
Summary: relog entries when moving files attached to forum posts
Keywords:
Revision: moodle--eduforge--1.3.3--patch-54
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Mon Sep 13 16:58:37 NZST 2004
Standard-date: 2004-09-13 04:58:37 GMT
Modified-files: mod/resource/coursefiles.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-54
Summary: resource module integration with virus scanning
Keywords:
Revision: moodle--eduforge--1.3.3--patch-55
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Tue Sep 14 16:15:47 NZST 2004
Standard-date: 2004-09-14 04:15:47 GMT
Modified-files: mod/scorm/coursefiles.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-55
Summary: scorm integration with upload/virus class
Keywords:
Revision: moodle--eduforge--1.3.3--patch-56
Archive: arch-eduforge@catalyst.net.nz--2004
Creator: Penny Leach <penny@catalyst.net.nz>
Date: Wed Sep 15 10:33:23 NZST 2004
Standard-date: 2004-09-14 22:33:23 GMT
Modified-files: admin/handlevirus.php
New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-56
Summary: fix for handlevirus.php since upload class changes
Keywords:
2004-09-14 22:58:13 +00:00
|
|
|
|
2002-08-03 02:29:21 +00:00
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
/// OTHER STANDARD FUNCTIONS ////////////////////////////////////////////////////////
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Deletes an assignment instance
|
|
|
|
*
|
|
|
|
* This is done by calling the delete_instance() method of the assignment type class
|
|
|
|
*/
|
2005-04-14 13:24:40 +00:00
|
|
|
function assignment_delete_instance($id){
|
2004-02-06 05:25:34 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
if (! $assignment = get_record('assignment', 'id', $id)) {
|
|
|
|
return false;
|
2004-02-06 05:25:34 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 09:20:42 +00:00
|
|
|
// fall back to base class if plugin missing
|
|
|
|
$classfile = "$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php";
|
|
|
|
if (file_exists($classfile)) {
|
|
|
|
require_once($classfile);
|
|
|
|
$assignmentclass = "assignment_$assignment->assignmenttype";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
debugging("Missing assignment plug-in: {$assignment->assignmenttype}. Using base class for deleting instead.");
|
|
|
|
$assignmentclass = "assignment_base";
|
|
|
|
}
|
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
$ass = new $assignmentclass();
|
|
|
|
return $ass->delete_instance($assignment);
|
|
|
|
}
|
2004-02-15 06:32:54 +00:00
|
|
|
|
2005-04-02 11:32:22 +00:00
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Updates an assignment instance
|
|
|
|
*
|
|
|
|
* This is done by calling the update_instance() method of the assignment type class
|
|
|
|
*/
|
2005-04-14 13:24:40 +00:00
|
|
|
function assignment_update_instance($assignment){
|
|
|
|
global $CFG;
|
2004-02-06 05:25:34 +00:00
|
|
|
|
2005-11-10 00:22:57 +00:00
|
|
|
$assignment->assignmenttype = clean_param($assignment->assignmenttype, PARAM_SAFEDIR);
|
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
require_once("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php");
|
|
|
|
$assignmentclass = "assignment_$assignment->assignmenttype";
|
|
|
|
$ass = new $assignmentclass();
|
|
|
|
return $ass->update_instance($assignment);
|
2007-06-03 09:10:52 +00:00
|
|
|
}
|
2004-02-06 05:25:34 +00:00
|
|
|
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Adds an assignment instance
|
|
|
|
*
|
|
|
|
* This is done by calling the add_instance() method of the assignment type class
|
|
|
|
*/
|
2005-04-14 13:24:40 +00:00
|
|
|
function assignment_add_instance($assignment) {
|
|
|
|
global $CFG;
|
2004-02-15 06:32:54 +00:00
|
|
|
|
2005-11-10 00:22:57 +00:00
|
|
|
$assignment->assignmenttype = clean_param($assignment->assignmenttype, PARAM_SAFEDIR);
|
|
|
|
|
2005-04-14 13:24:40 +00:00
|
|
|
require_once("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php");
|
|
|
|
$assignmentclass = "assignment_$assignment->assignmenttype";
|
|
|
|
$ass = new $assignmentclass();
|
|
|
|
return $ass->add_instance($assignment);
|
|
|
|
}
|
2004-02-15 06:32:54 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Returns an outline of a user interaction with an assignment
|
|
|
|
*
|
|
|
|
* This is done by calling the user_outline() method of the assignment type class
|
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
function assignment_user_outline($course, $user, $mod, $assignment) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
require_once("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php");
|
|
|
|
$assignmentclass = "assignment_$assignment->assignmenttype";
|
|
|
|
$ass = new $assignmentclass($mod->id, $assignment, $mod, $course);
|
|
|
|
return $ass->user_outline($user);
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Prints the complete info about a user's interaction with an assignment
|
|
|
|
*
|
|
|
|
* This is done by calling the user_complete() method of the assignment type class
|
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
function assignment_user_complete($course, $user, $mod, $assignment) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
require_once("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php");
|
|
|
|
$assignmentclass = "assignment_$assignment->assignmenttype";
|
|
|
|
$ass = new $assignmentclass($mod->id, $assignment, $mod, $course);
|
|
|
|
return $ass->user_complete($user);
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Function to be run periodically according to the moodle cron
|
|
|
|
*
|
|
|
|
* Finds all assignment notifications that have yet to be mailed out, and mails them
|
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
function assignment_cron () {
|
|
|
|
|
|
|
|
global $CFG, $USER;
|
|
|
|
|
2007-08-21 09:53:35 +00:00
|
|
|
/// first execute all crons in plugins
|
|
|
|
if ($plugins = get_list_of_plugins('mod/assignment/type')) {
|
|
|
|
foreach ($plugins as $plugin) {
|
|
|
|
require_once("$CFG->dirroot/mod/assignment/type/$plugin/assignment.class.php");
|
|
|
|
$assignmentclass = "assignment_$plugin";
|
|
|
|
$ass = new $assignmentclass();
|
|
|
|
$ass->cron();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
/// Notices older than 1 day will not be mailed. This is to avoid the problem where
|
|
|
|
/// cron has not been running for a long time, and then suddenly people are flooded
|
|
|
|
/// with mail from the past few weeks or months
|
|
|
|
|
|
|
|
$timenow = time();
|
|
|
|
$endtime = $timenow - $CFG->maxeditingtime;
|
|
|
|
$starttime = $endtime - 24 * 3600; /// One day earlier
|
|
|
|
|
|
|
|
if ($submissions = assignment_get_unmailed_submissions($starttime, $endtime)) {
|
|
|
|
|
2007-02-13 08:54:06 +00:00
|
|
|
$CFG->enablerecordcache = true; // We want all the caching we can get
|
|
|
|
|
|
|
|
$realuser = clone($USER);
|
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
foreach ($submissions as $key => $submission) {
|
|
|
|
if (! set_field("assignment_submissions", "mailed", "1", "id", "$submission->id")) {
|
|
|
|
echo "Could not update the mailed field for id $submission->id. Not mailed.\n";
|
|
|
|
unset($submissions[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$timenow = time();
|
|
|
|
|
|
|
|
foreach ($submissions as $submission) {
|
|
|
|
|
|
|
|
echo "Processing assignment submission $submission->id\n";
|
|
|
|
|
|
|
|
if (! $user = get_record("user", "id", "$submission->userid")) {
|
|
|
|
echo "Could not find user $post->userid\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $course = get_record("course", "id", "$submission->course")) {
|
|
|
|
echo "Could not find course $submission->course\n";
|
|
|
|
continue;
|
|
|
|
}
|
2007-02-13 08:54:06 +00:00
|
|
|
|
|
|
|
/// Override the language and timezone of the "current" user, so that
|
|
|
|
/// mail is customised for the receiver.
|
|
|
|
$USER = $user;
|
|
|
|
course_setup($course);
|
|
|
|
|
2007-02-13 08:43:17 +00:00
|
|
|
if (!has_capability('moodle/course:view', get_context_instance(CONTEXT_COURSE, $submission->course), $user->id)) {
|
2007-02-28 06:25:22 +00:00
|
|
|
echo fullname($user)." not an active participant in " . format_string($course->shortname) . "\n";
|
2005-04-17 15:38:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $teacher = get_record("user", "id", "$submission->teacher")) {
|
|
|
|
echo "Could not find teacher $submission->teacher\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $mod = get_coursemodule_from_instance("assignment", $submission->assignment, $course->id)) {
|
|
|
|
echo "Could not find course module for assignment id $submission->assignment\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $mod->visible) { /// Hold mail notification for hidden assignments until later
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$strassignments = get_string("modulenameplural", "assignment");
|
|
|
|
$strassignment = get_string("modulename", "assignment");
|
|
|
|
|
2007-02-13 08:54:06 +00:00
|
|
|
$assignmentinfo = new object();
|
2005-04-17 15:38:02 +00:00
|
|
|
$assignmentinfo->teacher = fullname($teacher);
|
|
|
|
$assignmentinfo->assignment = format_string($submission->name,true);
|
|
|
|
$assignmentinfo->url = "$CFG->wwwroot/mod/assignment/view.php?id=$mod->id";
|
|
|
|
|
|
|
|
$postsubject = "$course->shortname: $strassignments: ".format_string($submission->name,true);
|
|
|
|
$posttext = "$course->shortname -> $strassignments -> ".format_string($submission->name,true)."\n";
|
|
|
|
$posttext .= "---------------------------------------------------------------------\n";
|
2006-05-26 09:07:13 +00:00
|
|
|
$posttext .= get_string("assignmentmail", "assignment", $assignmentinfo)."\n";
|
2005-04-17 15:38:02 +00:00
|
|
|
$posttext .= "---------------------------------------------------------------------\n";
|
|
|
|
|
|
|
|
if ($user->mailformat == 1) { // HTML
|
|
|
|
$posthtml = "<p><font face=\"sans-serif\">".
|
|
|
|
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->".
|
|
|
|
"<a href=\"$CFG->wwwroot/mod/assignment/index.php?id=$course->id\">$strassignments</a> ->".
|
|
|
|
"<a href=\"$CFG->wwwroot/mod/assignment/view.php?id=$mod->id\">".format_string($submission->name,true)."</a></font></p>";
|
|
|
|
$posthtml .= "<hr /><font face=\"sans-serif\">";
|
|
|
|
$posthtml .= "<p>".get_string("assignmentmailhtml", "assignment", $assignmentinfo)."</p>";
|
|
|
|
$posthtml .= "</font><hr />";
|
|
|
|
} else {
|
|
|
|
$posthtml = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! email_to_user($user, $teacher, $postsubject, $posttext, $posthtml)) {
|
|
|
|
echo "Error: assignment cron: Could not send out mail for id $submission->id to user $user->id ($user->email)\n";
|
|
|
|
}
|
|
|
|
}
|
2007-02-13 08:54:06 +00:00
|
|
|
|
|
|
|
$USER = $realuser;
|
|
|
|
course_setup(SITEID); // reset cron user language, theme and timezone settings
|
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-06-03 09:10:52 +00:00
|
|
|
/**
|
|
|
|
* Return grade for given user or all users.
|
|
|
|
*
|
|
|
|
* @param int $assignmentid id of assignment
|
|
|
|
* @param int $userid optional user id, 0 means all users
|
|
|
|
* @return array array of grades, false if none
|
|
|
|
*/
|
2007-06-05 22:58:37 +00:00
|
|
|
function assignment_get_user_grades($assignment, $userid=0) {
|
2007-06-03 09:10:52 +00:00
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$user = $userid ? "AND u.id = $userid" : "";
|
|
|
|
|
2007-11-01 08:25:05 +00:00
|
|
|
$sql = "SELECT u.id, u.id AS userid, s.grade AS rawgrade, s.submissioncomment AS feedback, s.format AS feedbackformat,
|
|
|
|
s.teacher AS usermodified, s.timemarked AS dategraded, s.timemodified AS datesubmitted
|
2007-06-03 09:10:52 +00:00
|
|
|
FROM {$CFG->prefix}user u, {$CFG->prefix}assignment_submissions s
|
2007-06-05 22:58:37 +00:00
|
|
|
WHERE u.id = s.userid AND s.assignment = $assignment->id
|
2007-06-03 09:26:45 +00:00
|
|
|
$user";
|
2007-06-03 09:10:52 +00:00
|
|
|
|
|
|
|
return get_records_sql($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update grades by firing grade_updated event
|
|
|
|
*
|
2007-06-05 22:58:37 +00:00
|
|
|
* @param object $assignment null means all assignments
|
2007-06-03 09:10:52 +00:00
|
|
|
* @param int $userid specific user only, 0 mean all
|
|
|
|
*/
|
2007-06-05 22:58:37 +00:00
|
|
|
function assignment_update_grades($assignment=null, $userid=0, $nullifnone=true) {
|
2007-06-03 09:10:52 +00:00
|
|
|
global $CFG;
|
2007-06-05 22:58:37 +00:00
|
|
|
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2007-06-05 22:58:37 +00:00
|
|
|
if ($assignment != null) {
|
|
|
|
if ($grades = assignment_get_user_grades($assignment, $userid)) {
|
|
|
|
foreach($grades as $k=>$v) {
|
2007-06-20 23:06:29 +00:00
|
|
|
if ($v->rawgrade == -1) {
|
|
|
|
$grades[$k]->rawgrade = null;
|
2007-06-03 09:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-01 08:25:05 +00:00
|
|
|
assignment_grade_item_update($assignment, $grades);
|
2007-12-07 16:12:02 +00:00
|
|
|
} else {
|
2007-12-25 20:51:23 +00:00
|
|
|
assignment_grade_item_update($assignment);
|
2007-06-03 09:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2007-06-03 09:26:45 +00:00
|
|
|
$sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid
|
|
|
|
FROM {$CFG->prefix}assignment a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
|
|
|
|
WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
|
2007-06-03 09:10:52 +00:00
|
|
|
if ($rs = get_recordset_sql($sql)) {
|
2007-10-10 12:19:27 +00:00
|
|
|
while ($assignment = rs_fetch_next_record($rs)) {
|
2007-11-07 04:29:15 +00:00
|
|
|
if ($assignment->grade != 0) {
|
2007-10-10 12:19:27 +00:00
|
|
|
assignment_update_grades($assignment);
|
2007-11-01 08:25:05 +00:00
|
|
|
} else {
|
|
|
|
assignment_grade_item_update($assignment);
|
2007-06-03 09:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rs_close($rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-06-05 22:58:37 +00:00
|
|
|
* Create grade item for given assignment
|
2007-06-03 09:10:52 +00:00
|
|
|
*
|
2007-06-03 12:37:50 +00:00
|
|
|
* @param object $assignment object with extra cmidnumber
|
2007-11-29 14:43:04 +00:00
|
|
|
* @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
|
2007-06-05 22:58:37 +00:00
|
|
|
* @return int 0 if ok, error code otherwise
|
2007-06-03 09:10:52 +00:00
|
|
|
*/
|
2007-11-01 08:25:05 +00:00
|
|
|
function assignment_grade_item_update($assignment, $grades=NULL) {
|
2007-06-05 22:58:37 +00:00
|
|
|
global $CFG;
|
|
|
|
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
2007-06-03 09:10:52 +00:00
|
|
|
}
|
|
|
|
|
2007-06-03 12:37:50 +00:00
|
|
|
if (!isset($assignment->courseid)) {
|
|
|
|
$assignment->courseid = $assignment->course;
|
|
|
|
}
|
|
|
|
|
2007-06-05 22:58:37 +00:00
|
|
|
$params = array('itemname'=>$assignment->name, 'idnumber'=>$assignment->cmidnumber);
|
2007-06-03 09:10:52 +00:00
|
|
|
|
|
|
|
if ($assignment->grade > 0) {
|
|
|
|
$params['gradetype'] = GRADE_TYPE_VALUE;
|
|
|
|
$params['grademax'] = $assignment->grade;
|
|
|
|
$params['grademin'] = 0;
|
|
|
|
|
|
|
|
} else if ($assignment->grade < 0) {
|
|
|
|
$params['gradetype'] = GRADE_TYPE_SCALE;
|
|
|
|
$params['scaleid'] = -$assignment->grade;
|
|
|
|
|
|
|
|
} else {
|
2007-06-05 22:58:37 +00:00
|
|
|
$params['gradetype'] = GRADE_TYPE_NONE;
|
2007-06-03 09:10:52 +00:00
|
|
|
}
|
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
if ($grades === 'reset') {
|
|
|
|
$params['reset'] = true;
|
|
|
|
$grades = NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-01 08:25:05 +00:00
|
|
|
return grade_update('mod/assignment', $assignment->courseid, 'mod', 'assignment', $assignment->id, 0, $grades, $params);
|
2007-06-03 09:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete grade item for given assignment
|
|
|
|
*
|
2007-06-03 12:37:50 +00:00
|
|
|
* @param object $assignment object
|
2007-06-05 22:58:37 +00:00
|
|
|
* @return object assignment
|
2007-06-03 09:10:52 +00:00
|
|
|
*/
|
|
|
|
function assignment_grade_item_delete($assignment) {
|
2007-06-05 22:58:37 +00:00
|
|
|
global $CFG;
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
|
2007-06-03 12:37:50 +00:00
|
|
|
if (!isset($assignment->courseid)) {
|
|
|
|
$assignment->courseid = $assignment->course;
|
|
|
|
}
|
|
|
|
|
2007-06-06 23:04:24 +00:00
|
|
|
return grade_update('mod/assignment', $assignment->courseid, 'mod', 'assignment', $assignment->id, 0, NULL, array('deleted'=>1));
|
2007-06-03 09:10:52 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Returns the users with data in one assignment (students and teachers)
|
|
|
|
*
|
|
|
|
* @param $assignmentid int
|
|
|
|
* @return array of user objects
|
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
function assignment_get_participants($assignmentid) {
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
//Get students
|
|
|
|
$students = get_records_sql("SELECT DISTINCT u.id, u.id
|
|
|
|
FROM {$CFG->prefix}user u,
|
|
|
|
{$CFG->prefix}assignment_submissions a
|
|
|
|
WHERE a.assignment = '$assignmentid' and
|
|
|
|
u.id = a.userid");
|
|
|
|
//Get teachers
|
|
|
|
$teachers = get_records_sql("SELECT DISTINCT u.id, u.id
|
|
|
|
FROM {$CFG->prefix}user u,
|
|
|
|
{$CFG->prefix}assignment_submissions a
|
|
|
|
WHERE a.assignment = '$assignmentid' and
|
|
|
|
u.id = a.teacher");
|
|
|
|
|
|
|
|
//Add teachers to students
|
|
|
|
if ($teachers) {
|
|
|
|
foreach ($teachers as $teacher) {
|
|
|
|
$students[$teacher->id] = $teacher;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Return students array (it contains an array of unique users)
|
|
|
|
return ($students);
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Checks if a scale is being used by an assignment
|
|
|
|
*
|
|
|
|
* This is used by the backup code to decide whether to back up a scale
|
|
|
|
* @param $assignmentid int
|
|
|
|
* @param $scaleid int
|
|
|
|
* @return boolean True if the scale is used by the assignment
|
|
|
|
*/
|
2007-09-18 18:37:58 +00:00
|
|
|
function assignment_scale_used($assignmentid, $scaleid) {
|
2005-04-17 15:38:02 +00:00
|
|
|
|
|
|
|
$return = false;
|
|
|
|
|
|
|
|
$rec = get_record('assignment','id',$assignmentid,'grade',-$scaleid);
|
|
|
|
|
|
|
|
if (!empty($rec) && !empty($scaleid)) {
|
|
|
|
$return = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2007-09-18 18:37:58 +00:00
|
|
|
/**
|
|
|
|
* Checks if scale is being used by any instance of assignment
|
|
|
|
*
|
|
|
|
* This is used to find out if scale used anywhere
|
|
|
|
* @param $scaleid int
|
|
|
|
* @return boolean True if the scale is used by any assignment
|
|
|
|
*/
|
|
|
|
function assignment_scale_used_anywhere($scaleid) {
|
|
|
|
if ($scaleid and record_exists('assignment', 'grade', -$scaleid)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Make sure up-to-date events are created for all assignment instances
|
|
|
|
*
|
|
|
|
* This standard function will check all instances of this module
|
|
|
|
* and make sure there are up-to-date events created for each of them.
|
|
|
|
* If courseid = 0, then every assignment event in the site is checked, else
|
|
|
|
* only assignment events belonging to the course specified are checked.
|
|
|
|
* This function is used, in its new format, by restore_refresh_events()
|
|
|
|
*
|
|
|
|
* @param $courseid int optional If zero then all assignments for all courses are covered
|
|
|
|
* @return boolean Always returns true
|
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
function assignment_refresh_events($courseid = 0) {
|
|
|
|
|
|
|
|
if ($courseid == 0) {
|
|
|
|
if (! $assignments = get_records("assignment")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (! $assignments = get_records("assignment", "course", $courseid)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$moduleid = get_field('modules', 'id', 'name', 'assignment');
|
|
|
|
|
|
|
|
foreach ($assignments as $assignment) {
|
|
|
|
$event = NULL;
|
|
|
|
$event->name = addslashes($assignment->name);
|
|
|
|
$event->description = addslashes($assignment->description);
|
|
|
|
$event->timestart = $assignment->timedue;
|
|
|
|
|
|
|
|
if ($event->id = get_field('event', 'id', 'modulename', 'assignment', 'instance', $assignment->id)) {
|
|
|
|
update_event($event);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$event->courseid = $assignment->course;
|
|
|
|
$event->groupid = 0;
|
|
|
|
$event->userid = 0;
|
|
|
|
$event->modulename = 'assignment';
|
|
|
|
$event->instance = $assignment->id;
|
|
|
|
$event->eventtype = 'due';
|
|
|
|
$event->timeduration = 0;
|
|
|
|
$event->visible = get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $assignment->id);
|
|
|
|
add_event($event);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Print recent activity from all assignments in a given course
|
|
|
|
*
|
|
|
|
* This is used by the recent activity block
|
|
|
|
*/
|
2008-01-24 20:33:50 +00:00
|
|
|
function assignment_print_recent_activity($course, $viewfullnames, $timestart) {
|
|
|
|
global $CFG, $USER;
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
// do not use log table if possible, it may be huge
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if (!$submissions = get_records_sql("SELECT asb.id, asb.timemodified, cm.id AS cmid, asb.userid,
|
|
|
|
u.firstname, u.lastname, u.email, u.picture
|
|
|
|
FROM {$CFG->prefix}assignment_submissions asb
|
|
|
|
JOIN {$CFG->prefix}assignment a ON a.id = asb.assignment
|
|
|
|
JOIN {$CFG->prefix}course_modules cm ON cm.instance = a.id
|
|
|
|
JOIN {$CFG->prefix}modules md ON md.id = cm.module
|
|
|
|
JOIN {$CFG->prefix}user u ON u.id = asb.userid
|
|
|
|
WHERE asb.timemodified > $timestart AND
|
|
|
|
a.course = {$course->id} AND
|
|
|
|
md.name = 'assignment'
|
|
|
|
ORDER BY asb.timemodified ASC")) {
|
|
|
|
return false;
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$modinfo =& get_fast_modinfo($course); // reference needed because we might load the groups
|
|
|
|
$show = array();
|
|
|
|
$grader = array();
|
|
|
|
|
|
|
|
foreach($submissions as $submission) {
|
|
|
|
if (!array_key_exists($submission->cmid, $modinfo->cms)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$cm = $modinfo->cms[$submission->cmid];
|
|
|
|
if (!$cm->uservisible) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($submission->userid == $USER->id) {
|
|
|
|
$show[] = $submission;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the act of sumitting of assignemnt may be considered private - only graders will see it if specified
|
|
|
|
if (empty($CFG->assignment_showrecentsubmissions)) {
|
|
|
|
if (!array_key_exists($cm->id, $grader)) {
|
|
|
|
$grader[$cm->id] = has_capability('moodle/grade:viewall', get_context_instance(CONTEXT_MODULE, $cm->id));
|
|
|
|
}
|
|
|
|
if (!$grader[$cm->id]) {
|
|
|
|
continue;
|
2006-10-18 21:02:30 +00:00
|
|
|
}
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$groupmode = groups_get_activity_groupmode($cm, $course);
|
|
|
|
|
|
|
|
if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id))) {
|
|
|
|
if (isguestuser()) {
|
|
|
|
// shortcut - guest user does not belong into any group
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($modinfo->groups)) {
|
|
|
|
$modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
|
|
|
|
}
|
|
|
|
|
|
|
|
// this will be slow - show only users that share group with me in this cm
|
|
|
|
if (empty($modinfo->groups[$cm->id])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$usersgroups = groups_get_all_groups($course->id, $cm->userid, $cm->groupingid);
|
|
|
|
if (is_array($usersgroups)) {
|
|
|
|
$usersgroups = array_keys($usersgroups);
|
|
|
|
$interset = array_intersect($usersgroups, $modinfo->groups[$cm->id]);
|
|
|
|
if (empty($intersect)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
$show[] = $submission;
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if (empty($show)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
print_headline(get_string('newsubmissions', 'assignment').':');
|
|
|
|
|
|
|
|
foreach ($show as $submission) {
|
|
|
|
$cm = $modinfo->cms[$submission->cmid];
|
|
|
|
$link = $CFG->wwwroot.'/mod/assignment/view.php?id='.$cm->id;
|
|
|
|
print_recent_activity_note($submission->timemodified, $submission, $cm->name, $link, false, $viewfullnames);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
2008-01-24 20:33:50 +00:00
|
|
|
* Returns all assignments since a given time in specified forum.
|
2006-02-19 13:26:58 +00:00
|
|
|
*/
|
2008-01-24 20:33:50 +00:00
|
|
|
function assignment_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0) {
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
global $CFG, $COURSE, $USER;
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if ($COURSE->id == $courseid) {
|
|
|
|
$course = $COURSE;
|
2005-04-17 15:38:02 +00:00
|
|
|
} else {
|
2008-01-24 20:33:50 +00:00
|
|
|
$course = get_record('course', 'id', $courseid);
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
|
|
|
|
$modinfo =& get_fast_modinfo($course);
|
|
|
|
|
|
|
|
$cm = $modinfo->cms[$cmid];
|
|
|
|
|
|
|
|
if ($userid) {
|
|
|
|
$userselect = "AND u.id = $userid";
|
2005-04-17 15:38:02 +00:00
|
|
|
} else {
|
|
|
|
$userselect = "";
|
|
|
|
}
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if ($groupid) {
|
|
|
|
$groupselect = "AND gm.groupid = $groupid";
|
|
|
|
$groupjoin = "JOIN {$CFG->prefix}groups_members gm ON gm.userid=u.id";
|
|
|
|
} else {
|
|
|
|
$groupselect = "";
|
|
|
|
$groupjoin = "";
|
|
|
|
}
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if (!$submissions = get_records_sql("SELECT asb.id, asb.timemodified, asb.userid,
|
|
|
|
u.firstname, u.lastname, u.email, u.picture
|
|
|
|
FROM {$CFG->prefix}assignment_submissions asb
|
|
|
|
JOIN {$CFG->prefix}assignment a ON a.id = asb.assignment
|
|
|
|
JOIN {$CFG->prefix}user u ON u.id = asb.userid
|
|
|
|
$groupjoin
|
|
|
|
WHERE asb.timemodified > $timestart AND a.id = $cm->instance
|
|
|
|
$userselect $groupselect
|
|
|
|
ORDER BY asb.timemodified ASC")) {
|
|
|
|
return;
|
|
|
|
}
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$groupmode = groups_get_activity_groupmode($cm, $course);
|
|
|
|
$cm_context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
|
|
$grader = has_capability('moodle/grade:viewall', $cm_context);
|
|
|
|
$accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
|
|
|
|
$viewfullnames = has_capability('moodle/site:viewfullnames', $cm_context);
|
|
|
|
|
|
|
|
if (is_null($modinfo->groups)) {
|
|
|
|
$modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
|
|
|
|
}
|
|
|
|
|
|
|
|
$show = array();
|
|
|
|
|
|
|
|
foreach($submissions as $submission) {
|
|
|
|
if ($submission->userid == $USER->id) {
|
|
|
|
$show[] = $submission;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the act of sumitting of assignemnt may be considered private - only graders will see it if specified
|
|
|
|
if (!empty($CFG->assignment_limitrecentsubmissions)) {
|
|
|
|
if (!$grader) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if ($groupmode == SEPARATEGROUPS and !$accessallgroups) {
|
|
|
|
if (isguestuser()) {
|
|
|
|
// shortcut - guest user does not belong into any group
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this will be slow - show only users that share group with me in this cm
|
|
|
|
if (empty($modinfo->groups[$cm->id])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$usersgroups = groups_get_all_groups($course->id, $cm->userid, $cm->groupingid);
|
|
|
|
if (is_array($usersgroups)) {
|
|
|
|
$usersgroups = array_keys($usersgroups);
|
|
|
|
$interset = array_intersect($usersgroups, $modinfo->groups[$cm->id]);
|
|
|
|
if (empty($intersect)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$show[] = $submission;
|
|
|
|
}
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if (empty($show)) {
|
|
|
|
return;
|
|
|
|
}
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if ($grader) {
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
$userids = array();
|
|
|
|
foreach ($show as $id=>$submission) {
|
|
|
|
$userids[] = $submission->userid;
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
}
|
|
|
|
$grades = grade_get_grades($courseid, 'mod', 'assignment', $cm->instance, $userids);
|
|
|
|
}
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$aname = format_string($cm->name,true);
|
|
|
|
foreach ($show as $submission) {
|
|
|
|
$tmpactivity = new object();
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$tmpactivity->type = 'assignment';
|
|
|
|
$tmpactivity->cmid = $cm->id;
|
|
|
|
$tmpactivity->name = $aname;
|
|
|
|
$tmpactivity->section = $cm->section;
|
|
|
|
$tmpactivity->timestamp = $submission->timemodified;
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if ($grader) {
|
|
|
|
$tmpactivity->grade = $grades->items[0]->grades[$submission->userid]->str_long_grade;
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
|
|
|
|
$tmpactivity->user->userid = $submission->userid;
|
|
|
|
$tmpactivity->user->fullname = fullname($submission, $viewfullnames);
|
|
|
|
$tmpactivity->user->picture = $submission->picture;
|
|
|
|
|
|
|
|
$activities[$index++] = $tmpactivity;
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Print recent activity from all assignments in a given course
|
|
|
|
*
|
|
|
|
* This is used by course/recent.php
|
|
|
|
*/
|
2008-01-24 20:33:50 +00:00
|
|
|
function assignment_print_recent_mod_activity($activity, $courseid, $detail, $modnames) {
|
2005-04-17 15:38:02 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
echo '<table border="0" cellpadding="3" cellspacing="0" class="assignment-recent">';
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2007-01-08 03:34:44 +00:00
|
|
|
echo "<tr><td class=\"userpicture\" valign=\"top\">";
|
2008-01-24 20:33:50 +00:00
|
|
|
print_user_picture($activity->user->userid, $courseid, $activity->user->picture);
|
|
|
|
echo "</td><td>";
|
2005-04-17 15:38:02 +00:00
|
|
|
|
|
|
|
if ($detail) {
|
2008-01-24 20:33:50 +00:00
|
|
|
$modname = $modnames[$activity->type];
|
|
|
|
echo '<div class="title">';
|
|
|
|
echo "<img src=\"$CFG->modpixpath/assignment/icon.gif\" ".
|
|
|
|
"class=\"icon\" alt=\"$modname\">";
|
|
|
|
echo "<a href=\"$CFG->wwwroot/mod/assignment/view.php?id={$activity->cmid}\">{$activity->name}</a>";
|
|
|
|
echo '</div>';
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
if (isset($activity->grade)) {
|
|
|
|
echo '<div class="grade">';
|
|
|
|
echo get_string('grade').': ';
|
|
|
|
echo $activity->grade;
|
|
|
|
echo '</div>';
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
echo '<div class="user">';
|
|
|
|
echo "<a href=\"$CFG->wwwroot/user/view.php?id={$activity->user->userid}&course=$courseid\">"
|
|
|
|
."{$activity->user->fullname}</a> - ".userdate($activity->timestamp);
|
|
|
|
echo '</div>';
|
2005-04-17 15:38:02 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
echo "</td></tr></table>";
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// GENERIC SQL FUNCTIONS
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Fetch info from logs
|
|
|
|
*
|
|
|
|
* @param $log object with properties ->info (the assignment id) and ->userid
|
|
|
|
* @return array with assignment name and user firstname and lastname
|
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
function assignment_log_info($log) {
|
|
|
|
global $CFG;
|
|
|
|
return get_record_sql("SELECT a.name, u.firstname, u.lastname
|
2007-06-03 09:10:52 +00:00
|
|
|
FROM {$CFG->prefix}assignment a,
|
2005-04-17 15:38:02 +00:00
|
|
|
{$CFG->prefix}user u
|
2007-06-03 09:10:52 +00:00
|
|
|
WHERE a.id = '$log->info'
|
2005-04-17 15:38:02 +00:00
|
|
|
AND u.id = '$log->userid'");
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Return list of marked submissions that have not been mailed out for currently enrolled students
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
function assignment_get_unmailed_submissions($starttime, $endtime) {
|
2006-02-19 13:26:58 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
global $CFG;
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2005-04-17 15:38:02 +00:00
|
|
|
return get_records_sql("SELECT s.*, a.course, a.name
|
2007-06-03 09:10:52 +00:00
|
|
|
FROM {$CFG->prefix}assignment_submissions s,
|
2006-09-25 02:04:11 +00:00
|
|
|
{$CFG->prefix}assignment a
|
2007-06-03 09:10:52 +00:00
|
|
|
WHERE s.mailed = 0
|
|
|
|
AND s.timemarked <= $endtime
|
2006-09-14 09:08:07 +00:00
|
|
|
AND s.timemarked >= $starttime
|
2006-09-25 02:04:11 +00:00
|
|
|
AND s.assignment = a.id");
|
2006-09-14 09:08:07 +00:00
|
|
|
|
|
|
|
/* return get_records_sql("SELECT s.*, a.course, a.name
|
2007-06-03 09:10:52 +00:00
|
|
|
FROM {$CFG->prefix}assignment_submissions s,
|
2005-04-17 15:38:02 +00:00
|
|
|
{$CFG->prefix}assignment a,
|
|
|
|
{$CFG->prefix}user_students us
|
2007-06-03 09:10:52 +00:00
|
|
|
WHERE s.mailed = 0
|
|
|
|
AND s.timemarked <= $endtime
|
2005-04-17 15:38:02 +00:00
|
|
|
AND s.timemarked >= $starttime
|
|
|
|
AND s.assignment = a.id
|
|
|
|
AND s.userid = us.userid
|
|
|
|
AND a.course = us.course");
|
2006-09-14 09:08:07 +00:00
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Counts all real assignment submissions by ENROLLED students (not empty ones)
|
|
|
|
*
|
|
|
|
* There are also assignment type methods count_real_submissions() wich in the default
|
|
|
|
* implementation simply call this function.
|
|
|
|
* @param $groupid int optional If nonzero then count is restricted to this group
|
|
|
|
* @return int The number of submissions
|
|
|
|
*/
|
2008-01-24 20:33:50 +00:00
|
|
|
function assignment_count_real_submissions($cm, $groupid=0) {
|
2005-04-17 15:38:02 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2006-10-01 21:45:54 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
// this is all the users with this capability set, in this context or higher
|
|
|
|
if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $groupid, '', false)) {
|
|
|
|
$users = array_keys($users);
|
|
|
|
}
|
2006-10-01 21:45:54 +00:00
|
|
|
|
2008-01-24 20:33:50 +00:00
|
|
|
// if groupmembersonly used, remove users who are not in any group
|
|
|
|
if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
|
|
|
|
if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
|
|
|
|
$users = array_intersect($users, array_keys($groupingusers));
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-24 20:33:50 +00:00
|
|
|
|
|
|
|
if (empty($users)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$userlists = implode(',', $users);
|
|
|
|
|
|
|
|
return count_records_sql("SELECT COUNT('x')
|
|
|
|
FROM {$CFG->prefix}assignment_submissions
|
|
|
|
WHERE assignment = $cm->instance AND
|
|
|
|
timemodified > 0 AND
|
|
|
|
userid IN ($userlists)");
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all assignment submissions by ENROLLED students (even empty)
|
|
|
|
*
|
|
|
|
* There are also assignment type methods get_submissions() wich in the default
|
|
|
|
* implementation simply call this function.
|
|
|
|
* @param $sort string optional field names for the ORDER BY in the sql query
|
|
|
|
* @param $dir string optional specifying the sort direction, defaults to DESC
|
|
|
|
* @return array The submission objects indexed by id
|
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
function assignment_get_all_submissions($assignment, $sort="", $dir="DESC") {
|
|
|
|
/// Return all assignment submissions by ENROLLED students (even empty)
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if ($sort == "lastname" or $sort == "firstname") {
|
|
|
|
$sort = "u.$sort $dir";
|
|
|
|
} else if (empty($sort)) {
|
|
|
|
$sort = "a.timemodified DESC";
|
|
|
|
} else {
|
|
|
|
$sort = "a.$sort $dir";
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:08:07 +00:00
|
|
|
/* not sure this is needed at all since assignmenet already has a course define, so this join?
|
2005-04-17 15:38:02 +00:00
|
|
|
$select = "s.course = '$assignment->course' AND";
|
|
|
|
if ($assignment->course == SITEID) {
|
|
|
|
$select = '';
|
2006-09-14 09:08:07 +00:00
|
|
|
}*/
|
2007-06-03 09:10:52 +00:00
|
|
|
|
|
|
|
return get_records_sql("SELECT a.*
|
|
|
|
FROM {$CFG->prefix}assignment_submissions a,
|
2006-09-14 09:08:07 +00:00
|
|
|
{$CFG->prefix}user u
|
|
|
|
WHERE u.id = a.userid
|
2007-06-03 09:10:52 +00:00
|
|
|
AND a.assignment = '$assignment->id'
|
2006-09-14 09:08:07 +00:00
|
|
|
ORDER BY $sort");
|
2007-06-03 09:10:52 +00:00
|
|
|
|
|
|
|
/* return get_records_sql("SELECT a.*
|
|
|
|
FROM {$CFG->prefix}assignment_submissions a,
|
2005-04-17 15:38:02 +00:00
|
|
|
{$CFG->prefix}user_students s,
|
|
|
|
{$CFG->prefix}user u
|
|
|
|
WHERE a.userid = s.userid
|
|
|
|
AND u.id = a.userid
|
2007-06-03 09:10:52 +00:00
|
|
|
AND $select a.assignment = '$assignment->id'
|
2005-04-17 15:38:02 +00:00
|
|
|
ORDER BY $sort");
|
2006-09-14 09:08:07 +00:00
|
|
|
*/
|
2005-04-17 15:38:02 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 16:59:51 +00:00
|
|
|
/**
|
|
|
|
* Add a get_coursemodule_info function in case any assignment type wants to add 'extra' information
|
|
|
|
* for the course (see resource).
|
|
|
|
*
|
2007-08-03 11:55:28 +00:00
|
|
|
* Given a course_module object, this function returns any "extra" information that may be needed
|
2007-07-19 16:59:51 +00:00
|
|
|
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
|
2007-08-03 11:55:28 +00:00
|
|
|
*
|
2007-07-19 16:59:51 +00:00
|
|
|
* @param $coursemodule object The coursemodule object (record).
|
|
|
|
* @return object An object on information that the coures will know about (most noticeably, an icon).
|
2007-08-03 11:55:28 +00:00
|
|
|
*
|
2007-07-19 16:59:51 +00:00
|
|
|
*/
|
|
|
|
function assignment_get_coursemodule_info($coursemodule) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if (! $assignment = get_record('assignment', 'id', $coursemodule->instance)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php");
|
|
|
|
$assignmentclass = "assignment_$assignment->assignmenttype";
|
|
|
|
$ass = new $assignmentclass($coursemodule->id, $assignment);
|
|
|
|
|
|
|
|
return $ass->get_coursemodule_info($coursemodule);
|
|
|
|
}
|
2005-04-17 15:38:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// OTHER GENERAL FUNCTIONS FOR ASSIGNMENTS ///////////////////////////////////////
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Returns an array of installed assignment types indexed and sorted by name
|
|
|
|
*
|
|
|
|
* @return array The index is the name of the assignment type, the value its full name from the language strings
|
|
|
|
*/
|
2005-04-14 13:24:40 +00:00
|
|
|
function assignment_types() {
|
|
|
|
$types = array();
|
|
|
|
$names = get_list_of_plugins('mod/assignment/type');
|
|
|
|
foreach ($names as $name) {
|
|
|
|
$types[$name] = get_string('type'.$name, 'assignment');
|
2004-02-20 22:03:57 +00:00
|
|
|
}
|
2005-04-14 13:24:40 +00:00
|
|
|
asort($types);
|
|
|
|
return $types;
|
2004-02-15 06:32:54 +00:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:26:58 +00:00
|
|
|
/**
|
|
|
|
* Executes upgrade scripts for assignment types when necessary
|
|
|
|
*/
|
2005-04-14 13:24:40 +00:00
|
|
|
function assignment_upgrade_submodules() {
|
2005-07-15 17:32:36 +00:00
|
|
|
|
2007-08-29 14:42:39 +00:00
|
|
|
global $CFG;
|
2005-01-05 17:13:44 +00:00
|
|
|
|
2007-08-29 14:42:39 +00:00
|
|
|
/// Install/upgrade assignment types (it uses, simply, the standard plugin architecture)
|
|
|
|
upgrade_plugins('assignment_type', 'mod/assignment/type', "$CFG->wwwroot/$CFG->admin/index.php");
|
2005-01-05 17:13:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-03-14 21:26:37 +00:00
|
|
|
function assignment_print_overview($courses, &$htmlarray) {
|
2007-02-12 06:50:32 +00:00
|
|
|
|
2006-03-14 21:26:37 +00:00
|
|
|
global $USER, $CFG;
|
|
|
|
|
|
|
|
if (empty($courses) || !is_array($courses) || count($courses) == 0) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$assignments = get_all_instances_in_courses('assignment',$courses)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do assignment_base::isopen() here without loading the whole thing for speed
|
|
|
|
foreach ($assignments as $key => $assignment) {
|
|
|
|
$time = time();
|
2006-05-29 09:21:36 +00:00
|
|
|
if ($assignment->timedue) {
|
|
|
|
if ($assignment->preventlate) {
|
|
|
|
$isopen = ($assignment->timeavailable <= $time && $time <= $assignment->timedue);
|
|
|
|
} else {
|
|
|
|
$isopen = ($assignment->timeavailable <= $time);
|
|
|
|
}
|
2006-03-14 21:26:37 +00:00
|
|
|
}
|
2006-05-29 09:21:36 +00:00
|
|
|
if (empty($isopen) || empty($assignment->timedue)) {
|
2006-03-14 21:26:37 +00:00
|
|
|
unset($assignments[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$strduedate = get_string('duedate', 'assignment');
|
2006-05-29 08:37:51 +00:00
|
|
|
$strduedateno = get_string('duedateno', 'assignment');
|
2006-03-14 21:26:37 +00:00
|
|
|
$strgraded = get_string('graded', 'assignment');
|
|
|
|
$strnotgradedyet = get_string('notgradedyet', 'assignment');
|
|
|
|
$strnotsubmittedyet = get_string('notsubmittedyet', 'assignment');
|
|
|
|
$strsubmitted = get_string('submitted', 'assignment');
|
2006-03-15 03:36:33 +00:00
|
|
|
$strassignment = get_string('modulename', 'assignment');
|
2006-10-08 08:06:04 +00:00
|
|
|
$strreviewed = get_string('reviewed','assignment');
|
2006-03-14 21:26:37 +00:00
|
|
|
|
|
|
|
foreach ($assignments as $assignment) {
|
2006-03-15 04:01:10 +00:00
|
|
|
$str = '<div class="assignment overview"><div class="name">'.$strassignment. ': '.
|
2006-03-15 03:42:51 +00:00
|
|
|
'<a '.($assignment->visible ? '':' class="dimmed"').
|
2006-03-15 03:36:33 +00:00
|
|
|
'title="'.$strassignment.'" href="'.$CFG->wwwroot.
|
2006-03-15 03:42:51 +00:00
|
|
|
'/mod/assignment/view.php?id='.$assignment->coursemodule.'">'.
|
2006-03-15 03:47:08 +00:00
|
|
|
$assignment->name.'</a></div>';
|
2006-05-29 08:37:51 +00:00
|
|
|
if ($assignment->timedue) {
|
|
|
|
$str .= '<div class="info">'.$strduedate.': '.userdate($assignment->timedue).'</div>';
|
|
|
|
} else {
|
|
|
|
$str .= '<div class="info">'.$strduedateno.'</div>';
|
|
|
|
}
|
2006-10-03 23:34:03 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $assignment->coursemodule);
|
2006-08-14 05:55:40 +00:00
|
|
|
if (has_capability('mod/assignment:grade', $context)) {
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2006-09-14 09:08:07 +00:00
|
|
|
// count how many people can submit
|
|
|
|
$submissions = 0; // init
|
2007-05-28 08:55:15 +00:00
|
|
|
if ($students = get_users_by_capability($context, 'mod/assignment:submit', '', '', '', '', 0, '', false)) {
|
|
|
|
foreach ($students as $student) {
|
2007-12-04 06:25:42 +00:00
|
|
|
if (record_exists_sql("SELECT id FROM {$CFG->prefix}assignment_submissions
|
|
|
|
WHERE assignment = $assignment->id AND
|
2007-02-12 06:50:32 +00:00
|
|
|
userid = $student->id AND
|
|
|
|
teacher = 0 AND
|
|
|
|
timemarked = 0")) {
|
2007-06-03 09:10:52 +00:00
|
|
|
$submissions++;
|
2006-12-11 05:31:00 +00:00
|
|
|
}
|
2006-09-14 09:08:07 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-03 09:10:52 +00:00
|
|
|
|
2006-03-14 21:26:37 +00:00
|
|
|
if ($submissions) {
|
|
|
|
$str .= get_string('submissionsnotgraded', 'assignment', $submissions);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$sql = "SELECT *
|
|
|
|
FROM {$CFG->prefix}assignment_submissions
|
2006-06-26 16:16:43 +00:00
|
|
|
WHERE userid = '$USER->id'
|
|
|
|
AND assignment = '{$assignment->id}'";
|
2006-03-14 21:26:37 +00:00
|
|
|
if ($submission = get_record_sql($sql)) {
|
|
|
|
if ($submission->teacher == 0 && $submission->timemarked == 0) {
|
|
|
|
$str .= $strsubmitted . ', ' . $strnotgradedyet;
|
2006-10-08 08:06:04 +00:00
|
|
|
} else if ($submission->grade <= 0) {
|
|
|
|
$str .= $strsubmitted . ', ' . $strreviewed;
|
2006-03-14 21:26:37 +00:00
|
|
|
} else {
|
|
|
|
$str .= $strsubmitted . ', ' . $strgraded;
|
|
|
|
}
|
|
|
|
} else {
|
2006-03-15 03:36:33 +00:00
|
|
|
$str .= $strnotsubmittedyet . ' ' . assignment_display_lateness(time(), $assignment->timedue);
|
2006-03-14 21:26:37 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-15 03:42:51 +00:00
|
|
|
$str .= '</div>';
|
2006-03-15 03:36:33 +00:00
|
|
|
if (empty($htmlarray[$assignment->course]['assignment'])) {
|
|
|
|
$htmlarray[$assignment->course]['assignment'] = $str;
|
|
|
|
} else {
|
|
|
|
$htmlarray[$assignment->course]['assignment'] .= $str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function assignment_display_lateness($timesubmitted, $timedue) {
|
|
|
|
if (!$timedue) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
$time = $timedue - $timesubmitted;
|
|
|
|
if ($time < 0) {
|
|
|
|
$timetext = get_string('late', 'assignment', format_time($time));
|
|
|
|
return ' (<span class="late">'.$timetext.'</span>)';
|
|
|
|
} else {
|
|
|
|
$timetext = get_string('early', 'assignment', format_time($time));
|
|
|
|
return ' (<span class="early">'.$timetext.'</span>)';
|
2006-03-14 21:26:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-23 21:02:57 +00:00
|
|
|
function assignment_get_view_actions() {
|
|
|
|
return array('view');
|
|
|
|
}
|
|
|
|
|
|
|
|
function assignment_get_post_actions() {
|
|
|
|
return array('upload');
|
|
|
|
}
|
|
|
|
|
2007-01-02 09:33:07 +00:00
|
|
|
function assignment_get_types() {
|
2007-01-11 17:14:24 +00:00
|
|
|
global $CFG;
|
2007-01-02 09:33:07 +00:00
|
|
|
$types = array();
|
|
|
|
|
|
|
|
$type = new object();
|
|
|
|
$type->modclass = MOD_CLASS_ACTIVITY;
|
|
|
|
$type->type = "assignment_group_start";
|
|
|
|
$type->typestr = '--'.get_string('modulenameplural', 'assignment');
|
|
|
|
$types[] = $type;
|
|
|
|
|
|
|
|
$standardassignments = array('upload','online','uploadsingle','offline');
|
|
|
|
foreach ($standardassignments as $assignmenttype) {
|
|
|
|
$type = new object();
|
|
|
|
$type->modclass = MOD_CLASS_ACTIVITY;
|
|
|
|
$type->type = "assignment&type=$assignmenttype";
|
|
|
|
$type->typestr = get_string("type$assignmenttype", 'assignment');
|
|
|
|
$types[] = $type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Drop-in extra assignment types
|
|
|
|
$assignmenttypes = get_list_of_plugins('mod/assignment/type');
|
|
|
|
foreach ($assignmenttypes as $assignmenttype) {
|
|
|
|
if (!empty($CFG->{'assignment_hide_'.$assignmenttype})) { // Not wanted
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!in_array($assignmenttype, $standardassignments)) {
|
|
|
|
$type = new object();
|
|
|
|
$type->modclass = MOD_CLASS_ACTIVITY;
|
|
|
|
$type->type = "assignment&type=$assignmenttype";
|
|
|
|
$type->typestr = get_string("type$assignmenttype", 'assignment');
|
|
|
|
$types[] = $type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$type = new object();
|
|
|
|
$type->modclass = MOD_CLASS_ACTIVITY;
|
|
|
|
$type->type = "assignment_group_end";
|
|
|
|
$type->typestr = '--';
|
|
|
|
$types[] = $type;
|
|
|
|
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
/**
|
|
|
|
* Removes all grades from gradebook
|
|
|
|
* @param int $courseid
|
|
|
|
* @param string optional type
|
|
|
|
*/
|
|
|
|
function assignment_reset_gradebook($courseid, $type='') {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$type = $type ? "AND a.assignmenttype='$type'" : '';
|
|
|
|
|
|
|
|
$sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid
|
|
|
|
FROM {$CFG->prefix}assignment a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
|
|
|
|
WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id AND a.course=$courseid $type";
|
|
|
|
|
|
|
|
if ($assignments = get_records_sql($sql)) {
|
|
|
|
foreach ($assignments as $assignment) {
|
|
|
|
assignment_grade_item_update($assignment, 'reset');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is used by the reset_course_userdata function in moodlelib.
|
|
|
|
* This function will remove all posts from the specified assignment
|
|
|
|
* and clean up any related data.
|
|
|
|
* @param $data the data submitted from the reset course.
|
|
|
|
* @return array status array
|
|
|
|
*/
|
|
|
|
function assignment_reset_userdata($data) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$status = array();
|
|
|
|
|
|
|
|
foreach (get_list_of_plugins('mod/assignment/type') as $type) {
|
|
|
|
require_once("$CFG->dirroot/mod/assignment/type/$type/assignment.class.php");
|
|
|
|
$assignmentclass = "assignment_$type";
|
|
|
|
$ass = new $assignmentclass();
|
|
|
|
$status = array_merge($status, $ass->reset_userdata($data));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of the function for printing the form elements that control
|
|
|
|
* whether the course reset functionality affects the assignment.
|
|
|
|
* @param $mform form passed by reference
|
|
|
|
*/
|
|
|
|
function assignment_reset_course_form_definition(&$mform) {
|
|
|
|
$mform->addElement('header', 'assignmentheader', get_string('modulenameplural', 'assignment'));
|
|
|
|
$mform->addElement('advcheckbox', 'reset_assignment_submissions', get_string('deleteallsubmissions','assignment'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Course reset form defaults.
|
|
|
|
*/
|
|
|
|
function assignment_reset_course_form_defaults($course) {
|
|
|
|
return array('reset_assignment_submissions'=>1);
|
|
|
|
}
|
|
|
|
|
2006-03-15 03:36:33 +00:00
|
|
|
?>
|