Permalink
Browse files

MDL-32570 enrol_imsenterprise: don't hardcode default category id

  • Loading branch information...
danpoltawski committed Oct 1, 2013
1 parent c7c613b commit 756fbd91fd8be3df79a659a66694e85bb3150628
Showing with 20 additions and 2 deletions.
  1. +20 −2 enrol/imsenterprise/lib.php
@@ -412,10 +412,10 @@ function process_group_tag($tagcontents) {
} else {
// If not found and not allowed to create, stick with default
$this->log_line('Category '.$group->category.' not found in Moodle database, so using default category instead.');
$course->category = 1;
$course->category = $this->get_default_category_id();
}
} else {
$course->category = 1;
$course->category = $this->get_default_category_id();
}
$course->timecreated = time();
$course->startdate = time();
@@ -810,6 +810,24 @@ function enrol_imsenterprise_allow_group_member_remove($itemid, $groupid, $useri
return false;
}
/**
* Get the default category id (often known as 'Miscellaneous'),
* statically cached to avoid multiple DB lookups on big imports.
*
* @return int id of default category.
*/
private function get_default_category_id() {
static $defaultcategoryid = null;
if ($defaultcategoryid === null) {
$category = get_course_category();
$defaultcategoryid = $category->id;
}
return $defaultcategoryid;
}
} // end of class

0 comments on commit 756fbd9

Please sign in to comment.