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


PHP grade_item类代码示例

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


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

示例1: test_update_score

 /**
  * Tests update score without sending item details.
  * Grade item should not be created without item name.
  *
  * @return void
  */
 public function test_update_score()
 {
     global $DB;
     $this->set_user('admin');
     $this->assertEquals(0, $DB->count_records('grade_items'));
     // Add an mhaairs item directly.
     $iteminstance = 24993;
     $itemparams = array('courseid' => $this->course->id, 'itemtype' => 'manual', 'itemmodule' => 'mhaairs', 'iteminstance' => $iteminstance, 'itemname' => 'MH Assignment');
     $gitem = new \grade_item($itemparams, false);
     $gitem->insert('mhaairs');
     $this->assertEquals(2, $DB->count_records('grade_items'));
     $service = 'block_mhaairs_gradebookservice_external::update_grade';
     $grades = array('userid' => 'student1', 'rawgrade' => 93);
     $gradesjson = urlencode(json_encode($grades));
     $servicedata = array();
     $servicedata['source'] = 'mhaairs';
     $servicedata['courseid'] = 'tc1';
     $servicedata['itemtype'] = 'manual';
     $servicedata['itemmodule'] = 'mhaairs';
     $servicedata['iteminstance'] = 111;
     $servicedata['itemnumber'] = 0;
     $servicedata['grades'] = $gradesjson;
     $servicedata['itemdetails'] = null;
     // Send score via service without details, item by instance doesn't exist.
     $result = call_user_func_array($service, $servicedata);
     $this->assertEquals(GRADE_UPDATE_FAILED, $result);
     $this->assertEquals(2, $DB->count_records('grade_items'));
     // Set the existing item instance.
     $servicedata['iteminstance'] = $iteminstance;
     // Send score via service without details, item by instance exists.
     $result = call_user_func_array($service, $servicedata);
     $this->assertEquals(GRADE_UPDATE_OK, $result);
     $this->assertEquals(2, $DB->count_records('grade_items'));
     $this->assertEquals(1, $DB->count_records('grade_grades'));
     $usergrade = $DB->get_field('grade_grades', 'finalgrade', array('userid' => $this->student1->id));
     $this->assertEquals(93, $usergrade);
     // Set typical item details for score update.
     $itemdetails = array('courseid' => '3', 'idnumber' => '111', 'identity_type' => null, 'needsupdate' => 1, 'useexisting' => 0);
     $itemdetailsjson = urlencode(json_encode($grades));
     $servicedata['itemdetails'] = $itemdetailsjson;
     $grades = array('userid' => 'student1', 'rawgrade' => 94);
     $gradesjson = urlencode(json_encode($grades));
     $servicedata['grades'] = $gradesjson;
     // Send score via service to item with details.
     $result = call_user_func_array($service, $servicedata);
     $this->assertEquals(GRADE_UPDATE_OK, $result);
     $this->assertEquals(2, $DB->count_records('grade_items'));
     $this->assertEquals(1, $DB->count_records('grade_grades'));
     $usergrade = $DB->get_field('grade_grades', 'finalgrade', array('userid' => $this->student1->id));
     $this->assertEquals(94, $usergrade);
 }
开发者ID:itamart,项目名称:moodle-block_mhaairs,代码行数:57,代码来源:gradebookservice_update_score_test.php

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

示例3: definition_after_data

 function definition_after_data()
 {
     global $CFG, $COURSE;
     $mform =& $this->_form;
     if ($id = $mform->getElementValue('id')) {
         $grade_item = grade_item::fetch(array('id' => $id));
         //remove the aggregation coef element if not needed
         if ($grade_item->is_course_item()) {
             $mform->removeElement('aggregationcoef');
         } else {
             if ($grade_item->is_category_item()) {
                 $category = $grade_item->get_item_category();
                 $parent_category = $category->get_parent_category();
                 if (!$parent_category->is_aggregationcoef_used()) {
                     $mform->removeElement('aggregationcoef');
                 }
             } else {
                 $parent_category = $grade_item->get_parent_category();
                 if (!$parent_category->is_aggregationcoef_used()) {
                     $mform->removeElement('aggregationcoef');
                 }
             }
         }
     } else {
         $course_category = grade_category::fetch_course_category($COURSE->id);
         if (!$course_category->is_aggregationcoef_used()) {
             $mform->removeElement('aggregationcoef');
         }
     }
 }
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:30,代码来源:outcomeitem_form.php

