Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/datalib.php File Reference

Go to the source code of this file.

Namespaces

namespace  core

Enumerations

enum  MAX_COURSES_IN_CATEGORY
enum  MAX_COURSE_CATEGORIES
enum  LASTACCESS_UPDATE_SECS

Functions

 get_admins ()
 search_users ($courseid, $groupid, $searchtext, $sort='', array $exceptions=null)
 get_users ($get=true, $search='', $confirmed=false, array $exceptions=null, $sort='firstname ASC', $firstinitial='', $lastinitial='', $page='', $recordsperpage='', $fields='*', $extraselect='', array $extraparams=null)
 get_users_listing ($sort='lastaccess', $dir='ASC', $page=0, $recordsperpage=0, $search='', $firstinitial='', $lastinitial='', $extraselect='', array $extraparams=null, $extracontext=null)
 get_users_confirmed ()
 get_site ()
 OTHER SITE AND COURSE FUNCTIONS /////////////////////////////////////////////.
 get_courses ($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
 get_courses_page ($categoryid="all", $sort="c.sortorder ASC", $fields="c.*", &$totalcount, $limitfrom="", $limitnum="")
 get_courses_wmanagers ($categoryid=0, $sort="c.sortorder ASC", $fields=array())
 get_courses_search ($searchterms, $sort='fullname ASC', $page=0, $recordsperpage=50, &$totalcount)
 get_categories ($parent='none', $sort=NULL, $shallow=true)
 get_all_subcategories ($catid)
 get_course_category ($catid=0)
 fix_course_sortorder ()
 _fix_course_cats ($children, &$sortorder, $parent, $depth, $path, &$fixcontexts)
 get_my_remotecourses ($userid=0)
 get_my_remotehosts ()
 make_default_scale ()
 get_scales_menu ($courseid=0)
 update_timezone_records ($timezones)
 get_course_mods ($courseid)
 MODULE FUNCTIONS /////////////////////////////////////////////////.
 get_coursemodule_from_id ($modulename, $cmid, $courseid=0, $sectionnum=false, $strictness=IGNORE_MISSING)
 get_coursemodule_from_instance ($modulename, $instance, $courseid=0, $sectionnum=false, $strictness=IGNORE_MISSING)
 get_coursemodules_in_course ($modulename, $courseid, $extrafields='')
 get_all_instances_in_courses ($modulename, $courses, $userid=NULL, $includeinvisible=false)
 get_all_instances_in_course ($modulename, $course, $userid=NULL, $includeinvisible=false)
 instance_is_visible ($moduletype, $module)
 coursemodule_visible_for_user ($cm, $userid=0)
 add_to_log ($courseid, $module, $action, $url='', $info='', $cm=0, $user=0)
 LOG FUNCTIONS /////////////////////////////////////////////////////.
 user_accesstime_log ($courseid=0)
 get_logs ($select, array $params=null, $order='l.time DESC', $limitfrom='', $limitnum='', &$totalcount)
 get_logs_usercourse ($userid, $courseid, $coursestart)
 get_logs_userday ($userid, $courseid, $daystart)
 count_login_failures ($mode, $username, $lastlogin)
 print_object ($object)
 GENERAL HELPFUL THINGS ///////////////////////////////////.
 xmldb_debug ($message, $object)
 user_can_create_courses ()

Enumeration Type Documentation

Number of seconds to wait before updating lastaccess information in DB.

Definition at line 48 of file datalib.php.

The maximum number of course categories MAX_COURSES_IN_CATEGORY * MAX_COURSE_CATEGORIES must not be more than max integer!

Definition at line 43 of file datalib.php.

The maximum courses in a category MAX_COURSES_IN_CATEGORY * MAX_COURSE_CATEGORIES must not be more than max integer!

Definition at line 37 of file datalib.php.


Function Documentation

_fix_course_cats ( children,
&$  sortorder,
parent,
depth,
path,
&$  fixcontexts 
)

Internal recursive category verification function, do not use directly!

Todo:
Document the arguments of this function better

object MAX_COURSES_IN_CATEGORY CONTEXT_COURSECAT

Parameters:
array$children
int$sortorder
string$parent
int$depth
string$path
array$fixcontexts
Returns:
void

Definition at line 1167 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

add_to_log ( courseid,
module,
action,
url = '',
info = '',
cm = 0,
user = 0 
)

LOG FUNCTIONS /////////////////////////////////////////////////////.

Add an entry to the log table.

Add an entry to the log table. These are "action" focussed rather than web server hits, and provide a way to easily reconstruct what any particular student has been doing.

object object object SITEID DEBUG_DEVELOPER DEBUG_ALL

Parameters:
int$courseidThe course id
string$moduleThe module name - e.g. forum, journal, resource, course, user etc
string$action'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
string$urlThe file and parameters used to see the results of the action
string$infoAdditional description information
string$cmThe course_module->id if there is one
string$userIf log regards $user other than $USER
Returns:
void

Definition at line 1667 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

count_login_failures ( mode,
username,
lastlogin 
)

Returns an object with counts of failed login attempts

Returns information about failed login attempts. If the current user is an admin, then two numbers are returned: the number of attempts and the number of accounts. For non-admins, only the attempts on the given user are shown.

object CONTEXT_SYSTEM

Parameters:
string$modeEither 'admin' or 'everybody'
string$usernameThe username we are searching for
string$lastloginThe date from which we are searching
Returns:
int

Definition at line 1935 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

coursemodule_visible_for_user ( cm,
userid = 0 
)

Determine whether a course module is visible within a course, this is different from instance_is_visible() - faster and visibility for user

object object DEBUG_DEVELOPER CONTEXT_MODULE CONDITION_MISSING_EXTRATABLE

Parameters:
object$cmobject
int$useridempty means current user
Returns:
bool Success

Definition at line 1614 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Fixes course category and course sortorder, also verifies category and course parents and paths. (circular references are not fixed)

object object MAX_COURSES_IN_CATEGORY MAX_COURSE_CATEGORIES SITEID CONTEXT_COURSE

Returns:
void

Definition at line 975 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns list of all admins, using 1 DB query

Returns:
array

Definition at line 89 of file datalib.php.

Here is the caller graph for this function:

get_all_instances_in_course ( modulename,
course,
userid = NULL,
includeinvisible = false 
)

Returns an array of all the active instances of a particular module in a given course, sorted in the order they are defined.

Returns an array of all the active instances of a particular module in a given course, sorted in the order they are defined in the course. Returns an empty array on any errors.

The returned objects includle the columns cw.section, cm.visible, cm.groupmode and cm.groupingid, cm.groupmembersonly, and are indexed by cm.id.

Simply calls all_instances_in_courses() with a single provided course

Parameters:
string$modulenameThe name of the module to get instances for
object$courseThe course obect.
Returns:
array of module instance objects, including some extra fields from the course_modules and course_sections tables, or an empty array if an error occurred.
Parameters:
int$userid
int$includeinvisible

Definition at line 1563 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_all_instances_in_courses ( modulename,
courses,
userid = NULL,
includeinvisible = false 
)

Returns an array of all the active instances of a particular module in given courses, sorted in the order they are defined

Returns an array of all the active instances of a particular module in given courses, sorted in the order they are defined in the course. Returns an empty array on any errors.

The returned objects includle the columns cw.section, cm.visible, cm.groupmode and cm.groupingid, cm.groupmembersonly, and are indexed by cm.id.

object object

Parameters:
string$modulenameThe name of the module to get instances for
array$coursesan array of course objects.
int$userid
int$includeinvisible
Returns:
array of module instance objects, including some extra fields from the course_modules and course_sections tables, or an empty array if an error occurred.

Definition at line 1494 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_all_subcategories ( catid)

Returns an array of category ids of all the subcategories for a given category.

object

Parameters:
int$catid- The id of the category whose subcategories we want to find.
Returns:
array of category ids.

Definition at line 907 of file datalib.php.

get_categories ( parent = 'none',
sort = NULL,
shallow = true 
)

Returns a sorted list of categories. Each category object has a context property that is a context object.

When asking for $parent='none' it will return all the categories, regardless of depth. Wheen asking for a specific parent, the default is to return a "shallow" resultset. Pass false to $shallow and it will return all the child categories as well.

object CONTEXT_COURSECAT

Parameters:
string$parentThe parent category if any
string$sortthe sortorder
bool$shallow- set to false to get the children too
Returns:
array of categories

Definition at line 846 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_course_category ( catid = 0)

Return specified category, default if given does not exist

object MAX_COURSES_IN_CATEGORY CONTEXT_COURSECAT SYSCONTEXTID

Parameters:
int$catidcourse category id
Returns:
object caregory

Definition at line 931 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_course_mods ( courseid)

MODULE FUNCTIONS /////////////////////////////////////////////////.

Just gets a raw list of all modules in a course

object

Parameters:
int$courseidThe id of the course as found in the 'course' table.
Returns:
array

Definition at line 1337 of file datalib.php.

Here is the caller graph for this function:

get_coursemodule_from_id ( modulename,
cmid,
courseid = 0,
sectionnum = false,
strictness = IGNORE_MISSING 
)

Given an id of a course module, finds the coursemodule description

object

Parameters:
string$modulenamename of module type, eg. resource, assignment,... (optional, slower and less safe if not specified)
int$cmidcourse module id (id in course_modules table)
int$courseidoptional course id for extra validation
bool$sectionnuminclude relative section number (0,1,2 ...)
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found
Returns:
stdClass

Definition at line 1364 of file datalib.php.

Here is the caller graph for this function:

get_coursemodule_from_instance ( modulename,
instance,
courseid = 0,
sectionnum = false,
strictness = IGNORE_MISSING 
)

Given an instance number of a module, finds the coursemodule description

object

Parameters:
string$modulenamename of module type, eg. resource, assignment,...
int$instancemodule instance number (id in resource, assignment etc. table)
int$courseidoptional course id for extra validation
bool$sectionnuminclude relative section number (0,1,2 ...)
int$strictnessIGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found
Returns:
stdClass

Definition at line 1418 of file datalib.php.

get_coursemodules_in_course ( modulename,
courseid,
extrafields = '' 
)

Returns all course modules of given activity in course

Parameters:
string$modulenameThe module name (forum, quiz, etc.)
int$courseidThe course id to get modules for
string$extrafieldsextra fields starting with m.
Returns:
array Array of results

Definition at line 1456 of file datalib.php.

get_courses ( categoryid = "all",
sort = "c.sortorder ASC",
fields = "c.*" 
)

Returns list of courses, for whole site, or category

Returns list of courses, for whole site, or category Important: Using c.* for fields is extremely expensive because we are using distinct. You almost _NEVER_ need all the fields in such a large SELECT

object object object CONTEXT_COURSE

Parameters:
string | int$categoryidEither a category id or 'all' for everything
string$sortA field and direction to sort by
string$fieldsThe additional fields to return
Returns:
array Array of courses

Definition at line 380 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_courses_page ( categoryid = "all",
sort = "c.sortorder ASC",
fields = "c.*",
&$  totalcount,
limitfrom = "",
limitnum = "" 
)

Returns list of courses, for whole site, or category

Similar to get_courses, but allows paging Important: Using c.* for fields is extremely expensive because we are using distinct. You almost _NEVER_ need all the fields in such a large SELECT

object object object CONTEXT_COURSE

Parameters:
string | int$categoryidEither a category id or 'all' for everything
string$sortA field and direction to sort by
string$fieldsThe additional fields to return
int$totalcountReference for the number of courses
string$limitfromThe course to start from
string$limitnumThe number of courses to limit to
Returns:
array Array of courses

Definition at line 449 of file datalib.php.

Here is the call graph for this function:

get_courses_search ( searchterms,
sort = 'fullname ASC',
page = 0,
recordsperpage = 50,
&$  totalcount 
)

A list of courses that match a search

object object

Parameters:
array$searchtermsAn array of search criteria
string$sortA field and direction to sort by
int$pageThe page number to get
int$recordsperpageThe number of records per page
int$totalcountPassed in by reference.
Returns:
object $COURSE records

Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle

will use it to simulate the "-" operator with LIKE clause

Under Oracle and MSSQL, trim the + and - operators and perform simpler LIKE (or NOT LIKE) queries

Definition at line 732 of file datalib.php.

Here is the call graph for this function:

get_courses_wmanagers ( categoryid = 0,
sort = "c.sortorder ASC",
fields = array() 
)

Retrieve course records with the course managers and other related records that we need for print_course(). This allows print_courses() to do its job in a constant number of DB queries, regardless of the number of courses, role assignments, etc.

The returned array is indexed on c.id, and each course will have

  • $course->managers - array containing RA objects that include a $user obj with the minimal fields needed for fullname()

object object object CONTEXT_COURSE CONTEXT_SYSTEM CONTEXT_COURSECAT SITEID

Parameters:
int | string$categoryidEither the categoryid for the courses or 'all'
string$sortA SQL sort field and direction
array$fieldsAn array of additional fields to fetch
Returns:
array

Definition at line 523 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_logs ( select,
array params = null,
order = 'l.time DESC',
limitfrom = '',
limitnum = '',
&$  totalcount 
)

Select all log records based on SQL criteria

Todo:
Finish documenting this function

object

Parameters:
string$selectSQL select criteria
array$paramsnamed sql type params
string$orderSQL order by clause to sort the records returned
string$limitfrom?
int$limitnum?
int$totalcountPassed in by reference.
Returns:
object

Definition at line 1830 of file datalib.php.

Here is the caller graph for this function:

get_logs_usercourse ( userid,
courseid,
coursestart 
)

Select all log records for a given course and user

Todo:
Finish documenting this function

object DAYSECS

Parameters:
int$useridThe id of the user as found in the 'user' table.
int$courseidThe id of the course as found in the 'course' table.
string$coursestart?

Definition at line 1871 of file datalib.php.

get_logs_userday ( userid,
courseid,
daystart 
)

Select all log records for a given course, user, and day

object HOURSECS

Parameters:
int$useridThe id of the user as found in the 'user' table.
int$courseidThe id of the course as found in the 'course' table.
string$daystart?
Returns:
object

Definition at line 1901 of file datalib.php.

get_my_remotecourses ( userid = 0)

List of remote courses that a user has access to via MNET. Works only on the IDP

object object

Parameters:
intThe user id to get remote courses for
Returns:
array Array of $COURSE of course objects

Definition at line 1207 of file datalib.php.

Here is the caller graph for this function:

List of remote hosts that a user has access to via MNET. Works on the SP

object object

Returns:
array|bool Array of host objects or false

Definition at line 1236 of file datalib.php.

Here is the caller graph for this function:

get_scales_menu ( courseid = 0)

Returns a menu of all available scales from the site as well as the given course

object

Parameters:
int$courseidThe id of the course as found in the 'course' table.
Returns:
array

Definition at line 1285 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_site ( )

OTHER SITE AND COURSE FUNCTIONS /////////////////////////////////////////////.

Returns $course object of the top-level site.

Returns:
object A $COURSE object for the site, exception if not found

Definition at line 347 of file datalib.php.

Here is the caller graph for this function:

get_users ( get = true,
search = '',
confirmed = false,
array exceptions = null,
sort = 'firstname ASC',
firstinitial = '',
lastinitial = '',
page = '',
recordsperpage = '',
fields = '*',
extraselect = '',
array extraparams = null 
)

Returns a subset of users

object DEBUG_DEVELOPER SQL_PARAMS_NAMED

Parameters:
bool$getIf false then only a count of the records is returned
string$searchA simple string to search for
bool$confirmedA switch to allow/disallow unconfirmed users
array$exceptionsA list of IDs to ignore, eg 2,4,5,8,9,10
string$sortA SQL snippet for the sorting criteria to use
string$firstinitialUsers whose first name starts with $firstinitial
string$lastinitialUsers whose last name starts with $lastinitial
string$pageThe page or records to return
string$recordsperpageThe number of records to return per page
string$fieldsA comma separated list of fields to be returned from the chosen table.
Returns:
array|int|bool $USER records unless get is false in which case the integer count of the records found is returned. False is returned if an error is encountered.

Definition at line 196 of file datalib.php.

Here is the call graph for this function:

Full list of users that have confirmed their accounts.

object

Returns:
array of unconfirmed users

Definition at line 331 of file datalib.php.

get_users_listing ( sort = 'lastaccess',
dir = 'ASC',
page = 0,
recordsperpage = 0,
search = '',
firstinitial = '',
lastinitial = '',
extraselect = '',
array extraparams = null,
extracontext = null 
)
Todo:
Finish documenting this function
Parameters:
string$sortAn SQL field to sort by
string$dirThe sort direction ASC|DESC
int$pageThe page or records to return
int$recordsperpageThe number of records to return per page
string$searchA simple string to search for
string$firstinitialUsers whose first name starts with $firstinitial
string$lastinitialUsers whose last name starts with $lastinitial
string$extraselectAn additional SQL select statement to append to the query
array$extraparamsAdditional parameters to use for the above $extraselect
object$extracontextIf specified, will include user 'extra fields' as appropriate for current user and given context
Returns:
array Array of $USER records

Definition at line 268 of file datalib.php.

Here is the call graph for this function:

instance_is_visible ( moduletype,
module 
)

Determine whether a module instance is visible within a course

Given a valid module object with info about the id and course, and the module's type (eg "forum") returns whether the object is visible or not, groupmembersonly visibility not tested

object

Parameters:
$moduletypeName of the module eg 'forum'
$moduleObject which is the instance of the module
Returns:
bool Success

Definition at line 1581 of file datalib.php.

Here is the caller graph for this function:

This function creates a default separated/connected scale

This function creates a default separated/connected scale so there's something in the database. The locations of strings and files is a bit odd, but this is because we need to maintain backward compatibility with many different existing language translations and older sites.

object

Returns:
void

Definition at line 1260 of file datalib.php.

Here is the caller graph for this function:

print_object ( object)

GENERAL HELPFUL THINGS ///////////////////////////////////.

Dumps a given object's information for debugging purposes

When used in a CLI script, the object's information is written to the standard error output stream. When used in a web script, the object is dumped to a pre-formatted block with the "notifytiny" CSS class.

Parameters:
mixed$objectThe data to be printed
Returns:
void output is echo'd

Definition at line 1969 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

search_users ( courseid,
groupid,
searchtext,
sort = '',
array exceptions = null 
)

Search through course users

If $coursid specifies the site course then this function searches through all undeleted and confirmed users

object SITEID SQL_PARAMS_NAMED CONTEXT_COURSE

Parameters:
int$courseidThe course in question.
int$groupidThe group in question.
string$searchtextThe string to search for
string$sortA field to sort by
array$exceptionsA list of IDs to ignore, eg 2,4,5,8,9,10
Returns:
array

Definition at line 120 of file datalib.php.

Here is the call graph for this function:

update_timezone_records ( timezones)

Given a set of timezone records, put them in the database, replacing what is there

object

Parameters:
array$timezonesAn array of timezone records
Returns:
void

Clear out all the old stuff

Insert all the new stuff

Definition at line 1312 of file datalib.php.

user_accesstime_log ( courseid = 0)

Store user last access times - called when use enters a course or site

object object object LASTACCESS_UPDATE_SECS SITEID

Parameters:
int$courseid,emptymeans site
Returns:
void

Store site lastaccess time for the current user

Update $USER->lastaccess for next checks

no user_lastaccess for frontpage

Store course lastaccess times for the current user

Definition at line 1757 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

object CONTEXT_COURSECAT

Returns:
boolean Whether the user can create courses in any category in the system.

Definition at line 2003 of file datalib.php.

Here is the call graph for this function:

xmldb_debug ( message,
object 
)

This function is the official hook inside XMLDB stuff to delegate its debug to one external function.

Any script can avoid calls to this function by defining XMLDB_SKIP_DEBUG_HOOK before using XMLDB classes. Obviously, also, if this function doesn't exist, it isn't invoked ;-)

DEBUG_DEVELOPER

Parameters:
string$messagestring contains the error message
object$objectobject XMLDB object that fired the debug

Definition at line 1993 of file datalib.php.

Here is the call graph for this function:

 All Data Structures Namespaces Files Functions Variables Enumerations