当前位置: 首页>>代码示例>>PHP>>正文


PHP grade_item::fetch_course_item方法代码示例

本文整理汇总了PHP中grade_item::fetch_course_item方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_item::fetch_course_item方法的具体用法?PHP grade_item::fetch_course_item怎么用?PHP grade_item::fetch_course_item使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在grade_item的用法示例。


在下文中一共展示了grade_item::fetch_course_item方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init

 /**
  * Initialise the iterator
  * @return boolean success
  */
 function init()
 {
     global $CFG;
     $this->close();
     grade_regrade_final_grades($this->course->id);
     $course_item = grade_item::fetch_course_item($this->course->id);
     if ($course_item->needsupdate) {
         // can not calculate all final grades - sorry
         return false;
     }
     if (strpos($CFG->gradebookroles, ',') !== false) {
         $gradebookroles = " = {$CFG->gradebookroles}";
     } else {
         $gradebookroles = " IN ({$CFG->gradebookroles})";
     }
     $relatedcontexts = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $this->course->id));
     if ($this->groupid) {
         $groupsql = "INNER JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id";
         $groupwheresql = "AND gm.groupid = {$this->groupid}";
     } else {
         $groupsql = "";
         $groupwheresql = "";
     }
     $users_sql = "SELECT u.*\n                        FROM {$CFG->prefix}user u\n                             INNER JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid\n                             {$groupsql}\n                       WHERE ra.roleid {$gradebookroles}\n                             AND ra.contextid {$relatedcontexts}\n                             {$groupwheresql}\n                    ORDER BY u.id ASC";
     $this->users_rs = get_recordset_sql($users_sql);
     if (!empty($this->grade_items)) {
         $itemids = array_keys($this->grade_items);
         $itemids = implode(',', $itemids);
         $grades_sql = "SELECT g.*\n                             FROM {$CFG->prefix}grade_grades g\n                                  INNER JOIN {$CFG->prefix}user u ON g.userid = u.id\n                                  INNER JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid\n                                  {$groupsql}\n                            WHERE ra.roleid {$gradebookroles}\n                                  AND ra.contextid {$relatedcontexts}\n                                  AND g.itemid IN ({$itemids})\n                                  {$groupwheresql}\n                         ORDER BY g.userid ASC, g.itemid ASC";
         $this->grades_rs = get_recordset_sql($grades_sql);
     }
     return true;
 }
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:37,代码来源:lib.php

示例2: init

 /**
  * Initialise the iterator
  * @return boolean success
  */
 public function init()
 {
     global $CFG, $DB;
     $this->close();
     grade_regrade_final_grades($this->course->id);
     $course_item = grade_item::fetch_course_item($this->course->id);
     if ($course_item->needsupdate) {
         // can not calculate all final grades - sorry
         return false;
     }
     $coursecontext = get_context_instance(CONTEXT_COURSE, $this->course->id);
     $relatedcontexts = get_related_contexts_string($coursecontext);
     list($gradebookroles_sql, $params) = $DB->get_in_or_equal(explode(',', $CFG->gradebookroles), SQL_PARAMS_NAMED, 'grbr');
     //limit to users with an active enrolment
     list($enrolledsql, $enrolledparams) = get_enrolled_sql($coursecontext);
     $params = array_merge($params, $enrolledparams);
     if ($this->groupid) {
         $groupsql = "INNER JOIN {groups_members} gm ON gm.userid = u.id";
         $groupwheresql = "AND gm.groupid = :groupid";
         // $params contents: gradebookroles
         $params['groupid'] = $this->groupid;
     } else {
         $groupsql = "";
         $groupwheresql = "";
     }
     if (empty($this->sortfield1)) {
         // we must do some sorting even if not specified
         $ofields = ", u.id AS usrt";
         $order = "usrt ASC";
     } else {
         $ofields = ", u.{$this->sortfield1} AS usrt1";
         $order = "usrt1 {$this->sortorder1}";
         if (!empty($this->sortfield2)) {
             $ofields .= ", u.{$this->sortfield2} AS usrt2";
             $order .= ", usrt2 {$this->sortorder2}";
         }
         if ($this->sortfield1 != 'id' and $this->sortfield2 != 'id') {
             // user order MUST be the same in both queries,
             // must include the only unique user->id if not already present
             $ofields .= ", u.id AS usrt";
             $order .= ", usrt ASC";
         }
     }
     // $params contents: gradebookroles and groupid (for $groupwheresql)
     $users_sql = "SELECT u.* {$ofields}\n                        FROM {user} u\n                        JOIN ({$enrolledsql}) je ON je.id = u.id\n                             {$groupsql}\n                        JOIN (\n                                  SELECT DISTINCT ra.userid\n                                    FROM {role_assignments} ra\n                                   WHERE ra.roleid {$gradebookroles_sql}\n                                     AND ra.contextid {$relatedcontexts}\n                             ) rainner ON rainner.userid = u.id\n                         WHERE u.deleted = 0\n                             {$groupwheresql}\n                    ORDER BY {$order}";
     $this->users_rs = $DB->get_recordset_sql($users_sql, $params);
     if (!empty($this->grade_items)) {
         $itemids = array_keys($this->grade_items);
         list($itemidsql, $grades_params) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED, 'items');
         $params = array_merge($params, $grades_params);
         // $params contents: gradebookroles, enrolledparams, groupid (for $groupwheresql) and itemids
         $grades_sql = "SELECT g.* {$ofields}\n                             FROM {grade_grades} g\n                             JOIN {user} u ON g.userid = u.id\n                             JOIN ({$enrolledsql}) je ON je.id = u.id\n                                  {$groupsql}\n                             JOIN (\n                                      SELECT DISTINCT ra.userid\n                                        FROM {role_assignments} ra\n                                       WHERE ra.roleid {$gradebookroles_sql}\n                                         AND ra.contextid {$relatedcontexts}\n                                  ) rainner ON rainner.userid = u.id\n                              WHERE u.deleted = 0\n                              AND g.itemid {$itemidsql}\n                              {$groupwheresql}\n                         ORDER BY {$order}, g.itemid ASC";
         $this->grades_rs = $DB->get_recordset_sql($grades_sql, $params);
     } else {
         $this->grades_rs = false;
     }
     return true;
 }