示例4: get_hidden

 /**
  * Check grade hidden status. Uses data from both grade item and grade.
  *
  * @return int 0 means visible, 1 hidden always, timestamp hidden until
  */
 public function get_hidden()
 {
     $this->load_grade_item();
     $item_hidden = $this->grade_item->get_hidden();
     if ($item_hidden == 1) {
         return 1;
     } else {
         if ($item_hidden == 0) {
             return $this->hidden;
         } else {
             if ($this->hidden == 0) {
                 return $item_hidden;
             } else {
                 if ($this->hidden == 1) {
                     return 1;
                 } else {
                     if ($this->hidden > $item_hidden) {
                         return $this->hidden;
                     } else {
                         return $item_hidden;
                     }
                 }
             }
         }
     }
 }
开发者ID:sriysk,项目名称:moodle-integration,代码行数:31,代码来源:grade_grade.php

示例5: grade_export

 /**
  * Constructor should set up all the private variables ready to be pulled
  * @param object $course
  * @param int $groupid id of selected group, 0 means all
  * @param string $itemlist comma separated list of item ids, empty means all
  * @param boolean $export_feedback
  * @param boolean $export_letters
  * @note Exporting as letters will lead to data loss if that exported set it re-imported.
  */
 function grade_export($course, $groupid = 0, $itemlist = '', $export_feedback = false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2)
 {
     $this->course = $course;
     $this->groupid = $groupid;
     $this->grade_items = grade_item::fetch_all(array('courseid' => $this->course->id));
     $this->columns = array();
     if (!empty($itemlist)) {
         $itemids = explode(',', $itemlist);
         // remove items that are not requested
         foreach ($itemids as $itemid) {
             if (array_key_exists($itemid, $this->grade_items)) {
                 $this->columns[$itemid] =& $this->grade_items[$itemid];
             }
         }
     } else {
         foreach ($this->grade_items as $itemid => $unused) {
             $this->columns[$itemid] =& $this->grade_items[$itemid];
         }
     }
     $this->export_feedback = $export_feedback;
     $this->userkey = '';
     $this->previewrows = false;
     $this->updatedgradesonly = $updatedgradesonly;
     $this->displaytype = $displaytype;
     $this->decimalpoints = $decimalpoints;
 }
开发者ID:arshanam,项目名称:Moodle-ITScholars-LMS,代码行数:35,代码来源:lib.php

示例6: get_javascript_init_params

 protected function get_javascript_init_params($course, \cm_info $cm = null, \section_info $section = null)
 {
     global $DB, $CFG;
     require_once $CFG->libdir . '/gradelib.php';
     require_once $CFG->dirroot . '/course/lib.php';
     // Get grades as basic associative array.
     $gradeoptions = array();
     $items = \grade_item::fetch_all(array('courseid' => $course->id));
     // For some reason the fetch_all things return null if none.
     $items = $items ? $items : array();
     foreach ($items as $id => $item) {
         // Don't include the grade item if it's linked with a module that is being deleted.
         if (course_module_instance_pending_deletion($item->courseid, $item->itemmodule, $item->iteminstance)) {
             continue;
         }
         // Do not include grades for current item.
         if ($cm && $cm->instance == $item->iteminstance && $cm->modname == $item->itemmodule && $item->itemtype == 'mod') {
             continue;
         }
         $gradeoptions[$id] = $item->get_name(true);
     }
     \core_collator::asort($gradeoptions);
     // Change to JS array format and return.
     $jsarray = array();
     foreach ($gradeoptions as $id => $name) {
         $jsarray[] = (object) array('id' => $id, 'name' => $name);
     }
     return array($jsarray);
 }
开发者ID:lucaboesch,项目名称:moodle,代码行数:29,代码来源:frontend.php

示例7: fill_table

 function fill_table()
 {
     global $CFG;
     $numusers = $this->get_numusers();
     if ($courses = get_courses('all', null, 'c.id, c.shortname')) {
         foreach ($courses as $course) {
             // Get course grade_item
             $grade_item = grade_item::fetch(array('itemtype' => 'course', 'courseid' => $course->id));
             // Get the grade
             $finalgrade = get_field('grade_grades', 'finalgrade', 'itemid', $grade_item->id, 'userid', $this->user->id);
             /// prints rank
             if ($finalgrade) {
                 /// find the number of users with a higher grade
                 $sql = "SELECT COUNT(DISTINCT(userid))\n                            FROM {$CFG->prefix}grade_grades\n                            WHERE finalgrade > {$finalgrade}\n                            AND itemid = {$grade_item->id}";
                 $rank = count_records_sql($sql) + 1;
                 $rankdata = "{$rank}/{$numusers}";
             } else {
                 // no grade, no rank
                 $rankdata = "-";
             }
             $courselink = '<a href="' . $CFG->wwwroot . '/grade/report/user/index.php?id=' . $course->id . '">' . $course->shortname . '</a>';
             $this->table->add_data(array($courselink, round(grade_to_percentage($finalgrade, $grade_item->grademin, $grade_item->grademax), 1) . '%', $rankdata));
         }
         return true;
     } else {
         notify(get_string('nocourses', 'grades'));
         return false;
     }
 }
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:29,代码来源:lib.php

