本文整理汇总了PHP中grade_category::build_path方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_category::build_path方法的具体用法?PHP grade_category::build_path怎么用?PHP grade_category::build_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grade_category
的用法示例。
在下文中一共展示了grade_category::build_path方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_grade_category_build_path
function test_grade_category_build_path()
{
$grade_category = new grade_category($this->grade_categories[1]);
$this->assertTrue(method_exists($grade_category, 'build_path'));
$path = grade_category::build_path($grade_category);
$this->assertEqual($grade_category->path, $path);
}
示例2: after_execute
/**
* put all activity grade items in the correct grade category and mark all for recalculation
*/
protected function after_execute()
{
global $DB;
$conditions = array('backupid' => $this->get_restoreid(), 'itemname' => 'grade_item');
$rs = $DB->get_recordset('backup_ids_temp', $conditions);
// We need this for calculation magic later on.
$mappings = array();
if (!empty($rs)) {
foreach ($rs as $grade_item_backup) {
// Store the oldid with the new id.
$mappings[$grade_item_backup->itemid] = $grade_item_backup->newitemid;
$updateobj = new stdclass();
$updateobj->id = $grade_item_backup->newitemid;
//if this is an activity grade item that needs to be put back in its correct category
if (!empty($grade_item_backup->parentitemid)) {
$oldcategoryid = $this->get_mappingid('grade_category', $grade_item_backup->parentitemid, null);
if (!is_null($oldcategoryid)) {
$updateobj->categoryid = $oldcategoryid;
$DB->update_record('grade_items', $updateobj);
}
} else {
//mark course and category items as needing to be recalculated
$updateobj->needsupdate = 1;
$DB->update_record('grade_items', $updateobj);
}
}
}
$rs->close();
// We need to update the calculations for calculated grade items that may reference old
// grade item ids using ##gi\d+##.
// $mappings can be empty, use 0 if so (won't match ever)
list($sql, $params) = $DB->get_in_or_equal(array_values($mappings), SQL_PARAMS_NAMED, 'param', true, 0);
$sql = "SELECT gi.id, gi.calculation\n FROM {grade_items} gi\n WHERE gi.id {$sql} AND\n calculation IS NOT NULL";
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $gradeitem) {
// Collect all of the used grade item id references
if (preg_match_all('/##gi(\\d+)##/', $gradeitem->calculation, $matches) < 1) {
// This calculation doesn't reference any other grade items... EASY!
continue;
}
// For this next bit we are going to do the replacement of id's in two steps:
// 1. We will replace all old id references with a special mapping reference.
// 2. We will replace all mapping references with id's
// Why do we do this?
// Because there potentially there will be an overlap of ids within the query and we
// we substitute the wrong id.. safest way around this is the two step system
$calculationmap = array();
$mapcount = 0;
foreach ($matches[1] as $match) {
// Check that the old id is known to us, if not it was broken to begin with and will
// continue to be broken.
if (!array_key_exists($match, $mappings)) {
continue;
}
// Our special mapping key
$mapping = '##MAPPING' . $mapcount . '##';
// The old id that exists within the calculation now
$oldid = '##gi' . $match . '##';
// The new id that we want to replace the old one with.
$newid = '##gi' . $mappings[$match] . '##';
// Replace in the special mapping key
$gradeitem->calculation = str_replace($oldid, $mapping, $gradeitem->calculation);
// And record the mapping
$calculationmap[$mapping] = $newid;
$mapcount++;
}
// Iterate all special mappings for this calculation and replace in the new id's
foreach ($calculationmap as $mapping => $newid) {
$gradeitem->calculation = str_replace($mapping, $newid, $gradeitem->calculation);
}
// Update the calculation now that its being remapped
$DB->update_record('grade_items', $gradeitem);
}
$rs->close();
// Need to correct the grade category path and parent
$conditions = array('courseid' => $this->get_courseid());
$rs = $DB->get_recordset('grade_categories', $conditions);
// Get all the parents correct first as grade_category::build_path() loads category parents from the DB
foreach ($rs as $gc) {
if (!empty($gc->parent)) {
$grade_category = new stdClass();
$grade_category->id = $gc->id;
$grade_category->parent = $this->get_mappingid('grade_category', $gc->parent);
$DB->update_record('grade_categories', $grade_category);
}
}
$rs->close();
// Now we can rebuild all the paths
$rs = $DB->get_recordset('grade_categories', $conditions);
foreach ($rs as $gc) {
$grade_category = new stdClass();
$grade_category->id = $gc->id;
$grade_category->path = grade_category::build_path($gc);
$grade_category->depth = substr_count($grade_category->path, '/') - 1;
$DB->update_record('grade_categories', $grade_category);
}
$rs->close();
//.........这里部分代码省略.........
示例3: update
/**
* In addition to update() as defined in grade_object, call force_regrading of parent categories, if applicable.
*
* @param string $source from where was the object updated (mod/forum, manual, etc.)
* @return bool success
*/
public function update($source = null)
{
// load the grade item or create a new one
$this->load_grade_item();
// force recalculation of path;
if (empty($this->path)) {
$this->path = grade_category::build_path($this);
$this->depth = substr_count($this->path, '/') - 1;
$updatechildren = true;
} else {
$updatechildren = false;
}
$this->apply_forced_settings();
// these are exclusive
if ($this->droplow > 0) {
$this->keephigh = 0;
} else {
if ($this->keephigh > 0) {
$this->droplow = 0;
}
}
// Recalculate grades if needed
if ($this->qualifies_for_regrading()) {
$this->force_regrading();
}
$this->timemodified = time();
$result = parent::update($source);
// now update paths in all child categories
if ($result and $updatechildren) {
if ($children = grade_category::fetch_all(array('parent' => $this->id))) {
foreach ($children as $child) {
$child->path = null;
$child->depth = 0;
$child->update($source);
}
}
}
return $result;
}
示例4: after_execute
protected function after_execute() {
global $DB;
$conditions = array(
'backupid' => $this->get_restoreid(),
'itemname' => 'grade_item'//,
//'itemid' => $itemid
);
$rs = $DB->get_recordset('backup_ids_temp', $conditions);
if (!empty($rs)) {
foreach($rs as $grade_item_backup) {
$updateobj = new stdclass();
$updateobj->id = $grade_item_backup->newitemid;
//if this is an activity grade item that needs to be put back in its correct category
if (!empty($grade_item_backup->parentitemid)) {
$updateobj->categoryid = $this->get_mappingid('grade_category', $grade_item_backup->parentitemid);
} else {
//mark course and category items as needing to be recalculated
$updateobj->needsupdate=1;
}
$DB->update_record('grade_items', $updateobj);
}
}
$rs->close();
//need to correct the grade category path and parent
$conditions = array(
'courseid' => $this->get_courseid()
);
$grade_category = new stdclass();
$rs = $DB->get_recordset('grade_categories', $conditions);
if (!empty($rs)) {
//get all the parents correct first as grade_category::build_path() loads category parents from the DB
foreach($rs as $gc) {
if (!empty($gc->parent)) {
$grade_category->id = $gc->id;
$grade_category->parent = $this->get_mappingid('grade_category', $gc->parent);
$DB->update_record('grade_categories', $grade_category);
}
}
}
if (isset($grade_category->parent)) {
unset($grade_category->parent);
}
$rs->close();
$rs = $DB->get_recordset('grade_categories', $conditions);
if (!empty($rs)) {
//now we can rebuild all the paths
foreach($rs as $gc) {
$grade_category->id = $gc->id;
$grade_category->path = grade_category::build_path($gc);
$DB->update_record('grade_categories', $grade_category);
}
}
$rs->close();
//Restore marks items as needing update. Update everything now.
grade_regrade_final_grades($this->get_courseid());
}
示例5: restore_create_gradebook
//.........这里部分代码省略.........
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now build the GRADE_PREFERENCES record structure
$dbrec->courseid = $restore->course_id;
// categories are not backed up during import.
// however, depth 1 categories needs to be skipped during restore into exisiting course
// get the new grade category parent
//if (!empty($info['GRADE_CATEGORY']['#']['PARENT']['0']['#']) && $info['GRADE_CATEGORY']['#']['PARENT']['0']['#'] != '$@NULL@$') {
$parent = backup_getid($restore->backup_unique_code, 'grade_categories', backup_todb($info['GRADE_CATEGORY']['#']['PARENT']['0']['#']));
if (isset($parent->new_id)) {
$dbrec->parent = $parent->new_id;
} else {
// orphans should get adopted by course category
$dbrec->parent = $coursecategory->id;
}
//}
$dbrec->fullname = backup_todb($info['GRADE_CATEGORY']['#']['FULLNAME']['0']['#']);
$dbrec->aggregation = backup_todb($info['GRADE_CATEGORY']['#']['AGGREGATION']['0']['#']);
$dbrec->keephigh = backup_todb($info['GRADE_CATEGORY']['#']['KEEPHIGH']['0']['#']);
$dbrec->droplow = backup_todb($info['GRADE_CATEGORY']['#']['DROPLOW']['0']['#']);
$dbrec->aggregateoutcomes = backup_todb($info['GRADE_CATEGORY']['#']['AGGREGATEOUTCOMES']['0']['#']);
//Structure is equal to db, insert record
//if the fullname doesn't exist
if (!($prerec = get_record('grade_categories', 'courseid', $dbrec->courseid, 'fullname', $dbrec->fullname))) {
$newid = insert_record('grade_categories', $dbrec);
$status = backup_putid($restore->backup_unique_code, 'grade_categories', $rec->old_id, $newid);
// update this record so we can put in the right paths
// this can only be done after we got the new id
$dbrec->id = $newid;
include_once $CFG->dirroot . '/lib/grade/grade_category.php';
// rebuild the path, we need only parents info
// the order of restoring should ensure that the parent and grandparent(s)
// are already restored
$dbrec->path = grade_category::build_path($dbrec);
// this is not needed in the xml because
// given this parent and grandparent(s) we can recalculate the depth
$dbrec->depth = substr_count($dbrec->path, '/');
update_record('grade_categories', $dbrec);
} else {
// if fullname already exists, we should keep the current grade category
$status = backup_putid($restore->backup_unique_code, 'grade_categories', $rec->old_id, $rec->oldid);
}
}
//Increment counters
$counter++;
//Do some output
if ($counter % 1 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if ($counter % 20 == 0) {
echo "<br />";
}
}
backup_flush(300);
}
}
}
}
}
// process outcomes
if ($outcomecount && $continue) {
if (!defined('RESTORE_SILENTLY')) {
echo '<li>' . get_string('gradeoutcomes', 'grades') . '</li>';
}
$counter = 0;
while ($counter < $outcomecount) {
示例6: update
/**
* In addition to update() as defined in grade_object, call force_regrading of parent categories, if applicable.
* @param string $source from where was the object updated (mod/forum, manual, etc.)
* @return boolean success
*/
function update($source = null)
{
// load the grade item or create a new one
$this->load_grade_item();
// force recalculation of path;
if (empty($this->path)) {
$this->path = grade_category::build_path($this);
$this->depth = substr_count($this->path, '/') - 1;
}
// Recalculate grades if needed
if ($this->qualifies_for_regrading()) {
$this->force_regrading();
}
return parent::update($source);
}