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


PHP grade_grade::fetch方法代码示例

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


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

示例1: test_grade_grade_fetch

 function test_grade_grade_fetch()
 {
     $grade_grade = new grade_grade();
     $this->assertTrue(method_exists($grade_grade, 'fetch'));
     $grades = grade_grade::fetch(array('id' => $this->grade_grades[0]->id));
     $this->assertEqual($this->grade_grades[0]->id, $grades->id);
     $this->assertEqual($this->grade_grades[0]->rawgrade, $grades->rawgrade);
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:8,代码来源:testgradegrades.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_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

示例4: get_last_user_grades

 /**
  * Returns latest grades 
  * 
  * @param string $user Username
  * @param int $cid Course identifier
  */
 function get_last_user_grades($username, $limit)
 {
     global $CFG, $DB;
     $username = utf8_decode($username);
     $username = strtolower($username);
     $user = get_complete_user_data('username', $username);
     $uid = $user->id;
     if (!$limit) {
         $limit = 1000;
     }
     $SQL = "SELECT distinct(g.itemid), g.finalgrade,gi.courseid,gi.itemname,gi.id, g.timemodified as tm\n                      FROM {$CFG->prefix}grade_items gi\n                           JOIN {$CFG->prefix}grade_grades g      ON g.itemid = gi.id\n                           JOIN {$CFG->prefix}user u              ON u.id = g.userid\n                           JOIN {$CFG->prefix}role_assignments ra ON ra.userid = u.id\n                     WHERE g.finalgrade IS NOT NULL \n\t\t     \tand gi.itemname IS NOT NULL\n\t\t\t   AND u.id = ?\n                  \tORDER BY tm\n\t\t\tLIMIT {$limit}";
     $sum_array = array();
     $params = array($uid);
     if ($sums = $DB->get_records_sql($SQL, $params)) {
         $i = 0;
         foreach ($sums as $sum) {
             if (!($grade_grade = grade_grade::fetch(array('itemid' => $sum->id, 'userid' => $uid)))) {
                 $grade_grade = new grade_grade();
                 $grade_grade->userid = $this->user->id;
                 $grade_grade->itemid = $grade_object->id;
             }
             $grade_item = $grade_grade->load_grade_item();
             $scale = $grade_item->load_scale();
             $formatted_grade = grade_format_gradevalue($sum->finalgrade, $grade_item, true, GRADE_DISPLAY_TYPE_REAL);
             $t['itemname'] = $sum->itemname;
             $t['finalgrade'] = $formatted_grade;
             $t['average'] = $this->get_average_grade($grade_grade->itemid);
             $tareas[] = $t;
             $i++;
         }
         return $tareas;
     }
     return array();
 }
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:40,代码来源:auth.php

示例5: get_grades


//.........这里部分代码省略.........
             // If they only requested one activity we will already have the cm.
             $modulecm = $cm;
         } else {
             if (!empty($gradeitem->itemmodule)) {
                 $modulecm = $acitivityinstances[$gradeitem->itemmodule][$gradeitem->iteminstance];
             } else {
                 // Course grade item.
                 continue;
             }
         }
         // Make student feedback ready for output.
         foreach ($gradeitem->grades as $studentgrade) {
             if (!empty($studentgrade->feedback)) {
                 list($studentgrade->feedback, $categoryinfo->feedbackformat) = external_format_text($studentgrade->feedback, $studentgrade->feedbackformat, $modulecm->id, $params['component'], 'feedback', null);
             }
         }
     }
     // Convert from objects to arrays so all web service clients are supported.
     // While we're doing that we also remove grades the current user can't see due to hiding.
     $gradesarray = array();
     $canviewhidden = has_capability('moodle/grade:viewhidden', context_course::instance($params['courseid']));
     $gradesarray['items'] = array();
     foreach ($grades->items as $gradeitem) {
         // Switch the stdClass instance for a grade item instance so we can call is_hidden() and use the ID.
         $gradeiteminstance = self::get_grade_item($course->id, $gradeitem->itemtype, $gradeitem->itemmodule, $gradeitem->iteminstance, 0);
         if (!$canviewhidden && $gradeiteminstance->is_hidden()) {
             continue;
         }
         // Format mixed bool/integer parameters.
         $gradeitem->hidden = empty($gradeitem->hidden) ? 0 : $gradeitem->hidden;
         $gradeitem->locked = empty($gradeitem->locked) ? 0 : $gradeitem->locked;
         $gradeitemarray = (array) $gradeitem;
         $gradeitemarray['grades'] = array();
         if (!empty($gradeitem->grades)) {
             foreach ($gradeitem->grades as $studentid => $studentgrade) {
                 if (!$canviewhidden) {
                     // Need to load the grade_grade object to check visibility.
                     $gradegradeinstance = grade_grade::fetch(array('userid' => $studentid, 'itemid' => $gradeiteminstance->id));
                     // The grade grade may be legitimately missing if the student has no grade.
                     if (!empty($gradegradeinstance) && $gradegradeinstance->is_hidden()) {
                         continue;
                     }
                 }
                 // Format mixed bool/integer parameters.
                 $studentgrade->hidden = empty($studentgrade->hidden) ? 0 : $studentgrade->hidden;
                 $studentgrade->locked = empty($studentgrade->locked) ? 0 : $studentgrade->locked;
                 $studentgrade->overridden = empty($studentgrade->overridden) ? 0 : $studentgrade->overridden;
                 $gradeitemarray['grades'][$studentid] = (array) $studentgrade;
                 // Add the student ID as some WS clients can't access the array key.
                 $gradeitemarray['grades'][$studentid]['userid'] = $studentid;
             }
         }
         // If they requested grades for multiple activities load the cm object now.
         $modulecm = $cm;
         if (empty($modulecm) && !empty($gradeiteminstance->itemmodule)) {
             $modulecm = $acitivityinstances[$gradeiteminstance->itemmodule][$gradeiteminstance->iteminstance];
         }
         if ($gradeiteminstance->itemtype == 'course') {
             $gradesarray['items']['course'] = $gradeitemarray;
             $gradesarray['items']['course']['activityid'] = 'course';
         } else {
             $gradesarray['items'][$modulecm->id] = $gradeitemarray;
             // Add the activity ID as some WS clients can't access the array key.
             $gradesarray['items'][$modulecm->id]['activityid'] = $modulecm->id;
         }
     }
     $gradesarray['outcomes'] = array();
     foreach ($grades->outcomes as $outcome) {
         $modulecm = $cm;
         if (empty($modulecm)) {
             $modulecm = $acitivityinstances[$outcome->itemmodule][$outcome->iteminstance];
         }
         // Format mixed bool/integer parameters.
         $outcome->hidden = empty($outcome->hidden) ? 0 : $outcome->hidden;
         $outcome->locked = empty($outcome->locked) ? 0 : $outcome->locked;
         $gradesarray['outcomes'][$modulecm->id] = (array) $outcome;
         $gradesarray['outcomes'][$modulecm->id]['activityid'] = $modulecm->id;
         $gradesarray['outcomes'][$modulecm->id]['grades'] = array();
         if (!empty($outcome->grades)) {
             foreach ($outcome->grades as $studentid => $studentgrade) {
                 if (!$canviewhidden) {
                     // Need to load the grade_grade object to check visibility.
                     $gradeiteminstance = self::get_grade_item($course->id, $outcome->itemtype, $outcome->itemmodule, $outcome->iteminstance, $outcome->itemnumber);
                     $gradegradeinstance = grade_grade::fetch(array('userid' => $studentid, 'itemid' => $gradeiteminstance->id));
                     // The grade grade may be legitimately missing if the student has no grade.
                     if (!empty($gradegradeinstance) && $gradegradeinstance->is_hidden()) {
                         continue;
                     }
                 }
                 // Format mixed bool/integer parameters.
                 $studentgrade->hidden = empty($studentgrade->hidden) ? 0 : $studentgrade->hidden;
                 $studentgrade->locked = empty($studentgrade->locked) ? 0 : $studentgrade->locked;
                 $gradesarray['outcomes'][$modulecm->id]['grades'][$studentid] = (array) $studentgrade;
                 // Add the student ID into the grade structure as some WS clients can't access the key.
                 $gradesarray['outcomes'][$modulecm->id]['grades'][$studentid]['userid'] = $studentid;
             }
         }
     }
     return $gradesarray;
 }