示例8: grade_export

 /**
  * Constructor should set up all the private variables ready to be pulled
  * @param object $course
  * @param int $groupid id of selected group, 0 means all
  * @param string $itemlist comma separated list of item ids, empty means all
  * @param boolean $export_feedback
  * @param boolean $export_letters
  * @note Exporting as letters will lead to data loss if that exported set it re-imported.
  */
 function grade_export($course, $groupid = 0, $itemlist = '', $export_feedback = false, $updatedgradesonly = false, $displaytype = GRADE_DISPLAY_TYPE_REAL, $decimalpoints = 2)
 {
     $this->course = $course;
     $this->groupid = $groupid;
     $this->grade_items = grade_item::fetch_all(array('courseid' => $this->course->id));
     //Populating the columns here is required by /grade/export/(whatever)/export.php
     //however index.php, when the form is submitted, will construct the collection here
     //with an empty $itemlist then reconstruct it in process_form() using $formdata
     $this->columns = array();
     if (!empty($itemlist)) {
         if ($itemlist == '-1') {
             //user deselected all items
         } else {
             $itemids = explode(',', $itemlist);
             // remove items that are not requested
             foreach ($itemids as $itemid) {
                 if (array_key_exists($itemid, $this->grade_items)) {
                     $this->columns[$itemid] =& $this->grade_items[$itemid];
                 }
             }
         }
     } else {
         foreach ($this->grade_items as $itemid => $unused) {
             $this->columns[$itemid] =& $this->grade_items[$itemid];
         }
     }
     $this->export_feedback = $export_feedback;
     $this->userkey = '';
     $this->previewrows = false;
     $this->updatedgradesonly = $updatedgradesonly;
     $this->displaytype = $displaytype;
     $this->decimalpoints = $decimalpoints;
 }
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:42,代码来源:lib.php

