本文整理汇总了PHP中grade_item::get_parent_category方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_item::get_parent_category方法的具体用法?PHP grade_item::get_parent_category怎么用?PHP grade_item::get_parent_category使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grade_item
的用法示例。
在下文中一共展示了grade_item::get_parent_category方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit_module_post_actions
/**
* Common create/update module module actions that need to be processed as soon as a module is created/updaded.
* For example:create grade parent category, add outcomes, rebuild caches, regrade, save plagiarism settings...
* Please note this api does not trigger events as of MOODLE 2.6. Please trigger events before calling this api.
*
* @param object $moduleinfo the module info
* @param object $course the course of the module
*
* @return object moduleinfo update with grading management info
*/
function edit_module_post_actions($moduleinfo, $course)
{
global $CFG;
require_once $CFG->libdir . '/gradelib.php';
$modcontext = context_module::instance($moduleinfo->coursemodule);
$hasgrades = plugin_supports('mod', $moduleinfo->modulename, FEATURE_GRADE_HAS_GRADE, false);
$hasoutcomes = plugin_supports('mod', $moduleinfo->modulename, FEATURE_GRADE_OUTCOMES, true);
// Sync idnumber with grade_item.
if ($hasgrades && ($grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $moduleinfo->modulename, 'iteminstance' => $moduleinfo->instance, 'itemnumber' => 0, 'courseid' => $course->id)))) {
if ($grade_item->idnumber != $moduleinfo->cmidnumber) {
$grade_item->idnumber = $moduleinfo->cmidnumber;
$grade_item->update();
}
}
if ($hasgrades) {
$items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $moduleinfo->modulename, 'iteminstance' => $moduleinfo->instance, 'courseid' => $course->id));
} else {
$items = array();
}
// Create parent category if requested and move to correct parent category.
if ($items and isset($moduleinfo->gradecat)) {
if ($moduleinfo->gradecat == -1) {
$grade_category = new grade_category();
$grade_category->courseid = $course->id;
$grade_category->fullname = $moduleinfo->name;
$grade_category->insert();
if ($grade_item) {
$parent = $grade_item->get_parent_category();
$grade_category->set_parent($parent->id);
}
$moduleinfo->gradecat = $grade_category->id;
}
$gradecategory = $grade_item->get_parent_category();
foreach ($items as $itemid => $unused) {
$items[$itemid]->set_parent($moduleinfo->gradecat);
if ($itemid == $grade_item->id) {
// Use updated grade_item.
$grade_item = $items[$itemid];
}
if (!empty($moduleinfo->add)) {
if (grade_category::aggregation_uses_aggregationcoef($gradecategory->aggregation)) {
if ($gradecategory->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$grade_item->aggregationcoef = 1;
} else {
$grade_item->aggregationcoef = 0;
}
$grade_item->update();
}
}
}
}
require_once $CFG->libdir . '/grade/grade_outcome.php';
// Add outcomes if requested.
if ($hasoutcomes && ($outcomes = grade_outcome::fetch_all_available($course->id))) {
$grade_items = array();
// Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes.
$max_itemnumber = 999;
if ($items) {
foreach ($items as $item) {
if ($item->itemnumber > $max_itemnumber) {
$max_itemnumber = $item->itemnumber;
}
}
}
foreach ($outcomes as $outcome) {
$elname = 'outcome_' . $outcome->id;
if (property_exists($moduleinfo, $elname) and $moduleinfo->{$elname}) {
// So we have a request for new outcome grade item?
if ($items) {
$outcomeexists = false;
foreach ($items as $item) {
if ($item->outcomeid == $outcome->id) {
$outcomeexists = true;
break;
}
}
if ($outcomeexists) {
continue;
}
}
$max_itemnumber++;
$outcome_item = new grade_item();
$outcome_item->courseid = $course->id;
$outcome_item->itemtype = 'mod';
$outcome_item->itemmodule = $moduleinfo->modulename;
$outcome_item->iteminstance = $moduleinfo->instance;
$outcome_item->itemnumber = $max_itemnumber;
$outcome_item->itemname = $outcome->fullname;
$outcome_item->outcomeid = $outcome->id;
$outcome_item->gradetype = GRADE_TYPE_SCALE;
//.........这里部分代码省略.........