2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * This file contains the moodle hooks for the assign module. It delegates most functions to the assignment class.
21 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 defined('MOODLE_INTERNAL') || die();
27 * Adds an assignment instance
29 * This is done by calling the add_instance() method of the assignment type class
30 * @param stdClass $data
31 * @param mod_assign_mod_form $form
32 * @return int The instance id of the new assignment
34 function assign_add_instance(stdClass $data, mod_assign_mod_form $form) {
36 require_once($CFG->dirroot . '/mod/assign/locallib.php');
38 $assignment = new assign(context_module::instance($data->coursemodule), null, null);
39 return $assignment->add_instance($data, true);
43 * delete an assignment instance
47 function assign_delete_instance($id) {
49 require_once($CFG->dirroot . '/mod/assign/locallib.php');
50 $cm = get_coursemodule_from_instance('assign', $id, 0, false, MUST_EXIST);
51 $context = context_module::instance($cm->id);
53 $assignment = new assign($context, null, null);
54 return $assignment->delete_instance();
58 * Update an assignment instance
60 * This is done by calling the update_instance() method of the assignment type class
61 * @param stdClass $data
62 * @param mod_assign_mod_form $form
65 function assign_update_instance(stdClass $data, mod_assign_mod_form $form) {
67 require_once($CFG->dirroot . '/mod/assign/locallib.php');
68 $context = context_module::instance($data->coursemodule);
69 $assignment = new assign($context, null, null);
70 return $assignment->update_instance($data);
74 * Return the list if Moodle features this module supports
76 * @param string $feature FEATURE_xx constant for requested feature
77 * @return mixed True if module supports feature, null if doesn't know
79 function assign_supports($feature) {
81 case FEATURE_GROUPS: return true;
82 case FEATURE_GROUPINGS: return true;
83 case FEATURE_GROUPMEMBERSONLY: return true;
84 case FEATURE_MOD_INTRO: return true;
85 case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
86 case FEATURE_GRADE_HAS_GRADE: return true;
87 case FEATURE_GRADE_OUTCOMES: return true;
88 case FEATURE_BACKUP_MOODLE2: return true;
89 case FEATURE_SHOW_DESCRIPTION: return true;
90 case FEATURE_ADVANCED_GRADING: return true;
97 * Lists all gradable areas for the advanced grading methods gramework
99 * @return array('string'=>'string') An array with area names as keys and descriptions as values
101 function assign_grading_areas_list() {
102 return array('submissions'=>get_string('submissions', 'assign'));
107 * extend an assigment navigation settings
109 * @param settings_navigation $settings
110 * @param navigation_node $navref
113 function assign_extend_settings_navigation(settings_navigation $settings, navigation_node $navref) {
121 $context = $cm->context;
122 $course = $PAGE->course;
131 if (has_capability('gradereport/grader:view', $cm->context) && has_capability('moodle/grade:viewall', $cm->context)) {
132 $link = new moodle_url('/grade/report/grader/index.php', array('id' => $course->id));
133 $node = $navref->add(get_string('viewgradebook', 'assign'), $link, navigation_node::TYPE_SETTING);
136 // Link to download all submissions
137 if (has_capability('mod/assign:grade', $context)) {
138 $link = new moodle_url('/mod/assign/view.php', array('id' => $cm->id,'action'=>'grading'));
139 $node = $navref->add(get_string('viewgrading', 'assign'), $link, navigation_node::TYPE_SETTING);
141 $link = new moodle_url('/mod/assign/view.php', array('id' => $cm->id,'action'=>'downloadall'));
142 $node = $navref->add(get_string('downloadall', 'assign'), $link, navigation_node::TYPE_SETTING);
149 * Add a get_coursemodule_info function in case any assignment type wants to add 'extra' information
150 * for the course (see resource).
152 * Given a course_module object, this function returns any "extra" information that may be needed
153 * when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
155 * @param stdClass $coursemodule The coursemodule object (record).
156 * @return cached_cm_info An object on information that the courses will know about (most noticeably, an icon).
158 function assign_get_coursemodule_info($coursemodule) {
161 if (! $assignment = $DB->get_record('assign', array('id'=>$coursemodule->instance),
162 'id, name, alwaysshowdescription, allowsubmissionsfromdate, intro, introformat')) {
166 $result = new cached_cm_info();
167 $result->name = $assignment->name;
168 if ($coursemodule->showdescription) {
169 if ($assignment->alwaysshowdescription || time() > $assignment->allowsubmissionsfromdate) {
170 // Convert intro to html. Do not filter cached version, filters run at display time.
171 $result->content = format_module_intro('assign', $assignment, $coursemodule->id, false);
179 * Return a list of page types
180 * @param string $pagetype current page type
181 * @param stdClass $parentcontext Block's parent context
182 * @param stdClass $currentcontext Current context of block
184 function assign_page_type_list($pagetype, $parentcontext, $currentcontext) {
185 $module_pagetype = array(
186 'mod-assign-*' => get_string('page-mod-assign-x', 'assign'),
187 'mod-assign-view' => get_string('page-mod-assign-view', 'assign'),
189 return $module_pagetype;
193 * Print an overview of all assignments
196 * @param mixed $courses The list of courses to print the overview for
197 * @param array $htmlarray The array of html to return
199 function assign_print_overview($courses, &$htmlarray) {
200 global $USER, $CFG, $DB;
202 if (empty($courses) || !is_array($courses) || count($courses) == 0) {
206 if (!$assignments = get_all_instances_in_courses('assign',$courses)) {
210 $assignmentids = array();
212 // Do assignment_base::isopen() here without loading the whole thing for speed
213 foreach ($assignments as $key => $assignment) {
215 $isopen = $assignment->allowsubmissionsfromdate <= $time;
216 if ($assignment->duedate) {
217 if ($assignment->preventlatesubmissions) {
218 $isopen = ($isopen && $time <= $assignment->duedate);
222 $assignmentids[] = $assignment->id;
226 if (empty($assignmentids)){
227 // no assignments to look at - we're done
231 $strduedate = get_string('duedate', 'assign');
232 $strduedateno = get_string('duedateno', 'assign');
233 $strgraded = get_string('graded', 'assign');
234 $strnotgradedyet = get_string('notgradedyet', 'assign');
235 $strnotsubmittedyet = get_string('notsubmittedyet', 'assign');
236 $strsubmitted = get_string('submitted', 'assign');
237 $strassignment = get_string('modulename', 'assign');
238 $strreviewed = get_string('reviewed','assign');
241 // NOTE: we do all possible database work here *outside* of the loop to ensure this scales
243 list($sqlassignmentids, $assignmentidparams) = $DB->get_in_or_equal($assignmentids);
245 // build up and array of unmarked submissions indexed by assignment id/ userid
246 // for use where the user has grading rights on assignment
247 $rs = $DB->get_recordset_sql("SELECT s.assignment as assignment, s.userid as userid, s.id as id, s.status as status, g.timemodified as timegraded
248 FROM {assign_submission} s LEFT JOIN {assign_grades} g ON s.userid = g.userid and s.assignment = g.assignment
249 WHERE g.timemodified = 0 OR s.timemodified > g.timemodified
250 AND s.assignment $sqlassignmentids", $assignmentidparams);
252 $unmarkedsubmissions = array();
253 foreach ($rs as $rd) {
254 $unmarkedsubmissions[$rd->assignment][$rd->userid] = $rd->id;
259 // get all user submissions, indexed by assignment id
260 $mysubmissions = $DB->get_records_sql("SELECT a.id AS assignment, a.nosubmissions AS offline, g.timemodified AS timemarked, g.grader AS grader, g.grade AS grade, s.status AS status
261 FROM {assign} a LEFT JOIN {assign_grades} g ON g.assignment = a.id AND g.userid = ? LEFT JOIN {assign_submission} s ON s.assignment = a.id AND s.userid = ?
262 AND a.id $sqlassignmentids", array_merge(array($USER->id, $USER->id), $assignmentidparams));
264 foreach ($assignments as $assignment) {
265 // Do not show assignments that are not open
266 if (!in_array($assignment->id, $assignmentids)) {
269 $str = '<div class="assign overview"><div class="name">'.$strassignment. ': '.
270 '<a '.($assignment->visible ? '':' class="dimmed"').
271 'title="'.$strassignment.'" href="'.$CFG->wwwroot.
272 '/mod/assign/view.php?id='.$assignment->coursemodule.'">'.
273 format_string($assignment->name).'</a></div>';
274 if ($assignment->duedate) {
275 $str .= '<div class="info">'.$strduedate.': '.userdate($assignment->duedate).'</div>';
277 $str .= '<div class="info">'.$strduedateno.'</div>';
279 $context = context_module::instance($assignment->coursemodule);
280 if (has_capability('mod/assign:grade', $context)) {
282 // count how many people can submit
283 $submissions = 0; // init
284 if ($students = get_enrolled_users($context, 'mod/assign:view', 0, 'u.id')) {
285 foreach ($students as $student) {
286 if (isset($unmarkedsubmissions[$assignment->id][$student->id])) {
293 $link = new moodle_url('/mod/assign/view.php', array('id'=>$assignment->coursemodule, 'action'=>'grading'));
294 $str .= '<div class="details"><a href="'.$link.'">'.get_string('submissionsnotgraded', 'assign', $submissions).'</a></div>';
296 } if (has_capability('mod/assign:submit', $context)) {
297 $str .= '<div class="details">';
298 $str .= get_string('mysubmission', 'assign');
299 $submission = $mysubmissions[$assignment->id];
300 if ($submission->offline) {
301 $str .= get_string('offline', 'assign');
302 } else if(!$submission->status || $submission->status == 'draft'){
303 $str .= $strnotsubmittedyet;
305 $str .= get_string('submissionstatus_' . $submission->status, 'assign');
307 if (!$submission->grade || $submission->grade < 0) {
308 $str .= ', ' . get_string('notgraded', 'assign');
310 $str .= ', ' . get_string('graded', 'assign');
315 if (empty($htmlarray[$assignment->course]['assign'])) {
316 $htmlarray[$assignment->course]['assign'] = $str;
318 $htmlarray[$assignment->course]['assign'] .= $str;
324 * Print recent activity from all assignments in a given course
326 * This is used by the recent activity block
327 * @param mixed $course the course to print activity for
328 * @param bool $viewfullnames boolean to determine whether to show full names or not
329 * @param int $timestart the time the rendering started
331 function assign_print_recent_activity($course, $viewfullnames, $timestart) {
332 global $CFG, $USER, $DB, $OUTPUT;
334 // do not use log table if possible, it may be huge
336 if (!$submissions = $DB->get_records_sql("SELECT asb.id, asb.timemodified, cm.id AS cmid, asb.userid,
337 u.firstname, u.lastname, u.email, u.picture
338 FROM {assign_submission} asb
339 JOIN {assign} a ON a.id = asb.assignment
340 JOIN {course_modules} cm ON cm.instance = a.id
341 JOIN {modules} md ON md.id = cm.module
342 JOIN {user} u ON u.id = asb.userid
343 WHERE asb.timemodified > ? AND
346 ORDER BY asb.timemodified ASC", array($timestart, $course->id))) {
350 $modinfo = get_fast_modinfo($course); // no need pass this by reference as the return object already being cached
354 $showrecentsubmissions = get_config('mod_assign', 'showrecentsubmissions');
356 foreach($submissions as $submission) {
357 if (!array_key_exists($submission->cmid, $modinfo->get_cms())) {
360 $cm = $modinfo->get_cm($submission->cmid);
361 if (!$cm->uservisible) {
364 if ($submission->userid == $USER->id) {
365 $show[] = $submission;
369 $context = context_module::instance($submission->cmid);
370 // the act of sumbitting of assignment may be considered private - only graders will see it if specified
371 if (empty($showrecentsubmissions)) {
372 if (!array_key_exists($cm->id, $grader)) {
373 $grader[$cm->id] = has_capability('moodle/grade:viewall',$context);
375 if (!$grader[$cm->id]) {
380 $groupmode = groups_get_activity_groupmode($cm, $course);
382 if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
384 // shortcut - guest user does not belong into any group
388 if (is_null($modinfo->get_groups())) {
389 $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
392 // this will be slow - show only users that share group with me in this cm
393 if (empty($modinfo->groups[$cm->id])) {
396 $usersgroups = groups_get_all_groups($course->id, $submission->userid, $cm->groupingid);
397 if (is_array($usersgroups)) {
398 $usersgroups = array_keys($usersgroups);
399 $intersect = array_intersect($usersgroups, $modinfo->groups[$cm->id]);
400 if (empty($intersect)) {
405 $show[] = $submission;
412 echo $OUTPUT->heading(get_string('newsubmissions', 'assign').':', 3);
414 foreach ($show as $submission) {
415 $cm = $modinfo->get_cm($submission->cmid);
416 $link = $CFG->wwwroot.'/mod/assign/view.php?id='.$cm->id;
417 print_recent_activity_note($submission->timemodified, $submission, $cm->name, $link, false, $viewfullnames);
424 * Returns all assignments since a given time
426 * @param array $activities The activity information is returned in this array
427 * @param int $index The current index in the activities array
428 * @param int $timestart The earliest activity to show
429 * @param int $courseid Limit the search to this course
430 * @param int $cmid The course module id
431 * @param int $userid Optional user id
432 * @param int $groupid Optional group id
435 function assign_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0) {
436 global $CFG, $COURSE, $USER, $DB;
438 if ($COURSE->id == $courseid) {
441 $course = $DB->get_record('course', array('id'=>$courseid));
444 $modinfo = get_fast_modinfo($course); // no need pass this by reference as the return object already being cached
446 $cm = $modinfo->get_cm($cmid);
449 $userselect = "AND u.id = :userid";
450 $params['userid'] = $userid;
456 $groupselect = "AND gm.groupid = :groupid";
457 $groupjoin = "JOIN {groups_members} gm ON gm.userid=u.id";
458 $params['groupid'] = $groupid;
464 $params['cminstance'] = $cm->instance;
465 $params['timestart'] = $timestart;
467 $userfields = user_picture::fields('u', null, 'userid');
469 if (!$submissions = $DB->get_records_sql("SELECT asb.id, asb.timemodified,
471 FROM {assign_submission} asb
472 JOIN {assign} a ON a.id = asb.assignment
473 JOIN {user} u ON u.id = asb.userid
475 WHERE asb.timemodified > :timestart AND a.id = :cminstance
476 $userselect $groupselect
477 ORDER BY asb.timemodified ASC", $params)) {
481 $groupmode = groups_get_activity_groupmode($cm, $course);
482 $cm_context = context_module::instance($cm->id);
483 $grader = has_capability('moodle/grade:viewall', $cm_context);
484 $accessallgroups = has_capability('moodle/site:accessallgroups', $cm_context);
485 $viewfullnames = has_capability('moodle/site:viewfullnames', $cm_context);
487 if (is_null($modinfo->get_groups())) {
488 $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
491 $showrecentsubmissions = get_config('mod_assign', 'showrecentsubmissions');
493 $usersgroups = groups_get_all_groups($course->id, $USER->id, $cm->groupingid);
494 if (is_array($usersgroups)) {
495 $usersgroups = array_keys($usersgroups);
497 foreach($submissions as $submission) {
498 if ($submission->userid == $USER->id) {
499 $show[] = $submission;
502 // the act of submitting of assignment may be considered private - only graders will see it if specified
503 if (empty($showrecentsubmissions)) {
509 if ($groupmode == SEPARATEGROUPS and !$accessallgroups) {
511 // shortcut - guest user does not belong into any group
515 // this will be slow - show only users that share group with me in this cm
516 if (empty($modinfo->groups[$cm->id])) {
519 if (is_array($usersgroups)) {
520 $intersect = array_intersect($usersgroups, $modinfo->groups[$cm->id]);
521 if (empty($intersect)) {
526 $show[] = $submission;
534 require_once($CFG->libdir.'/gradelib.php');
536 foreach ($show as $id=>$submission) {
537 $userids[] = $submission->userid;
540 $grades = grade_get_grades($courseid, 'mod', 'assign', $cm->instance, $userids);
543 $aname = format_string($cm->name,true);
544 foreach ($show as $submission) {
545 $activity = new stdClass();
547 $activity->type = 'assign';
548 $activity->cmid = $cm->id;
549 $activity->name = $aname;
550 $activity->sectionnum = $cm->sectionnum;
551 $activity->timestamp = $submission->timemodified;
552 $activity->user = new stdClass();
554 $activity->grade = $grades->items[0]->grades[$submission->userid]->str_long_grade;
557 $userfields = explode(',', user_picture::fields());
558 foreach ($userfields as $userfield) {
559 if ($userfield == 'id') {
560 $activity->user->{$userfield} = $submission->userid; // aliased in SQL above
562 $activity->user->{$userfield} = $submission->{$userfield};
565 $activity->user->fullname = fullname($submission, $viewfullnames);
567 $activities[$index++] = $activity;
574 * Print recent activity from all assignments in a given course
576 * This is used by course/recent.php
577 * @param stdClass $activity
578 * @param int $courseid
579 * @param bool $detail
580 * @param array $modnames
582 function assign_print_recent_mod_activity($activity, $courseid, $detail, $modnames) {
583 global $CFG, $OUTPUT;
585 echo '<table border="0" cellpadding="3" cellspacing="0" class="assignment-recent">';
587 echo "<tr><td class=\"userpicture\" valign=\"top\">";
588 echo $OUTPUT->user_picture($activity->user);
592 $modname = $modnames[$activity->type];
593 echo '<div class="title">';
594 echo "<img src=\"" . $OUTPUT->pix_url('icon', 'assign') . "\" ".
595 "class=\"icon\" alt=\"$modname\">";
596 echo "<a href=\"$CFG->wwwroot/mod/assign/view.php?id={$activity->cmid}\">{$activity->name}</a>";
600 if (isset($activity->grade)) {
601 echo '<div class="grade">';
602 echo get_string('grade').': ';
603 echo $activity->grade;
607 echo '<div class="user">';
608 echo "<a href=\"$CFG->wwwroot/user/view.php?id={$activity->user->id}&course=$courseid\">"
609 ."{$activity->user->fullname}</a> - ".userdate($activity->timestamp);
612 echo "</td></tr></table>";
616 * Checks if a scale is being used by an assignment
618 * This is used by the backup code to decide whether to back up a scale
619 * @param int $assignmentid
620 * @param int $scaleid
621 * @return boolean True if the scale is used by the assignment
623 function assign_scale_used($assignmentid, $scaleid) {
627 $rec = $DB->get_record('assign', array('id'=>$assignmentid,'grade'=>-$scaleid));
629 if (!empty($rec) && !empty($scaleid)) {
637 * Checks if scale is being used by any instance of assignment
639 * This is used to find out if scale used anywhere
640 * @param int $scaleid
641 * @return boolean True if the scale is used by any assignment
643 function assign_scale_used_anywhere($scaleid) {
646 if ($scaleid and $DB->record_exists('assign', array('grade'=>-$scaleid))) {
654 * function to list the actions that correspond to a view of this module
655 * This is used by the participation report
658 function assign_get_view_actions() {
659 return array('view submission', 'view feedback');
663 * function to list the actions that correspond to a post of this module
664 * This is used by the participation report
667 function assign_get_post_actions() {
668 return array('upload', 'submit', 'submit for grading');
672 * Call cron on the assign module
674 function assign_cron() {
677 require_once($CFG->dirroot . '/mod/assign/locallib.php');
680 $plugins = get_plugin_list('assignsubmission');
682 foreach ($plugins as $name => $plugin) {
683 $disabled = get_config('assignsubmission_' . $name, 'disabled');
685 $class = 'assign_submission_' . $name;
686 require_once($CFG->dirroot . '/mod/assign/submission/' . $name . '/locallib.php');
690 $plugins = get_plugin_list('assignfeedback');
692 foreach ($plugins as $name => $plugin) {
693 $disabled = get_config('assignfeedback_' . $name, 'disabled');
695 $class = 'assign_feedback_' . $name;
696 require_once($CFG->dirroot . '/mod/assign/feedback/' . $name . '/locallib.php');
703 * Returns all other capabilities used by this module.
704 * @return array Array of capability strings
706 function assign_get_extra_capabilities() {
707 return array('gradereport/grader:view', 'moodle/grade:viewall', 'moodle/site:viewfullnames', 'moodle/site:config');
711 * Create grade item for given assignment
713 * @param stdClass $assign record with extra cmidnumber
714 * @param array $grades optional array/object of grade(s); 'reset' means reset grades in gradebook
715 * @return int 0 if ok, error code otherwise
717 function assign_grade_item_update($assign, $grades=NULL) {
719 require_once($CFG->libdir.'/gradelib.php');
721 if (!isset($assign->courseid)) {
722 $assign->courseid = $assign->course;
725 $params = array('itemname'=>$assign->name, 'idnumber'=>$assign->cmidnumber);
727 if ($assign->grade > 0) {
728 $params['gradetype'] = GRADE_TYPE_VALUE;
729 $params['grademax'] = $assign->grade;
730 $params['grademin'] = 0;
732 } else if ($assign->grade < 0) {
733 $params['gradetype'] = GRADE_TYPE_SCALE;
734 $params['scaleid'] = -$assign->grade;
737 $params['gradetype'] = GRADE_TYPE_TEXT; // allow text comments only
740 if ($grades === 'reset') {
741 $params['reset'] = true;
745 return grade_update('mod/assign', $assign->courseid, 'mod', 'assign', $assign->id, 0, $grades, $params);
749 * Return grade for given user or all users.
751 * @param stdClass $assign record of assign with an additional cmidnumber
752 * @param int $userid optional user id, 0 means all users
753 * @return array array of grades, false if none
755 function assign_get_user_grades($assign, $userid=0) {
757 require_once($CFG->dirroot . '/mod/assign/locallib.php');
759 $assignment = new assign(null, null, null);
760 $assignment->set_instance($assign);
761 return $assignment->get_user_grades_for_gradebook($userid);
765 * Update activity grades
767 * @param stdClass $assign database record
768 * @param int $userid specific user only, 0 means all
769 * @param bool $nullifnone - not used
771 function assign_update_grades($assign, $userid=0, $nullifnone=true) {
773 require_once($CFG->libdir.'/gradelib.php');
775 if ($assign->grade == 0) {
776 assign_grade_item_update($assign);
778 } else if ($grades = assign_get_user_grades($assign, $userid)) {
779 foreach($grades as $k=>$v) {
780 if ($v->rawgrade == -1) {
781 $grades[$k]->rawgrade = null;
784 assign_grade_item_update($assign, $grades);
787 assign_grade_item_update($assign);
792 * List the file areas that can be browsed
794 * @param stdClass $course
795 * @param stdClass $cm
796 * @param stdClass $context
799 function assign_get_file_areas($course, $cm, $context) {
801 require_once($CFG->dirroot . '/mod/assign/locallib.php');
804 $assignment = new assign($context, $cm, $course);
805 foreach ($assignment->get_submission_plugins() as $plugin) {
806 if ($plugin->is_visible()) {
807 $pluginareas = $plugin->get_file_areas();
810 $areas = array_merge($areas, $pluginareas);
814 foreach ($assignment->get_feedback_plugins() as $plugin) {
815 if ($plugin->is_visible()) {
816 $pluginareas = $plugin->get_file_areas();
819 $areas = array_merge($areas, $pluginareas);
828 * File browsing support for assign module.
830 * @param file_browser $browser
831 * @param object $areas
832 * @param object $course
834 * @param object $context
835 * @param string $filearea
837 * @param string $filepath
838 * @param string $filename
839 * @return object file_info instance or null if not found
841 function assign_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
843 require_once($CFG->dirroot . '/mod/assign/locallib.php');
845 if ($context->contextlevel != CONTEXT_MODULE) {
849 $fs = get_file_storage();
850 $filepath = is_null($filepath) ? '/' : $filepath;
851 $filename = is_null($filename) ? '.' : $filename;
853 // need to find the plugin this belongs to
854 $assignment = new assign($context, $cm, $course);
856 foreach ($assignment->get_submission_plugins() as $plugin) {
857 if ($plugin->is_visible()) {
858 $pluginareas = $plugin->get_file_areas();
860 if (array_key_exists($filearea, $pluginareas)) {
861 $pluginowner = $plugin;
867 foreach ($assignment->get_feedback_plugins() as $plugin) {
868 if ($plugin->is_visible()) {
869 $pluginareas = $plugin->get_file_areas();
871 if (array_key_exists($filearea, $pluginareas)) {
872 $pluginowner = $plugin;
883 $result = $pluginowner->get_file_info($browser, $filearea, $itemid, $filepath, $filename);
888 * Prints the complete info about a user's interaction with an assignment
890 * @param stdClass $course
891 * @param stdClass $user
892 * @param stdClass $coursemodule
893 * @param stdClass $assign the database assign record
895 * This prints the submission summary and feedback summary for this student
897 function assign_user_complete($course, $user, $coursemodule, $assign) {
899 require_once($CFG->dirroot . '/mod/assign/locallib.php');
900 $context = context_module::instance($coursemodule->id);
902 $assignment = new assign($context, $coursemodule, $course);
904 echo $assignment->view_student_summary($user, false);
908 * Print the grade information for the assignment for this user
910 * @param stdClass $course
911 * @param stdClass $user
912 * @param stdClass $coursemodule
913 * @param stdClass $assignment
915 function assign_user_outline($course, $user, $coursemodule, $assignment) {
917 require_once($CFG->libdir.'/gradelib.php');
918 require_once($CFG->dirroot.'/grade/grading/lib.php');
920 $gradinginfo = grade_get_grades($course->id,
926 $gradingitem = $gradinginfo->items[0];
927 $gradebookgrade = $gradingitem->grades[$user->id];
929 if (!$gradebookgrade) {
932 $result = new stdClass();
933 $result->info = get_string('outlinegrade', 'assign', $gradebookgrade->grade);
934 $result->time = $gradebookgrade->dategraded;