开发者ID:jtibbetts,项目名称:moodle,代码行数:101,代码来源:grades_external.php

示例6: is_locked

 /**
  * Returns the locked state of this grade_item (if the grade_item is locked OR no specific
  * $userid is given) or the locked state of a specific grade within this item if a specific
  * $userid is given and the grade_item is unlocked.
  *
  * @param int $userid The user's ID
  * @return bool Locked state
  */
 public function is_locked($userid = NULL)
 {
     global $CFG;
     // Override for any grade items belonging to activities which are in the process of being deleted.
     require_once $CFG->dirroot . '/course/lib.php';
     if (course_module_instance_pending_deletion($this->courseid, $this->itemmodule, $this->iteminstance)) {
         return true;
     }
     if (!empty($this->locked)) {
         return true;
     }
     if (!empty($userid)) {
         if ($grade = grade_grade::fetch(array('itemid' => $this->id, 'userid' => $userid))) {
             $grade->grade_item =& $this;
             // prevent db fetching of cached grade_item
             return $grade->is_locked();
         }
     }
     return false;
 }
开发者ID:lucaboesch,项目名称:moodle,代码行数:28,代码来源:grade_item.php

示例7: fill_table_recursive

 private function fill_table_recursive(&$element)
 {
     global $DB, $CFG;
     $type = $element['type'];
     $depth = $element['depth'];
     $grade_object = $element['object'];
     $eid = $grade_object->id;
     $element['userid'] = $this->user->id;
     $fullname = $this->gtree->get_element_header($element, true, true, true);
     $data = array();
     $hidden = '';
     $excluded = '';
     $class = '';
     $classfeedback = '';
     // If this is a hidden grade category, hide it completely from the user
     if ($type == 'category' && $grade_object->is_hidden() && !$this->canviewhidden && ($this->showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN || $this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_object->is_hiddenuntil())) {
         return false;
     }
     if ($type == 'category') {
         $this->evenodd[$depth] = ($this->evenodd[$depth] + 1) % 2;
     }
     $alter = $this->evenodd[$depth] == 0 ? 'even' : 'odd';
     /// Process those items that have scores associated
     if ($type == 'item' or $type == 'categoryitem' or $type == 'courseitem') {
         $header_row = "row_{$eid}_{$this->user->id}";
         $header_cat = "cat_{$grade_object->categoryid}_{$this->user->id}";
         if (!($grade_grade = grade_grade::fetch(array('itemid' => $grade_object->id, 'userid' => $this->user->id)))) {
             $grade_grade = new grade_grade();
             $grade_grade->userid = $this->user->id;
             $grade_grade->itemid = $grade_object->id;
         }
         $grade_grade->load_grade_item();
         /// Hidden Items
         if ($grade_grade->grade_item->is_hidden()) {
             $hidden = ' dimmed_text';
         }
         $hide = false;
         // If this is a hidden grade item, hide it completely from the user.
         if ($grade_grade->is_hidden() && !$this->canviewhidden && ($this->showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN || $this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_grade->is_hiddenuntil())) {
             $hide = true;
         } else {
             if (!empty($grade_object->itemmodule) && !empty($grade_object->iteminstance)) {
                 // The grade object can be marked visible but still be hidden if
                 // the student cannot see the activity due to conditional access
                 // and it's set to be hidden entirely.
                 $instances = $this->modinfo->get_instances_of($grade_object->itemmodule);
                 if (!empty($instances[$grade_object->iteminstance])) {
                     $cm = $instances[$grade_object->iteminstance];
                     if (!$cm->uservisible) {
                         // If there is 'availableinfo' text then it is only greyed
                         // out and not entirely hidden.
                         if (!$cm->availableinfo) {
                             $hide = true;
                         }
                     }
                 }
             }
         }
         if (!$hide) {
             /// Excluded Item
             if ($grade_grade->is_excluded()) {
                 $fullname .= ' [' . get_string('excluded', 'grades') . ']';
                 $excluded = ' excluded';
             }
             /// Other class information
             $class = "{$hidden} {$excluded}";
             if ($this->switch) {
                 // alter style based on whether aggregation is first or last
                 $class .= ($type == 'categoryitem' or $type == 'courseitem') ? " " . $alter . "d{$depth} baggt b2b" : " item b1b";
             } else {
                 $class .= ($type == 'categoryitem' or $type == 'courseitem') ? " " . $alter . "d{$depth} baggb" : " item b1b";
             }
             if ($type == 'categoryitem' or $type == 'courseitem') {
                 $header_cat = "cat_{$grade_object->iteminstance}_{$this->user->id}";
             }
             /// Name
             $data['itemname']['content'] = $fullname;
             $data['itemname']['class'] = $class;
             $data['itemname']['colspan'] = $this->maxdepth - $depth;
             $data['itemname']['celltype'] = 'th';
             $data['itemname']['id'] = $header_row;
             /// Actual Grade
             $gradeval = $grade_grade->finalgrade;
             if (!$this->canviewhidden) {
                 /// Virtual Grade (may be calculated excluding hidden items etc).
                 $adjustedgrade = $this->blank_hidden_total_and_adjust_bounds($this->courseid, $grade_grade->grade_item, $gradeval);
                 $gradeval = $adjustedgrade['grade'];
                 // We temporarily adjust the view of this grade item - because the min and
                 // max are affected by the hidden values in the aggregation.
                 $grade_grade->grade_item->grademax = $adjustedgrade['grademax'];
                 $grade_grade->grade_item->grademin = $adjustedgrade['grademin'];
             }
             if ($this->showfeedback) {
                 // Copy $class before appending itemcenter as feedback should not be centered
                 $classfeedback = $class;
             }
             $class .= " itemcenter ";
             if ($this->showweight) {
                 $data['weight']['class'] = $class;
                 $data['weight']['content'] = '-';
//.........这里部分代码省略.........
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:101,代码来源:lib.php

示例8: sub_test_update_final_grade

 protected function sub_test_update_final_grade()
 {
     // MDL-31713 Check that min and max are set on the grade_grade instance
     // if the grade is overridden before the activity has supplied a grade.
     $min = 2;
     $max = 8;
     // Create a brand new grade item.
     $grade_item = new grade_item();
     $this->assertTrue(method_exists($grade_item, 'insert'));
     $grade_item->courseid = $this->courseid;
     $grade_item->categoryid = $this->grade_categories[1]->id;
     $grade_item->itemname = 'brand new unit test grade item';
     $grade_item->itemtype = 'mod';
     $grade_item->itemmodule = 'quiz';
     $grade_item->iteminfo = 'Grade item used for unit testing';
     $grade_item->grademin = $min;
     $grade_item->grademax = $max;
     $grade_item->insert();
     // Override the student grade.
     $grade_item->update_final_grade($this->user[1]->id, 7, 'gradebook', '', FORMAT_MOODLE);
     // Check the student's grade has the correct min and max grade.
     $grade_grade = grade_grade::fetch(array('userid' => $this->user[1]->id, 'itemid' => $grade_item->id));
     $this->assertEquals($min, $grade_grade->rawgrademin);
     $this->assertEquals($max, $grade_grade->rawgrademax);
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:25,代码来源:grade_item_test.php

示例9: test_grade_item_compute

 function test_grade_item_compute()
 {
     $grade_item = new grade_item($this->grade_items[1]);
     $this->assertTrue(method_exists($grade_item, 'compute'));
     $grade_grade = grade_grade::fetch(array('id' => $this->grade_grades[3]->id));
     $grade_grade->delete();
     $grade_grade = grade_grade::fetch(array('id' => $this->grade_grades[4]->id));
     $grade_grade->delete();
     $grade_grade = grade_grade::fetch(array('id' => $this->grade_grades[5]->id));
     $grade_grade->delete();
     $grade_item->compute();
     $grade_grade = grade_grade::fetch(array('userid' => $this->grade_grades[3]->userid, 'itemid' => $this->grade_grades[3]->itemid));
     $this->assertEqual($this->grade_grades[3]->finalgrade, $grade_grade->finalgrade);
     $grade_grade = grade_grade::fetch(array('userid' => $this->grade_grades[4]->userid, 'itemid' => $this->grade_grades[4]->itemid));
     $this->assertEqual($this->grade_grades[4]->finalgrade, $grade_grade->finalgrade);
     $grade_grade = grade_grade::fetch(array('userid' => $this->grade_grades[5]->userid, 'itemid' => $this->grade_grades[5]->itemid));
     $this->assertEqual($this->grade_grades[5]->finalgrade, $grade_grade->finalgrade);
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:18,代码来源:testgradeitem.php

示例10: test_grade_import_commit

 /**
  * Tests for importing grades from an external source.
  */
 public function test_grade_import_commit()
 {
     global $USER, $DB, $CFG;
     $this->resetAfterTest();
     $importcode = get_new_importcode();
     $user1 = $this->getDataGenerator()->create_user();
     $user2 = $this->getDataGenerator()->create_user();
     $course = $this->getDataGenerator()->create_course();
     $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
     $itemname = $assign->name;
     $modulecontext = context_module::instance($assign->cmid);
     // The generator returns a dummy object, lets get the real assign object.
     $assign = new assign($modulecontext, false, false);
     $cm = $assign->get_course_module();
     // Enrol users in the course.
     $this->getDataGenerator()->enrol_user($user1->id, $course->id);
     $this->getDataGenerator()->enrol_user($user2->id, $course->id);
     // Enter a new grade into an existing grade item.
     $gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod'));
     // Keep this value around for a test further down.
     $originalgrade = 55;
     $this->import_grades(array('importcode' => $importcode, 'itemid' => $gradeitem->id, 'userid' => $user1->id, 'finalgrade' => $originalgrade));
     $status = grade_import_commit($course->id, $importcode, false, false);
     $this->assertTrue($status);
     // Get imported grade_grade.
     $gradegrade = grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id));
     $this->assertEquals($originalgrade, $gradegrade->finalgrade);
     // Overriden field will be a timestamp and will evaluate out to true.
     $this->assertTrue($gradegrade->is_overridden());
     // Create a new grade item and import into that.
     $importcode = get_new_importcode();
     $record = new stdClass();
     $record->itemname = 'New grade item';
     $record->importcode = $importcode;
     $record->importer = $USER->id;
     $insertid = $DB->insert_record('grade_import_newitem', $record);
     $finalgrade = 75;
     $this->import_grades(array('importcode' => $importcode, 'userid' => $user1->id, 'finalgrade' => $finalgrade, 'newgradeitem' => $insertid));
     $status = grade_import_commit($course->id, $importcode, false, false);
     $this->assertTrue($status);
     // Check that we have a new grade_item.
     $gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'manual'));
     $this->assertEquals($record->itemname, $gradeitem->itemname);
     // Grades were imported.
     $gradegrade = grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id));
     $this->assertEquals($finalgrade, $gradegrade->finalgrade);
     // As this is a new item the grade has not been overridden.
     $this->assertFalse($gradegrade->is_overridden());
     // Import feedback only.
     $importcode = get_new_importcode();
     $gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod'));
     $originalfeedback = 'feedback can be useful';
     $this->import_grades(array('importcode' => $importcode, 'userid' => $user1->id, 'itemid' => $gradeitem->id, 'feedback' => $originalfeedback, 'importonlyfeedback' => true));
     $status = grade_import_commit($course->id, $importcode, true, false);
     $this->assertTrue($status);
     $gradegrade = grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id));
     // The final grade should be the same as the first record further up. We are only altering the feedback.
     $this->assertEquals($originalgrade, $gradegrade->finalgrade);
     $this->assertTrue($gradegrade->is_overridden());
     // Import grades only.
     $importcode = get_new_importcode();
     $gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod'));
     $finalgrade = 60;
     $this->import_grades(array('importcode' => $importcode, 'userid' => $user1->id, 'itemid' => $gradeitem->id, 'finalgrade' => $finalgrade, 'feedback' => 'feedback can still be useful'));
     $status = grade_import_commit($course->id, $importcode, false, false);
     $this->assertTrue($status);
     $gradegrade = grade_grade::fetch(array('itemid' => $gradeitem->id, 'userid' => $user1->id));
     $this->assertEquals($finalgrade, $gradegrade->finalgrade);
     // The final feedback should not have changed.
     $this->assertEquals($originalfeedback, $gradegrade->feedback);
     $this->assertTrue($gradegrade->is_overridden());
     // Check that printing of import status is correct.
     $importcode = get_new_importcode();
     $gradeitem = grade_item::fetch(array('courseid' => $course->id, 'itemtype' => 'mod'));
     $this->import_grades(array('importcode' => $importcode, 'userid' => $user1->id, 'itemid' => $gradeitem->id));
     $url = $CFG->wwwroot . '/grade/index.php';
     $expectedresponse = "++ Grade import success ++\n<div class=\"continuebutton\"><form method=\"get\" action=\"{$url}\"><div><input type=\"submit\" value=\"Continue\" /><input type=\"hidden\" name=\"id\" value=\"{$course->id}\" /></div></form></div>";
     ob_start();
     $status = grade_import_commit($course->id, $importcode);
     $output = ob_get_contents();
     ob_end_clean();
     $this->assertTrue($status);
     $this->assertEquals($expectedresponse, $output);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:87,代码来源:importlib_test.php

