本文整理汇总了PHP中grade_grade类的典型用法代码示例。如果您正苦于以下问题:PHP grade_grade类的具体用法?PHP grade_grade怎么用?PHP grade_grade使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了grade_grade类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
global $DB;
$TIMELIMITHOURS = 8;
$timebound = time() - $TIMELIMITHOURS * 60 * 60;
$sql = 'SELECT id, itemid, userid FROM {grade_grades} WHERE locked = 0 AND overridden > 0 AND overridden < ?';
$records = $DB->get_records_sql($sql, array($timebound));
foreach ($records as $record) {
$gradeitem = \grade_item::fetch(array('id' => $record->itemid));
$grades = \grade_grade::fetch_users_grades($gradeitem, array($record->userid));
$grades[$record->userid]->set_locked(1);
}
}
开发者ID:ispedals,项目名称:moodle-local_gradelock,代码行数:13,代码来源:lock_grades.php
示例2: test_process_data
/**
* Tests grade_report_grader::process_data()
*
* process_data() processes submitted grade and feedback data
*/
public function test_process_data()
{
global $DB, $CFG;
$this->resetAfterTest(true);
$course = $this->getDataGenerator()->create_course();
$coursecontext = context_course::instance($course->id);
// Create and enrol a student.
$student = $this->getDataGenerator()->create_user(array('username' => 'Student Sam'));
$role = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST);
$this->getDataGenerator()->enrol_user($student->id, $course->id, $role->id);
// Test with limited grades.
$CFG->unlimitedgrades = 0;
$forummax = 80;
$forum1 = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => $forummax, 'course' => $course->id));
// Switch the stdClass instance for a grade item instance.
$forum1 = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum1->id, 'courseid' => $course->id));
$report = $this->create_report($course, $coursecontext);
$testgrade = 60.0;
$data = new stdClass();
$data->id = $course->id;
$data->report = 'grader';
$data->grade = array();
$data->grade[$student->id] = array();
$data->grade[$student->id][$forum1->id] = $testgrade;
$warnings = $report->process_data($data);
$this->assertEquals(count($warnings), 0);
$studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
$this->assertEquals($studentgrade->finalgrade, $testgrade);
// Grade above max. Should be pulled down to max.
$toobig = 200.0;
$data->grade[$student->id][$forum1->id] = $toobig;
$warnings = $report->process_data($data);
$this->assertEquals(count($warnings), 1);
$studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
$this->assertEquals($studentgrade->finalgrade, $forummax);
// Grade below min. Should be pulled up to min.
$toosmall = -10.0;
$data->grade[$student->id][$forum1->id] = $toosmall;
$warnings = $report->process_data($data);
$this->assertEquals(count($warnings), 1);
$studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
$this->assertEquals($studentgrade->finalgrade, 0);
// Test unlimited grades so we can give a student a grade about max.
$CFG->unlimitedgrades = 1;
$data->grade[$student->id][$forum1->id] = $toobig;
$warnings = $report->process_data($data);
$this->assertEquals(count($warnings), 0);
$studentgrade = grade_grade::fetch(array('itemid' => $forum1->id, '' => $student->id));
$this->assertEquals($studentgrade->finalgrade, $toobig);
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:55,代码来源:reportgrader_test.php
示例3: test_get_grade
/**
* Tests the gradebookservice get grade service.
*
* @return void
*/
public function test_get_grade()
{
global $DB;
$callback = 'block_mhaairs_gradebookservice_external::get_grade';
$this->set_user('admin');
// Add mhaairs grade item directly.
$params = array('courseid' => $this->course->id, 'itemtype' => 'manual', 'itemmodule' => 'mhaairs', 'iteminstance' => 101, 'itemname' => 'MH Assignment');
$gitem = new \grade_item($params, false);
$gitem->insert('mhaairs');
// Add user grade directly.
$params = array('itemid' => $gitem->id, 'userid' => $this->student1->id, 'finalgrade' => '95');
$ggrade = new \grade_grade($params, false);
$ggrade->insert('mhaairs');
// Service params.
$serviceparams = array('source' => 'mhaairs', 'courseid' => $this->course->id, 'itemtype' => 'manual', 'itemmodule' => 'mhaairs', 'iteminstance' => 101, 'itemnumber' => 0, 'grades' => null, 'itemdetails' => null);
// Grade details.
$grades = array('userid' => 'student1', 'identity_type' => '');
$gradesjson = urlencode(json_encode($grades));
$serviceparams['grades'] = $gradesjson;
$result = call_user_func_array($callback, $serviceparams);
$this->assertEquals('MH Assignment', $result['item']['itemname']);
$this->assertEquals($this->student1->id, $result['grades'][0]['userid']);
$this->assertEquals(95, $result['grades'][0]['grade']);
}
开发者ID:itamart,项目名称:moodle-block_mhaairs,代码行数:29,代码来源:gradebookservice_get_grade_test.php
示例4: test_task_timefilter
public function test_task_timefilter()
{
$task = new \local_gradelock\task\lock_grades();
$grade_grade = new grade_grade();
$grade_grade->itemid = $this->grade_items[0]->id;
$grade_grade->userid = 10;
$grade_grade->rawgrade = 88;
$grade_grade->rawgrademax = 110;
$grade_grade->rawgrademin = 18;
$grade_grade->load_grade_item();
$grade_grade->insert();
$grade_grade->grade_item->update_final_grade($this->user[0]->id, 100, 'gradebook', '', FORMAT_MOODLE);
$grade_grade->update();
$task->execute();
$grade_grade = grade_grade::fetch(array('userid' => $this->user[0]->id, 'itemid' => $this->grade_items[0]->id));
$this->assertFalse($grade_grade->is_locked());
}
开发者ID:ispedals,项目名称:moodle-local_gradelock,代码行数:17,代码来源:task_test.php
示例5: cleanup
public function cleanup()
{
// cleanup any clickers before the test
$user_id = iclicker_service::require_user();
$results = iclicker_service::get_registrations_by_user($user_id);
if ($results) {
echo "cleanup registrations for user: {$user_id} " . PHP_EOL;
foreach ($results as $reg) {
if ($reg->clicker_id == $this->clicker_id) {
iclicker_service::remove_registration($reg->id);
echo "cleanup: {$reg->id} " . PHP_EOL;
}
}
}
// cleanup the test grades
$def_grade_cats = grade_category::fetch_all(array('courseid' => $this->courseid, 'fullname' => iclicker_service::GRADE_CATEGORY_NAME));
$stuff_grade_cats = grade_category::fetch_all(array('courseid' => $this->courseid, 'fullname' => 'stuff'));
$grade_cats = $def_grade_cats;
if (is_array($def_grade_cats) && is_array($stuff_grade_cats)) {
$grade_cats = array_merge($def_grade_cats, $stuff_grade_cats);
} else {
if (is_array($stuff_grade_cats)) {
$grade_cats = $stuff_grade_cats;
}
}
if ($grade_cats) {
foreach ($grade_cats as $cat) {
$grade_items = grade_item::fetch_all(array('courseid' => $this->courseid, 'categoryid' => $cat->id));
if ($grade_items) {
foreach ($grade_items as $item) {
$grades = grade_grade::fetch_all(array('itemid' => $item->id));
if ($grades) {
foreach ($grades as $grade) {
$grade->delete("cleanup");
}
}
$item->delete("cleanup");
}
}
$cat->delete("cleanup");
}
}
}
开发者ID:dirkcgrunwald,项目名称:iclicker-moodle2-integrate,代码行数:43,代码来源:test_iclicker_service.php
示例6: locate_element
/**
* Parses the array in search of a given eid and returns a element object with
* information about the element it has found.
* @param int $eid Gradetree Element ID
* @return object element
*/
public function locate_element($eid)
{
// it is a grade - construct a new object
if (strpos($eid, 'n') === 0) {
if (!preg_match('/n(\\d+)u(\\d+)/', $eid, $matches)) {
return null;
}
$itemid = $matches[1];
$userid = $matches[2];
//extra security check - the grade item must be in this tree
if (!($item_el = $this->locate_element('i' . $itemid))) {
return null;
}
// $gradea->id may be null - means does not exist yet
$grade = new grade_grade(array('itemid' => $itemid, 'userid' => $userid));
$grade->grade_item =& $item_el['object'];
// this may speedup grade_grade methods!
return array('eid' => 'n' . $itemid . 'u' . $userid, 'object' => $grade, 'type' => 'grade');
} else {
if (strpos($eid, 'g') === 0) {
$id = (int) substr($eid, 1);
if (!($grade = grade_grade::fetch(array('id' => $id)))) {
return null;
}
//extra security check - the grade item must be in this tree
if (!($item_el = $this->locate_element('i' . $grade->itemid))) {
return null;
}
$grade->grade_item =& $item_el['object'];
// this may speedup grade_grade methods!
return array('eid' => 'g' . $id, 'object' => $grade, 'type' => 'grade');
}
}
// it is a category or item
foreach ($this->levels as $row) {
foreach ($row as $element) {
if ($element['type'] == 'filler') {
continue;
}
if ($element['eid'] == $eid) {
return $element;
}
}
}
return null;
}
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:52,代码来源:lib.php
示例7: fill_contributions_column
/**
* This function is called after the table has been built and the aggregationhints
* have been collected. We need this info to walk up the list of parents of each
* grade_item.
*
* @param $element - An array containing the table data for the current row.
*/
public function fill_contributions_column($element)
{
// Recursively iterate through all child elements.
if (isset($element['children'])) {
foreach ($element['children'] as $key => $child) {
$this->fill_contributions_column($element['children'][$key]);
}
} else {
if ($element['type'] == 'item') {
// This is a grade item (We don't do this for categories or we would double count).
$grade_object = $element['object'];
$itemid = $grade_object->id;
// Ignore anything with no hint - e.g. a hidden row.
if (isset($this->aggregationhints[$itemid])) {
// Normalise the gradeval.
$gradecat = $grade_object->load_parent_category();
if ($gradecat->aggregation == GRADE_AGGREGATE_SUM) {
// Natural aggregation/Sum of grades does not consider the mingrade, cannot traditionnally normalise it.
$graderange = $this->aggregationhints[$itemid]['grademax'];
if ($graderange != 0) {
$gradeval = $this->aggregationhints[$itemid]['grade'] / $graderange;
} else {
$gradeval = 0;
}
} else {
$gradeval = grade_grade::standardise_score($this->aggregationhints[$itemid]['grade'], $this->aggregationhints[$itemid]['grademin'], $this->aggregationhints[$itemid]['grademax'], 0, 1);
}
// Multiply the normalised value by the weight
// of all the categories higher in the tree.
$parent = null;
do {
if (!is_null($this->aggregationhints[$itemid]['weight'])) {
$gradeval *= $this->aggregationhints[$itemid]['weight'];
} else {
if (empty($parent)) {
// If we are in the first loop, and the weight is null, then we cannot calculate the contribution.
$gradeval = null;
break;
}
}
// The second part of this if is to prevent infinite loops
// in case of crazy data.
if (isset($this->aggregationhints[$itemid]['parent']) && $this->aggregationhints[$itemid]['parent'] != $itemid) {
$parent = $this->aggregationhints[$itemid]['parent'];
$itemid = $parent;
} else {
// We are at the top of the tree.
$parent = false;
}
} while ($parent);
// Finally multiply by the course grademax.
if (!is_null($gradeval)) {
// Convert to percent.
$gradeval *= 100;
}
// Now we need to loop through the "built" table data and update the
// contributions column for the current row.
$header_row = "row_{$grade_object->id}_{$this->user->id}";
foreach ($this->tabledata as $key => $row) {
if (isset($row['itemname']) && $row['itemname']['id'] == $header_row) {
// Found it - update the column.
$content = '-';
if (!is_null($gradeval)) {
$decimals = $grade_object->get_decimals();
$content = format_float($gradeval, $decimals, true) . ' %';
}
$this->tabledata[$key]['contributiontocoursetotal']['content'] = $content;
break;
}
}
}
}
}
}
开发者ID:Chocolate-lightning,项目名称:moodle,代码行数:81,代码来源:lib.php
示例8: sum_grades
/**
* Internal function for category grades summing
*
* @param grade_grade $grade The grade item
* @param float $oldfinalgrade Old Final grade
* @param array $items Grade items
* @param array $grade_values Grade values
* @param array $excluded Excluded
*/
private function sum_grades(&$grade, $oldfinalgrade, $items, $grade_values, $excluded)
{
if (empty($items)) {
return null;
}
// ungraded and excluded items are not used in aggregation
foreach ($grade_values as $itemid => $v) {
if (is_null($v)) {
unset($grade_values[$itemid]);
} else {
if (in_array($itemid, $excluded)) {
unset($grade_values[$itemid]);
}
}
}
// use 0 if grade missing, droplow used and aggregating all items
if (!$this->aggregateonlygraded and !empty($this->droplow)) {
foreach ($items as $itemid => $value) {
if (!isset($grade_values[$itemid]) and !in_array($itemid, $excluded)) {
$grade_values[$itemid] = 0;
}
}
}
$this->apply_limit_rules($grade_values, $items);
$sum = array_sum($grade_values);
$grade->finalgrade = $this->grade_item->bounded_grade($sum);
// update in db if changed
if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
$grade->update('aggregation');
}
return;
}
开发者ID:covex-nn,项目名称:moodle,代码行数:41,代码来源:grade_category.php
示例9: process_grade_grade
protected function process_grade_grade($data) {
$data = (object)($data);
unset($data->id);
$data->itemid = $this->get_new_parentid('grade_item');
$data->userid = $this->get_mappingid('user', $data->userid);
$data->usermodified = $this->get_mappingid('user', $data->usermodified);
$data->rawscaleid = $this->get_mappingid('scale', $data->rawscaleid);
// TODO: Ask, all the rest of locktime/exported... work with time... to be rolled?
$data->overridden = $this->apply_date_offset($data->overridden);
$grade = new grade_grade($data, false);
$grade->insert('restore');
// no need to save any grade_grade mapping
}
开发者ID:nottmoo,项目名称:moodle,代码行数:15,代码来源:restore_stepslib.php
示例10: reopen_submission_if_required
/**
* If the requirements are met - reopen the submission for another attempt.
* Only call this function when grading the latest attempt.
*
* @param int $userid The userid.
* @param stdClass $submission The submission (may be a group submission).
* @param bool $addattempt - True if the "allow another attempt" checkbox was checked.
* @return bool - true if another attempt was added.
*/
protected function reopen_submission_if_required($userid, $submission, $addattempt)
{
$instance = $this->get_instance();
$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.
$gradeitem = $this->get_grade_item();
if ($gradeitem) {
$gradegrade = grade_grade::fetch(array('userid' => $userid, 'itemid' => $gradeitem->id));
// Do not reopen if is_passed returns null, e.g. if there is no pass criterion set.
if ($gradegrade && $gradegrade->is_passed() === false) {
$shouldreopen = true;
}
}
}
if ($instance->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL && !empty($addattempt)) {
$shouldreopen = true;
}
if ($shouldreopen && !$maxattemptsreached) {
$this->add_attempt($userid);
return true;
}
return false;
}
开发者ID:mercysmart,项目名称:naikelas,代码行数:34,代码来源:locallib.php
示例11: test_blank_hidden_total_and_adjust_bounds
/**
* Tests grade_report::blank_hidden_total_and_adjust_bounds()
*/
public function test_blank_hidden_total_and_adjust_bounds()
{
global $DB;
$this->resetAfterTest(true);
$student = $this->getDataGenerator()->create_user();
$this->setUser($student);
// Create a course and two activities.
// One activity will be hidden.
$course = $this->getDataGenerator()->create_course();
$coursegradeitem = grade_item::fetch_course_item($course->id);
$coursecontext = context_course::instance($course->id);
$data = $this->getDataGenerator()->create_module('data', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
$datacm = get_coursemodule_from_id('data', $data->cmid);
$forum = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
$forumcm = get_coursemodule_from_id('forum', $forum->cmid);
// Insert student grades for the two activities.
$gi = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'data', 'iteminstance' => $data->id, 'courseid' => $course->id));
$datagrade = 50;
$grade_grade = new grade_grade();
$grade_grade->itemid = $gi->id;
$grade_grade->userid = $student->id;
$grade_grade->rawgrade = $datagrade;
$grade_grade->finalgrade = $datagrade;
$grade_grade->rawgrademax = 100;
$grade_grade->rawgrademin = 0;
$grade_grade->timecreated = time();
$grade_grade->timemodified = time();
$grade_grade->insert();
$gi = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum->id, 'courseid' => $course->id));
$forumgrade = 70;
$grade_grade = new grade_grade();
$grade_grade->itemid = $gi->id;
$grade_grade->userid = $student->id;
$grade_grade->rawgrade = $forumgrade;
$grade_grade->finalgrade = $forumgrade;
$grade_grade->rawgrademax = 100;
$grade_grade->rawgrademin = 0;
$grade_grade->timecreated = time();
$grade_grade->timemodified = time();
$grade_grade->insert();
// Hide the database activity.
set_coursemodule_visible($datacm->id, 0);
$gpr = new grade_plugin_return(array('type' => 'report', 'courseid' => $course->id));
$report = new grade_report_test($course->id, $gpr, $coursecontext, $student);
// Should return the supplied student total grade regardless of hiding.
$report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN);
$result = $report->blank_hidden_total_and_adjust_bounds($course->id, $coursegradeitem, $datagrade + $forumgrade);
$this->assertEquals(array('grade' => $datagrade + $forumgrade, 'grademax' => $coursegradeitem->grademax, 'grademin' => $coursegradeitem->grademin, 'aggregationstatus' => 'unknown', 'aggregationweight' => null), $result);
// Should blank the student total as course grade depends on a hidden item.
$report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_HIDE_TOTAL_IF_CONTAINS_HIDDEN);
$result = $report->blank_hidden_total_and_adjust_bounds($course->id, $coursegradeitem, $datagrade + $forumgrade);
$this->assertEquals(array('grade' => null, 'grademax' => $coursegradeitem->grademax, 'grademin' => $coursegradeitem->grademin, 'aggregationstatus' => 'unknown', 'aggregationweight' => null), $result);
// Should return the course total minus the hidden database activity grade.
$report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_SHOW_TOTAL_IF_CONTAINS_HIDDEN);
$result = $report->blank_hidden_total_and_adjust_bounds($course->id, $coursegradeitem, $datagrade + $forumgrade);
$this->assertEquals(array('grade' => floatval($forumgrade), 'grademax' => $coursegradeitem->grademax, 'grademin' => $coursegradeitem->grademin, 'aggregationstatus' => 'unknown', 'aggregationweight' => null), $result);
// Note: we cannot simply hide modules and call $report->blank_hidden_total() again.
// It stores grades in a static variable so $report->blank_hidden_total() will return incorrect totals
// In practice this isn't a problem. Grade visibility isn't altered mid-request outside of the unit tests.
// Add a second course to test:
// 1) How a course with no visible activities behaves.
// 2) That $report->blank_hidden_total() correctly moves on to the new course.
$course = $this->getDataGenerator()->create_course();
$coursegradeitem = grade_item::fetch_course_item($course->id);
$coursecontext = context_course::instance($course->id);
$data = $this->getDataGenerator()->create_module('data', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
$datacm = get_coursemodule_from_id('data', $data->cmid);
$forum = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
$forumcm = get_coursemodule_from_id('forum', $forum->cmid);
$gi = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'data', 'iteminstance' => $data->id, 'courseid' => $course->id));
$datagrade = 50;
$grade_grade = new grade_grade();
$grade_grade->itemid = $gi->id;
$grade_grade->userid = $student->id;
$grade_grade->rawgrade = $datagrade;
$grade_grade->finalgrade = $datagrade;
$grade_grade->rawgrademax = 100;
$grade_grade->rawgrademin = 0;
$grade_grade->timecreated = time();
$grade_grade->timemodified = time();
$grade_grade->insert();
$gi = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum->id, 'courseid' => $course->id));
$forumgrade = 70;
$grade_grade = new grade_grade();
$grade_grade->itemid = $gi->id;
$grade_grade->userid = $student->id;
$grade_grade->rawgrade = $forumgrade;
$grade_grade->finalgrade = $forumgrade;
$grade_grade->rawgrademax = 100;
$grade_grade->rawgrademin = 0;
$grade_grade->timecreated = time();
$grade_grade->timemodified = time();
$grade_grade->insert();
// Hide both activities.
set_coursemodule_visible($datacm->id, 0);
set_coursemodule_visible($forumcm->id, 0);
$gpr = new grade_plugin_return(array('type' => 'report', 'courseid' => $course->id));
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:reportlib_test.php
示例12: get_hiding_affected
/**
* Return array of grade item ids that are either hidden or indirectly depend
* on hidden grades, excluded grades are not returned.
* THIS IS A REALLY BIG HACK! to be replaced by conditional aggregation of hidden grades in 2.0
*
* @param array $grade_grades all course grades of one user, & used for better internal caching
* @param array $grade_items array of grade items, & used for better internal caching
* @return array This is an array of 3 arrays:
* unknown => list of item ids that may be affected by hiding (with the calculated grade as the value)
* altered => list of item ids that are definitely affected by hiding (with the calculated grade as the value)
* alteredgrademax => for each item in altered or unknown, the new value of the grademax
* alteredgrademin => for each item in altered or unknown, the new value of the grademin
* alteredgradestatus => for each item with a modified status - the value of the new status
* alteredgradeweight => for each item with a modified weight - the value of the new weight
*/
public static function get_hiding_affected(&$grade_grades, &$grade_items)
{
global $CFG;
if (count($grade_grades) !== count($grade_items)) {
print_error('invalidarraysize', 'debug', '', 'grade_grade::get_hiding_affected()!');
}
$dependson = array();
$todo = array();
$unknown = array();
// can not find altered
$altered = array();
// altered grades
$alteredgrademax = array();
// Altered grade max values.
$alteredgrademin = array();
// Altered grade min values.
$alteredaggregationstatus = array();
// Altered aggregation status.
$alteredaggregationweight = array();
// Altered aggregation weight.
$dependencydepth = array();
$hiddenfound = false;
foreach ($grade_grades as $itemid => $unused) {
$grade_grade =& $grade_grades[$itemid];
// We need the immediate dependencies of all every grade_item so we can calculate nested dependencies.
$dependson[$grade_grade->itemid] = $grade_items[$grade_grade->itemid]->depends_on();
if ($grade_grade->is_excluded()) {
//nothing to do, aggregation is ok
} else {
if ($grade_grade->is_hidden()) {
$hiddenfound = true;
$altered[$grade_grade->itemid] = null;
$alteredaggregationstatus[$grade_grade->itemid] = 'dropped';
$alteredaggregationweight[$grade_grade->itemid] = 0;
} else {
if ($grade_grade->is_locked() or $grade_grade->is_overridden()) {
// no need to recalculate locked or overridden grades
} else {
if (!empty($dependson[$grade_grade->itemid])) {
$dependencydepth[$grade_grade->itemid] = 1;
$todo[] = $grade_grade->itemid;
}
}
}
}
}
// Flatten the dependency tree and count number of branches to each leaf.
self::flatten_dependencies_array($dependson, $dependencydepth);
if (!$hiddenfound) {
return array('unknown' => array(), 'altered' => array(), 'alteredgrademax' => array(), 'alteredgrademin' => array(), 'alteredaggregationstatus' => array(), 'alteredaggregationweight' => array());
}
// This line ensures that $dependencydepth has the same number of items as $todo.
$dependencydepth = array_intersect_key($dependencydepth, array_flip($todo));
// We need to resort the todo list by the dependency depth. This guarantees we process the leaves, then the branches.
array_multisort($dependencydepth, $todo);
$max = count($todo);
$hidden_precursors = null;
for ($i = 0; $i < $max; $i++) {
$found = false;
foreach ($todo as $key => $do) {
$hidden_precursors = array_intersect($dependson[$do], $unknown);
if ($hidden_precursors) {
// this item depends on hidden grade indirectly
$unknown[$do] = $do;
unset($todo[$key]);
$found = true;
continue;
} else {
if (!array_intersect($dependson[$do], $todo)) {
$hidden_precursors = array_intersect($dependson[$do], array_keys($altered));
if (!$hidden_precursors) {
// hiding does not affect this grade
unset($todo[$key]);
$found = true;
continue;
} else {
// depends on altered grades - we should try to recalculate if possible
if ($grade_items[$do]->is_calculated() or !$grade_items[$do]->is_category_item() and !$grade_items[$do]->is_course_item()) {
// This is a grade item that is not a category or course and has been affected by grade hiding.
// I guess this means it is a calculation that needs to be recalculated.
$unknown[$do] = $do;
unset($todo[$key]);
$found = true;
continue;
} else {
//.........这里部分代码省略.........
开发者ID:sriysk,项目名称:moodle-integration,代码行数:101,代码来源:grade_grade.php
示例13: generate_random_raw_grade
protected function generate_random_raw_grade($item, $userid)
{
$grade = new grade_grade();
$grade->itemid = $item->id;
$grade->userid = $userid;
$grade->grademin = 0;
$grade->grademax = 1;
$valuetype = "grade{$item->gradetype}";
$grade->rawgrade = rand(0, 1000) / 1000;
$grade->insert();
return $grade->rawgrade;
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:12,代码来源:grade_category_test.php
示例14: std_meta
/**
* Return standard meta data for module
*
* @param cm_info $mod
* @param string $timeopenfld
* @param string $timeclosefld
* @param string $keyfield
* @param string $submissiontable
* @param string $submittedonfld
* @param string $submitstrkey
* @param bool $isgradeable
* @param string $submitselect - sql to further filter submission row select statement - e.g. st.status='finished'
* @return bool | \theme_snap\activity_meta
*/
protected static function std_meta(\cm_info $mod, $timeopenfld, $timeclosefld, $keyfield, $submissiontable, $submittedonfld, $submitstrkey, $isgradeable = false, $submitselect = '')
{
global $USER;
$courseid = $mod->course;
// Create meta data object.
$meta = new \theme_snap\activity_meta();
$meta->submitstrkey = $submitstrkey;
$meta->submittedstr = get_string($submitstrkey, 'theme_snap');
$meta->notsubmittedstr = get_string('not' . $submitstrkey, 'theme_snap');
if (get_string_manager()->string_exists($mod->modname . 'draft', 'theme_snap')) {
$meta->draftstr = get_string($mod->modname . 'draft', 'theme_snap');
} else {
$meta->drafstr = get_string('draft', 'theme_snap');
}
if (get_string_manager()->string_exists($mod->modname . 'reopened', 'theme_snap')) {
$meta->reopenedstr = get_string($mod->modname . 'reopened', 'theme_snap');
} else {
$meta->reopenedstr = get_string('reopened', 'theme_snap');
}
// If module is not visible to the user then don't bother getting meta data.
if (!$mod->uservisible) {
return $meta;
}
$activitydates = self::instance_activity_dates($courseid, $mod, $timeopenfld, $timeclosefld);
$meta->timeopen = $activitydates->timeopen;
$meta->timeclose = $activitydates->timeclose;
// TODO: use activity specific "teacher" capabilities.
if (has_capability('mod/assign:grade', \context_course::instance($courseid))) {
$meta->isteacher = true;
// Teacher - useful teacher meta data.
$methodnsubmissions = $mod->modname . '_num_submissions';
$methodnungraded = $mod->modname . '_num_submissions_ungraded';
if (method_exists('theme_snap\\activity', $methodnsubmissions)) {
$meta->numsubmissions = call_user_func('theme_snap\\activity::' . $methodnsubmissions, $courseid, $mod->instance);
}
if (method_exists('theme_snap\\activity', $methodnungraded)) {
$meta->numrequiregrading = call_user_func('theme_snap\\activity::' . $methodnungraded, $courseid, $mod->instance);
}
} else {
// Student - useful student meta data - only display if activity is available.
if (empty($activitydates->timeopen) || usertime($activitydates->timeopen) <= time()) {
$submissionrow = self::get_submission_row($courseid, $mod, $submissiontable, $keyfield, $submitselect);
if (!empty($submissionrow)) {
if ($submissionrow->status) {
switch ($submissionrow->status) {
case 'draft':
$meta->draft = true;
break;
case 'reopened':
$meta->reopened = true;
break;
case 'submitted':
$meta->submitted = true;
break;
}
} else {
$meta->submitted = true;
$meta->timesubmitted = !empty($submissionrow->{$submittedonfld}) ? $submissionrow->{$submittedonfld} : null;
}
// If submitted on field uses modified field then fall back to timecreated if modified is 0.
if (empty($meta->timesubmitted) && ($submittedonfld = 'timemodified')) {
if (isset($submissionrow->timemodified)) {
$meta->timesubmitted = $submissionrow->timemodified;
} else {
$meta->timesubmitted = $submissionrow->timecreated;
}
}
}
}
$graderow = false;
if ($isgradeable) {
$graderow = self::grade_row($courseid, $mod);
}
if ($graderow) {
$gradeitem = \grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $mod->modname, 'iteminstance' => $mod->instance));
$grade = new \grade_grade(array('itemid' => $gradeitem->id, 'userid' => $USER->id));
$coursecontext = \context_course::instance($courseid);
$canviewhiddengrade = has_capability('moodle/grade:viewhidden', $coursecontext);
if (!$grade->is_hidden() || $canviewhiddengrade) {
$meta->grade = true;
}
}
}
return $meta;
}
开发者ID:nbartley,项目名称:moodle-theme_snap,代码行数:99,代码来源:activity.php
示例15: delete_user
/**
* Marks user deleted in internal user database and notifies the auth plugin.
* Also unenrols user from all roles and does other cleanup.
* @param object $user Userobject before delete (without system magic quotes)
* @return boolean success
*/
function delete_user($user)
{
global $CFG;
require_once $CFG->libdir . '/grouplib.php';
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->dirroot . '/message/lib.php';
begin_sql();
// delete all grades - backup is kept in grade_grades_history table
if ($grades = grade_grade::fetch_all(array('userid' => $user->id))) {
foreach ($grades as $grade) {
$grade->delete('userdelete');
}
}
//move unread messages from this user to read
message_move_userfrom_unread2read($user->id);
// remove from all groups
delete_records('groups_members', 'userid', $user->id);
// unenrol from all roles in all contexts
role_unassign(0, $user->id);
// this might be slow but it is really needed - modules might do some extra cleanup!
// now do a final accesslib cleanup - removes all role assingments in user context and context itself
delete_context(CONTEXT_USER, $user->id);
require_once $CFG->dirroot . '/tag/lib.php';
tag_set('user', $user->id, array());
// workaround for bulk deletes of users with the same email address
$delname = addslashes("{$user->email}." . time());
while (record_exists('user', 'username', $delname)) {
// no need to use mnethostid here
$delname++;
}
// mark internal user record as "deleted"
$updateuser = new object();
$updateuser->id = $user->id;
$updateuser->deleted = 1;
$updateuser->username = $delname;
// Remember it just in case
$updateuser->email = md5($user->username);
// Store hash of username, useful importing/restoring users
$updateuser->idnumber = '';
// Clear this field to free it up
$updateuser->timemodified = time();
if (update_record('user', $updateuser)) {
commit_sql();
// notify auth plugin - do not block the delete even when plugin fails
$authplugin = get_auth_plugin($user->auth);
$authplugin->user_delete($user);
events_trigger('user_deleted', $user);
return true;
} else {
rollback_sql();
return false;
}
}
开发者ID:nadavkav,项目名称:rtlMoodle,代码行数:59,代码来源:moodlelib.php
示例16: grade_report_grader
//$users = $report_evalcomix->load_users();
//$finalgrades = $report_evalcomix->get_grades();
$numpages = (int) ($numusers / $studentsperpage);
if ($numusers % $studentsperpage > 0) {
$numpages += 1;
}
for ($ipage = 0; $ipage < $numpages; ++$ipage) {
$report_grader = new grade_report_grader($courseid, null, $context, $ipage, $sortitemid);
$report_grader->load_users();
$report_grader->load_final_grades();
foreach ($report_grader->users as $userid => $user) {
if ($report_grader->canviewhidden) {
$altered = array();
$unknown = array();
} else {
$hidingaffected = grade_grade::get_hiding_affected($report_grader->grades[$userid], $report_grader->gtree->get_items());
$altered = $hidingaffected['altered'];
$unknown = $hidingaffected['unknown'];
unset($hidingaffected);
}
foreach ($report_grader->gtree->items as $itemid => $unused) {
$item =& $report_grader->gtree->items[$itemid];
$grade = $report_grader->grades[$userid][$item->id];
// Get the decimal points preference for this item
$decimalpoints = $item->get_decimals();
if (in_array($itemid, $unknown)) {
$gradeval = null;
} else {
if (array_key_exists($itemid, $altered)) {
$gradeval = $altered[$itemid];
} else {
开发者ID:srpaedagogus,项目名称:aulavirtual,代码行数:31,代码来源:index.php
示例17: grade_cron
/**
* Grading cron job
*/
function grade_cron()
{
global $CFG;
$now = time();
$sql = "SELECT i.*\n FROM {$CFG->prefix}grade_items i\n WHERE i.locked = 0 AND i.locktime > 0 AND i.locktime < {$now} AND EXISTS (\n SELECT 'x' FROM {$CFG->prefix}grade_items c WHERE c.itemtype='course' AND c.needsupdate=0 AND c.courseid=i.courseid)";
// go through all courses that have proper final grades and lock them if needed
if ($rs = get_recordset_sql($sql)) {
if ($rs->RecordCount() > 0) {
while ($item = rs_fetch_next_record($rs)) {
$grade_item = new grade_item($item, false);
$gr
|
请发表评论