Skip to content

Commit

Permalink
MDL-14679 towards course conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jun 2, 2008
1 parent a598a97 commit 6bb0816
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 89 deletions.
6 changes: 3 additions & 3 deletions course/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
print_error("unknowcategory");
}

if (!$category = get_record("course_categories", "id", $id)) {
if (!$category = $DB->get_record("course_categories", array("id"=>$id))) {
print_error("unknowcategory");
}

Expand Down Expand Up @@ -222,8 +222,8 @@
$movecourse = $DB->get_record('course', array('id'=>$moveup));
$swapcourse = $DB->get_record('course', array('category'=>$category->id, 'sortorder'=>($movecourse->sortorder-1)));
} else {
$movecourse = get_record('course', array('id'=>$movedown));
$swapcourse = get_record('course', array('category'=>$category->id, 'sortorder'=>($movecourse->sortorder+1)));
$movecourse = $DB->get_record('course', array('id'=>$movedown));
$swapcourse = $DB->get_record('course', array('category'=>$category->id, 'sortorder'=>($movecourse->sortorder+1)));
}

if ($swapcourse and $movecourse) { // Renumber everything for robustness
Expand Down
30 changes: 15 additions & 15 deletions course/editcategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
} elseif (!is_null($id) && !$categoryadd) { // Show Edit category form: $id is given as the identifier of the category being edited
$strtitle = get_string("editcategorysettings");
$context = get_context_instance(CONTEXT_COURSECAT, $id);
if (!$category = get_record("course_categories", "id", $id)) {
if (!$category = $DB->get_record("course_categories", array("id"=>$id))) {
print_error("unknowcategory");
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@
if ($resort and confirm_sesskey()) {
if ($courses = get_courses($id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) {
// move it off the range
$count = get_record_sql('SELECT MAX(sortorder) AS max, 1
$count = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1
FROM ' . $CFG->prefix . 'course WHERE category=' . $category->id);
$count = $count->max + 100;
begin_sql();
Expand Down Expand Up @@ -209,7 +209,7 @@
require_capability('moodle/category:update', $context);
require_capability('moodle/category:update', get_context_instance(CONTEXT_COURSECAT, $moveto));
if (!$destcategory = get_record("course_categories", "id", $data->moveto)) {
if (!$destcategory = $DB->get_record("course_categories", array("id"=>$data->moveto))) {
pritn_error("unknowcategory");
}
// TODO function to move the category
Expand All @@ -219,10 +219,10 @@
if ((!empty($hide) or !empty($show)) and confirm_sesskey()) {
require_capability('moodle/category:visibility', $context);
if (!empty($hide)) {
$category = get_record("course_categories", "id", $hide);
$category = $DB->get_record("course_categories", array("id"=>$hide));
$visible = 0;
} else {
$category = get_record("course_categories", "id", $show);
$category = $DB->get_record("course_categories", array("id"=>$show));
$visible = 1;
}
if ($category) {
Expand All @@ -242,19 +242,19 @@
// TODO something like fix_course_sortorder() ?
// we are going to need to know the range
$max = get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM ' . $CFG->prefix . 'course_categories WHERE id=' . $category->id);
$max = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM ' . $CFG->prefix . 'course_categories WHERE id=' . $category->id);
$max = $max->max + 100;
if (!empty($moveup)) {
$movecategory = get_record('course_categories', 'id', $moveup);
$swapcategory = get_record('course_categories',
'category', $category->id,
'sortorder', $movecategory->sortorder - 1);
$movecategory = $DB->get_record('course_categories', array('id'=>$moveup));
$swapcategory = $DB->get_record('course_categories',
array('category'=>$category->id,
'sortorder'=>$movecategory->sortorder - 1));
} else {
$movecategory = get_record('course_categories', 'id', $movedown);
$swapcategory = get_record('course_categories',
'category', $category->id,
'sortorder', $movecategory->sortorder + 1);
$movecategory = $DB->get_record('course_categories', array('id'=>$movedown));
$swapcategory = $DB->get_record('course_categories',
array('category'=> $category->id,
'sortorder'=>$movecategory->sortorder + 1));
}
if ($swapcourse and $movecourse) { // Renumber everything for robustness
Expand All @@ -273,7 +273,7 @@
} // End of editing stuff
// Print out all the sub-categories
if ($subcategories = get_records("course_categories", "parent", $category->id, "sortorder ASC")) {
if ($subcategories = $DB->get_records("course_categories", array("parent"=>$category->id), "sortorder ASC")) {
$firstentry = true;
foreach ($subcategories as $subcategory) {
if ($subcategory->visible or has_capability('moodle/course:create', $context)) {
Expand Down
4 changes: 2 additions & 2 deletions course/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
print_error("invalidshortname");
}
} else {
if (!$course = get_record("course", array("id"=>$id))) {
if (!$course = $DB->get_record("course", array("id"=>$id))) {
print_error("invalidcourseid");
}
}
Expand Down Expand Up @@ -61,7 +61,7 @@
if ($managerroles = get_config('', 'coursemanager')) {
$coursemanagerroles = split(',', $managerroles);
foreach ($coursemanagerroles as $roleid) {
$role = get_record('role','id',$roleid);
$role = $DB->get_record('role', array('id'=>$roleid));
$canseehidden = has_capability('moodle/role:viewhiddenassigns', $context);
$roleid = (int) $roleid;
if ($users = get_role_users($roleid, $context, true, '', 'u.lastname ASC', $canseehidden)) {
Expand Down
8 changes: 4 additions & 4 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ function print_mnet_log($hostid, $course, $user=0, $date=0, $order="l.time ASC",
if (isset($ldcache[$log->module][$log->action])) {
$ld = $ldcache[$log->module][$log->action];
} else {
$ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
$ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
$ldcache[$log->module][$log->action] = $ld;
}
if (0 && $ld && !empty($log->info)) {
Expand Down Expand Up @@ -511,7 +511,7 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
if (isset($ldcache[$log->module][$log->action])) {
$ld = $ldcache[$log->module][$log->action];
} else {
$ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
$ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
$ldcache[$log->module][$log->action] = $ld;
}
if ($ld && !empty($log->info)) {
Expand Down Expand Up @@ -781,10 +781,10 @@ function print_log_graph($course, $userid=0, $type="course.png", $date=0) {


function print_overview($courses) {
global $CFG, $USER;
global $CFG, $USER, $DB;

$htmlarray = array();
if ($modules = get_records('modules')) {
if ($modules = $DB->get_records('modules')) {
foreach ($modules as $mod) {
if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
Expand Down
26 changes: 13 additions & 13 deletions course/pending.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
$rejectnotice = optional_param('rejectnotice', '', PARAM_CLEANHTML);

if (!empty($approve) and confirm_sesskey()) {
if ($course = get_record("course_request","id",$approve)) {
if ($course = $DB->get_record("course_request", array("id"=>$approve))) {
foreach (array_keys((array)$course) as $key) {
$course->$key = addslashes($course->$key);
}

// place at beginning of category
fix_course_sortorder();

if (empty($CFG->defaultrequestcategory) or !record_exists('course_categories', 'id', $CFG->defaultrequestcategory)) {
if (empty($CFG->defaultrequestcategory) or !$DB->record_exists('course_categories', array('id'=>$CFG->defaultrequestcategory))) {
// default to first top level directory, hacky but means things don't break
$CFG->defaultrequestcategory = get_field('course_categories', 'id', 'parent', '0');
$CFG->defaultrequestcategory = $DB->get_field('course_categories', 'id', array('parent'=>'0'));
}

$course->category = $CFG->defaultrequestcategory;
$course->sortorder = get_field_sql("SELECT min(sortorder)-1 FROM {$CFG->prefix}course WHERE category=$course->category");
$course->sortorder = $DB->get_field_sql("SELECT min(sortorder)-1 FROM {course} WHERE category=?", array($course->category));
if (empty($course->sortorder)) {
$course->sortorder = 1000;
}
Expand All @@ -45,7 +45,7 @@
if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
$course->restrictmodules = 1;
}
if ($courseid = insert_record("course",$course)) {
if ($courseid = $DB->insert_record("course",$course)) {
$page = page_create_object(PAGE_COURSE_VIEW, $courseid);
blocks_repopulate_page($page); // Return value not checked because you can always edit later
$context = get_context_instance(CONTEXT_COURSE, $courseid);
Expand All @@ -55,11 +55,11 @@
$allowedmods = explode(',',$CFG->defaultallowedmodules);
update_restricted_mods($course,$allowedmods);
}
delete_records('course_request','id',$approve);
$DB->delete_records('course_request', array('id'=>$approve));
$success = 1;
}
if (!empty($success)) {
$user = get_record('user','id',$teacherid);
$user = $DB->get_record('user', array('id'=>$teacherid));
$a->name = $course->fullname;
$a->url = $CFG->wwwroot.'/course/view.php?id='.$courseid;
$a->teacher = $course->teacher;
Expand All @@ -80,7 +80,7 @@
print_header($strtitle,$strheading,build_navigation(array(array('name'=>$strheading,'link'=>'','type'=>'misc'))));

if (!empty($reject) and confirm_sesskey()) {
if ($reject = get_record("course_request","id",$reject)) {
if ($reject = $DB->get_record("course_request", array("id"=>$reject))) {
if (empty($rejectnotice)) {
// display a form for writing a reason
print_simple_box_start('center');
Expand All @@ -89,13 +89,13 @@
print_simple_box_end();
}
else {
$user = get_record("user","id",$reject->requester);
$user = $DB->get_record("user", array("id"=>$reject->requester));
email_to_user($user,$USER,get_string('courserejectsubject'),get_string('courserejectemail','moodle',$rejectnotice));
delete_records("course_request","id",$reject->id);
$DB->delete_records("course_request", array("id"=>$reject->id));
notice(get_string('courserejected'),'pending.php');
}
}
} else if ($pending = get_records("course_request")) {
} else if ($pending = $DB->get_records("course_request")) {
// loop through
$table->cellpadding = 4;
$table->cellspacing = 3;
Expand All @@ -104,9 +104,9 @@
get_string('requestreason'),'');
$strrequireskey = get_string('requireskey');
foreach ($pending as $course) {
$requester = get_record('user','id',$course->requester);
$requester = $DB->get_record('user', array('id'=>$course->requester));
// check here for shortname collisions and warn about them.
if ($match = get_record("course","shortname",$course->shortname)) {
if ($match = $DB->get_record("course", array("shortname"=>$course->shortname))) {
$course->shortname .= ' [*]';
$collision = 1;
}
Expand Down
14 changes: 7 additions & 7 deletions course/recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

$id = required_param('id', PARAM_INT);

if (!$course = get_record('course', 'id', $id) ) {
if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error("That's an invalid course id");
}

Expand Down Expand Up @@ -45,7 +45,7 @@
$dateinfo = get_string('alldays');

if (!empty($param->user)) {
if (!$u = get_record('user', 'id', $param->user) ) {
if (!$u = $DB->get_record('user', array('id'=>$param->user))) {
print_error("That's an invalid user!");
}
$userinfo = fullname($u);
Expand All @@ -70,11 +70,11 @@
$hiddenfilter = "AND cs.visible = 1";
}
$sections = array();
if ($ss = get_records_sql("SELECT cs.id, cs.section, cs.sequence, cs.summary, cs.visible
FROM {$CFG->prefix}course_sections cs
WHERE cs.course = $course->id AND cs.section <= $course->numsections
$hiddenfilter
ORDER BY section")) {
if ($ss = $DB->get_records_sql("SELECT cs.id, cs.section, cs.sequence, cs.summary, cs.visible
FROM {course_sections} cs
WHERE cs.course = ? AND cs.section <= ?
$hiddenfilter
ORDER BY section", array($course->id, $course->numsections))) {
foreach ($ss as $section) {
$sections[$section->section] = $section;
}
Expand Down
8 changes: 4 additions & 4 deletions course/reset_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class course_reset_form extends moodleform {
function definition (){
global $CFG, $COURSE;
global $CFG, $COURSE, $DB;

$mform =& $this->_form;

Expand Down Expand Up @@ -49,7 +49,7 @@ function definition (){
}

$unsupported_mods = array();
if ($allmods = get_records('modules') ) {
if ($allmods = $DB->get_records('modules') ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
if (!count_records($modname, 'course', $COURSE->id)) {
Expand Down Expand Up @@ -91,7 +91,7 @@ function definition (){
}

function load_defaults() {
global $CFG, $COURSE;
global $CFG, $COURSE, $DB;

$mform =& $this->_form;

Expand All @@ -103,7 +103,7 @@ function load_defaults() {
$defaults['reset_roles'] = array($CFG->defaultcourseroleid);
}

if ($allmods = get_records('modules') ) {
if ($allmods = $DB->get_records('modules') ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$modfile = $CFG->dirroot."/mod/$modname/lib.php";
Expand Down
16 changes: 8 additions & 8 deletions course/rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


// Authorise the user and verify some incoming data
if (!$course = get_record('course', 'id', $courseid)) {
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
error_log('AJAX commands.php: Course does not exist');
die;
}
Expand Down Expand Up @@ -69,7 +69,7 @@

case 'section':

if (!record_exists('course_sections','course',$course->id,'section',$id)) {
if (!$DB->record_exists('course_sections', array('course'=>$course->id, 'section'=>$id))) {
error_log('AJAX commands.php: Bad Section ID '.$id);
die;
}
Expand All @@ -87,7 +87,7 @@
break;

case 'resource':
if (!$mod = get_record('course_modules', 'id', $id, 'course', $course->id)) {
if (!$mod = $DB->get_record('course_modules', array('id'=>$id, 'course'=>$course->id))) {
error_log('AJAX commands.php: Bad course module ID '.$id);
die;
}
Expand All @@ -113,13 +113,13 @@
break;

case 'move':
if (!$section = get_record('course_sections','course',$course->id,'section',$sectionid)) {
if (!$section = $DB->get_record('course_sections', array('course'=>$course->id, 'section'=>$sectionid))) {
error_log('AJAX commands.php: Bad section ID '.$sectionid);
die;
}

if ($beforeid > 0){
$beforemod = get_record('course_modules', 'id', $beforeid);
$beforemod = $DB->get_record('course_modules', array('id'=>$beforeid));
} else {
$beforemod = NULL;
}
Expand All @@ -140,7 +140,7 @@
$newcourse = new object;
$newcourse->id = $course->id;
$newcourse->marker = $value;
if (!update_record('course',$newcourse)) {
if (!$DB->update_record('course', $newcourse)) {
error_log('AJAX commands.php: Failed to update course marker for course '.$newcourse->id);
die;
}
Expand All @@ -157,11 +157,11 @@
break;

case 'resource':
if (!$cm = get_record('course_modules', 'id', $id, 'course', $course->id)) {
if (!$cm = $DB->get_record('course_modules', array('id'=>$id, 'course'=>$course->id))) {
error_log('AJAX rest.php: Bad course module ID '.$id);
die;
}
if (!$mod = get_record('modules', 'id', $cm->module)) {
if (!$mod = $DB->get_record('modules', array('id'=>$cm->module))) {
error_log('AJAX rest.php: Bad module ID '.$cm->module);
die;
}
Expand Down
4 changes: 2 additions & 2 deletions course/scales.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

print_header($strscales);

if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) {
if ($scales = $DB->get_records("scale", array("courseid"=>$course->id), "name ASC")) {
print_heading($strcustomscales);

if (has_capability('moodle/course:managescales', $context)) {
Expand Down Expand Up @@ -58,7 +58,7 @@
}
}

if ($scales = get_records("scale", "courseid", "0", "name ASC")) {
if ($scales = $DB->get_records("scale", array("courseid"=>0), "name ASC")) {
print_heading($strstandardscales);
foreach ($scales as $scale) {
$scalemenu = make_menu_from_list($scale->scale);
Expand Down
Loading

0 comments on commit 6bb0816

Please sign in to comment.