本文整理汇总了PHP中grade_get_grades函数的典型用法代码示例。如果您正苦于以下问题:PHP grade_get_grades函数的具体用法?PHP grade_get_grades怎么用?PHP grade_get_grades使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了grade_get_grades函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_user_assign_grade
/**
* Utility method to get the grade for a user.
* @param $user
* @param $assign
* @param $course
* @return testable_assign
*/
private function get_user_assign_grade($user, $assign, $course)
{
$gradebookgrades = \grade_get_grades($course->id, 'mod', 'assign', $assign->get_instance()->id, $user->id);
$gradebookitem = array_shift($gradebookgrades->items);
$grade = $gradebookitem->grades[$user->id];
return $grade->str_grade;
}
示例2: add_attaches_to_posts
/** add info about this users attaches to the postsdata object
*
* @global object $DB
* @global record $USER
* @param record $postsdata
* @return boolean, true if succeded
*/
public static function add_attaches_to_posts($courseid, &$postsdata)
{
global $DB, $USER;
if (empty($postsdata->posts)) {
return false;
}
$posts = $postsdata->posts;
$params = array($USER->id);
list($inpoststr, $inparams) = $DB->get_in_or_equal(array_keys($posts));
$params = array_merge($params, $inparams);
$params[] = $courseid;
// ... fetch attaches an grade_items.
$sql = "SELECT at.id as atid, at.postid, at.coursemoduleid, gi.*\n FROM {format_socialwall_attaches} at\n JOIN {course_modules} cm ON cm.id = at.coursemoduleid\n JOIN {modules} m ON m.id = cm.module\n LEFT JOIN\n (SELECT gg.id, gri.iteminstance, gri.itemmodule, gri.itemtype\n FROM {grade_items} gri\n JOIN {grade_grades} gg ON (gg.itemid = gri.id AND userid = ?)) as\n gi ON (gi.itemmodule = m.name AND gi.iteminstance = cm.instance)\n WHERE postid {$inpoststr} AND cm.course = ?";
if (!($attaches = $DB->get_records_sql($sql, $params))) {
return false;
}
foreach ($attaches as $attachment) {
if (!isset($postsdata->posts[$attachment->postid]->attaches)) {
$postsdata->posts[$attachment->postid]->attaches = array();
$postsdata->posts[$attachment->postid]->grades = array();
}
$postsdata->posts[$attachment->postid]->attaches[$attachment->atid] = $attachment;
if (!empty($attachment->iteminstance)) {
$gradedata = grade_get_grades($courseid, $attachment->itemtype, $attachment->itemmodule, $attachment->iteminstance, $USER->id);
// Add author of grades, to retrieve complete user record later.
if (!empty($gradedata->outcomes[0]->grades[$USER->id])) {
$usermodified = $gradedata->outcomes[0]->grades[$USER->id]->usermodified;
$postsdata->authors[$usermodified] = $usermodified;
$postsdata->posts[$attachment->postid]->grades[$attachment->coursemoduleid] = $gradedata->outcomes[0];
}
if (!empty($gradedata->items[0]->grades[$USER->id])) {
$usermodified = $gradedata->items[0]->grades[$USER->id]->usermodified;
$postsdata->authors[$usermodified] = $usermodified;
$postsdata->posts[$attachment->postid]->grades[$attachment->coursemoduleid] = $gradedata->items[0];
}
}
}
return true;
}
示例3: __construct
//.........这里部分代码省略.........
// Add a column for the list of valid marking workflow states.
$columns[] = 'gradecanbechanged';
$headers[] = get_string('gradecanbechanged', 'assign');
}
if (!$this->is_downloading() && $this->hasgrade) {
// We have to call this column userid so we can use userid as a default sortable column.
$columns[] = 'userid';
$headers[] = get_string('edit');
}
// Submission plugins.
if ($assignment->is_any_submission_plugin_enabled()) {
$columns[] = 'timesubmitted';
$headers[] = get_string('lastmodifiedsubmission', 'assign');
foreach ($this->assignment->get_submission_plugins() as $plugin) {
if ($this->is_downloading()) {
if ($plugin->is_visible() && $plugin->is_enabled()) {
foreach ($plugin->get_editor_fields() as $field => $description) {
$index = 'plugin' . count($this->plugincache);
$this->plugincache[$index] = array($plugin, $field);
$columns[] = $index;
$headers[] = $plugin->get_name();
}
}
} else {
if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
$index = 'plugin' . count($this->plugincache);
$this->plugincache[$index] = array($plugin);
$columns[] = $index;
$headers[] = $plugin->get_name();
}
}
}
}
// Time marked.
$columns[] = 'timemarked';
$headers[] = get_string('lastmodifiedgrade', 'assign');
// Feedback plugins.
foreach ($this->assignment->get_feedback_plugins() as $plugin) {
if ($this->is_downloading()) {
if ($plugin->is_visible() && $plugin->is_enabled()) {
foreach ($plugin->get_editor_fields() as $field => $description) {
$index = 'plugin' . count($this->plugincache);
$this->plugincache[$index] = array($plugin, $field);
$columns[] = $index;
$headers[] = $description;
}
}
} else {
if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
$index = 'plugin' . count($this->plugincache);
$this->plugincache[$index] = array($plugin);
$columns[] = $index;
$headers[] = $plugin->get_name();
}
}
}
// Exclude 'Final grade' column in downloaded grading worksheets.
if (!$this->is_downloading()) {
// Final grade.
$columns[] = 'finalgrade';
$headers[] = get_string('finalgrade', 'grades');
}
// Load the grading info for all users.
$this->gradinginfo = grade_get_grades($this->assignment->get_course()->id, 'mod', 'assign', $this->assignment->get_instance()->id, $users);
if (!empty($CFG->enableoutcomes) && !empty($this->gradinginfo->outcomes)) {
$columns[] = 'outcomes';
$headers[] = get_string('outcomes', 'grades');
}
// Set the columns.
$this->define_columns($columns);
$this->define_headers($headers);
foreach ($extrauserfields as $extrafield) {
$this->column_class($extrafield, $extrafield);
}
$this->no_sorting('recordid');
$this->no_sorting('finalgrade');
$this->no_sorting('userid');
$this->no_sorting('select');
$this->no_sorting('outcomes');
if ($assignment->get_instance()->teamsubmission) {
$this->no_sorting('team');
}
$plugincolumnindex = 0;
foreach ($this->assignment->get_submission_plugins() as $plugin) {
if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
$submissionpluginindex = 'plugin' . $plugincolumnindex++;
$this->no_sorting($submissionpluginindex);
}
}
foreach ($this->assignment->get_feedback_plugins() as $plugin) {
if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
$feedbackpluginindex = 'plugin' . $plugincolumnindex++;
$this->no_sorting($feedbackpluginindex);
}
}
// When there is no data we still want the column headers printed in the csv file.
if ($this->is_downloading()) {
$this->start_output();
}
}
示例4: save_grade
/**
* Save grade update.
*
* @param int $userid
* @param stdClass $data
* @return bool - was the grade saved
*/
public function save_grade($userid, $data)
{
// Need grade permission.
require_capability('mod/assign:grade', $this->context);
$instance = $this->get_instance();
$submission = null;
if ($instance->teamsubmission) {
$submission = $this->get_group_submission($userid, 0, false, $data->attemptnumber);
} else {
$submission = $this->get_user_submission($userid, false, $data->attemptnumber);
}
if ($instance->teamsubmission && $data->applytoall) {
$groupid = 0;
if ($this->get_submission_group($userid)) {
$group = $this->get_submission_group($userid);
if ($group) {
$groupid = $group->id;
}
}
$members = $this->get_submission_group_members($groupid, true);
foreach ($members as $member) {
// User may exist in multple groups (which should put them in the default group).
$this->apply_grade_to_user($data, $member->id, $data->attemptnumber);
$this->process_outcomes($member->id, $data);
}
} else {
$this->apply_grade_to_user($data, $userid, $data->attemptnumber);
$this->process_outcomes($userid, $data);
}
$maxattemptsreached = !empty($submission) && $submission->attemptnumber >= $instance->maxattempts - 1 && $instance->maxattempts != ASSIGN_UNLIMITED_ATTEMPTS;
$shouldreopen = false;
if ($instance->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS) {
// Check the gradetopass from the gradebook.
$gradinginfo = grade_get_grades($this->get_course()->id, 'mod', 'assign', $instance->id, $userid);
// What do we do if the grade has not been added to the gradebook (e.g. blind marking)?
$gradingitem = null;
$gradebookgrade = null;
if (isset($gradinginfo->items[0])) {
$gradingitem = $gradinginfo->items[0];
$gradebookgrade = $gradingitem->grades[$userid];
}
if ($gradebookgrade) {
// TODO: This code should call grade_grade->is_passed().
$shouldreopen = true;
if (is_null($gradebookgrade->grade)) {
$shouldreopen = false;
}
if (empty($gradingitem->gradepass) || $gradingitem->gradepass == $gradingitem->grademin) {
$shouldreopen = false;
}
if ($gradebookgrade->grade >= $gradingitem->gradepass) {
$shouldreopen = false;
}
}
}
if ($instance->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL && !empty($data->addattempt)) {
$shouldreopen = true;
}
// Never reopen if we are editing a previous attempt.
if ($data->attemptnumber != -1) {
$shouldreopen = false;
}
if ($shouldreopen && !$maxattemptsreached) {
$this->add_attempt($userid);
}
return true;
}
示例5: assign_user_outline
/**
* Print the grade information for the assignment for this user
*
* @param stdClass $course
* @param stdClass $user
* @param stdClass $coursemodule
* @param stdClass $assignment
*/
function assign_user_outline($course, $user, $coursemodule, $assignment)
{
global $CFG;
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->dirroot . '/grade/grading/lib.php';
$gradinginfo = grade_get_grades($course->id, 'mod', 'assign', $assignment->id, $user->id);
$gradingitem = $gradinginfo->items[0];
$gradebookgrade = $gradingitem->grades[$user->id];
if (!$gradebookgrade) {
return null;
}
$result = new stdClass();
$result->info = get_string('outlinegrade', 'assign', $gradebookgrade->grade);
$result->time = $gradebookgrade->dategraded;
return $result;
}
示例6: facetoface_get_grade
/**
* Get a grade for the given user from the gradebook.
*
* @param integer $userid ID of the user
* @param integer $courseid ID of the course
* @param integer $facetofaceid ID of the Face-to-face activity
*
* @returns object String grade and the time that it was graded
*/
function facetoface_get_grade($userid, $courseid, $facetofaceid) {
$ret = new stdClass();
$ret->grade = 0;
$ret->dategraded = 0;
$grading_info = grade_get_grades($courseid, 'mod', 'facetoface', $facetofaceid, $userid);
if (!empty($grading_info->items)) {
$ret->grade = $grading_info->items[0]->grades[$userid]->str_grade;
$ret->dategraded = $grading_info->items[0]->grades[$userid]->dategraded;
}
return $ret;
}
示例7: process_outcomes
/**
* Save outcomes submitted from grading form.
*
* @param int $userid
* @param stdClass $formdata
* @param int $sourceuserid The user ID under which the outcome data is accessible. This is relevant
* for an outcome set to a user but applied to an entire group.
*/
protected function process_outcomes($userid, $formdata, $sourceuserid = null)
{
global $CFG, $USER;
if (empty($CFG->enableoutcomes)) {
return;
}
if ($this->grading_disabled($userid)) {
return;
}
require_once $CFG->libdir . '/gradelib.php';
$data = array();
$gradinginfo = grade_get_grades($this->get_course()->id, 'mod', 'assign', $this->get_instance()->id, $userid);
if (!empty($gradinginfo->outcomes)) {
foreach ($gradinginfo->outcomes as $index => $oldoutcome) {
$name = 'outcome_' . $index;
$sourceuserid = $sourceuserid !== null ? $sourceuserid : $userid;
if (isset($formdata->{$name}[$sourceuserid]) && $oldoutcome->grades[$userid]->grade != $formdata->{$name}[$sourceuserid]) {
$data[$index] = $formdata->{$name}[$sourceuserid];
}
}
}
if (count($data) > 0) {
grade_update_outcomes('mod/assign', $this->course->id, 'mod', 'assign', $this->get_instance()->id, $userid, $data);
}
}
示例8: display_submissions
/**
* Display all the submissions ready for grading
*/
function display_submissions($message = '')
{
global $CFG, $db, $USER;
require_once $CFG->libdir . '/gradelib.php';
/* first we check to see if the form has just been submitted
* to request user_preference updates
*/
/*if (isset($_POST['updatepref'])){
$perpage = optional_param('perpage', 10, PARAM_INT);
$perpage = ($perpage <= 0) ? 10 : $perpage ;
set_user_preference('problemstatement_perpage', $perpage);
set_user_preference('problemstatement_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL));
}*/
/* next we get perpage and quickgrade (allow quick grade) params
* from database
*/
$perpage = get_user_preferences('problemstatement_perpage', 10);
$quickgrade = get_user_preferences('problemstatement_quickgrade', 0);
$grading_info = grade_get_grades($this->course->id, 'mod', 'problemstatement', $this->problemstatement->id);
if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {
$uses_outcomes = true;
} else {
$uses_outcomes = false;
}
$page = optional_param('page', 0, PARAM_INT);
$strsaveallfeedback = get_string('saveallfeedback', 'problemstatement');
/// Some shortcuts to make the code read better
$course = $this->course;
$problemstatement = $this->problemstatement;
$cm = $this->cm;
$tabindex = 1;
//tabindex for quick grading tabbing; Not working for dropdowns yet
add_to_log($course->id, 'problemstatement', 'view submission', 'submissions.php?id=' . $this->problemstatement->id, $this->problemstatement->id, $this->cm->id);
$navigation = build_navigation($this->strsubmissions, $this->cm);
print_header_simple(format_string($this->problemstatement->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strproblemstatement), navmenu($course, $cm));
$course_context = get_context_instance(CONTEXT_COURSE, $course->id);
if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">' . get_string('seeallcoursegrades', 'grades') . '</a></div>';
}
if (!empty($message)) {
echo $message;
// display messages here if any
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// Check to see if groups are being used in this problemstatement
/// find out current groups mode
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
groups_print_activity_menu($cm, 'submissions.php?id=' . $this->cm->id);
/// Get all ppl that are allowed to submit problemstatements
if ($users = get_users_by_capability($context, 'mod/problemstatement:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
$users = array_keys($users);
}
// 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));
}
}
$tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
if ($uses_outcomes) {
$tablecolumns[] = 'outcome';
// no sorting based on outcomes column
}
$tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'problemstatement'), get_string('lastmodified') . ' (' . $course->student . ')', get_string('lastmodified') . ' (' . $course->teacher . ')', get_string('status'), get_string('finalgrade', 'grades'));
if ($uses_outcomes) {
$tableheaders[] = get_string('outcome', 'grades');
}
require_once $CFG->libdir . '/tablelib.php';
$table = new flexible_table('mod-problemstatement-submissions');
$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($CFG->wwwroot . '/mod/problemstatement/submissions.php?id=' . $this->cm->id . '&currentgroup=' . $currentgroup);
$table->sortable(true, 'lastname');
//sorted by lastname by default
$table->collapsible(true);
$table->initialbars(true);
$table->column_suppress('picture');
$table->column_suppress('fullname');
$table->column_class('picture', 'picture');
$table->column_class('fullname', 'fullname');
$table->column_class('grade', 'grade');
$table->column_class('submissioncomment', 'comment');
$table->column_class('timemodified', 'timemodified');
$table->column_class('timemarked', 'timemarked');
$table->column_class('status', 'status');
$table->column_class('finalgrade', 'finalgrade');
if ($uses_outcomes) {
$table->column_class('outcome', 'outcome');
}
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'submissions');
$table->set_attribute('width', '100%');
//$table->set_attribute('align', 'center');
$table->no_sorting('finalgrade');
$table->no_sorting('outcome');
//.........这里部分代码省略.........
示例9: execute
/**
* Performs the synchronisation of grades.
*
* @return bool|void
*/
public function execute()
{
global $DB, $CFG;
require_once $CFG->dirroot . '/enrol/lti/ims-blti/OAuth.php';
require_once $CFG->dirroot . '/enrol/lti/ims-blti/OAuthBody.php';
require_once $CFG->dirroot . '/lib/completionlib.php';
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->dirroot . '/grade/querylib.php';
// Check if the authentication plugin is disabled.
if (!is_enabled_auth('lti')) {
mtrace('Skipping task - ' . get_string('pluginnotenabled', 'auth', get_string('pluginname', 'auth_lti')));
return true;
}
// Check if the enrolment plugin is disabled - isn't really necessary as the task should not run if
// the plugin is disabled, but there is no harm in making sure core hasn't done something wrong.
if (!enrol_is_enabled('lti')) {
mtrace('Skipping task - ' . get_string('enrolisdisabled', 'enrol_lti'));
return true;
}
// Get all the enabled tools.
if ($tools = \enrol_lti\helper::get_lti_tools(array('status' => ENROL_INSTANCE_ENABLED, 'gradesync' => 1))) {
foreach ($tools as $tool) {
mtrace("Starting - Grade sync for shared tool '{$tool->id}' for the course '{$tool->courseid}'.");
// Variables to keep track of information to display later.
$usercount = 0;
$sendcount = 0;
// We check for all the users - users can access the same tool from different consumers.
if ($ltiusers = $DB->get_records('enrol_lti_users', array('toolid' => $tool->id), 'lastaccess DESC')) {
$completion = new \completion_info(get_course($tool->courseid));
foreach ($ltiusers as $ltiuser) {
$mtracecontent = "for the user '{$ltiuser->userid}' in the tool '{$tool->id}' for the course " . "'{$tool->courseid}'";
$usercount = $usercount + 1;
// Check if we do not have a serviceurl - this can happen if the sync process has an unexpected error.
if (empty($ltiuser->serviceurl)) {
mtrace("Skipping - Empty serviceurl {$mtracecontent}.");
continue;
}
// Check if we do not have a sourceid - this can happen if the sync process has an unexpected error.
if (empty($ltiuser->sourceid)) {
mtrace("Skipping - Empty sourceid {$mtracecontent}.");
continue;
}
// Need a valid context to continue.
if (!($context = \context::instance_by_id($tool->contextid))) {
mtrace("Failed - Invalid contextid '{$tool->contextid}' for the tool '{$tool->id}'.");
continue;
}
// Ok, let's get the grade.
$grade = false;
if ($context->contextlevel == CONTEXT_COURSE) {
// Check if the user did not completed the course when it was required.
if ($tool->gradesynccompletion && !$completion->is_course_complete($ltiuser->userid)) {
mtrace("Skipping - Course not completed {$mtracecontent}.");
continue;
}
// Get the grade.
if ($grade = grade_get_course_grade($ltiuser->userid, $tool->courseid)) {
$grademax = floatval($grade->item->grademax);
$grade = $grade->grade;
}
} else {
if ($context->contextlevel == CONTEXT_MODULE) {
$cm = get_coursemodule_from_id(false, $context->instanceid, 0, false, MUST_EXIST);
if ($tool->gradesynccompletion) {
$data = $completion->get_data($cm, false, $ltiuser->userid);
if ($data->completionstate != COMPLETION_COMPLETE_PASS && $data->completionstate != COMPLETION_COMPLETE) {
mtrace("Skipping - Activity not completed {$mtracecontent}.");
continue;
}
}
$grades = grade_get_grades($cm->course, 'mod', $cm->modname, $cm->instance, $ltiuser->userid);
if (!empty($grades->items[0]->grades)) {
$grade = reset($grades->items[0]->grades);
if (!empty($grade->item)) {
$grademax = floatval($grade->item->grademax);
} else {
$grademax = floatval($grades->items[0]->grademax);
}
$grade = $grade->grade;
}
}
}
if ($grade === false || $grade === null || strlen($grade) < 1) {
mtrace("Skipping - Invalid grade {$mtracecontent}.");
continue;
}
// No need to be dividing by zero.
if (empty($grademax)) {
mtrace("Skipping - Invalid grade {$mtracecontent}.");
continue;
}
// This can happen if the sync process has an unexpected error.
if ($grade == $ltiuser->lastgrade) {
mtrace("Not sent - The grade {$mtracecontent} was not sent as the grades are the same.");
continue;
//.........这里部分代码省略.........
示例10: view_feedback
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>';
}
示例11: quiz_grade_item_update
/**
* Create grade item for given quiz
*
* @param object $quiz object with extra cmidnumber
* @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
* @return int 0 if ok, error code otherwise
*/
function quiz_grade_item_update($quiz, $grades = NULL)
{
global $CFG;
if (!function_exists('grade_update')) {
//workaround for buggy PHP versions
require_once $CFG->libdir . '/gradelib.php';
}
if (array_key_exists('cmidnumber', $quiz)) {
//it may not be always present
$params = array('itemname' => $quiz->name, 'idnumber' => $quiz->cmidnumber);
} else {
$params = array('itemname' => $quiz->name);
}
if ($quiz->grade > 0) {
$params['gradetype'] = GRADE_TYPE_VALUE;
$params['grademax'] = $quiz->grade;
$params['grademin'] = 0;
} else {
$params['gradetype'] = GRADE_TYPE_NONE;
}
/* description by TJ:
1/ If the quiz is set to not show scores while the quiz is still open, and is set to show scores after
the quiz is closed, then create the grade_item with a show-after date that is the quiz close date.
2/ If the quiz is set to not show scores at either of those times, create the grade_item as hidden.
3/ If the quiz is set to show scores, create the grade_item visible.
*/
if (!($quiz->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED) and !($quiz->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN)) {
$params['hidden'] = 1;
} else {
if ($quiz->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED and !($quiz->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN)) {
if ($quiz->timeclose) {
$params['hidden'] = $quiz->timeclose;
} else {
$params['hidden'] = 1;
}
} else {
// a) both open and closed enabled
// b) open enabled, closed disabled - we can not "hide after", grades are kept visible even after closing
$params['hidden'] = 0;
}
}
if ($grades === 'reset') {
$params['reset'] = true;
$grades = NULL;
}
$gradebook_grades = grade_get_grades($quiz->course, 'mod', 'quiz', $quiz->id);
if (!empty($gradebook_grades->items)) {
$grade_item = $gradebook_grades->items[0];
if ($grade_item->locked) {
$confirm_regrade = optional_param('confirm_regrade', 0, PARAM_INT);
if (!$confirm_regrade) {
$message = get_string('gradeitemislocked', 'grades');
$back_link = $CFG->wwwroot . '/mod/quiz/report.php?q=' . $quiz->id . '&mode=overview';
$regrade_link = qualified_me() . '&confirm_regrade=1';
print_box_start('generalbox', 'notice');
echo '<p>' . $message . '</p>';
echo '<div class="buttons">';
print_single_button($regrade_link, null, get_string('regradeanyway', 'grades'), 'post', $CFG->framename);
print_single_button($back_link, null, get_string('cancel'), 'post', $CFG->framename);
echo '</div>';
print_box_end();
return GRADE_UPDATE_ITEM_LOCKED;
}
}
}
return grade_update('mod/quiz', $quiz->course, 'mod', 'quiz', $quiz->id, 0, $grades, $params);
}
示例12: facetoface_write_activity_attendance
/**
* Write in the worksheet the given facetoface attendance information
* filtered by location.
*
* This function includes lots of custom SQL because it's otherwise
* way too slow.
*
* @param object $worksheet Currently open worksheet
* @param integer $startingrow Index of the starting row (usually 1)
* @param integer $facetofaceid ID of the facetoface activity
* @param string $location Location to filter by
* @param string $coursename Name of the course (optional)
* @param string $activityname Name of the facetoface activity (optional)
* @param object $dateformat Use to write out dates in the spreadsheet
* @returns integer Index of the last row written
*/
function facetoface_write_activity_attendance(&$worksheet, $startingrow, $facetofaceid, $location, $coursename, $activityname, $dateformat)
{
global $CFG, $DB;
$trainerroles = facetoface_get_trainer_roles();
$userfields = facetoface_get_userfields();
$customsessionfields = facetoface_get_session_customfields();
$timenow = time();
$i = $startingrow;
$locationcondition = '';
$locationparam = array();
if (!empty($location)) {
$locationcondition = "AND s.location = ?";
$locationparam = array($location);
}
// Fast version of "facetoface_get_attendees()" for all sessions.
$sessionsignups = array();
$signups = $DB->get_records_sql("\n SELECT\n su.id AS submissionid,\n s.id AS sessionid,\n u.*,\n f.course AS courseid,\n ss.grade,\n sign.timecreated\n FROM\n {facetoface} f\n JOIN\n {facetoface_sessions} s\n ON s.facetoface = f.id\n JOIN\n {facetoface_signups} su\n ON s.id = su.sessionid\n JOIN\n {facetoface_signups_status} ss\n ON su.id = ss.signupid\n LEFT JOIN\n (\n SELECT\n ss.signupid,\n MAX(ss.timecreated) AS timecreated\n FROM\n {facetoface_signups_status} ss\n INNER JOIN\n {facetoface_signups} s\n ON s.id = ss.signupid\n INNER JOIN\n {facetoface_sessions} se\n ON s.sessionid = se.id\n AND se.facetoface = {$facetofaceid}\n WHERE\n ss.statuscode IN (?,?)\n GROUP BY\n ss.signupid\n ) sign\n ON su.id = sign.signupid\n JOIN\n {user} u\n ON u.id = su.userid\n WHERE\n f.id = ?\n AND ss.superceded != 1\n AND ss.statuscode >= ?\n ORDER BY\n s.id, u.firstname, u.lastname\n ", array(MDL_F2F_STATUS_BOOKED, MDL_F2F_STATUS_WAITLISTED, $facetofaceid, MDL_F2F_STATUS_APPROVED));
if ($signups) {
// Get all grades at once.
$userids = array();
foreach ($signups as $signup) {
if ($signup->id > 0) {
$userids[] = $signup->id;
}
}
$gradinginfo = grade_get_grades(reset($signups)->courseid, 'mod', 'facetoface', $facetofaceid, $userids);
foreach ($signups as $signup) {
$userid = $signup->id;
if ($customuserfields = facetoface_get_user_customfields($userid, $userfields)) {
foreach ($customuserfields as $fieldname => $value) {
if (!isset($signup->{$fieldname})) {
$signup->{$fieldname} = $value;
}
}
}
// Set grade.
if (!empty($gradinginfo->items) and !empty($gradinginfo->items[0]->grades[$userid])) {
$signup->grade = $gradinginfo->items[0]->grades[$userid]->str_grade;
}
$sessionsignups[$signup->sessionid][$signup->id] = $signup;
}
}
// Fast version of "facetoface_get_sessions($facetofaceid, $location)".
$sql = "SELECT d.id as dateid, s.id, s.datetimeknown, s.capacity,\n s.duration, d.timestart, d.timefinish\n FROM {facetoface_sessions} s\n JOIN {facetoface_sessions_dates} d ON s.id = d.sessionid\n WHERE\n s.facetoface = ?\n AND d.sessionid = s.id\n {$locationcondition}\n ORDER BY s.datetimeknown, d.timestart";
$sessions = $DB->get_records_sql($sql, array_merge(array($facetofaceid), $locationparam));
$i = $i - 1;
// Will be incremented BEFORE each row is written.
foreach ($sessions as $session) {
$customdata = $DB->get_records('facetoface_session_data', array('sessionid' => $session->id), '', 'fieldid, data');
$sessiondate = false;
$starttime = get_string('wait-listed', 'facetoface');
$finishtime = get_string('wait-listed', 'facetoface');
$status = get_string('wait-listed', 'facetoface');
$sessiontrainers = facetoface_get_trainers($session->id);
if ($session->datetimeknown) {
// Display only the first date.
if (method_exists($worksheet, 'write_date')) {
// Needs the patch in MDL-20781.
$sessiondate = (int) $session->timestart;
} else {
$sessiondate = userdate($session->timestart, get_string('strftimedate', 'langconfig'));
}
$starttime = userdate($session->timestart, get_string('strftimetime', 'langconfig'));
$finishtime = userdate($session->timefinish, get_string('strftimetime', 'langconfig'));
if ($session->timestart < $timenow) {
$status = get_string('sessionover', 'facetoface');
} else {
$signupcount = 0;
if (!empty($sessionsignups[$session->id])) {
$signupcount = count($sessionsignups[$session->id]);
}
if ($signupcount >= $session->capacity) {
$status = get_string('bookingfull', 'facetoface');
} else {
$status = get_string('bookingopen', 'facetoface');
}
}
}
if (!empty($sessionsignups[$session->id])) {
foreach ($sessionsignups[$session->id] as $attendee) {
$i++;
$j = 0;
// Custom session fields.
foreach ($customsessionfields as $field) {
//.........这里部分代码省略.........
示例13: test_update_submission
public function test_update_submission()
{
$this->create_extra_users();
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$this->setUser($this->extrastudents[0]);
$now = time();
$submission = $assign->get_user_submission($this->extrastudents[0]->id, true);
$assign->testable_update_submission($submission, $this->extrastudents[0]->id, true, false);
$this->setUser($this->teachers[0]);
// Verify the gradebook update.
$gradinginfo = grade_get_grades($this->course->id, 'mod', 'assign', $assign->get_instance()->id, $this->extrastudents[0]->id);
$this->assertEquals($this->extrastudents[0]->id, $gradinginfo->items[0]->grades[$this->extrastudents[0]->id]->usermodified);
// Now verify group assignments.
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance(array('teamsubmission' => 1));
$this->setUser($this->extrastudents[0]);
$now = time();
$submission = $assign->get_group_submission($this->extrastudents[0]->id, 0, true);
$assign->testable_update_submission($submission, $this->extrastudents[0]->id, true, true);
// Check that at least 2 active members and 1 suspended member of the submission group had their submission updated.
$this->setUser($this->editingteachers[0]);
$gradinginfo = grade_get_grades($this->course->id, 'mod', 'assign', $assign->get_instance()->id, $this->extrastudents[0]->id);
$this->assertEquals($this->extrastudents[0]->id, $gradinginfo->items[0]->grades[$this->extrastudents[0]->id]->usermodified);
$gradinginfo = grade_get_grades($this->course->id, 'mod', 'assign', $assign->get_instance()->id, $this->extrastudents[self::GROUP_COUNT]->id);
$this->assertEquals($this->extrastudents[self::GROUP_COUNT]->id, $gradinginfo->items[0]->grades[$this->extrastudents[self::GROUP_COUNT]->id]->usermodified);
$gradinginfo = grade_get_grades($this->course->id, 'mod', 'assign', $assign->get_instance()->id, $this->extrasuspendedstudents[0]->id);
$this->assertEquals($this->extrasuspendedstudents[0]->id, $gradinginfo->items[0]->grades[$this->extrasuspendedstudents[0]->id]->usermodified);
// Check the same with non-editing teacher and make sure submission is not updated for suspended user.
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance(array('teamsubmission' => 1));
$this->setUser($this->extrastudents[1]);
$now = time();
$submission = $assign->get_group_submission($this->extrastudents[1]->id, 0, true);
$assign->testable_update_submission($submission, $this->extrastudents[1]->id, true, true);
$this->setUser($this->teachers[0]);
$gradinginfo = grade_get_grades($this->course->id, 'mod', 'assign', $assign->get_instance()->id, $this->extrastudents[1]->id);
$this->assertEquals($this->extrastudents[1]->id, $gradinginfo->items[0]->grades[$this->extrastudents[1]->id]->usermodified);
$gradinginfo = grade_get_grades($this->course->id, 'mod', 'assign', $assign->get_instance()->id, $this->extrastudents[self::GROUP_COUNT + 1]->id);
$this->assertEquals($this->extrastudents[self::GROUP_COUNT + 1]->id, $gradinginfo->items[0]->grades[$this->extrastudents[self::GROUP_COUNT + 1]->id]->usermodified);
$gradinginfo = grade_get_grades($this->course->id, 'mod', 'assign', $assign->get_instance()->id, $this->extrasuspendedstudents[1]->id);
$this->assertEquals($this->extrasuspendedstudents[1]->id, $gradinginfo->items[0]->grades[$this->extrasuspendedstudents[1]->id]->usermodified);
// Now verify blind marking.
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance(array('blindmarking' => 1));
$this->setUser($this->extrastudents[0]);
$now = time();
$submission = $assign->get_user_submission($this->extrastudents[0]->id, true);
$assign->testable_update_submission($submission, $this->extrastudents[0]->id, true, false);
$this->setUser($this->editingteachers[0]);
$gradinginfo = grade_get_grades($this->course->id, 'mod', 'assign', $assign->get_instance()->id, $this->extrastudents[0]->id);
$this->assertEquals(null, $gradinginfo->items[0]->grades[$this->extrastudents[0]->id]->datesubmitted);
}
示例14: process_data
/**
* Process and save the data from the feedback form. Mostly lifted from
* $assignmentinstance->process_feedback().
*
* @param object $data from the feedback form
* @param $params
* @return string
*/
public function process_data($data, $params)
{
global $CFG, $DB;
// TODO validate data.
require_once $CFG->libdir . '/gradelib.php';
require_once "{$CFG->dirroot}/repository/lib.php";
// 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.
// This seems to be something that the pop up javascript will change in the normal run of
// things. Normally it will be the -1 default.
if ((int) $data->saveuserid !== -1) {
$data->userid = $data->saveuserid;
}
if (!empty($data->cancel)) {
// User hit cancel button.
return 'cancelled';
}
// Get DB records.
$coursemodule = $DB->get_record('course_modules', array('id' => $params['coursemoduleid']), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $coursemodule->course), '*', MUST_EXIST);
$assignment = $DB->get_record('assignment', array('id' => $coursemodule->instance), '*', MUST_EXIST);
/* @var stdClass[] $grading_info */
$grading_info = grade_get_grades($coursemodule->course, 'mod', 'assignment', $assignment->id, $data->userid);
$submission = $DB->get_record('assignment_submissions', array('assignment' => $assignment->id, 'userid' => $data->userid), '*', MUST_EXIST);
$user = $DB->get_record('user', array('id' => $data->userid), '*', MUST_EXIST);
$assignmentinstance = $this->get_assignment_instance($assignment, $coursemodule, $course);
// If 'revert to draft' has been clicked, we want a confirm button only.
// We don't want to return yet because the main use case is to comment/grade and then
// ask the student to improve.
if (!empty($data->unfinalize) || !empty($data->revertbutton)) {
$this->unfinalise_submission($submission, $assignment, $coursemodule, $course);
}
if (!$grading_info) {
return 'Could not retrieve grading info.';
}
// Check to see if grade has been locked or overridden. If so, we can't save anything.
if ($grading_info->items[0]->grades[$data->userid]->locked || $grading_info->items[0]->grades[$data->userid]->overridden) {
return 'Grade is locked or overridden';
}
// Advanced grading if enabled. From assignment_base->validate_and_process_feedback().
// Sort out the form ready to tell it to display.
list($mformdata, $advancedgradingwarning) = $this->get_mform_data_object($course, $assignment, $submission, $user, $coursemodule, $assignmentinstance);
$submitform = new block_ajax_marking_assignment_form(block_ajax_marking_form_url($params), $mformdata);
$submitform->set_data($mformdata);
if ($submitform->is_submitted() || !empty($data->revertbutton)) {
// Possibly redundant.
// Form was submitted (= a submit button other than 'cancel' or 'next' has been
// clicked).
if (!$submitform->is_validated()) {
return 'form not validated';
}
/* @var gradingform_instance $gradinginstance */
$gradinginstance = $submitform->use_advanced_grading();
// Preprocess advanced grading here.
if ($gradinginstance) {
$formdata = $submitform->get_data();
// Create submission if it did not exist yet because we need submission->id for
// storing the grading instance.
$advancedgrading = $formdata->advancedgrading;
// Calculates the gradebook grade based on the rubrics.
$data->xgrade = $gradinginstance->submit_and_get_grade($advancedgrading, $submission->id);
}
}
// Save outcomes if necessary.
if (!empty($CFG->enableoutcomes)) {
$assignmentinstance->process_outcomes($data->userid);
}
$submission = $this->save_submission($submission, $data);
if (!$submission) {
return 'Problem saving feedback';
}
// Trigger grade event to update gradebook.
$assignment->cmidnumber = $coursemodule->id;
assignment_update_grades($assignment, $data->userid);
add_to_log($coursemodule->course, 'assignment', 'update grades', 'submissions.php?id=' . $coursemodule->id . '&user=' . $data->userid, $data->userid, $coursemodule->id);
// Save files if necessary.
$this->save_files($assignment, $submission, $data);
return '';
}
示例15: get_gradebook_grades
/**
* Returns the information about the user's grades as they are stored in the gradebook
*
* The submission grade is returned for users with the capability mod/workshop:submit and the
* assessment grade is returned for users with the capability mod/workshop:peerassess. Unless the
* user has the capability to view hidden grades, grades must be visible to be returned. Null
* grades are not returned. If none grade is to be returned, this method returns false.
*
* @param int $userid the user's id
* @return workshop_final_grades|false
*/
public function get_gradebook_grades($userid)
{
global $CFG;
require_once $CFG->libdir . '/gradelib.php';
if (empty($userid)) {
throw new coding_exception('User id expected, empty value given.');
}
// Read data via the Gradebook API
$gradebook = grade_get_grades($this->course->id, 'mod', 'workshop', $this->id, $userid);
$grades = new workshop_final_grades();
if (has_capability('mod/workshop:submit', $this->context, $userid)) {
if (!empty($gradebook->items[0]->grades)) {
$submissiongrade = reset($gradebook->items[0]->grades);
if (!is_null($submissiongrade->grade)) {
if (!$submissiongrade->hidden or has_capability('moodle/grade:viewhidden', $this->context, $userid)) {
$grades->submissiongrade = $submissiongrade;
}
}
}
}
if (has_capability('mod/workshop:peerassess', $this->context, $userid)) {
if (!empty($gradebook->items[1]->grades)) {
$assessmentgrade = reset($gradebook->items[1]->grades);
if (!is_null($assessmentgrade->grade)) {
if (!$assessmentgrade->hidden or has_capability('moodle/grade:viewhidden', $this->context, $userid)) {
$grades->assessmentgrade = $assessmentgrade;
}
}
}
}
if (!is_null($grades->submissiongrade) or !is_null($grades->assessmentgrade)) {
return $grades;
}
return false;
}