开发者ID:ravivare,项目名称:moodle-1,代码行数:62,代码来源:lib.php

示例3: init

 /**
  * Initialise the iterator
  * @return boolean success
  */
 function init()
 {
     global $CFG;
     $this->close();
     grade_regrade_final_grades($this->course->id);
     $course_item = grade_item::fetch_course_item($this->course->id);
     if ($course_item->needsupdate) {
         // can not calculate all final grades - sorry
         return false;
     }
     if (strpos($CFG->gradebookroles, ',') === false) {
         $gradebookroles = " = {$CFG->gradebookroles}";
     } else {
         $gradebookroles = " IN ({$CFG->gradebookroles})";
     }
     $relatedcontexts = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $this->course->id));
     if ($this->groupid) {
         $groupsql = "INNER JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id";
         $groupwheresql = "AND gm.groupid = {$this->groupid}";
     } else {
         $groupsql = "";
         $groupwheresql = "";
     }
     if (empty($this->sortfield1)) {
         // we must do some sorting even if not specified
         $ofields = ", u.id AS usrt";
         $order = "usrt ASC";
     } else {
         $ofields = ", u.{$this->sortfield1} AS usrt1";
         $order = "usrt1 {$this->sortorder1}";
         if (!empty($this->sortfield2)) {
             $ofields .= ", u.{$this->sortfield2} AS usrt2";
             $order .= ", usrt2 {$this->sortorder2}";
         }
         if ($this->sortfield1 != 'id' and $this->sortfield2 != 'id') {
             // user order MUST be the same in both queries, must include the only unique user->id if not already present
             $ofields .= ", u.id AS usrt";
             $order .= ", usrt ASC";
         }
     }
     $users_sql = "SELECT u.* {$ofields}\n                        FROM {$CFG->prefix}user u\n                             INNER JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid\n                             {$groupsql}\n                       WHERE ra.roleid {$gradebookroles}\n                             AND ra.contextid {$relatedcontexts}\n                             {$groupwheresql}\n                    ORDER BY {$order}";
     $this->users_rs = get_recordset_sql($users_sql);
     if (!empty($this->grade_items)) {
         $itemids = array_keys($this->grade_items);
         $itemids = implode(',', $itemids);
         $grades_sql = "SELECT g.* {$ofields}\n                             FROM {$CFG->prefix}grade_grades g\n                                  INNER JOIN {$CFG->prefix}user u ON g.userid = u.id\n                                  INNER JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid\n                                  {$groupsql}\n                            WHERE ra.roleid {$gradebookroles}\n                                  AND ra.contextid {$relatedcontexts}\n                                  AND g.itemid IN ({$itemids})\n                                  {$groupwheresql}\n                         ORDER BY {$order}, g.itemid ASC";
         $this->grades_rs = get_recordset_sql($grades_sql);
     } else {
         $this->grades_rs = false;
     }
     return true;
 }
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:56,代码来源:lib.php

示例4: iomadcertificate_print_course_grade

/**
 * Prepare to print the course grade.
 *
 * @deprecated since iomadcertificate version 2012052501
 * @param stdClass $course
 * @return mixed
 */
