本文整理汇总了PHP中grade_item::set_locked方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_item::set_locked方法的具体用法?PHP grade_item::set_locked怎么用?PHP grade_item::set_locked使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grade_item
的用法示例。
在下文中一共展示了grade_item::set_locked方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load_test_data
/**
* 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: set_locked
/**
* 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;
}