Permalink
Browse files

Many many changes lumped in here ... not finished yet either.

Basically all the Database functions are in lib/datalib.php
and the web functions are all in lib/weblib.php, so
moodlelib.php is much thinner than it was.

Data functions have been extended ... most old calls will
still work, but now many more SQL commands can be performed
using the datalib functions rather than using SQL.  I'm
currently moving through the whole tree replacing SQL
calls or at least concentrating them in one section of
mod/xxx/lib.php

Still working on forums, quizzes, surveys, resources.

The tree is currently not full working ... some things are
half-completed ... will resume tomorrow.
  • Loading branch information...
1 parent 03f13d2 commit 9fa49e22abc3078b0855b411c1220337fc87d90d moodler committed Dec 20, 2002
View
@@ -125,14 +125,9 @@
/// Print list of potential admins
if ($search) {
- $users = get_records_sql("SELECT * from user WHERE confirmed = 1 AND deleted = 0
- AND (firstname LIKE '%$search%' OR
- lastname LIKE '%$search%' OR
- email LIKE '%$search%')
- AND username <> 'guest' AND username <> 'changeme'");
+ $users = get_users_search($search);
} else {
- $users = get_records_sql("SELECT * from user WHERE confirmed = 1 AND deleted = 0
- AND username <> 'guest' AND username <> 'changeme'");
+ $users = get_users_confirmed();
}
View
@@ -11,7 +11,7 @@
// eg wget -q -O /dev/null 'http://moodle.somewhere.edu/admin/cron.php'
// or php /web/moodle/admin/cron.php
- $FULLME = "we don't care";
+ $FULLME = "cron";
require("../config.php");
@@ -21,7 +21,7 @@
// Run all cron jobs for each module
- if ($mods = get_records_sql("SELECT * FROM modules WHERE cron > 0 AND (($timenow - lastcron) > cron)")) {
+ if ($mods = get_records_select("modules", "cron > 0 AND (($timenow - lastcron) > cron)")) {
foreach ($mods as $mod) {
$libfile = "$CFG->dirroot/mod/$mod->name/lib.php";
if (file_exists($libfile)) {
@@ -42,11 +42,8 @@
// Unenrol users who haven't logged in for $CFG->longtimenosee
if ($CFG->longtimenosee) { // value in days
- $cutofftime = $timenow - ($CFG->longtimenosee * 3600 * 24);
- if ($users = get_records_sql("SELECT u.* FROM user u, user_students s
- WHERE lastaccess > '0' AND
- lastaccess < '$cutofftime' AND
- u.id = s.user GROUP BY u.id")) {
+ $longtime = $timenow - ($CFG->longtimenosee * 3600 * 24);
+ if ($users = get_users_longtimenosee($longtime)) {
foreach ($users as $user) {
if (unenrol_student($user->id)) {
echo "Deleted student enrolment for $user->firstname $user->lastname ($user->id)\n";
@@ -58,11 +55,8 @@
// Delete users who haven't confirmed within seven days
- $cutofftime = $timenow - (7 * 24 * 3600);
- if ($users = get_records_sql("SELECT * FROM user
- WHERE confirmed = '0' AND
- firstaccess > '0' AND
- firstaccess < '$cutofftime'")) {
+ $oneweek = $timenow - (7 * 24 * 3600);
+ if ($users = get_users_unconfirmed($oneweek)) {
foreach ($users as $user) {
if (delete_records("user", "id", $user->id)) {
echo "Deleted unconfirmed user for $user->firstname $user->lastname ($user->id)\n";
View
@@ -205,16 +205,14 @@
include_once("$CFG->dirroot/lib/defaults.php");
- $CFG = (array)$CFG;
foreach ($defaults as $name => $value) {
- if (!isset($CFG[$name])) {
- $config->name = $name;
- $config->value = $CFG[$name] = $value;
- insert_record("config", $config);
+ if (!isset($CFG->$name)) {
+ $CFG->$name = $value;
+ set_config($name, $value);
$configchange = true;
}
}
- $CFG = (object)$CFG;
+
/// If any new configurations were found then send to the config page to check
@@ -228,7 +226,7 @@
}
/// Set up the admin user
- if (! record_exists_sql("SELECT * FROM user_admins")) { // No admin user yet
+ if (! record_exists("user_admins")) { // No admin user yet
redirect("user.php");
}
View
@@ -13,7 +13,7 @@
optional_variable($dir, "ASC");
optional_variable($page, 0);
- if (! record_exists_sql("SELECT * FROM user_admins")) { // No admin user yet
+ if (! record_exists("user_admins")) { // No admin user yet
$user->firstname = "Admin";
$user->lastname = "User";
$user->username = "admin";
@@ -126,11 +126,7 @@
// Carry on with the user listing
- if (!$user = get_record_sql("SELECT count(*) as count FROM user WHERE username <> 'guest' AND deleted <> '1'")) {
- error("Could not search for users?");
- }
-
- $usercount = $user->count;
+ $usercount = get_users_count();
$columns = array("name", "email", "city", "country", "lastaccess");
@@ -153,9 +149,7 @@
$sort = "firstname";
}
- if ($users = get_records_sql("SELECT id, username, email, firstname, lastname, city, country, lastaccess from user WHERE username <> 'guest'
- AND deleted <> '1' ORDER BY $sort $dir LIMIT $page,$recordsperpage")) {
-
+ if ($users = get_users_listing($sort, $dir, $page, $recordsperpage)) {
print_heading("$usercount ".get_string("users"));
$a->start = $page;
View
@@ -37,12 +37,14 @@
// a different database you will need to set up all your tables by hand //
// which could be a big job. See doc/install.html //
-$CFG->dbtype = "mysql"; // eg mysql (postgres7, oracle, access etc)
+$CFG->dbtype = "mysql"; // mysql or postgres7
$CFG->dbhost = "localhost"; // eg localhost
-$CFG->dbname = "moodle"; // eg moodle
+$CFG->dbname = "moodletest"; // eg moodle
$CFG->dbuser = "username";
$CFG->dbpass = "password";
+$CFG->prefix = "mdl_"; // Prefix value to use for all table names
+
///////////////////////////////////////////////////////////////////////////
// Now you need to tell Moodle where it is located. Specify the full
View
@@ -57,7 +57,7 @@
/// Get the existing categories
- if (!$categories = get_all_categories()) {
+ if (!$categories = get_categories()) {
// Try and make one
$cat->name = get_string("miscellaneous");
if ($cat->id = insert_record("course_categories", $cat)) {
@@ -86,7 +86,7 @@
}
/// Find any orphan courses that don't yet have a valid category and set to default
- if ($courses = get_records_sql("SELECT * FROM course WHERE category > 0")) {
+ if ($courses = get_courses()) {
foreach ($courses as $course) {
if (!isset( $categories[$course->category] )) {
set_field("course", "category", $default, "id", $course->id);
View
@@ -23,7 +23,7 @@
print_header("$site->shortname: $strdeletecourse", $site->fullname,
"<A HREF=\"$CFG->wwwroot/admin\">$stradministration</A> -> $strdeletecourse");
- if ($courses = get_records_sql("SELECT * from course WHERE category > 0 ORDER BY fullname")) {
+ if ($courses = get_courses()) {
print_heading(get_string("choosecourse"));
print_simple_box_start("CENTER");
foreach ($courses as $course) {
@@ -71,7 +71,7 @@
$strdeleted = get_string("deleted");
// First delete every instance of every module
- if ($allmods = get_records_sql("SELECT * FROM modules") ) {
+ if ($allmods = get_records("modules") ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$modfile = "../mod/$modname/lib.php";
View
@@ -96,7 +96,7 @@
}
}
- $form->categories = get_records_sql_menu("SELECT id,name FROM course_categories");
+ $form->categories = get_records_select_menu("course_categories", "", "name", "id,name");
$form->courseformats = array (
"weeks" => get_string("formatweeks"),
View
@@ -11,7 +11,7 @@
$strmycourses = get_string("mycourses");
$strfulllistofcourses = get_string("fulllistofcourses");
- if (!$categories = get_all_categories()) {
+ if (!$categories = get_categories()) {
error("Could not find any course categories!");
}
View
@@ -17,27 +17,16 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today"
$users = array();
if ($course->category) {
- if ($students = get_records_sql("SELECT u.* FROM user u, user_students s
- WHERE s.course = '$course->id' AND s.user = u.id
- ORDER BY u.lastaccess DESC")) {
- foreach ($students as $student) {
- $users["$student->id"] = "$student->firstname $student->lastname";
- }
- }
- if ($teachers = get_records_sql("SELECT u.* FROM user u, user_teachers t
- WHERE t.course = '$course->id' AND t.user = u.id
- ORDER BY u.lastaccess DESC")) {
- foreach ($teachers as $teacher) {
- $users["$teacher->id"] = "$teacher->firstname $teacher->lastname";
- }
+ if (!$users = get_course_users($course->id, "u.lastaccess DESC")) {
+ $users = array();
}
- if ($guest = get_user_info_from_db("username", "guest")) {
+ if ($guest = get_guest()) {
$users["$guest->id"] = "$guest->firstname $guest->lastname";
}
}
if (isadmin()) {
- if ($ccc = get_records_sql("SELECT * FROM course ORDER BY fullname")) {
+ if ($ccc = get_records("course", "", "", "fullname")) {
foreach ($ccc as $cc) {
if ($cc->category) {
$courses["$cc->id"] = "$cc->fullname";
@@ -121,7 +110,7 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
} else {
$selector = "WHERE l.user = u.id"; // Show all courses
- if ($ccc = get_records_sql("SELECT * FROM course ORDER BY fullname")) {
+ if ($ccc = get_courses(-1)) {
foreach ($ccc as $cc) {
$courses[$cc->id] = "$cc->shortname";
}
@@ -137,8 +126,7 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
$selector .= " AND l.time > '$date' AND l.time < '$enddate'";
}
- if (!$logs = get_records_sql("SELECT l.*, u.firstname, u.lastname, u.picture
- FROM log l, user u $selector $order")){
+ if (!$logs = get_logs($select, $order)) {
notify("No logs found!");
print_footer($course);
exit;
@@ -147,11 +135,13 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
$count=0;
$tt = getdate(time());
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
- echo "<P ALIGN=CENTER>Displaying ".count($logs)." records</P>";
+ echo "<P ALIGN=CENTER>";
+ print_string("displayingrecords", "", count($logs));
+ echo "</P>";
echo "<TABLE BORDER=0 ALIGN=center CELLPADDING=3 CELLSPACING=3>";
foreach ($logs as $log) {
- if ($ld = get_record_sql("SELECT * FROM log_display WHERE module='$log->module' AND action='$log->action'")) {
+ if ($ld = get_record("log_display", "module", "$log->module", "action", "$log->action")) {
$log->info = get_field($ld->mtable, $ld->field, "id", $log->info);
}
@@ -179,11 +169,11 @@ function print_all_courses($category="all", $style="full", $maxcount=999, $width
global $CFG, $USER;
if ($category == "all") {
- $courses = get_records_sql("SELECT * FROM course WHERE category > 0 ORDER BY fullname ASC");
+ $courses = get_courses();
} else if ($category == "my") {
if (isset($USER->id)) {
- if ($courses = get_records_sql("SELECT * FROM course WHERE category > 0 ORDER BY fullname ASC")) {
+ if ($courses = get_courses()) {
foreach ($courses as $key => $course) {
if (!isteacher($course->id) and !isstudent($course->id)) {
unset($courses[$key]);
@@ -193,7 +183,7 @@ function print_all_courses($category="all", $style="full", $maxcount=999, $width
}
} else {
- $courses = get_records("course", "category", $category, "fullname ASC");
+ $courses = get_courses($category);
}
if ($style == "minimal") {
@@ -297,7 +287,7 @@ function print_recent_activity($course) {
echo "</FONT></P>";
}
- if (! $logs = get_records_sql("SELECT * FROM log WHERE time > '$USER->lastlogin' AND course = '$course->id' ORDER BY time ASC")) {
+ if (! $logs = get_records_select("log", "time > '$USER->lastlogin' AND course = '$course->id'", "time ASC")) {
return;
}
@@ -400,11 +390,7 @@ function get_array_of_activities($courseid) {
$mod = array();
- if (!$rawmods = get_records_sql("SELECT cm.*, m.name as modname
- FROM modules m, course_modules cm
- WHERE cm.course = '$courseid'
- AND cm.deleted = '0'
- AND cm.module = m.id ") ) {
+ if (!$rawmods = get_course_mods($courseid)) {
return NULL;
}
@@ -435,7 +421,7 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname
$modnamesplural= NULL; // all course module names (plural form)
$modnamesused = NULL; // course module names used
- if ($allmods = get_records_sql("SELECT * FROM modules") ) {
+ if ($allmods = get_records("modules")) {
foreach ($allmods as $mod) {
$modnames[$mod->name] = get_string("modulename", "$mod->name");
$modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name");
@@ -445,11 +431,7 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname
error("No modules are installed!");
}
- if ($rawmods = get_records_sql("SELECT cm.*, m.name as modname
- FROM modules m, course_modules cm
- WHERE cm.course = '$courseid'
- AND cm.deleted = '0'
- AND cm.module = m.id ") ) {
+ if ($rawmods = get_course_mods($courseid)) {
foreach($rawmods as $mod) { // Index the mods
$mods[$mod->id] = $mod;
$mods[$mod->id]->modfullname = $modnames[$mod->modname];
@@ -459,17 +441,13 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname
}
}
+
function get_all_sections($courseid) {
- return get_records_sql("SELECT section, id, course, summary, sequence
- FROM course_sections
- WHERE course = '$courseid'
- ORDER BY section");
+ return get_records("course_sections", "course", "$courseid", "sections",
+ "section, id, course, summary, sequence");
}
-function get_all_categories() {
- return get_records_sql("SELECT * FROM course_categories ORDER by name");
-}
function print_section_block($heading, $course, $section, $mods, $modnames, $modnamesused,
$absolute=true, $width="100%", $isediting=false) {
@@ -684,7 +662,7 @@ function print_course_categories($categories, $selected="none", $width=180) {
$strrequireskey = get_string("requireskey");
if ($selected == "index") { // Print comprehensive index of categories with courses
- if ($courses = get_records_sql("SELECT * FROM course WHERE category > 0 ORDER BY shortname")) {
+ if ($courses = get_courses()) {
if (isset($USER->id) and !isadmin()) {
print_simple_box_start("CENTER", "100%", $THEME->cellheading);
print_heading("<A HREF=\"course/index.php?category=my\">".get_string("mycourses")."</A>", "LEFT");
@@ -773,9 +751,7 @@ function add_mod_to_section($mod) {
// Returns the course_sections ID where the mod is inserted
GLOBAL $db;
- if ($section = get_record_sql("SELECT * FROM course_sections
- WHERE course = '$mod->course' AND section = '$mod->section'") ) {
-
+ if ($section = get_record("course_sections", "course", "$mod->course", "section", "$mod->section")) {
if ($section->sequence) {
$newsequence = "$section->sequence,$mod->coursemodule";
} else {
@@ -857,9 +833,8 @@ function move_module($cm, $move) {
return true;
} else { // Push onto end of previous section
$prevsectionnumber = $thissection->section - 1;
- if (! $prevsection = get_record_sql("SELECT * FROM course_sections
- WHERE course='$thissection->course'
- AND section='$prevsectionnumber' ")) {
+ if (! $prevsection = get_record("course_sections", "course", "$thissection->course",
+ "section", "$prevsectionnumber")) {
error("Previous section ($prevsection->id) doesn't exist");
}
@@ -902,9 +877,8 @@ function move_module($cm, $move) {
if ($last) {
$nextsectionnumber = $thissection->section + 1;
- if ($nextsection = get_record_sql("SELECT * FROM course_sections
- WHERE course='$thissection->course'
- AND section='$nextsectionnumber' ")) {
+ if ($nextsection = get_record("course_sections", "course", "$thissection->course",
+ "section", "$nextsectionnumber")) {
if ($nextsection->sequence) {
$newsequence = "$cm->id,$nextsection->sequence";
Oops, something went wrong.

0 comments on commit 9fa49e2

Please sign in to comment.