function iomadcertificate_print_course_grade($course)
{
    debugging('iomadcertificate_print_course_grade is deprecated, please use iomadcertificate_get_grade instead. Ideally
               you should be using iomadcertificate_get_grade in your iomadcertificate type which will either get the course
               or module grade depending on your iomadcertificate settings.', DEBUG_DEVELOPER);
    global $USER, $DB;
    if ($course_item = grade_item::fetch_course_item($course->id)) {
        $grade = new grade_grade(array('itemid' => $course_item->id, 'userid' => $USER->id));
        $course_item->gradetype = GRADE_TYPE_VALUE;
        $coursegrade = new stdClass();
        $coursegrade->points = grade_format_gradevalue($grade->finalgrade, $course_item, true, GRADE_DISPLAY_TYPE_REAL, $decimals = 2);
        $coursegrade->percentage = grade_format_gradevalue($grade->finalgrade, $course_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE, $decimals = 2);
        $coursegrade->letter = grade_format_gradevalue($grade->finalgrade, $course_item, true, GRADE_DISPLAY_TYPE_LETTER, $decimals = 0);
        return $coursegrade;
    }
    return false;
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:24,代码来源:deprecatedlib.php

示例5: course_feedback

 /**
  * Does this course have any visible feedback for current user?.
  *
  * @param $course
  * @return stdClass | null
  */
 public static function course_feedback($course)
 {
     global $USER;
     // Get course context.
     $coursecontext = \context_course::instance($course->id);
     // Security check - should they be allowed to see course grade?
     $onlyactive = true;
     if (!is_enrolled($coursecontext, $USER, 'moodle/grade:view', $onlyactive)) {
         return self::skipgradewarning('User not enrolled on course with capability moodle/grade:view');
     }
     // Security check - are they allowed to see the grade report for the course?
     if (!has_capability('gradereport/user:view', $coursecontext)) {
         return self::skipgradewarning('User does not have required course capability gradereport/user:view');
     }
     // See if user can view hidden grades for this course.
     $canviewhidden = has_capability('moodle/grade:viewhidden', $coursecontext);
     // Do not show grade if grade book disabled for students.
     // Note - moodle/grade:viewall is a capability held by teachers and thus used to exclude them from not getting
     // the grade.
     if (empty($course->showgrades) && !has_capability('moodle/grade:viewall', $coursecontext)) {
         return self::skipgradewarning('Course set up to not show gradebook to students');
     }
     // Get course grade_item.
     $courseitem = \grade_item::fetch_course_item($course->id);
     // Get the stored grade.
     $coursegrade = new \grade_grade(array('itemid' => $courseitem->id, 'userid' => $USER->id));
     $coursegrade->grade_item =& $courseitem;
     // Return null if can't view.
     if ($coursegrade->is_hidden() && !$canviewhidden) {
         return self::skipgradewarning('Course grade is hidden from students');
     }
     // Use user grade report to get course total - this is to take hidden grade settings into account.
     $gpr = new \grade_plugin_return(array('type' => 'report', 'plugin' => 'user', 'courseid' => $course->id, 'userid' => $USER->id));
     $report = new \grade_report_user($course->id, $gpr, $coursecontext, $USER->id);
     $report->fill_table();
     $visiblegradefound = false;
     foreach ($report->tabledata as $item) {
         if (self::item_has_grade_or_feedback($item)) {
             $visiblegradefound = true;
             break;
         }
     }
     $feedbackhtml = '';
     if ($visiblegradefound) {
         // Just output - feedback available.
         $url = new \moodle_url('/grade/report/user/index.php', array('id' => $course->id));
         $feedbackhtml = \html_writer::link($url, get_string('feedbackavailable', 'theme_snap'), array('class' => 'coursegrade'));
     }
     return (object) array('feedbackhtml' => $feedbackhtml);
 }
开发者ID:nbartley,项目名称:moodle-theme_snap,代码行数:56,代码来源:local.php

示例6: certificate_print_course_grade

/**
 * Prepare to print the course grade.
 *
 * @param stdClass $course
 * @return mixed
 */
function certificate_print_course_grade($course)
{
    global $USER, $DB;
    if ($course_item = grade_item::fetch_course_item($course->id)) {
        $grade = new grade_grade(array('itemid' => $course_item->id, 'userid' => $USER->id));
        $course_item->gradetype = GRADE_TYPE_VALUE;
        $coursegrade = new stdClass();
        $coursegrade->points = grade_format_gradevalue($grade->finalgrade, $course_item, true, GRADE_DISPLAY_TYPE_REAL, $decimals = 2);
        $coursegrade->percentage = grade_format_gradevalue($grade->finalgrade, $course_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE, $decimals = 2);
        $coursegrade->letter = grade_format_gradevalue($grade->finalgrade, $course_item, true, GRADE_DISPLAY_TYPE_LETTER, $decimals = 0);
        return $coursegrade;
    }
    return false;
}
开发者ID:noisyjerm,项目名称:moodle-mod_certificate,代码行数:20,代码来源:lib.php

示例7: test_methodonlyupdatesunlockedenrolmentsforspecificuserid

 /**
  * Validate that the method respects the locked status when run for a
  * specific user
  */
 public function test_methodonlyupdatesunlockedenrolmentsforspecificuserid()
 {
     global $DB;
     $this->load_csv_data();
     // Set up enrolments.
     $this->make_course_enrollable();
     enrol_try_internal_enrol(2, 100, 1);
     enrol_try_internal_enrol(2, 101, 1);
     // Set required PM course grade.
     $pmcourse = new \course(array('id' => 100, 'completion_grade' => 50));
     $pmcourse->save();
     // Set up course grade item.
     $coursegradeitem = \grade_item::fetch_course_item(2);
     $coursegradeitem->grademax = 100;
     $coursegradeitem->needsupdate = false;
     $coursegradeitem->locked = true;
     $coursegradeitem->update();
     // Assign student grades.
     $coursegradegrade = new \grade_grade(array('itemid' => 1, 'userid' => 100, 'finalgrade' => 100));
     $coursegradegrade->insert();
     $coursegradegrade = new \grade_grade(array('itemid' => 1, 'userid' => 101, 'finalgrade' => 100));
     $coursegradegrade->insert();
     // Enrol the student.
     $student = new \student();
     $student->userid = 103;
     $student->classid = 100;
     $student->grade = 0;
     $student->completestatusid = STUSTATUS_NOTCOMPLETE;
     $student->locked = 1;
     $student->save();
     // Call and validate that locked record is not changed.
     $sync = new \local_elisprogram\moodle\synchronize();
     $sync->synchronize_moodle_class_grades(100);
     $this->assert_student_exists(100, 103, 0, STUSTATUS_NOTCOMPLETE, null, null, 1);
     $DB->execute("UPDATE {" . \student::TABLE . "} SET locked = 0");
     // Call and validate that unlocked record is changed.
     $sync = new \local_elisprogram\moodle\synchronize();
     $sync->synchronize_moodle_class_grades(100);
     // Validate count.
     $count = $DB->count_records(\student::TABLE, array('completestatusid' => STUSTATUS_PASSED));
     $this->assertEquals(1, $count);
     // NOTE: this method does not lock enrolments.
     $this->assert_student_exists(100, 103, 100, STUSTATUS_PASSED, null, null, 0);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:48,代码来源:synchronizemoodleclassgrades_test.php

示例8: sub_test_grade_item_fetch_course_item

 protected function sub_test_grade_item_fetch_course_item()
 {
     $grade_item = grade_item::fetch_course_item($this->courseid);
     $this->assertTrue(method_exists($grade_item, 'fetch_course_item'));
     $this->assertEquals($grade_item->itemtype, 'course');
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:6,代码来源:grade_item_test.php

示例9: 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

示例10: update_raw_grade


//.........这里部分代码省略.........
     if (is_null($grade)) {
         //fetch from db
         $grade = new grade_grade(array('itemid' => $this->id, 'userid' => $userid));
     }
     $grade->grade_item =& $this;
     // prevent db fetching of this grade_item
     if (empty($usermodified)) {
         $grade->usermodified = $USER->id;
     } else {
         $grade->usermodified = $usermodified;
     }
     if ($grade->is_locked()) {
         // do not update locked grades at all
         return false;
     }
     $locktime = $grade->get_locktime();
     if ($locktime and $locktime < time()) {
         // do not update grades that should be already locked and force regrade
         $this->force_regrading();
         return false;
     }
     $oldgrade = new object();
     $oldgrade->finalgrade = $grade->finalgrade;
     $oldgrade->rawgrade = $grade->rawgrade;
     $oldgrade->rawgrademin = $grade->rawgrademin;
     $oldgrade->rawgrademax = $grade->rawgrademax;
     $oldgrade->rawscaleid = $grade->rawscaleid;
     $oldgrade->feedback = $grade->feedback;
     $oldgrade->feedbackformat = $grade->feedbackformat;
     // use new min and max
     $grade->rawgrade = $grade->rawgrade;
     $grade->rawgrademin = $this->grademin;
     $grade->rawgrademax = $this->grademax;
     $grade->rawscaleid = $this->scaleid;
     // change raw grade?
     if ($rawgrade !== false) {
         $grade->rawgrade = $rawgrade;
     }
     // empty feedback means no feedback at all
     if ($feedback === '') {
         $feedback = null;
     }
     // do we have comment from teacher?
     if ($feedback !== false and !$grade->is_overridden()) {
         $grade->feedback = $feedback;
         $grade->feedbackformat = $feedbackformat;
     }
     // update final grade if possible
     if (!$grade->is_locked() and !$grade->is_overridden()) {
         $grade->finalgrade = $this->adjust_raw_grade($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax);
     }
     // TODO: hack alert - create new fields for these in 2.0
     $oldgrade->timecreated = $grade->timecreated;
     $oldgrade->timemodified = $grade->timemodified;
     $grade->timecreated = $datesubmitted;
     if ($grade->is_overridden()) {
         // keep original graded date - update_final_grade() sets this for overridden grades
     } else {
         if (is_null($grade->rawgrade) and is_null($grade->feedback)) {
             // no grade and feedback means no grading yet
             $grade->timemodified = null;
         } else {
             if (!empty($dategraded)) {
                 // fine - module sends info when graded (yay!)
                 $grade->timemodified = $dategraded;
             } else {
                 if (grade_floats_different($grade->finalgrade, $oldgrade->finalgrade) or $grade->feedback !== $oldgrade->feedback) {
                     // guess - if either grade or feedback changed set new graded date
                     $grade->timemodified = time();
                 } else {
                     //keep original graded date
                 }
             }
         }
     }
     // end of hack alert
     if (empty($grade->id)) {
         $result = (bool) $grade->insert($source);
     } else {
         if (grade_floats_different($grade->finalgrade, $oldgrade->finalgrade) or grade_floats_different($grade->rawgrade, $oldgrade->rawgrade) or grade_floats_different($grade->rawgrademin, $oldgrade->rawgrademin) or grade_floats_different($grade->rawgrademax, $oldgrade->rawgrademax) or $grade->rawscaleid != $oldgrade->rawscaleid or $grade->feedback !== $oldgrade->feedback or $grade->feedbackformat != $oldgrade->feedbackformat or $grade->timecreated != $oldgrade->timecreated or $grade->timemodified != $oldgrade->timemodified) {
             $result = $grade->update($source);
         } else {
             return $result;
         }
     }
     if (!$result) {
         // something went wrong - better force final grade recalculation
         $this->force_regrading();
     } else {
         if (!$this->needsupdate) {
             $course_item = grade_item::fetch_course_item($this->courseid);
             if (!$course_item->needsupdate) {
                 if (grade_regrade_final_grades($this->courseid, $userid, $this) !== true) {
                     $this->force_regrading();
                 }
             }
         }
     }
     return $result;
 }
开发者ID:r007,项目名称:PMoodle,代码行数:101,代码来源:grade_item.php

示例11: update_specific_module_test

 /**
  * Test a specific type of module.
  *
  * @param string $modulename - the module name to test
  */
 private function update_specific_module_test($modulename)
 {
     global $DB, $CFG;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     // Warnings: you'll need to change this line if ever you come to test a module not following Moodle standard.
     require_once $CFG->dirroot . '/mod/' . $modulename . '/lib.php';
     // Enable avaibility.
     // If not enabled all conditional fields will be ignored.
     set_config('enableavailability', 1);
     // Enable course completion.
     // If not enabled all completion settings will be ignored.
     set_config('enablecompletion', COMPLETION_ENABLED);
     // Enable forum RSS feeds.
     set_config('enablerssfeeds', 1);
     set_config('forum_enablerssfeeds', 1);
     $course = $this->getDataGenerator()->create_course(array('numsections' => 1, 'enablecompletion' => COMPLETION_ENABLED), array('createsections' => true));
     $grouping = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
     // Create assign module instance for testing gradeitem.
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
     $params['course'] = $course->id;
     $instance = $generator->create_instance($params);
     $assigncm = get_coursemodule_from_instance('assign', $instance->id);
     // Create the test forum to update.
     $initvalues = new stdClass();
     $initvalues->introformat = FORMAT_HTML;
     $initvalues->course = $course->id;
     $forum = self::getDataGenerator()->create_module('forum', $initvalues);
     // Retrieve course module.
     $cm = get_coursemodule_from_instance('forum', $forum->id);
     // Module test values.
     $moduleinfo = new stdClass();
     // Always mandatory generic values to any module.
     $moduleinfo->coursemodule = $cm->id;
     $moduleinfo->modulename = $modulename;
     $moduleinfo->course = $course->id;
     $moduleinfo->groupingid = $grouping->id;
     $moduleinfo->visible = true;
     // Sometimes optional generic values for some modules.
     $moduleinfo->name = 'My test module';
     $moduleinfo->showdescription = 1;
     // standard boolean
     require_once $CFG->libdir . '/gradelib.php';
     $gradecats = grade_get_categories_menu($moduleinfo->course, false);
     $gradecatid = current(array_keys($gradecats));
     // Retrieve the first key of $gradecats
     $moduleinfo->gradecat = $gradecatid;
     $moduleinfo->groupmode = VISIBLEGROUPS;
     $moduleinfo->cmidnumber = 'idnumber_XXX';
     // Completion common to all module.
     $moduleinfo->completion = COMPLETION_TRACKING_AUTOMATIC;
     $moduleinfo->completionview = COMPLETION_VIEW_REQUIRED;
     $moduleinfo->completiongradeitemnumber = 1;
     $moduleinfo->completionexpected = time() + 7 * 24 * 3600;
     $moduleinfo->completionunlocked = 1;
     // Conditional activity.
     $coursegradeitem = grade_item::fetch_course_item($moduleinfo->course);
     //the activity will become available only when the user reach some grade into the course itself.
     $moduleinfo->availability = json_encode(\core_availability\tree::get_root_json(array(\availability_date\condition::get_json('>=', time()), \availability_date\condition::get_json('<', time() + 7 * 24 * 3600), \availability_grade\condition::get_json($coursegradeitem->id, 10, 80), \availability_profile\condition::get_json(false, 'email', 'contains', '@'), \availability_completion\condition::get_json($assigncm->id, COMPLETION_COMPLETE)), '&'));
     // Grading and Advanced grading.
     require_once $CFG->dirroot . '/rating/lib.php';
     $moduleinfo->assessed = RATING_AGGREGATE_AVERAGE;
     $moduleinfo->scale = 10;
     // Note: it could be minus (for specific course scale). It is a signed number.
     $moduleinfo->assesstimestart = time();
     $moduleinfo->assesstimefinish = time() + 7 * 24 * 3600;
     // RSS.
     $moduleinfo->rsstype = 2;
     $moduleinfo->rssarticles = 10;
     // Optional intro editor (depends of module).
     $draftid_editor = 0;
     file_prepare_draft_area($draftid_editor, null, null, null, null);
     $moduleinfo->introeditor = array('text' => 'This is a module', 'format' => FORMAT_HTML, 'itemid' => $draftid_editor);
     // Following is the advanced grading method area called 'submissions' for the 'assign' module.
     if (plugin_supports('mod', $modulename, FEATURE_GRADE_HAS_GRADE, false) && !plugin_supports('mod', $modulename, FEATURE_RATE, false)) {
         $moduleinfo->grade = 100;
     }
     // Plagiarism form values.
     // No plagiarism plugin installed by default. Use this space to make your own test.
     // Values specific to the module.
     $modulesetvalues = $modulename . '_update_set_values';
     $this->{$modulesetvalues}($moduleinfo);
     // Create the module.
     $result = update_module($moduleinfo);
     // Retrieve the module info.
     $dbmodinstance = $DB->get_record($moduleinfo->modulename, array('id' => $result->instance));
     $dbcm = get_coursemodule_from_instance($moduleinfo->modulename, $result->instance);
     // Retrieve the grade item.
     $gradeitem = $DB->get_record('grade_items', array('courseid' => $moduleinfo->course, 'iteminstance' => $dbmodinstance->id, 'itemmodule' => $moduleinfo->modulename));
     // Compare the values common to all module instances.
     $this->assertEquals($moduleinfo->modulename, $dbcm->modname);
     $this->assertEquals($moduleinfo->course, $dbcm->course);
     $this->assertEquals($moduleinfo->groupingid, $dbcm->groupingid);
     $this->assertEquals($moduleinfo->visible, $dbcm->visible);
     $this->assertEquals($moduleinfo->completion, $dbcm->completion);
//.........这里部分代码省略.........
开发者ID:uniedpa,项目名称:moodle,代码行数:101,代码来源:courselib_test.php

示例12: fill_table

 function fill_table()
 {
     global $CFG;
     // MDL-11679, only show 'mycourses' instead of all courses
     if ($courses = get_my_courses($this->user->id, 'c.sortorder ASC', 'id, shortname')) {
         $numusers = $this->get_numusers(false);
         foreach ($courses as $course) {
             $courselink = '<a href="' . $CFG->wwwroot . '/grade/report/user/index.php?id=' . $course->id . '">' . $course->shortname . '</a>';
             // Get course grade_item
             $grade_item = grade_item::fetch_course_item($course->id);
             // Get the grade
             $grade = new grade_grade(array('itemid' => $grade_item->id, 'userid' => $this->user->id));
             $grade->grade_item =& $grade_item;
             $finalgrade = $grade->finalgrade;
             // TODO: this DOES NOT work properly if there are any hidden grades,
             //       rank might be wrong & totals might be different from user report!!!
             if ($grade->is_hidden() and !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $course->id))) {
                 $finalgrade = null;
             }
             $data = array($courselink, grade_format_gradevalue($finalgrade, $grade_item, true));
             if (!$this->showrank) {
                 //nothing to do
             } else {
                 if (!is_null($finalgrade)) {
                     /// find the number of users with a higher grade
                     $sql = "SELECT COUNT(DISTINCT(userid))\n                              FROM {$CFG->prefix}grade_grades\n                             WHERE finalgrade IS NOT NULL AND finalgrade > {$finalgrade}\n                                   AND itemid = {$grade_item->id}";
                     $rank = count_records_sql($sql) + 1;
                     $data[] = "{$rank}/{$numusers}";
                 } else {
                     // no grade, no rank
                     $data[] = '-';
                 }
             }
             $this->table->add_data($data);
         }
         return true;
     } else {
         notify(get_string('nocourses', 'grades'));
         return false;
     }
 }
开发者ID:r007,项目名称:PMoodle,代码行数:41,代码来源:lib.php

示例13: certificate_get_grade

/**
 * Returns the grade to display for the certificate.
 *
 * @param stdClass $certificate
 * @param stdClass $course
 * @param int $userid
 * @param bool $valueonly if true return only the points, %age, or letter with no prefix
 * @return string the grade result
 */
function certificate_get_grade($certificate, $course, $userid = null, $valueonly = false)
{
    global $USER;
    if (empty($userid)) {
        $userid = $USER->id;
    }
    if ($certificate->printgrade > 0) {
        if ($certificate->printgrade == 1) {
            if ($course_item = grade_item::fetch_course_item($course->id)) {
                // Check we want to add a prefix to the grade.
                $strprefix = '';
                if (!$valueonly) {
                    $strprefix = get_string('coursegrade', 'certificate') . ': ';
                }
                $grade = new grade_grade(array('itemid' => $course_item->id, 'userid' => $userid));
                $course_item->gradetype = GRADE_TYPE_VALUE;
                $coursegrade = new stdClass();
                $coursegrade->points = grade_format_gradevalue($grade->finalgrade, $course_item, true, GRADE_DISPLAY_TYPE_REAL, $decimals = 2);
                $coursegrade->percentage = grade_format_gradevalue($grade->finalgrade, $course_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE, $decimals = 2);
                $coursegrade->letter = grade_format_gradevalue($grade->finalgrade, $course_item, true, GRADE_DISPLAY_TYPE_LETTER, $decimals = 0);
                if ($certificate->gradefmt == 1) {
                    $grade = $strprefix . $coursegrade->percentage;
                } else {
                    if ($certificate->gradefmt == 2) {
                        $grade = $strprefix . $coursegrade->points;
                    } else {
                        if ($certificate->gradefmt == 3) {
                            $grade = $strprefix . $coursegrade->letter;
                        }
                    }
                }
                return $grade;
            }
        } else {
            // Print the mod grade
            if ($modinfo = certificate_get_mod_grade($course, $certificate->printgrade, $userid)) {
                // Check we want to add a prefix to the grade.
                $strprefix = '';
                if (!$valueonly) {
                    $strprefix = $modinfo->name . ' ' . get_string('grade', 'certificate') . ': ';
                }
                if ($certificate->gradefmt == 1) {
                    $grade = $strprefix . $modinfo->percentage;
                } else {
                    if ($certificate->gradefmt == 2) {
                        $grade = $strprefix . $modinfo->points;
                    } else {
                        if ($certificate->gradefmt == 3) {
                            $grade = $strprefix . $modinfo->letter;
                        }
                    }
                }
                return $grade;
            }
        }
    } else {
        if ($certificate->printgrade < 0) {
            // Must be a category id.
            if ($category_item = grade_item::fetch(array('itemtype' => 'category', 'iteminstance' => -$certificate->printgrade))) {
                $category_item->gradetype = GRADE_TYPE_VALUE;
                $grade = new grade_grade(array('itemid' => $category_item->id, 'userid' => $userid));
                $category_grade = new stdClass();
                $category_grade->points = grade_format_gradevalue($grade->finalgrade, $category_item, true, GRADE_DISPLAY_TYPE_REAL, $decimals = 2);
                $category_grade->percentage = grade_format_gradevalue($grade->finalgrade, $category_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE, $decimals = 2);
                $category_grade->letter = grade_format_gradevalue($grade->finalgrade, $category_item, true, GRADE_DISPLAY_TYPE_LETTER, $decimals = 0);
                if ($certificate->gradefmt == 1) {
                    $formattedgrade = $category_grade->percentage;
                } else {
                    if ($certificate->gradefmt == 2) {
                        $formattedgrade = $category_grade->points;
                    } else {
                        if ($certificate->gradefmt == 3) {
                            $formattedgrade = $category_grade->letter;
                        }
                    }
                }
                return $formattedgrade;
            }
        }
    }
    return '';
}
开发者ID:ccle,项目名称:moodle-mod_certificate,代码行数:91,代码来源:locallib.php

示例14: date

//            }
            $row[] = date('d M, Y', $course->timemodified);
            //$modules = $mycourse->progress_modules_in_use($course->id);
            //$events = $mycourse->progress_event_information($modules, $course->id);
            //$attempts = $mycourse->progress_attempts($modules, $course->id, $events, $userid);
            //$percent = $mycourse->progress_percentage($events, $attempts);
            //$completedcount = $mycourse->progress_percentage($events, $attempts, true);
            //$bar = '<div class="dynamic_bar" style="width:' . $percent . '%"></div>';
            //$title = $completedcount . ' out of ' . sizeof($events) . ' graded activities are completed.';
            //$html = '<div class="main_list_bar" title="' . $title . '">
            //        <div class="task_bar">' . $bar . '</div>
            //        <div class="percent">' . $percent . '%' . '</div>
            //        </div>';
            //$row[] = $html;

            $course_item = grade_item::fetch_course_item($course->id);
            $course_grade = new grade_grade(array('itemid' => $course_item->id, 'userid' => $userid));
            $final_grade = round($course_grade->finalgrade, 2);
            $row[] = html_writer::tag('a', $final_grade, array('href' => $CFG->wwwroot . '/grade/report/user/index.php?id=' . $course->id));
        } else if ($is_teacher) {
            $row[] = html_writer::tag('a', 'Submit', array('href' => $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id));
        }
        $row[] = html_writer::tag('a', 'Launch', array('href' => $CFG->wwwroot . '/course/view.php?id=' . $course->id));
        $data[] = $row;
    }
    $table = new html_table();
    //$table->head  = array('Course', 'Enrolled on', 'Progress', 'Launch Course');
    $table->align = array('left', 'center', 'center', 'center');
    if ($is_student)
        $table->size = array('25%', '23%', '13%', '12%');
    if ($is_teacher)
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:31,代码来源:index_bk.php

