*
* Completely general function - it just runs some SQL and reports success.
*
-* @param type description
+* @param type description
*/
function execute_sql($command, $feedback=true) {
/// Completely general function - it just runs some SQL and reports success.
* Lines that are blank or that start with "#" are ignored.
* Only tested with mysql dump files (mysqldump -p -d moodle)
*
-* @param type description
+* @param type description
*/
function modify_database($sqlfile="", $sqlstring="") {
*
* Add a new field to a table, or modify an existing one (if oldfield is defined).
*
-* @param type description
+* @param type description
*/
function table_column($table, $oldfield, $field, $type="integer", $size="10",
*
* Returns true or false depending on whether the specified record exists
*
-* @param type description
+* @param type description
*/
function record_exists($table, $field1="", $value1="", $field2="", $value2="", $field3="", $value3="") {
*
* The sql statement is provided as a string.
*
-* @param type description
+* @param type description
*/
function record_exists_sql($sql) {
*
* Get all the records and count them
*
-* @param type description
+* @param type description
*/
function count_records($table, $field1="", $value1="", $field2="", $value2="", $field3="", $value3="") {
*
* Get all the records and count them
*
-* @param type description
+* @param type description
*
*/
function count_records_select($table, $select="") {
*
* The sql statement is provided as a string.
*
-* @param type description
+* @param type description
*/
function count_records_sql($sql) {
*
* Get a single record as an object
*
-* @param string $table the name of the table to select from
-* @param string $field1 the name of the field for the first criteria
-* @param string $value1 the value of the field for the first criteria
-* @param string $field2 the name of the field for the second criteria
-* @param string $value2 the value of the field for the second criteria
-* @param string $field3 the name of the field for the third criteria
-* @param string $value3 the value of the field for the third criteria
-* @return object(fieldset) a fieldset object containing the first record selected
+* @param string $table the name of the table to select from
+* @param string $field1 the name of the field for the first criteria
+* @param string $value1 the value of the field for the first criteria
+* @param string $field2 the name of the field for the second criteria
+* @param string $value2 the value of the field for the second criteria
+* @param string $field3 the name of the field for the third criteria
+* @param string $value3 the value of the field for the third criteria
+* @return object(fieldset) a fieldset object containing the first record selected
*/
function get_record($table, $field1, $value1, $field2="", $value2="", $field3="", $value3="") {
-
+
global $CFG;
$select = "WHERE $field1 = '$value1'";
* The sql statement is provided as a string.
* A LIMIT is normally added to only look for 1 record
*
-* @param type description
+* @param type description
*/
function get_record_sql($sql) {
*
* "select" is a fragment of SQL to define the selection criteria
*
-* @param type description
+* @param type description
*/
function get_record_select($table, $select="", $fields="*") {
* The "key" is the first column returned, eg usually "id"
* limitfrom and limitnum must both be specified or not at all
*
-* @param type description
+* @param type description
*/
function get_records($table, $field="", $value="", $sort="", $fields="*", $limitfrom="", $limitnum="") {
* The "key" is the first column returned, eg usually "id"
* limitfrom and limitnum must both be specified or not at all
*
-* @param type description
+* @param type description
*/
function get_records_select($table, $select="", $sort="", $fields="*", $limitfrom="", $limitnum="") {
* Can optionally be sorted eg "time ASC" or "time DESC"
* The "key" is the first column returned, eg usually "id"
*
-* @param type description
+* @param type description
*/
function get_records_list($table, $field="", $values="", $sort="", $fields="*") {
* The "key" is the first column returned, eg usually "id"
* The sql statement is provided as a string.
*
-* @param type description
+* @param type description
*/
function get_records_sql($sql) {
* If "fields" is specified, only those fields are returned
* The "key" is the first column returned, eg usually "id"
*
-* @param type description
+* @param type description
*/
function get_records_menu($table, $field="", $value="", $sort="", $fields="*") {
* "select" is a fragment of SQL to define the selection criteria
* Returns associative array of first two fields
*
-* @param type description
+* @param type description
*/
function get_records_select_menu($table, $select="", $sort="", $fields="*") {
* combination with the choose_from_menu function to create
* a form menu.
*
-* @param type description
+* @param type description
*/
function get_records_sql_menu($sql) {
*
* longdesc
*
-* @param type description
+* @param type description
*/
function get_field($table, $return, $field1, $value1, $field2="", $value2="", $field3="", $value3="") {
*
* longdesc
*
-* @param type description
+* @param type description
*/
function set_field($table, $newfield, $newvalue, $field1, $value1, $field2="", $value2="", $field3="", $value3="") {
*
* Delete one or more records from a table
*
-* @param type description
+* @param type description
*/
function delete_records($table, $field1="", $value1="", $field2="", $value2="", $field3="", $value3="") {
*
* "select" is a fragment of SQL to define the selection criteria
*
-* @param type description
+* @param type description
*/
function delete_records_select($table, $select="") {
* If the return ID isn't required, then this just reports success as true/false.
* $dataobject is an object containing needed data
*
-* @param type description
+* @param type description
*/
function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
* Relies on $dataobject having a variable "id" to
* specify the record to update
*
-* @param type description
+* @param type description
*/
function update_record($table, $dataobject) {
* in the user record, as well as membership information
* Suitable for setting as $USER session cookie.
*
-* @param type description
+* @param type description
*/
function get_user_info_from_db($field, $value) {
*
* longdesc
*
-* @param type description
+* @param type description
*/
function adminlogin($username, $md5password) {
*
* longdesc
*
-* @param type description
+* @param type description
*/
function get_guest() {
return get_user_info_from_db("username", "guest");
*
* longdesc
*
-* @param type description
+* @param type description
*/
function get_admin () {
*
* longdesc
*
-* @param type description
+* @param type description
*/
function get_admins() {
*
* longdesc
*
-* @param type description
+* @param type description
*/
function get_creators() {
*
* longdesc
*
-* @param type description
+* @param type description
*/
function get_teacher($courseid) {
*
* used to print recent activity
*
-* @param type description
+* @param type description
*/
function get_recent_enrolments($courseid, $timestart) {
/**
* Returns list of all students in this course
*
-* @param type description
+* @param type description
*/
function get_course_students($courseid, $sort="s.timeaccess", $dir="", $page=0, $recordsperpage=99999,
$firstinitial="", $lastinitial="", $group=NULL, $search="") {
/**
* Counts the students in a given course, or a subset of them
*
-* @param type description
+* @param type description
*/
function count_course_students($course, $search="", $firstinitial="", $lastinitial="", $group=NULL) {
/**
* Returns list of all teachers in this course
*
-* @param type description
+* @param type description
*/
function get_course_teachers($courseid, $sort="t.authority ASC") {
*
* If the "course" is actually the site, then return all site users.
*
-* @param type description
+* @param type description
*/
function get_course_users($courseid, $sort="timeaccess DESC") {
*
* or teaching in courses on this server
*
-* @param type description
+* @param type description
*/
function get_site_users($sort="u.lastaccess DESC", $select="") {
*
* longdesc
*
-* @param bookean $get if false then only a count of the records is returned
-* @param string $search a simple string to search for
-* @param boolean $confirmed a switch to allow/disallow unconfirmed users
-* @param array(int) $exceptions a list of IDs to ignore, eg 2,4,5,8,9,10
-* @param string $sort a SQL snippet for the sorting criteria to use
+* @param bookean $get if false then only a count of the records is returned
+* @param string $search a simple string to search for
+* @param boolean $confirmed a switch to allow/disallow unconfirmed users
+* @param array(int) $exceptions a list of IDs to ignore, eg 2,4,5,8,9,10
+* @param string $sort a SQL snippet for the sorting criteria to use
*/
function get_users($get=true, $search="", $confirmed=false, $exceptions="", $sort="firstname ASC",
$firstinitial="", $lastinitial="") {
*
* longdesc
*
-* @param type description
+* @param type description
*/
function get_users_listing($sort="lastaccess", $dir="ASC", $page=0, $recordsperpage=99999,
$search="", $firstinitial="", $lastinitial="") {
*
* longdesc
*
-* @param type description
+* @param type description
*/
function get_users_confirmed() {
global $CFG;
*
* longdesc
*
-* @param type description
+* @param type description
*/
function get_users_unconfirmed($cutofftime=2000000000) {
global $CFG;
*
* longdesc
*
-* @param type description
+* @param type description
*/
function get_users_longtimenosee($cutofftime) {
global $CFG;
* in the given course. If userid isn't specified, then return a
* list of all groups in the course.
*
-* @param type description
+* @param type description
*/
function get_groups($courseid, $userid=0) {
global $CFG;
/**
* Returns an array of user objects
*
-* @param type description
+* @param type description
*/
function get_group_users($groupid, $sort="u.lastaccess DESC") {
global $CFG;
/**
* An efficient way of finding all the users who aren't in groups yet
*
-* @param type description
+* @param type description
*/
function get_users_not_in_group($courseid) {
global $CFG;
/**
* Returns an array of user objects
*
-* @param type description
+* @param type description
*/
function get_group_students($groupid, $sort="u.lastaccess DESC") {
global $CFG;
/**
* Returns the user's group in a particular course
*
-* @param type description
+* @param type description
*/
function user_group($courseid, $userid) {
global $CFG;
*
* Returns $course object of the top-level site.
*
-* @param type description
+* @param type description
*/
function get_site () {
*
* Returns list of courses, for whole site, or category
*
-* @param type description
+* @param type description
*/
function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*") {
*
* Similar to get_courses, but allows paging
*
-* @param type description
+* @param type description
*/
function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c.*",
&$totalcount, $limitfrom="", $limitnum="") {
*
* longdesc
*
-* @param type description
+* @param type description
*/
-function get_my_courses($userid, $sort="visible DESC,fullname ASC") {
+function get_my_courses($userid, $sort="visible DESC,sortorder ASC") {
global $CFG;
*
* Returns a list of courses that match a search
*
-* @param type description
+* @param type description
*/
function get_courses_search($searchterms, $sort="fullname ASC", $page=0, $recordsperpage=50, &$totalcount) {
*
* Returns a sorted list of categories
*
-* @param type description
+* @param type description
*/
function get_categories($parent="none", $sort="sortorder ASC") {
/**
-* reconcile $courseorder with a category object
-*
-* Given a category object, this function makes sure the courseorder
-* variable reflects the real world.
+* This recursive function makes sure that the courseorder is consecutive
*
-* @param type description
+* @param type description
*/
-function fix_course_sortorder($categoryid, $sort="sortorder ASC") {
-
- if (!$courses = get_records("course", "category", "$categoryid", "$sort", "id, sortorder")) {
- set_field("course_categories", "coursecount", 0, "id", $categoryid);
- return true;
- }
-
+function fix_course_sortorder($categoryid=0, $n=0) {
+
$count = 0;
- $modified = false;
-
- foreach ($courses as $course) {
- if ($course->sortorder != $count) {
- set_field("course", "sortorder", $count, "id", $course->id);
- $modified = true;
+ if ($courses = get_courses($categoryid)) {
+ foreach ($courses as $course) {
+ set_field('course', 'sortorder', $n, 'id', $course->id);
+ $n++;
+ $count++;
}
- $count++;
- }
-
- if ($modified) {
- set_field("course_categories", "timemodified", time(), "id", $categoryid);
}
set_field("course_categories", "coursecount", $count, "id", $categoryid);
-
- return true;
+
+ if ($categories = get_categories($categoryid)) {
+ foreach ($categories as $category) {
+ $n = fix_course_sortorder($category->id, $n);
+ }
+ }
+
+ return $n;
}
/**
* need to maintain backward compatibility with many different
* existing language translations and older sites.
*
-* @param type description
+* @param type description
*/
function make_default_scale() {
*
* Returns a menu of all available scales from the site as well as the given course
*
-* @param type description
+* @param type description
*/
function get_scales_menu($courseid=0) {
*
* Just gets a raw list of all modules in a course
*
-* @param type description
+* @param type description
*/
function get_course_mods($courseid) {
global $CFG;
*
* Given an instance of a module, finds the coursemodule description
*
-* @param type description
+* @param type description
*/
function get_coursemodule_from_instance($modulename, $instance, $courseid) {
* module in a given course, sorted in the order they are defined
* in the course. Returns false on any errors.
*
-* @param string $modulename the name of the module to get instances for
-* @param object(course) $course this depends on an accurate $course->modinfo
+* @param string $modulename the name of the module to get instances for
+* @param object(course) $course this depends on an accurate $course->modinfo
*/
function get_all_instances_in_course($modulename, $course) {
* and the module's type (eg "forum") returns whether the object
* is visible or not
*
-* @param type description
+* @param type description
*/
function instance_is_visible($moduletype, $module) {
* than web server hits, and provide a way to easily reconstruct what
* any particular student has been doing.
*
-* @param int $course the course id
-* @param string $module the module name - e.g. forum, journal, resource, course, user etc
-* @param string $action view, edit, post (often but not always the same as the file.php)
-* @param string $url the file and parameters used to see the results of the action
-* @param string $info additional description information
-* @param string $cm the course_module->id if there is one
-* @param string $user if log regards $user other than $USER
+* @param int $course the course id
+* @param string $module the module name - e.g. forum, journal, resource, course, user etc
+* @param string $action view, edit, post (often but not always the same as the file.php)
+* @param string $url the file and parameters used to see the results of the action
+* @param string $info additional description information
+* @param string $cm the course_module->id if there is one
+* @param string $user if log regards $user other than $USER
*/
function add_to_log($courseid, $module, $action, $url="", $info="", $cm=0, $user=0) {
*
* select all log records based on SQL criteria
*
-* @param string $select SQL select criteria
-* @param string $order SQL order by clause to sort the records returned
+* @param string $select SQL select criteria
+* @param string $order SQL order by clause to sort the records returned
*/
function get_logs($select, $order="l.time DESC", $limitfrom="", $limitnum="", &$totalcount) {
global $CFG;
*
* select all log records for a given course and user
*
-* @param type description
+* @param type description
*/
function get_logs_usercourse($userid, $courseid, $coursestart) {
global $CFG;
*
* select all log records for a given course, user, and day
*
-* @param type description
+* @param type description
*/
function get_logs_userday($userid, $courseid, $daystart) {
global $CFG;
* dump a given object's information in a PRE block
* Mostly just for debugging
*
-* @param type description
+* @param type description
*/
function print_object($object) {