示例9: test_duplicate

 /**
  * Tests the backup and restore of single activity to same course (duplicate)
  * when it contains fields and views.
  */
 public function test_duplicate()
 {
     global $DB, $CFG;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $generator = $this->getDataGenerator();
     $dataformgenerator = $generator->get_plugin_generator('mod_dataform');
     // Create a course.
     $course = $generator->create_course();
     // DATAFORM 1.
     $params = array('course' => $course->id, 'grade' => 100);
     $dataform1 = $dataformgenerator->create_instance($params);
     $df1 = mod_dataform_dataform::instance($dataform1->id);
     // Add fields.
     $fieldtypes = array_keys(core_component::get_plugin_list('dataformfield'));
     $fieldtypescount = count($fieldtypes);
     foreach ($fieldtypes as $type) {
         $df1->field_manager->add_field($type);
     }
     // Add views.
     $viewtypes = array_keys(core_component::get_plugin_list('dataformview'));
     $viewtypescount = count($viewtypes);
     foreach ($viewtypes as $type) {
         $df1->view_manager->add_view($type);
     }
     // Fetch the grade item.
     $params = array('itemtype' => 'mod', 'itemmodule' => 'dataform', 'iteminstance' => $dataform1->id, 'courseid' => $course->id, 'itemnumber' => 0);
     $gradeitem1 = grade_item::fetch($params);
     // Check number of dataforms.
     $this->assertEquals(1, $DB->count_records('dataform'));
     // Check number of fields.
     $this->assertEquals($fieldtypescount, $DB->count_records('dataform_fields'));
     $this->assertEquals($fieldtypescount, $DB->count_records('dataform_fields', array('dataid' => $dataform1->id)));
     // Check number of views.
     $this->assertEquals($viewtypescount, $DB->count_records('dataform_views'));
     $this->assertEquals($viewtypescount, $DB->count_records('dataform_views', array('dataid' => $dataform1->id)));
     // Check number of filters.
     // $this->assertEquals(2, $DB->count_records('dataform_filters'));
     // $this->assertEquals(2, $DB->count_records('dataform_filters', array('dataid' => $dataform1->id)));.
     // DUPLICATE the dataform instance.
     $dataform2 = $dataformgenerator->duplicate_instance($course, $dataform1->cmid);
     // Check number of dataforms.
     $this->assertEquals(2, $DB->count_records('dataform'));
     // Check duplication of fields.
     $this->assertEquals($fieldtypescount * 2, $DB->count_records('dataform_fields'));
     $this->assertEquals($fieldtypescount, $DB->count_records('dataform_fields', array('dataid' => $dataform1->id)));
     $this->assertEquals($fieldtypescount, $DB->count_records('dataform_fields', array('dataid' => $dataform2->id)));
     // Check duplication of views.
     $this->assertEquals($viewtypescount * 2, $DB->count_records('dataform_views'));
     $this->assertEquals($viewtypescount, $DB->count_records('dataform_views', array('dataid' => $dataform1->id)));
     $this->assertEquals($viewtypescount, $DB->count_records('dataform_views', array('dataid' => $dataform2->id)));
     // Check number of filters.
     // $this->assertEquals(4, $DB->count_records('dataform_filters');
     // $this->assertEquals(2, $DB->count_records('dataform_filters', array('dataid' => $dataform1->id));
     // $this->assertEquals(2, $DB->count_records('dataform_filters', array('dataid' => $dataform2->id));.
     // Dataform cleanup.
     $dataformgenerator->delete_all_instances();
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:62,代码来源:backup_restore_test.php

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

示例11: 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();
     // 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);
     $testgrade = 60.0;
     $data = new stdClass();
     $data->id = $course->id;
     $data->report = 'grader';
     $data->timepageload = time();
     $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;
     $data->timepageload = time();
     $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;
     $data->timepageload = time();
     $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;
     $data->timepageload = time();
     $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:evltuma,项目名称:moodle,代码行数:58,代码来源:report_graderlib_test.php

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

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

示例14: test_grade_edit_tree_column_range_get_item_cell

 public function test_grade_edit_tree_column_range_get_item_cell()
 {
     global $DB, $CFG;
     $this->resetAfterTest(true);
     // Make some things we need.
     $scale = $this->getDataGenerator()->create_scale();
     $course = $this->getDataGenerator()->create_course();
     $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
     $modulecontext = context_module::instance($assign->id);
     // The generator returns a dummy object, lets get the real assign object.
     $assign = new assign($modulecontext, false, false);
     $cm = $assign->get_course_module();
     // Get range column.
     $column = grade_edit_tree_column::factory('range');
     $gradeitemparams = array('itemtype' => 'mod', 'itemmodule' => $cm->modname, 'iteminstance' => $cm->instance, 'courseid' => $cm->course, 'itemnumber' => 0);
     // Lets set the grade to something we know.
     $instance = $assign->get_instance();
     $instance->grade = 70;
     $instance->instance = $instance->id;
     $assign->update_instance($instance);
     $gradeitem = grade_item::fetch($gradeitemparams);
     $cell = $column->get_item_cell($gradeitem, array());
     $this->assertEquals(GRADE_TYPE_VALUE, $gradeitem->gradetype);
     $this->assertEquals(null, $gradeitem->scaleid);
     $this->assertEquals(70.0, (double) $cell->text, "Grade text is 70", 0.01);
     // Now change it to a scale.
     $instance = $assign->get_instance();
     $instance->grade = -$scale->id;
     $instance->instance = $instance->id;
     $assign->update_instance($instance);
     $gradeitem = grade_item::fetch($gradeitemparams);
     $cell = $column->get_item_cell($gradeitem, array());
     // Make the expected scale text.
     $scaleitems = null;
     $scaleitems = explode(',', $scale->scale);
     $scalestring = end($scaleitems) . ' (' . count($scaleitems) . ')';
     $this->assertEquals(GRADE_TYPE_SCALE, $gradeitem->gradetype);
     $this->assertEquals($scale->id, $gradeitem->scaleid);
     $this->assertEquals($scalestring, $cell->text, "Grade text matches scale");
     // Now change it to no grade.
     $instance = $assign->get_instance();
     $instance->grade = 0;
     $instance->instance = $instance->id;
     $assign->update_instance($instance);
     $gradeitem = grade_item::fetch($gradeitemparams);
     $cell = $column->get_item_cell($gradeitem, array());
     $this->assertEquals(GRADE_TYPE_TEXT, $gradeitem->gradetype);
     $this->assertEquals(null, $gradeitem->scaleid);
     $this->assertEquals(' - ', $cell->text, 'Grade text matches empty value of " - "');
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:50,代码来源:edittreelib_test.php

示例15: validation

 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $mform =& $this->_form;
     // check the calculation formula
     if ($data['calculation'] != '') {
         $grade_item = grade_item::fetch(array('id' => $data['id'], 'courseid' => $data['courseid']));
         $calculation = calc_formula::unlocalize(stripslashes($data['calculation']));
         $result = $grade_item->validate_formula($calculation);
         if ($result !== true) {
             $errors['calculation'] = $result;
         }
     }
     return $errors;
 }
开发者ID:janeklb,项目名称:moodle,代码行数:15,代码来源:calculation_form.php


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