示例15: fill_table

 public function fill_table()
 {
     global $CFG, $DB, $OUTPUT;
     // MDL-11679, only show user's courses instead of all courses
     if ($courses = enrol_get_users_courses($this->user->id, false, 'id, shortname, showgrades')) {
         $numusers = $this->get_numusers(false);
         foreach ($courses as $course) {
             if (!$course->showgrades) {
                 continue;
             }
             $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
             if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
                 // The course is hidden and the user isn't allowed to see it
                 continue;
             }
             $courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
             $courselink = html_writer::link(new moodle_url('/grade/report/user/index.php', array('id' => $course->id, 'userid' => $this->user->id)), $courseshortname);
             $canviewhidden = has_capability('moodle/grade:viewhidden', $coursecontext);
             // Get course grade_item
             $course_item = grade_item::fetch_course_item($course->id);
             // Get the stored grade
             $course_grade = new grade_grade(array('itemid' => $course_item->id, 'userid' => $this->user->id));
             $course_grade->grade_item =& $course_item;
             $finalgrade = $course_grade->finalgrade;
             if (!$canviewhidden and !is_null($finalgrade)) {
                 if ($course_grade->is_hidden()) {
                     $finalgrade = null;
                 } else {
                     $finalgrade = $this->blank_hidden_total($course->id, $course_item, $finalgrade);
                 }
             }
             $data = array($courselink, grade_format_gradevalue($finalgrade, $course_item, true));
             if (!$this->showrank) {
                 //nothing to do
             } else {
                 if (!is_null($finalgrade)) {
                     /// find the number of users with a higher grade
                     /// please note this can not work if hidden grades involved :-( to be fixed in 2.0
                     $params = array($finalgrade, $course_item->id);
                     $sql = "SELECT COUNT(DISTINCT(userid))\n                              FROM {grade_grades}\n                             WHERE finalgrade IS NOT NULL AND finalgrade > ?\n                                   AND itemid = ?";
                     $rank = $DB->count_records_sql($sql, $params) + 1;
                     $data[] = "{$rank}/{$numusers}";
                 } else {
                     // no grade, no rank
                     $data[] = '-';
                 }
             }
             $this->table->add_data($data);
         }
         return true;
     } else {
         echo $OUTPUT->notification(get_string('nocourses', 'grades'));
         return false;
     }
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:55,代码来源:lib.php


注:本文中的grade_item::fetch_course_item方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。