示例11: fill_table

 function fill_table()
 {
     global $CFG;
     $numusers = $this->get_numusers(false);
     // total course users
     $items =& $this->gseq->items;
     $grades = array();
     $canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->courseid));
     // fetch or create all grades
     foreach ($items as $key => $unused) {
         if (!($grade_grade = grade_grade::fetch(array('itemid' => $items[$key]->id, 'userid' => $this->user->id)))) {
             $grade_grade = new grade_grade();
             $grade_grade->userid = $this->user->id;
             $grade_grade->itemid = $items[$key]->id;
         }
         $grades[$key] = $grade_grade;
         $grades[$key]->grade_item =& $items[$key];
     }
     if ($canviewhidden) {
         $altered = array();
         $unknown = array();
     } else {
         $hiding_affected = grade_grade::get_hiding_affected($grades, $items);
         $altered = $hiding_affected['altered'];
         $unknown = $hiding_affected['unknown'];
         unset($hiding_affected);
     }
     foreach ($items as $itemid => $unused) {
         $grade_item =& $items[$itemid];
         $grade_grade =& $grades[$itemid];
         if (!$canviewhidden and $grade_item->is_hidden()) {
             if ($this->showhiddenitems == 0) {
                 // no hidden items at all
                 continue;
             } else {
                 if ($this->showhiddenitems == 1 and !$grade_item->is_hiddenuntil()) {
                     // hidden until that are still hidden are visible
                     continue;
                 }
             }
         }
         $class = 'gradeitem';
         if ($grade_item->is_course_item()) {
             $class = 'courseitem';
         } else {
             if ($grade_item->is_category_item()) {
                 $class = 'categoryitem';
             }
         }
         if (in_array($itemid, $unknown)) {
             $gradeval = null;
         } else {
             if (array_key_exists($itemid, $altered)) {
                 $gradeval = $altered[$itemid];
             } else {
                 $gradeval = $grade_grade->finalgrade;
             }
         }
         $data = array();
         // all users should know which items are still hidden
         $hidden = '';
         if ($grade_item->is_hidden()) {
             $hidden = ' hidden ';
         }
         $element = $this->gseq->locate_element($this->gseq->get_item_eid($grade_item));
         $header = $this->gseq->get_element_header($element, true, true, true);
         /// prints grade item name
         $data[] = '<span class="' . $hidden . $class . '">' . $header . '</span>';
         /// prints category
         $cat = $grade_item->get_parent_category();
         $data[] = '<span class="' . $hidden . $class . '">' . $cat->get_name() . '</span>';
         $hidden = '';
         if ($grade_item->is_hidden()) {
             // can not see grades in hidden items
             $hidden = ' hidden ';
         } else {
             if ($canviewhidden and $grade_grade->is_hidden()) {
                 // if user can see hidden grades, indicate which ones are hidden
                 $hidden = ' hidden ';
             }
         }
         /// prints the grade
         if ($grade_grade->is_excluded()) {
             $excluded = get_string('excluded', 'grades') . ' ';
         } else {
             $excluded = '';
         }
         if ($grade_item->needsupdate) {
             $data[] = '<span class="' . $hidden . $class . ' gradingerror">' . get_string('error') . '</span>';
         } else {
             if (!empty($CFG->grade_hiddenasdate) and $grade_grade->get_datesubmitted() and !$canviewhidden and $grade_grade->is_hidden() and !$grade_item->is_category_item() and !$grade_item->is_course_item()) {
                 // the problem here is that we do not have the time when grade value was modified, 'timemodified' is general modification date for grade_grades records
                 $data[] = '<span class="' . $hidden . $class . ' datesubmitted">' . $excluded . get_string('submittedon', 'grades', userdate($grade_grade->get_datesubmitted(), get_string('strftimedatetimeshort'))) . '</span>';
             } else {
                 $data[] = '<span class="' . $hidden . $class . '">' . $excluded . grade_format_gradevalue($gradeval, $grade_item, true) . '</span>';
             }
         }
         /// prints percentage
         if ($grade_item->needsupdate) {
             $data[] = '<span class="' . $hidden . $class . 'gradingerror">' . get_string('error') . '</span>';
//.........这里部分代码省略.........
开发者ID:r007,项目名称:PMoodle,代码行数:101,代码来源:lib.php

示例12: time

     if ($alis = grade_grade::fetch(array('itemid' => $itemids['min'], 'userid' => $student->id))) {
         $alis->rawgrade = $mtg['grade'];
         $alis->finalgrade = $mtg['grade'];
         $alis->timemodified = time();
         $alis->update('report_targetgrades');
     } else {
         $alis = new grade_grade();
         $alis->itemid = $itemids['min'];
         $alis->userid = $student->id;
         $alis->rawgrade = $mtg['grade'];
         $alis->finalgrade = $mtg['grade'];
         $alis->timecreated = time();
         $alis->timemodified = time();
         $alis->insert('report_targetgrades');
     }
     if ($alis_num = grade_grade::fetch(array('itemid' => $itemids['alisnum'], 'userid' => $student->id))) {
         $alis_num->rawgrade = $mtg['number'];
         $alis_num->finalgrade = $mtg['number'];
         $alis_num->timemodified = time();
         $alis_num->update('report_targetgrades');
     } else {
         $alis_num = new grade_grade();
         $alis_num->itemid = $itemids['alisnum'];
         $alis_num->userid = $student->id;
         $alis_num->rawgrade = $mtg['number'];
         $alis_num->finalgrade = $mtg['number'];
         $alis_num->timecreated = time();
         $alis_num->timemodified = time();
         $alis_num->insert('report_targetgrades');
     }
 } catch (tg\no_data_for_student_exception $e) {
开发者ID:rtsfc,项目名称:moodle-report_targetgrades,代码行数:31,代码来源:distribute.php

示例13: test_gradebook

 function test_gradebook()
 {
     global $DB;
     $this->resetAfterTest(true);
     // reset all changes automatically after this test
     $location_str = 'manual';
     // try to get category
     $grade_category = grade_category::fetch(array('courseid' => $this->courseid, 'fullname' => $this->cat_name));
     // NOTE: grade category will not be null but it will be empty
     $this->assertFalse($grade_category);
     // create a category
     $params = new stdClass();
     $params->courseid = $this->courseid;
     $params->fullname = $this->cat_name;
     $grade_category = new grade_category($params, false);
     $this->assertTrue(method_exists($grade_category, 'insert'));
     $grade_category->insert($location_str);
     // now we will really get the category that we just made
     $grade_category_fetched = grade_category::fetch(array('courseid' => $this->courseid, 'fullname' => $this->cat_name));
     $this->assertTrue($grade_category_fetched !== false);
     $this->assertEquals($grade_category->id, $grade_category_fetched->id);
     $this->assertEquals($grade_category->courseid, $grade_category_fetched->courseid);
     $this->assertEquals($grade_category->path, $grade_category_fetched->path);
     $this->assertEquals($grade_category->fullname, $grade_category_fetched->fullname);
     $this->assertEquals($grade_category->parent, $grade_category_fetched->parent);
     // try to get grade item
     $grade_item = grade_item::fetch(array('courseid' => $this->courseid, 'categoryid' => $grade_category->id, 'itemname' => $this->item_name));
     // NOTE: grade category will not be null but it will be empty
     $this->assertFalse($grade_item);
     // create a grade item
     $grade_item = new grade_item();
     $this->assertTrue(method_exists($grade_item, 'insert'));
     $grade_item->courseid = $this->courseid;
     $grade_item->categoryid = $grade_category->id;
     $grade_item->idnumber = $this->item_name;
     // lookup
     $grade_item->itemname = $this->item_name;
     // display
     $grade_item->itemtype = 'blocks';
     $grade_item->itemmodule = 'iclicker';
     $grade_item->iteminfo = 'blocks/iclicker for unit testing';
     // grademax=100, grademin=0
     $grade_item->grademax = 100.0;
     $grade_item->insert($location_str);
     // now we will really get the new item
     $grade_item_fetched = grade_item::fetch(array('courseid' => $this->courseid, 'categoryid' => $grade_category->id, 'itemname' => $this->item_name));
     $this->assertTrue($grade_item_fetched !== false);
     $this->assertEquals($grade_item->id, $grade_item_fetched->id);
     $this->assertEquals($grade_item->courseid, $grade_item_fetched->courseid);
     $this->assertEquals($grade_item->categoryid, $grade_item_fetched->categoryid);
     $this->assertEquals($grade_item->itemname, $grade_item_fetched->itemname);
     // get empty grades list
     $all_grades = grade_grade::fetch_all(array('itemid' => $grade_item->id));
     $this->assertFalse($all_grades);
     // add grade
     $grade_grade = new grade_grade();
     $this->assertTrue(method_exists($grade_grade, 'insert'));
     $grade_grade->itemid = $grade_item->id;
     $grade_grade->userid = $this->studentid1;
     $grade_grade->rawgrade = $this->grade_score;
     $grade_grade->insert($location_str);
     // get new grade
     $grade_grade_fetched = grade_grade::fetch(array('itemid' => $grade_item->id, 'userid' => $this->studentid1));
     $this->assertTrue($grade_grade_fetched !== false);
     $this->assertEquals($grade_grade->id, $grade_grade_fetched->id);
     $this->assertEquals($grade_grade->itemid, $grade_grade_fetched->itemid);
     $this->assertEquals($grade_grade->userid, $grade_grade_fetched->userid);
     $this->assertEquals($grade_grade->rawgrade, $grade_grade_fetched->rawgrade);
     // update the grade
     $grade_grade->rawgrade = 50;
     $result = $grade_grade->update($location_str);
     $this->assertTrue($result);
     $grade_grade_fetched = grade_grade::fetch(array('id' => $grade_grade->id));
     $this->assertTrue($grade_grade_fetched !== false);
     $this->assertEquals($grade_grade->id, $grade_grade_fetched->id);
     $this->assertEquals($grade_grade->rawgrade, $grade_grade_fetched->rawgrade);
     $this->assertEquals(50, $grade_grade_fetched->rawgrade);
     // get grades
     $all_grades = grade_grade::fetch_all(array('itemid' => $grade_item->id));
     $this->assertTrue($all_grades !== false);
     $this->assertEquals(1, sizeof($all_grades));
     // add more grades
     $grade_grade2 = new grade_grade();
     $grade_grade2->itemid = $grade_item->id;
     $grade_grade2->userid = $this->studentid2;
     $grade_grade2->rawgrade = $this->grade_score;
     $grade_grade2->insert($location_str);
     // get grades
     $all_grades = grade_grade::fetch_all(array('itemid' => $grade_item->id));
     $this->assertTrue($all_grades !== false);
     $this->assertEquals(2, sizeof($all_grades));
     // make sure this can run
     $result = $grade_item->regrade_final_grades();
     $this->assertTrue($result);
     // remove grades
     $this->assertTrue(method_exists($grade_grade, 'delete'));
     $result = $grade_grade->delete($location_str);
     $this->assertTrue($result);
     $result = $grade_grade2->delete($location_str);
     $this->assertTrue($result);
//.........这里部分代码省略.........
开发者ID:dirkcgrunwald,项目名称:iclicker-moodle2-integrate,代码行数:101,代码来源:gradebook_test.php

示例14: fill_table_recursive

    /**
     * Fill the table with data.
     *
     * @param $element - An array containing the table data for the current row.
     */
    private function fill_table_recursive(&$element) {
        global $DB, $CFG;

        $type = $element['type'];
        $depth = $element['depth'];
        $grade_object = $element['object'];
        $eid = $grade_object->id;
        $element['userid'] = $this->user->id;
        $fullname = $this->gtree->get_element_header($element, true, true, true, true, true);
        $data = array();
        $hidden = '';
        $excluded = '';
        $itemlevel = ($type == 'categoryitem' || $type == 'category' || $type == 'courseitem') ? $depth : ($depth + 1);
        $class = 'level' . $itemlevel . ' level' . ($itemlevel % 2 ? 'odd' : 'even');
        $classfeedback = '';

        // If this is a hidden grade category, hide it completely from the user
        if ($type == 'category' && $grade_object->is_hidden() && !$this->canviewhidden && (
                $this->showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN ||
                ($this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_object->is_hiddenuntil()))) {
            return false;
        }

        if ($type == 'category') {
            $this->evenodd[$depth] = (($this->evenodd[$depth] + 1) % 2);
        }
        $alter = ($this->evenodd[$depth] == 0) ? 'even' : 'odd';

        /// Process those items that have scores associated
        if ($type == 'item' or $type == 'categoryitem' or $type == 'courseitem') {
            $header_row = "row_{$eid}_{$this->user->id}";
            $header_cat = "cat_{$grade_object->categoryid}_{$this->user->id}";

            if (! $grade_grade = grade_grade::fetch(array('itemid'=>$grade_object->id,'userid'=>$this->user->id))) {
                $grade_grade = new grade_grade();
                $grade_grade->userid = $this->user->id;
                $grade_grade->itemid = $grade_object->id;
            }

            $grade_grade->load_grade_item();

            /// Hidden Items
            if ($grade_grade->grade_item->is_hidden()) {
                $hidden = ' dimmed_text';
            }

            $hide = false;
            // If this is a hidden grade item, hide it completely from the user.
            if ($grade_grade->is_hidden() && !$this->canviewhidden && (
                    $this->showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN ||
                    ($this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_grade->is_hiddenuntil()))) {
                $hide = true;
            } else if (!empty($grade_object->itemmodule) && !empty($grade_object->iteminstance)) {
                // The grade object can be marked visible but still be hidden if
                // the student cannot see the activity due to conditional access
                // and it's set to be hidden entirely.
                $instances = $this->modinfo->get_instances_of($grade_object->itemmodule);
                if (!empty($instances[$grade_object->iteminstance])) {
                    $cm = $instances[$grade_object->iteminstance];
                    if (!$cm->uservisible) {
                        // If there is 'availableinfo' text then it is only greyed
                        // out and not entirely hidden.
                        if (!$cm->availableinfo) {
                            $hide = true;
                        }
                    }
                }
            }

            // Actual Grade - We need to calculate this whether the row is hidden or not.
            $gradeval = $grade_grade->finalgrade;
            $hint = $grade_grade->get_aggregation_hint();
            if (!$this->canviewhidden) {
                /// Virtual Grade (may be calculated excluding hidden items etc).
                $adjustedgrade = $this->blank_hidden_total_and_adjust_bounds($this->courseid,
                                                                             $grade_grade->grade_item,
                                                                             $gradeval);

                $gradeval = $adjustedgrade['grade'];

                // We temporarily adjust the view of this grade item - because the min and
                // max are affected by the hidden values in the aggregation.
                $grade_grade->grade_item->grademax = $adjustedgrade['grademax'];
                $grade_grade->grade_item->grademin = $adjustedgrade['grademin'];
                $hint['status'] = $adjustedgrade['aggregationstatus'];
                $hint['weight'] = $adjustedgrade['aggregationweight'];
            } else {
                // The max and min for an aggregation may be different to the grade_item.
                if (!is_null($gradeval)) {
                    $grade_grade->grade_item->grademax = $grade_grade->rawgrademax;
                    $grade_grade->grade_item->grademin = $grade_grade->rawgrademin;
                }
            }


//.........这里部分代码省略.........
开发者ID:anilch,项目名称:Personel,代码行数:101,代码来源:lib.php

示例15: test_upgrade_calculated_grade_items_regrade

 function test_upgrade_calculated_grade_items_regrade()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     // Create a user.
     $user = $this->getDataGenerator()->create_user();
     // Create a course.
     $course = $this->getDataGenerator()->create_course();
     // Enrol the user in the course.
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $maninstance1 = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $manual = enrol_get_plugin('manual');
     $manual->enrol_user($maninstance1, $user->id, $studentrole->id);
     set_config('upgrade_calculatedgradeitemsonlyregrade', 1);
     // Creating a category for a grade item.
     $gradecategory = new grade_category();
     $gradecategory->fullname = 'calculated grade category';
     $gradecategory->courseid = $course->id;
     $gradecategory->insert();
     $gradecategoryid = $gradecategory->id;
     // This is a manual grade item.
     $gradeitem = new grade_item();
     $gradeitem->itemname = 'grade item one';
     $gradeitem->itemtype = 'manual';
     $gradeitem->categoryid = $gradecategoryid;
     $gradeitem->courseid = $course->id;
     $gradeitem->idnumber = 'gi1';
     $gradeitem->insert();
     // Changing the category into a calculated grade category.
     $gradecategoryitem = grade_item::fetch(array('iteminstance' => $gradecategory->id));
     $gradecategoryitem->calculation = '=##gi' . $gradeitem->id . '##/2';
     $gradecategoryitem->grademax = 50;
     $gradecategoryitem->grademin = 15;
     $gradecategoryitem->update();
     // Setting a grade for the student.
     $grade = $gradeitem->get_grade($user->id, true);
     $grade->finalgrade = 50;
     $grade->update();
     grade_regrade_final_grades($course->id);
     $grade = grade_grade::fetch(array('itemid' => $gradecategoryitem->id, 'userid' => $user->id));
     $grade->rawgrademax = 100;
     $grade->rawgrademin = 0;
     $grade->update();
     $this->assertNotEquals($gradecategoryitem->grademax, $grade->rawgrademax);
     $this->assertNotEquals($gradecategoryitem->grademin, $grade->rawgrademin);
     // This is the function that we are testing. If we comment out this line, then the test fails because the grade items
     // are not flagged for regrading.
     upgrade_calculated_grade_items();
     grade_regrade_final_grades($course->id);
     $grade = grade_grade::fetch(array('itemid' => $gradecategoryitem->id, 'userid' => $user->id));
     $this->assertEquals($gradecategoryitem->grademax, $grade->rawgrademax);
     $this->assertEquals($gradecategoryitem->grademin, $grade->rawgrademin);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:53,代码来源:upgradelib_test.php


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