コード例 #1
0
 /**
  * Load initial test information
  *
  * @param  string $assignmentname   Assignment name
  * @param  int $student1rawgrade    Student 1 grade
  * @param  int $student2rawgrade    Student 2 grade
  * @return array                    Array of vars with test information
  */
 protected function load_test_data($assignmentname, $student1rawgrade, $student2rawgrade)
 {
     global $DB;
     // Adds a course, a teacher, 2 students, an assignment and grades for the students.
     $course = $this->getDataGenerator()->create_course();
     $coursecontext = context_course::instance($course->id);
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $student1 = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($student1->id, $course->id, $studentrole->id);
     $student2 = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($student2->id, $course->id, $studentrole->id);
     $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
     $teacher = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id);
     $parent = $this->getDataGenerator()->create_user();
     $this->setUser($parent);
     $student1context = context_user::instance($student1->id);
     // Creates a new role, gives it the capability and gives $USER that role.
     $parentroleid = $this->assignUserCapability('moodle/grade:viewall', $student1context->id);
     // Enrol the user in the course using the new role.
     $this->getDataGenerator()->enrol_user($parent->id, $course->id, $parentroleid);
     $assignment = $this->getDataGenerator()->create_module('assign', array('name' => $assignmentname, 'course' => $course->id));
     $modcontext = get_coursemodule_from_instance('assign', $assignment->id, $course->id);
     $assignment->cmidnumber = $modcontext->id;
     $student1grade = array('userid' => $student1->id, 'rawgrade' => $student1rawgrade);
     $student2grade = array('userid' => $student2->id, 'rawgrade' => $student2rawgrade);
     $studentgrades = array($student1->id => $student1grade, $student2->id => $student2grade);
     assign_grade_item_update($assignment, $studentgrades);
     // Insert a custom grade scale to be used by an outcome.
     $gradescale = new grade_scale();
     $gradescale->name = 'unittestscale3';
     $gradescale->courseid = $course->id;
     $gradescale->userid = 0;
     $gradescale->scale = 'Distinction, Very Good, Good, Pass, Fail';
     $gradescale->description = 'This scale is used to mark standard assignments.';
     $gradescale->insert();
     // Insert an outcome.
     $data = new stdClass();
     $data->courseid = $course->id;
     $data->fullname = 'Team work';
     $data->shortname = 'Team work';
     $data->scaleid = $gradescale->id;
     $outcome = new grade_outcome($data, false);
     $outcome->insert();
     $outcomegradeitem = new grade_item();
     $outcomegradeitem->itemname = $outcome->shortname;
     $outcomegradeitem->itemtype = 'mod';
     $outcomegradeitem->itemmodule = 'assign';
     $outcomegradeitem->iteminstance = $assignment->id;
     $outcomegradeitem->outcomeid = $outcome->id;
     $outcomegradeitem->cmid = 0;
     $outcomegradeitem->courseid = $course->id;
     $outcomegradeitem->aggregationcoef = 0;
     $outcomegradeitem->itemnumber = 1;
     // The activity's original grade item will be 0.
     $outcomegradeitem->gradetype = GRADE_TYPE_SCALE;
     $outcomegradeitem->scaleid = $outcome->scaleid;
     // This next two values for testing that returns parameters are correcly formatted.
     $outcomegradeitem->set_locked(true);
     $outcomegradeitem->hidden = '';
     $outcomegradeitem->insert();
     $assignmentgradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $assignment->id, 'itemnumber' => 0, 'courseid' => $course->id));
     $outcomegradeitem->set_parent($assignmentgradeitem->categoryid);
     $outcomegradeitem->move_after_sortorder($assignmentgradeitem->sortorder);
     return array($course, $assignment, $student1, $student2, $teacher, $parent);
 }
コード例 #2
0
ファイル: grade_category.php プロジェクト: covex-nn/moodle
 /**
  * Sets the grade_item's locked variable and updates the grade_item.
  *
  * Calls set_locked() on the categories' grade_item
  *
  * @param int  $lockedstate 0, 1 or a timestamp int(10) after which date the item will be locked.
  * @param bool $cascade lock/unlock child objects too
  * @param bool $refresh refresh grades when unlocking
  * @return bool success if category locked (not all children mayb be locked though)
  */
 public function set_locked($lockedstate, $cascade = false, $refresh = true)
 {
     $this->load_grade_item();
     $result = $this->grade_item->set_locked($lockedstate, $cascade, true);
     if ($cascade) {
         //process all children - items and categories
         if ($children = grade_item::fetch_all(array('categoryid' => $this->id))) {
             foreach ($children as $child) {
                 $child->set_locked($lockedstate, true, false);
                 if (empty($lockedstate) and $refresh) {
                     //refresh when unlocking
                     $child->refresh_grades();
                 }
             }
         }
         if ($children = grade_category::fetch_all(array('parent' => $this->id))) {
             foreach ($children as $child) {
                 $child->set_locked($lockedstate, true, true);
             }
         }
     }
     return $result;
 }
コード例 #3
0
 function test_grade_grade_set_locked()
 {
     $grade_item = new grade_item($this->grade_items[0]);
     $grade = new grade_grade($grade_item->get_final(1));
     $this->assertTrue(method_exists($grade, 'set_locked'));
     $this->assertTrue(empty($grade_item->locked));
     $this->assertTrue(empty($grade->locked));
     $this->assertTrue($grade->set_locked(true));
     $this->assertFalse(empty($grade->locked));
     $this->assertTrue($grade->set_locked(false));
     $this->assertTrue(empty($grade->locked));
     $this->assertTrue($grade_item->set_locked(true));
     $grade = new grade_grade($grade_item->get_final(1));
     $this->assertFalse(empty($grade->locked));
     $this->assertFalse($grade->set_locked(false));
     $this->assertTrue($grade_item->set_locked(false));
     $grade = new grade_grade($grade_item->get_final(1));
     $this->assertTrue($grade->set_locked(false));
 }