本文整理汇总了PHP中fix_course_sortorder函数的典型用法代码示例。如果您正苦于以下问题:PHP fix_course_sortorder函数的具体用法?PHP fix_course_sortorder怎么用?PHP fix_course_sortorder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fix_course_sortorder函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
global $DB;
foreach ($this->arguments as $argument) {
try {
$course = $DB->get_record('course', array('id' => $argument));
} catch (Exception $e) {
print get_class($e) . " thrown within the exception handler. Message: " . $e->getMessage() . " on line " . $e->getLine();
}
if ($course instanceof \stdClass) {
delete_course($course);
} else {
print "Course not found\n";
}
}
fix_course_sortorder();
}
示例2: execute
public function execute()
{
global $CFG;
require_once $CFG->dirroot . '/course/lib.php';
$options = $this->expandedOptions;
$arguments = $this->arguments;
$this->checkFileArg($arguments[0]);
$this->categorystack = array();
if ($options['parent']) {
$this->categorystack[] = $options['parent'];
} else {
$this->categorystack[] = 0;
}
$this->coursesmap = array();
$this->parser = xml_parser_create();
xml_set_element_handler($this->parser, array(&$this, "start_element"), array(&$this, "end_element"));
if (!($fp = fopen($arguments[0], "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($this->parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser)));
}
}
xml_parser_free($this->parser);
fix_course_sortorder();
}
示例3: course_rollover
/**
* Roll over an existing Moodle course into a new one using a customized backup
* and restore routine
*
* @param int $courseid Id of the course we are copying
* @param int $categoryid
* @return int|boolean Id of the newly created course
*/
function course_rollover($courseid, $categoryid = null)
{
global $DB;
if ($course = $DB->get_record('course', array('id' => $courseid))) {
//figure out the category
if ($categoryid === null) {
$categoryid = $course->category;
}
//make sure the category is valid
if (!$DB->record_exists('course_categories', array('id' => $categoryid))) {
//invalid category
return false;
}
//perform backup without including user info
$controller = new rollover_backup_controller($courseid);
$controller->get_plan()->get_setting('users')->set_value(false);
$controller->execute_plan();
//get directory name for use in restore
$backupid = $controller->get_backupid();
//start a database transaction to make sure restore is atomic, etc
$transaction = $DB->start_delegated_transaction();
//create the new course
$result = restore_dbops::create_new_course($course->fullname, $course->shortname, $categoryid);
//restore the content into it within the current transaction without including user information
$controller = new rollover_restore_controller($backupid, $result);
$controller->get_plan()->get_setting('users')->set_value(false);
$controller->execute_precheck();
$controller->execute_plan();
//make sure the sort order is defined as expected
fix_course_sortorder();
try {
//try to finalize
$transaction->allow_commit();
} catch (dml_transaction_exception $e) {
//failure
$result = false;
}
return $result;
} else {
//invalid course specified
return false;
}
}
示例4: main_upgrade
//.........这里部分代码省略.........
execute_sql(" CREATE INDEX {$CFG->prefix}user_students_courseuserid_idx ON {$CFG->prefix}user_students (course,userid) ");
execute_sql(" CREATE INDEX {$CFG->prefix}user_teachers_courseuserid_idx ON {$CFG->prefix}user_teachers (course,userid) ");
}
if ($oldversion < 2003072802) {
table_column("course_categories", "", "description", "text", "", "", "");
table_column("course_categories", "", "parent", "integer", "10", "unsigned");
table_column("course_categories", "", "sortorder", "integer", "10", "unsigned");
table_column("course_categories", "", "courseorder", "text", "", "", "");
table_column("course_categories", "", "visible", "integer", "1", "unsigned", "1");
table_column("course_categories", "", "timemodified", "integer", "10", "unsigned");
}
if ($oldversion < 2003080400) {
notify("If the following command fails you may want to change the type manually, from TEXT to INTEGER. Moodle should keep working even if you don't.");
table_column("course_categories", "courseorder", "courseorder", "integer", "10", "unsigned");
table_column("course", "", "sortorder", "integer", "10", "unsigned", "0", "", "category");
}
if ($oldversion < 2003081502) {
execute_sql(" CREATE TABLE {$CFG->prefix}scale (\n id SERIAL PRIMARY KEY,\n courseid integer NOT NULL default '0',\n userid integer NOT NULL default '0',\n name varchar(255) NOT NULL default '',\n scale text,\n description text,\n timemodified integer NOT NULL default '0'\n )");
}
if ($oldversion < 2003081503) {
table_column("forum", "", "scale", "integer", "10", "unsigned", "0", "", "assessed");
get_scales_menu(0);
// Just to force the default scale to be created
}
if ($oldversion < 2003081600) {
table_column("user_teachers", "", "editall", "integer", "1", "unsigned", "1", "", "role");
table_column("user_teachers", "", "timemodified", "integer", "10", "unsigned", "0", "", "editall");
}
if ($oldversion < 2003081900) {
table_column("course_categories", "courseorder", "coursecount", "integer", "10", "unsigned", "0");
}
if ($oldversion < 2003080700) {
notify("Cleaning up categories and course ordering...");
fix_course_sortorder();
}
if ($oldversion < 2003082001) {
table_column("course", "", "showgrades", "integer", "2", "unsigned", "1", "", "format");
}
if ($oldversion < 2003082101) {
execute_sql(" CREATE INDEX {$CFG->prefix}course_category_idx ON {$CFG->prefix}course (category) ");
}
if ($oldversion < 2003082702) {
execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'user report', 'user', 'CONCAT(firstname,\" \",lastname)') ");
}
if ($oldversion < 2003091000) {
# Old field that was never added!
table_column("course", "", "showrecent", "integer", "10", "unsigned", "1", "", "numsections");
}
if ($oldversion < 2003091400) {
table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score");
}
if ($oldversion < 2003092900) {
table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker");
}
if ($oldversion < 2003102700) {
table_column("user_students", "", "timeaccess", "integer", "10", "unsigned", "0", "", "time");
table_column("user_teachers", "", "timeaccess", "integer", "10", "unsigned", "0", "", "timemodified");
$db->debug = false;
$CFG->debug = 0;
notify("Calculating access times. Please wait - this may take a long time on big sites...", "green");
flush();
if ($courses = get_records_select("course", "category > 0")) {
foreach ($courses as $course) {
notify("Processing " . format_string($course->fullname) . " ...", "green");
flush();
if ($users = get_records_select("user_teachers", "course = '{$course->id}'", "id", "id, userid, timeaccess")) {
示例5: create_categories
/**
* Create categories
*
* @param array $categories - see create_categories_parameters() for the array structure
* @return array - see create_categories_returns() for the array structure
* @since Moodle 2.3
*/
public static function create_categories($categories)
{
global $CFG, $DB;
require_once $CFG->dirroot . "/course/lib.php";
$params = self::validate_parameters(self::create_categories_parameters(), array('categories' => $categories));
$transaction = $DB->start_delegated_transaction();
$createdcategories = array();
foreach ($params['categories'] as $category) {
if ($category['parent']) {
if (!$DB->record_exists('course_categories', array('id' => $category['parent']))) {
throw new moodle_exception('unknowcategory');
}
$context = context_coursecat::instance($category['parent']);
} else {
$context = context_system::instance();
}
self::validate_context($context);
require_capability('moodle/category:manage', $context);
// Check name.
if (textlib::strlen($category['name']) > 255) {
throw new moodle_exception('categorytoolong');
}
$newcategory = new stdClass();
$newcategory->name = $category['name'];
$newcategory->parent = $category['parent'];
$newcategory->sortorder = 999;
// Same as in the course/editcategory.php .
// Format the description.
if (!empty($category['description'])) {
$newcategory->description = $category['description'];
}
$newcategory->descriptionformat = external_validate_format($category['descriptionformat']);
if (isset($category['theme']) and !empty($CFG->allowcategorythemes)) {
$newcategory->theme = $category['theme'];
}
// Check id number.
if (!empty($category['idnumber'])) {
// Same as in course/editcategory_form.php .
if (textlib::strlen($category['idnumber']) > 100) {
throw new moodle_exception('idnumbertoolong');
}
if ($existing = $DB->get_record('course_categories', array('idnumber' => $category['idnumber']))) {
if ($existing->id) {
throw new moodle_exception('idnumbertaken');
}
}
$newcategory->idnumber = $category['idnumber'];
}
$newcategory = create_course_category($newcategory);
// Populate special fields.
fix_course_sortorder();
$createdcategories[] = array('id' => $newcategory->id, 'name' => $newcategory->name);
}
$transaction->allow_commit();
return $createdcategories;
}
示例6: process_category_group_node
private function process_category_group_node($groupnode, $xpath)
{
global $DB, $CFG;
$group = new stdClass();
if ($groupnode->getAttribute("recstatus") != 3) {
$groupname = $xpath->evaluate("description/short", $groupnode)->item(0);
if ($groupname) {
$group->name = $groupname->nodeValue;
}
$groupdescription = $xpath->evaluate("sourcedid/id", $groupnode)->item(0);
if ($groupdescription) {
$group->description = htmlspecialchars_decode($groupdescription->nodeValue);
}
$parentgroup = $xpath->evaluate("relationship/sourcedid/id", $groupnode)->item(0);
if ($parentgroup) {
$parentid = $DB->get_field_select('course_categories', 'id', 'description =\'
' . htmlspecialchars_decode($parentgroup->nodeValue) . '\'');
if ($parentid) {
$group->parent = $parentid;
}
} else {
$group->parent = 0;
}
$id = $DB->get_record_select('course_categories', 'description=\'' . $group->description . '\'');
if (!$id) {
$group->id = $DB->insert_record('course_categories', $group);
$classname = context_helper::get_class_for_level(CONTEXT_COURSECAT);
$group->context = $classname::instance($group->id, IGNORE_MISSING);
mark_context_dirty($group->context->path);
$DB->update_record('course_categories', $group);
fix_course_sortorder();
}
} else {
$groupname = $xpath->evaluate("description/short", $groupnode)->item(0);
if ($groupname) {
$group->name = $groupname->nodeValue;
}
$groupdescription = $xpath->evaluate("sourcedid/id", $groupnode)->item(0);
if ($groupdescription) {
$group->description = htmlspecialchars_decode($groupdescription->nodeValue);
}
$parentgroup = $xpath->evaluate("relationship/sourcedid/id", $groupnode)->item(0);
if ($parentgroup) {
$parentid = $DB->get_field_select('course_categories', 'id', 'description =\'
' . htmlspecialchars_decode($parentgroup->nodeValue) . '\'');
if ($parentid) {
$group->parent = $parentid;
}
} else {
$group->parent = 0;
}
$id = $DB->get_record_select('course_categories', 'description=\'' . $group->description . '\'');
if ($id) {
if ($children = $DB->get_records('course_categories', array('parent' => $id->id), 'sortorder ASC')) {
echo 'has cats!';
} else {
if ($courses = $DB->get_records('course', array('category' => $id->id), 'sortorder ASC')) {
echo 'has courses!';
} else {
$DB->delete_records('course_categories', array('id' => $id->id));
delete_context(CONTEXT_COURSECAT, $id->id);
}
}
}
}
}
示例7: change_sortorder_by_one
/**
* Changes the sort order of this categories parent shifting this category up or down one.
*
* @global \moodle_database $DB
* @param bool $up If set to true the category is shifted up one spot, else its moved down.
* @return bool True on success, false otherwise.
*/
public function change_sortorder_by_one($up)
{
global $DB;
$params = array($this->sortorder, $this->parent);
if ($up) {
$select = 'sortorder < ? AND parent = ?';
$sort = 'sortorder DESC';
} else {
$select = 'sortorder > ? AND parent = ?';
$sort = 'sortorder ASC';
}
fix_course_sortorder();
$swapcategory = $DB->get_records_select('course_categories', $select, $params, $sort, '*', 0, 1);
$swapcategory = reset($swapcategory);
if ($swapcategory) {
$DB->set_field('course_categories', 'sortorder', $swapcategory->sortorder, array('id' => $this->id));
$DB->set_field('course_categories', 'sortorder', $this->sortorder, array('id' => $swapcategory->id));
$this->sortorder = $swapcategory->sortorder;
$event = \core\event\course_category_updated::create(array('objectid' => $this->id, 'context' => $this->get_context()));
$event->set_legacy_logdata(array(SITEID, 'category', 'move', 'management.php?categoryid=' . $this->id, $this->id));
$event->trigger();
// Finally reorder courses.
fix_course_sortorder();
cache_helper::purge_by_event('changesincoursecat');
return true;
}
return false;
}
示例8: setup
/**
* Setup the DB fixture data
*/
public function setup()
{
parent::setUp();
$tables = array('block_instance', 'cache_flags', 'capabilities', 'context', 'context_temp', 'course', 'course_modules', 'course_categories', 'course_sections', 'files', 'files_cleanup', 'grade_items', 'grade_categories', 'groups', 'groups_members', 'modules', 'role', 'role_names', 'role_context_levels', 'role_assignments', 'role_capabilities', 'user');
$this->create_test_tables($tables, 'lib');
$this->create_test_table('forum', 'mod/forum');
$this->switch_to_test_db();
global $DB, $CFG;
// Insert needed capabilities
$DB->insert_record('capabilities', array('id' => 45, 'name' => 'moodle/course:update', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 4));
$DB->insert_record('capabilities', array('id' => 14, 'name' => 'moodle/site:backup', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 28));
$DB->insert_record('capabilities', array('id' => 17, 'name' => 'moodle/site:restore', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 28));
$DB->insert_record('capabilities', array('id' => 52, 'name' => 'moodle/course:managefiles', 'cattype' => 'write', 'contextlevel' => 50, 'component' => 'moodle', 'riskbitmask' => 4));
$DB->insert_record('capabilities', array('id' => 73, 'name' => 'moodle/user:editownprofile', 'cattype' => 'write', 'contextlevel' => 10, 'component' => 'moodle', 'riskbitmask' => 16));
// Insert system context
$DB->insert_record('context', array('id' => 1, 'contextlevel' => 10, 'instanceid' => 0, 'path' => '/1', 'depth' => 1));
$DB->insert_record('context', array('id' => 2, 'contextlevel' => 50, 'instanceid' => 1, 'path' => '/1/2', 'depth' => 2));
// Insert site course
$DB->insert_record('course', array('category' => 0, 'sortorder' => 1, 'fullname' => 'Test site', 'shortname' => 'test', 'format' => 'site', 'modinfo' => 'a:0:{}'));
// User and capability stuff (stolen from testaccesslib.php)
$syscontext = get_system_context(false);
$adminrole = create_role(get_string('administrator'), 'admin', get_string('administratordescription'), 'moodle/legacy:admin');
/// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
assign_capability('moodle/site:doanything', CAP_ALLOW, $adminrole, $syscontext->id);
update_capabilities('moodle');
update_capabilities('mod/forum');
$contexts = $this->load_test_data('context', array('contextlevel', 'instanceid', 'path', 'depth'), array(1 => array(40, 666, '', 2)));
$contexts[0] = $syscontext;
$contexts[1]->path = $contexts[0]->path . '/' . $contexts[1]->id;
$this->testdb->set_field('context', 'path', $contexts[1]->path, array('id' => $contexts[1]->id));
$users = $this->load_test_data('user', array('username', 'confirmed', 'deleted'), array('a' => array('a', 1, 0)));
$admin = $this->testdb->get_record('role', array('shortname' => 'admin'));
$ras = $this->load_test_data('role_assignments', array('userid', 'roleid', 'contextid'), array('a' => array($users['a']->id, $admin->id, $contexts[0]->id)));
$this->switch_global_user_id(1);
accesslib_clear_all_caches_for_unit_testing();
// Create a coursecat
$newcategory = new stdClass();
$newcategory->name = 'test category';
$newcategory->sortorder = 999;
if (!($newcategory->id = $DB->insert_record('course_categories', $newcategory))) {
print_error('cannotcreatecategory', '', '', format_string($newcategory->name));
}
$newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id);
mark_context_dirty($newcategory->context->path);
fix_course_sortorder();
// Required to build course_categories.depth and .path.
$this->coursecat = $DB->get_record('course_categories', array('id' => $newcategory->id));
// Create a course
$coursedata = new stdClass();
$coursedata->category = $newcategory->id;
$coursedata->shortname = 'testcourse';
$coursedata->fullname = 'Test Course';
try {
$this->course = create_course($coursedata);
} catch (moodle_exception $e) {
// Most likely the result of an aborted unit test: the test course was not correctly deleted
$this->course = $DB->get_record('course', array('shortname' => $coursedata->shortname));
}
// Create a user
$this->user = new stdClass();
$this->user->username = 'testuser09987654321';
$this->user->password = 'password';
$this->user->firstname = 'TestUser';
$this->user->lastname = 'TestUser';
$this->user->email = 'fakeemail@fake.org';
try {
$this->user->id = create_user($this->user);
} catch (moodle_exception $e) {
// Most likely the result of an aborted unit test: the test user was not correctly deleted
$this->user->id = $DB->get_field('user', 'id', array('username' => $this->user->username));
}
// Assign user to course
// role_assign(5, $this->user->id, 0, get_context_instance(CONTEXT_COURSE, $this->course->id)->id);
// Create a module
$module = new stdClass();
$module->intro = 'Forum used for testing filelib API';
$module->type = 'general';
$module->forcesubscribe = 1;
$module->format = 1;
$module->name = 'Test Forum';
$module->module = $DB->get_field('modules', 'id', array('name' => 'forum'));
$module->modulename = 'forum';
$module->add = 'forum';
$module->cmidnumber = '';
$module->course = $this->course->id;
$module->instance = forum_add_instance($module, '');
$this->section = get_course_section(1, $this->course->id);
$module->section = $this->section->id;
$module->coursemodule = add_course_module($module);
add_mod_to_section($module);
$module->cmidnumber = set_coursemodule_idnumber($module->coursemodule, '');
rebuild_course_cache($this->course->id);
$this->module = $DB->get_record('forum', array('id' => $module->instance));
$this->module->instance = $module->instance;
// Update local copy of course
$this->course = $DB->get_record('course', array('id' => $this->course->id));
}
示例9: create_course
function create_course($course_ext, $skip_fix_course_sortorder = 0)
{
global $CFG;
// override defaults with template course
if (!empty($CFG->enrol_ldap_template)) {
$course = get_record("course", 'shortname', $CFG->enrol_ldap_template);
unset($course->id);
// so we are clear to reinsert the record
unset($course->sortorder);
} else {
// set defaults
$course = new object();
$course->student = get_string('defaultcoursestudent');
$course->students = get_string('defaultcoursestudents');
$course->teacher = get_string('defaultcourseteacher');
$course->teachers = get_string('defaultcourseteachers');
$course->format = 'topics';
}
// override with required ext data
$course->idnumber = $course_ext[$CFG->enrol_ldap_course_idnumber][0];
$course->fullname = $course_ext[$CFG->enrol_ldap_course_fullname][0];
$course->shortname = $course_ext[$CFG->enrol_ldap_course_shortname][0];
if (empty($course->idnumber) || empty($course->fullname) || empty($course->shortname)) {
// we are in trouble!
error_log("Cannot create course: missing required data from the LDAP record!");
error_log(var_export($course, true));
return false;
}
$course->summary = empty($CFG->enrol_ldap_course_summary) || empty($course_ext[$CFG->enrol_ldap_course_summary][0]) ? '' : $course_ext[$CFG->enrol_ldap_course_summary][0];
if (!empty($CFG->enrol_ldap_category)) {
// optional ... but ensure it is set!
$course->category = $CFG->enrol_ldap_category;
}
if ($course->category == 0) {
// must be avoided as it'll break moodle
$course->category = 1;
// the misc 'catch-all' category
}
// define the sortorder (yuck)
$sort = get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM ' . $CFG->prefix . 'course WHERE category=' . $course->category);
$sort = $sort->max;
$sort++;
$course->sortorder = $sort;
// override with local data
$course->startdate = time();
$course->timecreated = time();
$course->visible = 1;
$course = addslashes_recursive($course);
// store it and log
if ($newcourseid = insert_record("course", $course)) {
// Set up new course
$section = new object();
$section->course = $newcourseid;
// Create a default section.
$section->section = 0;
$section->id = insert_record("course_sections", $section);
$page = page_create_object(PAGE_COURSE_VIEW, $newcourseid);
blocks_repopulate_page($page);
// Return value no
if (!$skip_fix_course_sortorder) {
fix_course_sortorder();
}
add_to_log($newcourseid, "course", "new", "view.php?id={$newcourseid}", "enrol/ldap auto-creation");
} else {
error_log("Could not create new course from LDAP from DN:" . $course_ext['dn']);
notify("Serious Error! Could not create the new course!");
return false;
}
return $newcourseid;
}
示例10: cron
/**
* Read in an IMS Enterprise file.
* Originally designed to handle v1.1 files but should be able to handle
* earlier types as well, I believe.
*
*/
public function cron() {
global $CFG;
// Get configs.
$imsfilelocation = $this->get_config('imsfilelocation');
$logtolocation = $this->get_config('logtolocation');
$mailadmins = $this->get_config('mailadmins');
$prevtime = $this->get_config('prev_time');
$prevmd5 = $this->get_config('prev_md5');
$prevpath = $this->get_config('prev_path');
if (empty($imsfilelocation)) {
$filename = "$CFG->dataroot/1/imsenterprise-enrol.xml"; // Default location.
} else {
$filename = $imsfilelocation;
}
$this->logfp = false;
if (!empty($logtolocation)) {
$this->logfp = fopen($logtolocation, 'a');
}
$fileisnew = false;
if ( file_exists($filename) ) {
core_php_time_limit::raise();
$starttime = time();
$this->log_line('----------------------------------------------------------------------');
$this->log_line("IMS Enterprise enrol cron process launched at " . userdate(time()));
$this->log_line('Found file '.$filename);
$this->xmlcache = '';
// Make sure we understand how to map the IMS-E roles to Moodle roles.
$this->load_role_mappings();
// Make sure we understand how to map the IMS-E course names to Moodle course names.
$this->load_course_mappings();
$md5 = md5_file($filename); // NB We'll write this value back to the database at the end of the cron.
$filemtime = filemtime($filename);
// Decide if we want to process the file (based on filepath, modification time, and MD5 hash)
// This is so we avoid wasting the server's efforts processing a file unnecessarily.
if (empty($prevpath) || ($filename != $prevpath)) {
$fileisnew = true;
} else if (isset($prevtime) && ($filemtime <= $prevtime)) {
$this->log_line('File modification time is not more recent than last update - skipping processing.');
} else if (isset($prevmd5) && ($md5 == $prevmd5)) {
$this->log_line('File MD5 hash is same as on last update - skipping processing.');
} else {
$fileisnew = true; // Let's process it!
}
if ($fileisnew) {
// The <properties> tag is allowed to halt processing if we're demanding a matching target.
$this->continueprocessing = true;
// Run through the file and process the group/person entries.
if (($fh = fopen($filename, "r")) != false) {
$line = 0;
while ((!feof($fh)) && $this->continueprocessing) {
$line++;
$curline = fgets($fh);
$this->xmlcache .= $curline; // Add a line onto the XML cache.
while (true) {
// If we've got a full tag (i.e. the most recent line has closed the tag) then process-it-and-forget-it.
// Must always make sure to remove tags from cache so they don't clog up our memory.
if ($tagcontents = $this->full_tag_found_in_cache('group', $curline)) {
$this->process_group_tag($tagcontents);
$this->remove_tag_from_cache('group');
} else if ($tagcontents = $this->full_tag_found_in_cache('person', $curline)) {
$this->process_person_tag($tagcontents);
$this->remove_tag_from_cache('person');
} else if ($tagcontents = $this->full_tag_found_in_cache('membership', $curline)) {
$this->process_membership_tag($tagcontents);
$this->remove_tag_from_cache('membership');
} else if ($tagcontents = $this->full_tag_found_in_cache('comments', $curline)) {
$this->remove_tag_from_cache('comments');
} else if ($tagcontents = $this->full_tag_found_in_cache('properties', $curline)) {
$this->process_properties_tag($tagcontents);
$this->remove_tag_from_cache('properties');
} else {
break;
}
}
}
fclose($fh);
fix_course_sortorder();
}
$timeelapsed = time() - $starttime;
//.........这里部分代码省略.........
示例11: fix_course_sortorder
/**
* This recursive function makes sure that the courseorder is consecutive
*
* @param type description
*
* $n is the starting point, offered only for compatilibity -- will be ignored!
* $safe (bool) prevents it from assuming category-sortorder is unique, used to upgrade
* safely from 1.4 to 1.5
*/
function fix_course_sortorder($categoryid = 0, $n = 0, $safe = 0, $depth = 0, $path = '')
{
global $CFG;
$count = 0;
$catgap = 1000;
// "standard" category gap
$tolerance = 200;
// how "close" categories can get
if ($categoryid > 0) {
// update depth and path
$cat = get_record('course_categories', 'id', $categoryid);
if ($cat->parent == 0) {
$depth = 0;
$path = '';
} else {
if ($depth == 0) {
// doesn't make sense; get from DB
// this is only called if the $depth parameter looks dodgy
$parent = get_record('course_categories', 'id', $cat->parent);
$path = $parent->path;
$depth = $parent->depth;
}
}
$path = $path . '/' . $categoryid;
$depth = $depth + 1;
if ($cat->path !== $path) {
set_field('course_categories', 'path', addslashes($path), 'id', $categoryid);
}
if ($cat->depth != $depth) {
set_field('course_categories', 'depth', $depth, 'id', $categoryid);
}
}
// get some basic info about courses in the category
$info = get_record_sql('SELECT MIN(sortorder) AS min,
MAX(sortorder) AS max,
COUNT(sortorder) AS count
FROM ' . $CFG->prefix . 'course
WHERE category=' . $categoryid);
if (is_object($info)) {
// no courses?
$max = $info->max;
$count = $info->count;
$min = $info->min;
unset($info);
}
if ($categoryid > 0 && $n == 0) {
// only passed category so don't shift it
$n = $min;
}
// $hasgap flag indicates whether there's a gap in the sequence
$hasgap = false;
if ($max - $min + 1 != $count) {
$hasgap = true;
}
// $mustshift indicates whether the sequence must be shifted to
// meet its range
$mustshift = false;
if ($min < $n + $tolerance || $min > $n + $tolerance + $catgap) {
$mustshift = true;
}
// actually sort only if there are courses,
// and we meet one ofthe triggers:
// - safe flag
// - they are not in a continuos block
// - they are too close to the 'bottom'
if ($count && ($safe || $hasgap || $mustshift)) {
// special, optimized case where all we need is to shift
if ($mustshift && !$safe && !$hasgap) {
$shift = $n + $catgap - $min;
if ($shift < $count) {
$shift = $count + $catgap;
}
// UPDATE course SET sortorder=sortorder+$shift
execute_sql("UPDATE {$CFG->prefix}course\n SET sortorder=sortorder+{$shift}\n WHERE category={$categoryid}", 0);
$n = $n + $catgap + $count;
} else {
// do it slowly
$n = $n + $catgap;
// if the new sequence overlaps the current sequence, lack of transactions
// will stop us -- shift things aside for a moment...
if ($safe || $n >= $min && $n + $count + 1 < $min && $CFG->dbfamily === 'mysql') {
$shift = $max + $n + 1000;
execute_sql("UPDATE {$CFG->prefix}course\n SET sortorder=sortorder+{$shift}\n WHERE category={$categoryid}", 0);
}
$courses = get_courses($categoryid, 'c.sortorder ASC', 'c.id,c.sortorder');
begin_sql();
$tx = true;
// transaction sanity
foreach ($courses as $course) {
if ($tx && $course->sortorder != $n) {
// save db traffic
//.........这里部分代码省略.........
示例12: update_course
/**
* Update a course and return true or false
*
* @param object $data - all the data needed for an entry in the 'course' table
*/
function update_course($data)
{
global $USER, $CFG;
// Preprocess allowed mods
$allowedmods = empty($data->allowedmods) ? array() : $data->allowedmods;
unset($data->allowedmods);
// Normal teachers can't change setting
if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
unset($data->restrictmodules);
}
$movecat = false;
$oldcourse = get_record('course', 'id', $data->id);
// should not fail, already tested above
if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $oldcourse->category)) or !has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $data->category))) {
// can not move to new category, keep the old one
unset($data->category);
} elseif ($oldcourse->category != $data->category) {
$movecat = true;
}
// Update with the new data
if (update_record('course', $data)) {
$course = get_record('course', 'id', $data->id);
add_to_log($course->id, "course", "update", "edit.php?id={$course->id}", $course->id);
// "Admins" can change allowed mods for a course
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
update_restricted_mods($course, $allowedmods);
}
if ($movecat) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);
context_moved($context, $newparent);
}
fix_course_sortorder();
// Test for and remove blocks which aren't appropriate anymore
$page = page_create_object(PAGE_COURSE_VIEW, $course->id);
blocks_remove_inappropriate($page);
// put custom role names into db
$context = get_context_instance(CONTEXT_COURSE, $course->id);
foreach ($data as $dname => $dvalue) {
// is this the right param?
$dvalue = clean_param($dvalue, PARAM_NOTAGS);
if (!strstr($dname, 'role_')) {
continue;
}
$dt = explode('_', $dname);
$roleid = $dt[1];
// make up our mind whether we want to delete, update or insert
if (empty($dvalue)) {
delete_records('role_names', 'contextid', $context->id, 'roleid', $roleid);
} else {
if ($t = get_record('role_names', 'contextid', $context->id, 'roleid', $roleid)) {
$t->name = $dvalue;
update_record('role_names', $t);
} else {
$t->contextid = $context->id;
$t->roleid = $roleid;
$t->name = $dvalue;
insert_record('role_names', $t);
}
}
}
//trigger events
events_trigger('course_updated', $course);
return true;
}
return false;
}
示例13: process_group_tag
//.........这里部分代码省略.........
// Second, look in the course alias table to see if the code should be translated to something else
if($aliases = get_field('enrol_coursealias', 'toids', 'fromid', $group->coursecode)){
$this->log_line("Found alias of course code: Translated $group->coursecode to $aliases");
// Alias is allowed to be a comma-separated list, so let's split it
$group->coursecode = explode(',', $aliases);
}
*/
// For compatibility with the (currently inactive) course aliasing, we need this to be an array
$group->coursecode = array($group->coursecode);
// Third, check if the course(s) exist
foreach ($group->coursecode as $coursecode) {
$coursecode = trim($coursecode);
if (!get_field('course', 'id', 'idnumber', $coursecode)) {
if (!$CFG->enrol_createnewcourses) {
$this->log_line("Course {$coursecode} not found in Moodle's course idnumbers.");
} else {
// Create the (hidden) course(s) if not found
$course->fullname = $group->description;
$course->shortname = $coursecode;
$course->idnumber = $coursecode;
$course->format = 'topics';
$course->visible = 0;
// Insert default names for teachers/students, from the current language
$site = get_site();
if (current_language() == $CFG->lang) {
$course->teacher = $site->teacher;
$course->teachers = $site->teachers;
$course->student = $site->student;
$course->students = $site->students;
} else {
$course->teacher = get_string("defaultcourseteacher");
$course->teachers = get_string("defaultcourseteachers");
$course->student = get_string("defaultcoursestudent");
$course->students = get_string("defaultcoursestudents");
}
// Handle course categorisation (taken from the group.org.orgunit field if present)
if (strlen($group->category) > 0) {
// If the category is defined and exists in Moodle, we want to store it in that one
if ($catid = get_field('course_categories', 'id', 'name', addslashes($group->category))) {
$course->category = $catid;
} elseif ($CFG->enrol_createnewcategories) {
// Else if we're allowed to create new categories, let's create this one
$newcat->name = $group->category;
$newcat->visible = 0;
if ($catid = insert_record('course_categories', $newcat)) {
$course->category = $catid;
$this->log_line("Created new (hidden) category, #{$catid}: {$newcat->name}");
} else {
$this->log_line('Failed to create new category: ' . $newcat->name);
}
} 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;
}
} else {
$course->category = 1;
}
$course->timecreated = time();
$course->startdate = time();
$course->numsections = 1;
// Choose a sort order that puts us at the start of the list!
$sortinfo = get_record_sql('SELECT MIN(sortorder) AS min,
MAX(sortorder) AS max
FROM ' . $CFG->prefix . 'course WHERE category<>0');
if (is_object($sortinfo)) {
// no courses?
$max = $sortinfo->max;
$min = $sortinfo->min;
unset($sortinfo);
$course->sortorder = $min - 1;
} else {
$course->sortorder = 1000;
}
if ($course->id = insert_record('course', addslashes_object($course))) {
// Setup the blocks
$page = page_create_object(PAGE_COURSE_VIEW, $course->id);
blocks_repopulate_page($page);
// Return value not checked because you can always edit later
$section = NULL;
$section->course = $course->id;
// Create a default section.
$section->section = 0;
$section->id = insert_record("course_sections", $section);
fix_course_sortorder();
add_to_log(SITEID, "course", "new", "view.php?id={$course->id}", "{$course->fullname} (ID {$course->id})");
$this->log_line("Created course {$coursecode} in Moodle (Moodle ID is {$course->id})");
} else {
$this->log_line('Failed to create course ' . $coursecode . ' in Moodle');
}
}
} elseif ($recstatus == 3 && ($courseid = get_field('course', 'id', 'idnumber', $coursecode))) {
// If course does exist, but recstatus==3 (delete), then set the course as hidden
set_field('course', 'visible', '0', 'id', $courseid);
}
}
// End of foreach(coursecode)
}
}
示例14: save_category
/**
* Save the course category
*
* @author Andrew Zoltay
* date 2011-05-30
* @global type $DB
* @param string $categoryname
* @param int $parent
* @return boolean - success or failure
*/
function save_category($categoryname, $parent = 0)
{
global $DB;
// First off - don't save any categories that are null.
if (empty($categoryname) or is_null($categoryname)) {
return false;
}
// Next check to see if category already exists.
$categoryid = $DB->get_field_select('course_categories', 'id', 'name = ? AND parent = ?', array($categoryname, $parent));
// Finally save the category if it hasnt been found.
if ($categoryid) {
echo 'Found existing cat: ' . $categoryname . ' with id=' . $categoryid . '</br>';
return $categoryid;
} else {
// Save the new category.
$newcategory->name = $categoryname;
$newcategory->description = '';
// Don't define a description.
$newcategory->descriptionformat = 1;
// Default to HTML format.
$newcategory->parent = $parent;
$newcategory->sortorder = 999;
$newcategory->id = $DB->insert_record('course_categories', $newcategory);
$newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id);
$categorycontext = $newcategory->context;
mark_context_dirty($newcategory->context->path);
// Now that we have the context, we need to update the category's path info.
$DB->update_record('course_categories', $newcategory);
fix_course_sortorder();
echo 'Added new cat: ' . $categoryname . ' with id=' . $newcategory->id . '</br>';
return $newcategory->id;
}
}
示例15: delete_courses
/**
* Delete courses
*
* @param array $courseids A list of course ids
* @since Moodle 2.2
*/
public static function delete_courses($courseids)
{
global $CFG, $DB;
require_once $CFG->dirroot . "/course/lib.php";
// Parameter validation.
$params = self::validate_parameters(self::delete_courses_parameters(), array('courseids' => $courseids));
$warnings = array();
foreach ($params['courseids'] as $courseid) {
$course = $DB->get_record('course', array('id' => $courseid));
if ($course === false) {
$warnings[] = array('item' => 'course', 'itemid' => $courseid, 'warningcode' => 'unknowncourseidnumber', 'message' => 'Unknown course ID ' . $courseid);
continue;
}
// Check if the context is valid.
$coursecontext = context_course::instance($course->id);
self::validate_context($coursecontext);
// Check if the current user has permission.
if (!can_delete_course($courseid)) {
$warnings[] = array('item' => 'course', 'itemid' => $courseid, 'warningcode' => 'cannotdeletecourse', 'message' => 'You do not have the permission to delete this course' . $courseid);
continue;
}
if (delete_course($course, false) === false) {
$warnings[] = array('item' => 'course', 'itemid' => $courseid, 'warningcode' => 'cannotdeletecategorycourse', 'message' => 'Course ' . $courseid . ' failed to be deleted');
continue;
}
}
fix_course_sortorder();
return array('warnings' => $warnings);
}