assignment.class.php
来自「很棒的在线教学系统」· PHP 代码 · 共 1,080 行 · 第 1/3 页
PHP
1,080 行
<?php // $Id: assignment.class.php,v 1.32.2.15 2008/10/09 11:22:14 poltawski Exp $require_once($CFG->libdir.'/formslib.php');define('ASSIGNMENT_STATUS_SUBMITTED', 'submitted'); // student thinks it is finisheddefine('ASSIGNMENT_STATUS_CLOSED', 'closed'); // teacher prevents more submissions/** * Extend the base assignment class for assignments where you upload a single file * */class assignment_upload extends assignment_base { function assignment_upload($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) { parent::assignment_base($cmid, $assignment, $cm, $course); $this->type = 'upload'; } function view() { global $USER; require_capability('mod/assignment:view', $this->context); add_to_log($this->course->id, 'assignment', 'view', "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id); $this->view_header(); if ($this->assignment->timeavailable > time() and !has_capability('mod/assignment:grade', $this->context) // grading user can see it anytime and $this->assignment->var3) { // force hiding before available date print_simple_box_start('center', '', '', 0, 'generalbox', 'intro'); print_string('notavailableyet', 'assignment'); print_simple_box_end(); } else { $this->view_intro(); } $this->view_dates(); if (has_capability('mod/assignment:submit', $this->context)) { $filecount = $this->count_user_files($USER->id); $submission = $this->get_submission($USER->id); $this->view_feedback(); if (!$this->drafts_tracked() or !$this->isopen() or $this->is_finalized($submission)) { print_heading(get_string('submission', 'assignment'), '', 3); } else { print_heading(get_string('submissiondraft', 'assignment'), '', 3); } if ($filecount and $submission) { print_simple_box($this->print_user_files($USER->id, true), 'center'); } else { if (!$this->isopen() or $this->is_finalized($submission)) { print_simple_box(get_string('nofiles', 'assignment'), 'center'); } else { print_simple_box(get_string('nofilesyet', 'assignment'), 'center'); } } $this->view_upload_form(); if ($this->notes_allowed()) { print_heading(get_string('notes', 'assignment'), '', 3); $this->view_notes(); } $this->view_final_submission(); } $this->view_footer(); } function view_feedback($submission=NULL) { global $USER, $CFG; require_once($CFG->libdir.'/gradelib.php'); if (!$submission) { /// Get submission for this assignment $submission = $this->get_submission($USER->id); } if (empty($submission->timemarked)) { /// Nothing to show, so print nothing if ($this->count_responsefiles($USER->id)) { print_heading(get_string('responsefiles', 'assignment', $this->course->teacher), '', 3); $responsefiles = $this->print_responsefiles($USER->id, true); print_simple_box($responsefiles, 'center'); } return; } $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; } if ($grade->grade === null and empty($grade->str_feedback)) { /// Nothing to show yet return; } $graded_date = $grade->dategraded; $graded_by = $grade->usermodified; /// We need the teacher info if (!$teacher = get_record('user', 'id', $graded_by)) { error('Could not find the teacher'); } /// Print the feedback print_heading(get_string('submissionfeedback', 'assignment'), '', 3); echo '<table cellspacing="0" class="feedback">'; echo '<tr>'; echo '<td class="left picture">'; print_user_picture($teacher, $this->course->id, $teacher->picture); echo '</td>'; echo '<td class="topic">'; echo '<div class="from">'; echo '<div class="fullname">'.fullname($teacher).'</div>'; echo '<div class="time">'.userdate($graded_date).'</div>'; echo '</div>'; echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td class="left side"> </td>'; echo '<td class="content">'; if ($this->assignment->grade) { echo '<div class="grade">'; echo get_string("grade").': '.$grade->str_long_grade; echo '</div>'; echo '<div class="clearer"></div>'; } echo '<div class="comment">'; echo $grade->str_feedback; echo '</div>'; echo '</tr>'; echo '<tr>'; echo '<td class="left side"> </td>'; echo '<td class="content">'; echo $this->print_responsefiles($USER->id, true); echo '</tr>'; echo '</table>'; } function view_upload_form() { global $CFG, $USER; $submission = $this->get_submission($USER->id); $struploadafile = get_string('uploadafile'); $maxbytes = $this->assignment->maxbytes == 0 ? $this->course->maxbytes : $this->assignment->maxbytes; $strmaxsize = get_string('maxsize', '', display_size($maxbytes)); if ($this->is_finalized($submission)) { // no uploading return; } if ($this->can_upload_file($submission)) { echo '<div style="text-align:center">'; echo '<form enctype="multipart/form-data" method="post" action="upload.php">'; echo '<fieldset class="invisiblefieldset">'; echo "<p>$struploadafile ($strmaxsize)</p>"; echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />'; echo '<input type="hidden" name="action" value="uploadfile" />'; require_once($CFG->libdir.'/uploadlib.php'); upload_print_form_fragment(1,array('newfile'),null,false,null,0,$this->assignment->maxbytes,false); echo '<input type="submit" name="save" value="'.get_string('uploadthisfile').'" />'; echo '</fieldset>'; echo '</form>'; echo '</div>'; echo '<br />'; } } function view_notes() { global $USER; if ($submission = $this->get_submission($USER->id) and !empty($submission->data1)) { print_simple_box(format_text($submission->data1, FORMAT_HTML), 'center', '630px'); } else { print_simple_box(get_string('notesempty', 'assignment'), 'center'); } if ($this->can_update_notes($submission)) { $options = array ('id'=>$this->cm->id, 'action'=>'editnotes'); echo '<div style="text-align:center">'; print_single_button('upload.php', $options, get_string('edit'), 'post', '_self', false); echo '</div>'; } } function view_final_submission() { global $CFG, $USER; $submission = $this->get_submission($USER->id); if ($this->isopen() and $this->can_finalize($submission)) { //print final submit button print_heading(get_string('submitformarking','assignment'), '', 3); echo '<div style="text-align:center">'; echo '<form method="post" action="upload.php">'; echo '<fieldset class="invisiblefieldset">'; echo '<input type="hidden" name="id" value="'.$this->cm->id.'" />'; echo '<input type="hidden" name="action" value="finalize" />'; echo '<input type="submit" name="formarking" value="'.get_string('sendformarking', 'assignment').'" />'; echo '</fieldset>'; echo '</form>'; echo '</div>'; } else if (!$this->isopen()) { print_heading(get_string('nomoresubmissions','assignment'), '', 3); } else if ($this->drafts_tracked() and $state = $this->is_finalized($submission)) { if ($state == ASSIGNMENT_STATUS_SUBMITTED) { print_heading(get_string('submitedformarking','assignment'), '', 3); } else { print_heading(get_string('nomoresubmissions','assignment'), '', 3); } } else { //no submission yet } } /** * Return true if var3 == hide description till available day * *@return boolean */ function description_is_hidden() { return ($this->assignment->var3 && (time() <= $this->assignment->timeavailable)); } function custom_feedbackform($submission, $return=false) { global $CFG; $mode = optional_param('mode', '', PARAM_ALPHA); $offset = optional_param('offset', 0, PARAM_INT); $forcerefresh = optional_param('forcerefresh', 0, PARAM_BOOL); $output = get_string('responsefiles', 'assignment').': '; $output .= '<form enctype="multipart/form-data" method="post" '. "action=\"$CFG->wwwroot/mod/assignment/upload.php\">"; $output .= '<div>'; $output .= '<input type="hidden" name="id" value="'.$this->cm->id.'" />'; $output .= '<input type="hidden" name="action" value="uploadresponse" />'; $output .= '<input type="hidden" name="mode" value="'.$mode.'" />'; $output .= '<input type="hidden" name="offset" value="'.$offset.'" />'; $output .= '<input type="hidden" name="userid" value="'.$submission->userid.'" />'; require_once($CFG->libdir.'/uploadlib.php'); $output .= upload_print_form_fragment(1,array('newfile'),null,false,null,0,0,true); $output .= '<input type="submit" name="save" value="'.get_string('uploadthisfile').'" />'; $output .= '</div>'; $output .= '</form>'; if ($forcerefresh) { $output .= $this->update_main_listing($submission); } $responsefiles = $this->print_responsefiles($submission->userid, true); if (!empty($responsefiles)) { $output .= $responsefiles; } if ($return) { return $output; } echo $output; return; } function print_student_answer($userid, $return=false){ global $CFG; $filearea = $this->file_area_name($userid); $submission = $this->get_submission($userid); $output = ''; if ($basedir = $this->file_area($userid)) { if ($this->drafts_tracked() and $this->isopen() and !$this->is_finalized($submission)) { $output .= '<strong>'.get_string('draft', 'assignment').':</strong> '; } if ($this->notes_allowed() and !empty($submission->data1)) { $output .= link_to_popup_window ('/mod/assignment/type/upload/notes.php?id='.$this->cm->id.'&userid='.$userid, 'notes'.$userid, get_string('notes', 'assignment'), 500, 780, get_string('notes', 'assignment'), 'none', true, 'notesbutton'.$userid); $output .= ' '; } if ($files = get_directory_list($basedir, 'responses')) { require_once($CFG->libdir.'/filelib.php'); foreach ($files as $key => $file) { $icon = mimeinfo('icon', $file); $ffurl = get_file_url("$filearea/$file"); $output .= '<a href="'.$ffurl.'" ><img class="icon" src="'.$CFG->pixpath.'/f/'.$icon.'" alt="'.$icon.'" />'.$file.'</a> '; } } } $output = '<div class="files">'.$output.'</div>'; $output .= '<br />'; return $output; } /** * 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 */ function print_user_files($userid=0, $return=false) { global $CFG, $USER; $mode = optional_param('mode', '', PARAM_ALPHA); $offset = optional_param('offset', 0, PARAM_INT); if (!$userid) { if (!isloggedin()) { return ''; } $userid = $USER->id; } $filearea = $this->file_area_name($userid); $output = ''; $submission = $this->get_submission($userid); $candelete = $this->can_delete_files($submission); $strdelete = get_string('delete'); if ($this->drafts_tracked() and $this->isopen() and !$this->is_finalized($submission) and !empty($mode)) { // only during grading $output .= '<strong>'.get_string('draft', 'assignment').':</strong><br />'; } if ($this->notes_allowed() and !empty($submission->data1) and !empty($mode)) { // only during grading $npurl = $CFG->wwwroot."/mod/assignment/type/upload/notes.php?id={$this->cm->id}&userid=$userid&offset=$offset&mode=single"; $output .= '<a href="'.$npurl.'">'.get_string('notes', 'assignment').'</a><br />'; } if ($basedir = $this->file_area($userid)) { if ($files = get_directory_list($basedir, 'responses')) { require_once($CFG->libdir.'/filelib.php');
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?