/**
* Constructor.
*
* @param string $uniqueid Unique ID.
* @param int $courseid Course ID.
* @param int $groupid Group ID.
*/
public function __construct($uniqueid, $courseid, $groupid)
{
global $DB, $PAGE;
parent::__construct($uniqueid);
// Block XP stuff.
$this->xpmanager = block_xp_manager::get($courseid);
$this->xpoutput = $PAGE->get_renderer('block_xp');
$context = context_course::instance($courseid);
// Define columns.
$this->define_columns(array('userpic', 'fullname', 'lvl', 'xp', 'progress', 'actions'));
$this->define_headers(array('', get_string('fullname'), get_string('level', 'block_xp'), get_string('xp', 'block_xp'), get_string('progress', 'block_xp'), ''));
// Get all the users that are enrolled and can earn XP.
$ids = array();
$users = get_enrolled_users($context, 'block/xp:earnxp', $groupid);
foreach ($users as $user) {
$ids[$user->id] = $user->id;
}
unset($users);
// Get the users which might not be enrolled or are revoked the permission, but still should
// be displayed in the report for the teachers' benefit. We need to filter out the users which
// are not a member of the group though.
if (empty($groupid)) {
$sql = 'SELECT userid FROM {block_xp} WHERE courseid = :courseid';
$params = array('courseid' => $courseid);
} else {
$sql = 'SELECT b.userid
FROM {block_xp} b
JOIN {groups_members} gm
ON b.userid = gm.userid
AND gm.groupid = :groupid
WHERE courseid = :courseid';
$params = array('courseid' => $courseid, 'groupid' => $groupid);
}
$entries = $DB->get_recordset_sql($sql, $params);
foreach ($entries as $entry) {
$ids[$entry->userid] = $entry->userid;
}
$entries->close();
list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'param', true, null);
// Define SQL.
$this->sql = new stdClass();
$this->sql->fields = user_picture::fields('u') . ', COALESCE(x.lvl, 1) AS lvl, x.xp, ' . context_helper::get_preload_record_columns_sql('ctx');
$this->sql->from = "{user} u\n JOIN {context} ctx\n ON ctx.instanceid = u.id\n AND ctx.contextlevel = :contextlevel\n LEFT JOIN {block_xp} x\n ON (x.userid = u.id AND x.courseid = :courseid)";
$this->sql->where = "u.id {$insql}";
$this->sql->params = array_merge($inparams, array('courseid' => $courseid, 'contextlevel' => CONTEXT_USER));
// Define various table settings.
$this->sortable(true, 'lvl', SORT_DESC);
$this->no_sorting('userpic');
$this->no_sorting('progress');
$this->collapsible(false);
}
/**
* Returns submissions by part (and unsubmitted users if appropriate)
*
* @global type $DB
* @global type $USER
* @param object $cm course module object
* @param int $partid specific part id, includes all if 0
* @param int $userid specific user id, includes all if 0
* @param int $submissionsonly flag to include/remove non submitted students from results
* @return array of submissions by part
*/
public function get_submissions($cm, $partid = 0, $userid = 0, $submissionsonly = 0)
{
global $DB, $USER;
// If no part id is specified then get them all.
$sql = " turnitintooltwoid = ? ";
$sqlparams = array($this->id);
if ($partid == 0) {
$parts = $this->get_parts();
} else {
$part = $this->get_part_details($partid);
$parts[$partid] = $part;
$sql .= " AND submission_part = ? ";
$sqlparams[] = $partid;
}
$context = context_module::instance($cm->id);
$istutor = has_capability('mod/turnitintooltwo:grade', $context);
// If logged in as instructor then get for all users.
$allnamefields = get_all_user_name_fields();
if ($istutor && $userid == 0) {
$users = get_enrolled_users($context, 'mod/turnitintooltwo:submit', groups_get_activity_group($cm), 'u.id, ' . implode($allnamefields, ', '));
$users = !$users ? array() : $users;
} else {
if ($istutor) {
$user = $DB->get_record('user', array('id' => $userid), 'id, ' . implode($allnamefields, ', '));
$users = array($userid => $user);
$sql .= " AND userid = ? ";
$sqlparams[] = $userid;
} else {
$users = array($USER->id => $USER);
$sql .= " AND userid = ? ";
$sqlparams[] = $USER->id;
}
}
// Populate the submissions array to show all users for all parts.
$submissions = array();
foreach ($parts as $part) {
$submissions[$part->id] = array();
foreach ($users as $user) {
$emptysubmission = new stdClass();
$emptysubmission->userid = $user->id;
$emptysubmission->firstname = $user->firstname;
$emptysubmission->lastname = $user->lastname;
$emptysubmission->fullname = fullname($user);
$emptysubmission->submission_unanon = 0;
$emptysubmission->nmoodle = 0;
if ($submissionsonly == 0) {
$submissions[$part->id][$user->id] = $emptysubmission;
}
}
}
// Get submissions that were made where a moodle userid is known.
// Contains moodle users both enrolled or not enrolled.
if ($submissionsdata = $DB->get_records_select("turnitintooltwo_submissions", " userid != 0 AND " . $sql, $sqlparams)) {
foreach ($submissionsdata as $submission) {
$user = new turnitintooltwo_user($submission->userid, 'Learner', false);
$submission->firstname = $user->firstname;
$submission->lastname = $user->lastname;
$submission->fullname = $user->fullname;
$submission->tii_user_id = $user->tii_user_id;
$submission->nmoodle = 0;
if (isset($users[$user->id])) {
// User is a moodle user ie in array from moodle user call above.
$submissions[$submission->submission_part][$user->id] = $submission;
} else {
if (groups_get_activity_group($cm) == 0) {
// User is not a moodle user ie not in array from moodle user call above and group list is set to all users.
$submission->nmoodle = 1;
$submissions[$submission->submission_part][$user->id] = $submission;
}
}
}
}
// Now get submissions that were made by a non moodle students.
// These are unknown to moodle possibly non-enrolled on turnitin.
// Possibly real but not yet linked Turnitin users. If group list is set do not get these non group users.
if ($submissionsdata = $DB->get_records_select("turnitintooltwo_submissions", " userid = 0 AND " . $sql, $sqlparams) and groups_get_activity_group($cm) == 0) {
foreach ($submissionsdata as $submission) {
$submission->nmoodle = 1;
$submission->userid = $submission->submission_nmuserid;
$submission->firstname = $submission->submission_nmfirstname;
$submission->lastname = $submission->submission_nmlastname;
$submissions[$submission->submission_part][$submission->userid] = $submission;
}
}
return $submissions;
}
/**
* Display a single submission, ready for grading on a popup window
*
* This default method prints the teacher info and submissioncomment box at the top and
* 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
*
* @global object
* @global object
* @param string $extra_javascript
*/
function display_submission($offset=-1,$userid =-1, $display=true) {
global $CFG, $DB, $PAGE, $OUTPUT;
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->libdir.'/tablelib.php');
require_once("$CFG->dirroot/repository/lib.php");
if ($userid==-1) {
$userid = required_param('userid', PARAM_INT);
}
if ($offset==-1) {
$offset = required_param('offset', PARAM_INT);//offset for where to start looking for student.
}
$filter = optional_param('filter', 0, PARAM_INT);
if (!$user = $DB->get_record('user', array('id'=>$userid))) {
print_error('nousers');
}
if (!$submission = $this->get_submission($user->id)) {
$submission = $this->prepare_new_submission($userid);
}
if ($submission->timemodified > $submission->timemarked) {
$subtype = 'assignmentnew';
} else {
$subtype = 'assignmentold';
}
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array($user->id));
$gradingdisabled = $grading_info->items[0]->grades[$userid]->locked || $grading_info->items[0]->grades[$userid]->overridden;
/// construct SQL, using current offset to find the data of the next student
$course = $this->course;
$assignment = $this->assignment;
$cm = $this->cm;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// Get all ppl that can submit assignments
$currentgroup = groups_get_activity_group($cm);
$users = get_enrolled_users($context, 'mod/assignment:view', $currentgroup, 'u.id');
if ($users) {
$users = array_keys($users);
// if groupmembersonly used, remove users who are not in any group
if (!empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {
if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
$users = array_intersect($users, array_keys($groupingusers));
}
}
}
$nextid = 0;
$where = '';
if($filter == 'submitted') {
$where .= 's.timemodified > 0 AND ';
} else if($filter == 'requiregrading') {
$where .= 's.timemarked < s.timemodified AND ';
}
if ($users) {
$userfields = user_picture::fields('u', array('lastaccess'));
$select = "SELECT $userfields,
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 {user} u '.
'LEFT JOIN {assignment_submissions} s ON u.id = s.userid
AND s.assignment = '.$this->assignment->id.' '.
'WHERE '.$where.'u.id IN ('.implode(',', $users).') ';
if ($sort = flexible_table::get_sort_for_table('mod-assignment-submissions')) {
$sort = 'ORDER BY '.$sort.' ';
}
$auser = $DB->get_records_sql($select.$sql.$sort, null, $offset, 2);
if (is_array($auser) && count($auser)>1) {
$nextuser = next($auser);
/// Calculate user status
$nextuser->status = ($nextuser->timemarked > 0) && ($nextuser->timemarked >= $nextuser->timemodified);
$nextid = $nextuser->id;
}
}
if ($submission->teacher) {
$teacher = $DB->get_record('user', array('id'=>$submission->teacher));
} else {
global $USER;
//.........这里部分代码省略.........
开发者ID:nuckey,项目名称:moodle,代码行数:101,代码来源:lib.php
示例15: assign_print_overview
/**
* Print an overview of all assignments
* for the courses.
*
* @param mixed $courses The list of courses to print the overview for
* @param array $htmlarray The array of html to return
*/
function assign_print_overview($courses, &$htmlarray)
{
global $USER, $CFG, $DB;
if (empty($courses) || !is_array($courses) || count($courses) == 0) {
return array();
}
if (!($assignments = get_all_instances_in_courses('assign', $courses))) {
return;
}
$assignmentids = array();
// Do assignment_base::isopen() here without loading the whole thing for speed
foreach ($assignments as $key => $assignment) {
$time = time();
$isopen = false;
if ($assignment->duedate) {
$duedate = false;
if ($assignment->cutoffdate) {
$duedate = $assignment->cutoffdate;
}
if ($duedate) {
$isopen = $assignment->allowsubmissionsfromdate <= $time && $time <= $duedate;
} else {
$isopen = $assignment->allowsubmissionsfromdate <= $time;
}
}
if ($isopen) {
$assignmentids[] = $assignment->id;
}
}
if (empty($assignmentids)) {
// no assignments to look at - we're done
return true;
}
$strduedate = get_string('duedate', 'assign');
$strcutoffdate = get_string('nosubmissionsacceptedafter', 'assign');
$strnolatesubmissions = get_string('nolatesubmissions', 'assign');
$strduedateno = get_string('duedateno', 'assign');
$strduedateno = get_string('duedateno', 'assign');
$strgraded = get_string('graded', 'assign');
$strnotgradedyet = get_string('notgradedyet', 'assign');
$strnotsubmittedyet = get_string('notsubmittedyet', 'assign');
$strsubmitted = get_string('submitted', 'assign');
$strassignment = get_string('modulename', 'assign');
$strreviewed = get_string('reviewed', 'assign');
// NOTE: we do all possible database work here *outside* of the loop to ensure this scales
//
list($sqlassignmentids, $assignmentidparams) = $DB->get_in_or_equal($assignmentids);
// build up and array of unmarked submissions indexed by assignment id/ userid
// for use where the user has grading rights on assignment
$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\n FROM {assign_submission} s LEFT JOIN {assign_grades} g ON s.userid = g.userid and s.assignment = g.assignment\n WHERE g.timemodified = 0 OR s.timemodified > g.timemodified\n AND s.assignment {$sqlassignmentids}", $assignmentidparams);
$unmarkedsubmissions = array();
foreach ($rs as $rd) {
$unmarkedsubmissions[$rd->assignment][$rd->userid] = $rd->id;
}
$rs->close();
// get all user submissions, indexed by assignment id
$mysubmissions = $DB->get_records_sql("SELECT a.id AS assignment, a.nosubmissions AS nosubmissions, g.timemodified AS timemarked, g.grader AS grader, g.grade AS grade, s.status AS status\n 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 = ?\n AND a.id {$sqlassignmentids}", array_merge(array($USER->id, $USER->id), $assignmentidparams));
foreach ($assignments as $assignment) {
// Do not show assignments that are not open
if (!in_array($assignment->id, $assignmentids)) {
continue;
}
$str = '<div class="assign overview"><div class="name">' . $strassignment . ': ' . '<a ' . ($assignment->visible ? '' : ' class="dimmed"') . 'title="' . $strassignment . '" href="' . $CFG->wwwroot . '/mod/assign/view.php?id=' . $assignment->coursemodule . '">' . format_string($assignment->name) . '</a></div>';
if ($assignment->duedate) {
$str .= '<div class="info">' . $strduedate . ': ' . userdate($assignment->duedate) . '</div>';
} else {
$str .= '<div class="info">' . $strduedateno . '</div>';
}
if ($assignment->cutoffdate) {
if ($assignment->cutoffdate == $assignment->duedate) {
$str .= '<div class="info">' . $strnolatesubmissions . '</div>';
} else {
$str .= '<div class="info">' . $strcutoffdate . ': ' . userdate($assignment->cutoffdate) . '</div>';
}
}
$context = context_module::instance($assignment->coursemodule);
if (has_capability('mod/assign:grade', $context)) {
// count how many people can submit
$submissions = 0;
// init
if ($students = get_enrolled_users($context, 'mod/assign:view', 0, 'u.id')) {
foreach ($students as $student) {
if (isset($unmarkedsubmissions[$assignment->id][$student->id])) {
$submissions++;
}
}
}
if ($submissions) {
$link = new moodle_url('/mod/assign/view.php', array('id' => $assignment->coursemodule, 'action' => 'grading'));
$str .= '<div class="details"><a href="' . $link . '">' . get_string('submissionsnotgraded', 'assign', $submissions) . '</a></div>';
}
}
if (has_capability('mod/assign:submit', $context)) {
//.........这里部分代码省略.........
请发表评论