本文整理汇总了PHP中assign::update_instance方法的典型用法代码示例。如果您正苦于以下问题:PHP assign::update_instance方法的具体用法?PHP assign::update_instance怎么用?PHP assign::update_instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类assign
的用法示例。
在下文中一共展示了assign::update_instance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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 " - "');
}
示例2: assign_update_instance
/**
* Update an assignment instance
*
* This is done by calling the update_instance() method of the assignment type class
* @param stdClass $data
* @param mod_assign_mod_form $form
* @return object
*/
function assign_update_instance(stdClass $data, mod_assign_mod_form $form) {
global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
$context = context_module::instance($data->coursemodule);
$assignment = new assign($context, null, null);
return $assignment->update_instance($data);
}