[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/lib/ -> datalib.php (summary)

Library of functions for database manipulation. Other main libraries: - weblib.php - functions that produce web output - moodlelib.php - general-purpose Moodle functions

Author: Martin Dougiamas and many others
License: http://www.gnu.org/copyleft/gpl.html GNU Public License
File Size: 2280 lines (81 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 45 functions

  addslashes_object()
  get_admin()
  get_admins()
  get_courses_in_metacourse()
  get_courses_notin_metacourse()
  count_courses_notin_metacourse()
  search_users()
  get_site_users()
  get_users()
  get_users_listing()
  get_users_confirmed()
  get_site()
  get_courses()
  get_courses_page()
  get_courses_wmanagers()
  get_my_courses()
  get_courses_search()
  get_categories()
  get_all_subcategories()
  fix_course_sortorder()
  fix_coursecategory_orphans()
  get_my_remotecourses()
  get_my_remotehosts()
  make_default_scale()
  get_scales_menu()
  update_timezone_records()
  get_course_mods()
  get_coursemodule_from_id()
  get_coursemodule_from_instance()
  get_coursemodules_in_course()
  get_all_instances_in_courses()
  get_all_instances_in_course()
  instance_is_visible()
  coursemodule_visible_for_user()
  add_to_log()
  user_accesstime_log()
  get_logs()
  get_logs_usercourse()
  get_logs_userday()
  count_login_failures()
  print_object()
  course_parent_visible()
  xmldb_debug()
  user_can_create_courses()
  get_creatable_categories()

Functions
Functions that are not part of a class:

addslashes_object( $dataobject )   X-Ref
Escape all dangerous characters in a data record

$dataobject is an object containing needed data
Run over each field exectuting addslashes() function
to escape SQL unfriendly characters (e.g. quotes)
Handy when writing back data read from the database

param: $dataobject Object containing the database record
return: object Same object with neccessary characters escaped

get_admin()   X-Ref
Returns $user object of the main admin user
primary admin = admin with lowest role_assignment id among admins

return: object(admin) An associative array representing the admin user.

get_admins()   X-Ref
Returns list of all admins, using 1 DB query. It depends on DB schema v1.7
but does not depend on the v1.9 datastructures (context.path, etc).

return: object

get_courses_in_metacourse($metacourseid)   X-Ref
No description

get_courses_notin_metacourse($metacourseid,$count=false)   X-Ref
No description

count_courses_notin_metacourse($metacourseid)   X-Ref
No description

search_users($courseid, $groupid, $searchtext, $sort='', $exceptions='')   X-Ref
Search through course users

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

param: int $courseid The course in question.
param: int $groupid The group in question.
param: string $searchtext ?
param: string $sort ?
param: string $exceptions ?
return: object

get_site_users($sort='u.lastaccess DESC', $fields='*', $exceptions='')   X-Ref
Returns a list of all site users
Obsolete, just calls get_course_users(SITEID)

param: string $fields A comma separated list of fields to be returned from the chosen table.
return: object|false  {@link $USER} records or false if error.

get_users($get=true, $search='', $confirmed=false, $exceptions='', $sort='firstname ASC',$firstinitial='', $lastinitial='', $page='', $recordsperpage='', $fields='*', $extraselect='')   X-Ref
Returns a subset of users

param: bool $get If false then only a count of the records is returned
param: string $search A simple string to search for
param: bool $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: string $firstinitial ?
param: string $lastinitial ?
param: string $page ?
param: string $recordsperpage ?
param: string $fields A comma separated list of fields to be returned from the chosen table.
return: object|false|int  {@link $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.

get_users_listing($sort='lastaccess', $dir='ASC', $page=0, $recordsperpage=0,$search='', $firstinitial='', $lastinitial='', $extraselect='')   X-Ref
shortdesc (optional)

longdesc

param: string $sort ?
param: string $dir ?
param: int $categoryid ?
param: int $categoryid ?
param: string $search ?
param: string $firstinitial ?
param: string $lastinitial ?

get_users_confirmed()   X-Ref
Full list of users that have confirmed their accounts.

return: object

get_site()   X-Ref
Returns $course object of the top-level site.

return: course  A {@link $COURSE} object for the site

get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")   X-Ref
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

param: type description

get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c.*",&$totalcount, $limitfrom="", $limitnum="")   X-Ref
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

param: type description

get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()   X-Ref
No description

get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NULL, $doanything=false,$limit=0)   X-Ref
Convenience function - lists courses that a user has access to view.

For admins and others with access to "every" course in the system, we should
try to get courses with explicit RAs.

NOTE: this function is heavily geared towards the perspective of the user
passed in $userid. So it will hide courses that the user cannot see
(for any reason) even if called from cron or from another $USER's
perspective.

If you really want to know what courses are assigned to the user,
without any hiding or scheming, call the lower-level
get_user_courses_bycap().


Notes inherited from get_user_courses_bycap():

- $fields is an array of fieldnames to ADD
so name the fields you really need, which will
be added and uniq'd

- the course records have $c->context which is a fully
valid context object. Saves you a query per course!

param: int $userid The user of interest
param: string $sort the sortorder in the course table
param: array $fields - names of _additional_ fields to return (also accepts a string)
param: bool $doanything True if using the doanything flag
param: int $limit Maximum number of records to return, or 0 for unlimited
return: array {@link $COURSE} of course objects

get_courses_search($searchterms, $sort='fullname ASC', $page=0, $recordsperpage=50, &$totalcount)   X-Ref
A list of courses that match a search

param: array $searchterms ?
param: string $sort ?
param: int $page ?
param: int $recordsperpage ?
param: int $totalcount Passed in by reference. ?
return: object {@link $COURSE} records

get_categories($parent='none', $sort=NULL, $shallow=true)   X-Ref
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.


param: string $parent The parent category if any
param: string $sort the sortorder
param: bool   $shallow - set to false to get the children too
return: array of categories

get_all_subcategories($catid)   X-Ref
Returns an array of category ids of all the subcategories for a given
category.

param: $catid - The id of the category whose subcategories we want to find.
return: array of category ids.

fix_course_sortorder($categoryid=0, $n=0, $safe=0, $depth=0, $path='')   X-Ref
This recursive function makes sure that the courseorder is consecutive

param: type description

fix_coursecategory_orphans()   X-Ref
Ensure all courses have a valid course category
useful if a category has been removed manually


get_my_remotecourses($userid=0)   X-Ref
List of remote courses that a user has access to via MNET.
Works only on the IDP

return: array {@link $COURSE} of course objects

get_my_remotehosts()   X-Ref
List of remote hosts that a user has access to via MNET.
Works on the SP

return: array of host objects

make_default_scale()   X-Ref
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.


get_scales_menu($courseid=0)   X-Ref
Returns a menu of all available scales from the site as well as the given course

param: int $courseid The id of the course as found in the 'course' table.
return: object

update_timezone_records($timezones)   X-Ref
Given a set of timezone records, put them in the database,  replacing what is there

param: array $timezones An array of timezone records

get_course_mods($courseid)   X-Ref
Just gets a raw list of all modules in a course

param: int $courseid The id of the course as found in the 'course' table.
return: object

get_coursemodule_from_id($modulename, $cmid, $courseid=0)   X-Ref
Given an id of a course module, finds the coursemodule description

param: string $modulename name of module type, eg. resource, assignment,...
param: int $cmid course module id (id in course_modules table)
param: int $courseid optional course id for extra validation
return: object course module instance with instance and module name

get_coursemodule_from_instance($modulename, $instance, $courseid=0)   X-Ref
Given an instance number of a module, finds the coursemodule description

param: string $modulename name of module type, eg. resource, assignment,...
param: int $instance module instance number (id in resource, assignment etc. table)
param: int $courseid optional course id for extra validation
return: object course module instance with instance and module name

get_coursemodules_in_course($modulename, $courseid, $extrafields='')   X-Ref
Returns all course modules of given activity in course

param: string $modulename (forum, quiz, etc.)
param: int $courseid
param: string $extrafields extra fields starting with m.
return: array of cm objects, false if not found or error

get_all_instances_in_courses($modulename, $courses, $userid=NULL, $includeinvisible=false)   X-Ref
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.

param: string $modulename The name of the module to get instances for
param: array $courses an array of course objects.
return: array of module instance objects, including some extra fields from the course_modules

get_all_instances_in_course($modulename, $course, $userid=NULL, $includeinvisible=false)   X-Ref
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.

param: string $modulename The name of the module to get instances for
param: object $course The course obect.
return: array of module instance objects, including some extra fields from the course_modules

instance_is_visible($moduletype, $module)   X-Ref
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

param: $moduletype Name of the module eg 'forum'
param: $module Object which is the instance of the module
return: bool

coursemodule_visible_for_user($cm, $userid=0)   X-Ref
Determine whether a course module is visible within a course,
this is different from instance_is_visible() - faster and visibility for user

param: object $cm object
param: int $userid empty means current user
return: bool

add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0)   X-Ref
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.

param: int     $courseid  The course id
param: string  $module  The module name - e.g. forum, journal, resource, course, user etc
param: string  $action  'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
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

user_accesstime_log($courseid=0)   X-Ref
Store user last access times - called when use enters a course or site

Note: we use ADOdb code directly in this function to save some CPU
cycles here and there. They are simple operations not needing any
of the postprocessing performed by dmllib.php

param: int $courseid, empty means site
return: void

get_logs($select, $order='l.time DESC', $limitfrom='', $limitnum='', &$totalcount)   X-Ref
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 $limitfrom ?
param: int $limitnum ?
param: int $totalcount Passed in by reference.
return: object

get_logs_usercourse($userid, $courseid, $coursestart)   X-Ref
Select all log records for a given course and user

param: int $userid The id of the user as found in the 'user' table.
param: int $courseid The id of the course as found in the 'course' table.
param: string $coursestart ?

get_logs_userday($userid, $courseid, $daystart)   X-Ref
Select all log records for a given course, user, and day

param: int $userid The id of the user as found in the 'user' table.
param: int $courseid The id of the course as found in the 'course' table.
param: string $daystart ?
return: object

count_login_failures($mode, $username, $lastlogin)   X-Ref
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.

param: string $mode Either 'admin', 'teacher' or 'everybody'
param: string $username The username we are searching for
param: string $lastlogin The date from which we are searching
return: int

print_object($object)   X-Ref
Dump a given object's information in a PRE block.

Mostly just used for debugging.

param: mixed $object The data to be printed

course_parent_visible($course = null)   X-Ref
No description

xmldb_debug($message, $object)   X-Ref
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 ;-)

param: $message string contains the error message
param: $object object XMLDB object that fired the debug

user_can_create_courses()   X-Ref
true or false function to see if user can create any courses at all

return: bool

get_creatable_categories()   X-Ref
get the list of categories the current user can create courses in

return: array



Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7