Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Preference API: Difference between revisions

From MoodleDocs
No edit summary
Line 5: Line 5:
  |}
  |}
  <noinclude>
  <noinclude>


==Preference API database table==
==Preference API database table==
Line 37: Line 36:
|}
|}


==Preference API Usage==
==Preference API overview==
 
The Preference API has been implemented in lib/moodlelib.php. It's used for the storage and retrieval of user preferences. These preferences are stored in the database for users with an account, however for guests or people who are not logged in the preferences are stored in a PHP Session. All of these functions operate on the current user by default, however you can specify the user you wish to operate on by passing a user ID or a moodle user object to the $user parameter.
 
====get_user_preferences($name = null, $default = null, $user = null)====
This function can be used to fetch a given preference and return the value given in $default if that value does not exist. If you do not specify a $name then all preferences will be returned.
 
====set_user_preference($name, $value, $user = null)====
Example function description.
 
====set_user_preferences(array $prefarray, $user = null)====
Example function description.


===Title for the example goes here===
====unset_user_preference($name, $user = null)====
Example function description.


Description of the example:
====set_user_preference($name, $value, $user = null)====
Example function description.


<code php>
==Preference API Usage==
shortexamplecode();
</code>


===Title for the second example goes here===
===Title for the example goes here===


Description of the example:
Description of the example:
Line 54: Line 64:
shortexamplecode();
shortexamplecode();
</code>
</code>
==Preference API overview==
The Preference API has been implemented in lib/moodlelib.php.
====examplefunction()====
Example function description.


==See also==
==See also==

Revision as of 08:22, 12 January 2012

Moodle 2.0


WORK IN PROGRESS: I've currently just created a template, so please ignore this page until this wip notices has been removed. However, you are free to help in the construction of this page by improving it. Please review the tion=history edit history if you would like to contact the user who put up this notice. If this article has not been edited by that user in a while, please remove this template.


Preference API database table

Field Type Default Info
id unsigned int(10) auto-incrementing The unique ID for this preference.
userid unsigned int(10) The user that the preference belongs to
name varchar(255) The name of the preference
value varchar(255) The value of the preference

Preference API overview

The Preference API has been implemented in lib/moodlelib.php. It's used for the storage and retrieval of user preferences. These preferences are stored in the database for users with an account, however for guests or people who are not logged in the preferences are stored in a PHP Session. All of these functions operate on the current user by default, however you can specify the user you wish to operate on by passing a user ID or a moodle user object to the $user parameter.

get_user_preferences($name = null, $default = null, $user = null)

This function can be used to fetch a given preference and return the value given in $default if that value does not exist. If you do not specify a $name then all preferences will be returned.

set_user_preference($name, $value, $user = null)

Example function description.

set_user_preferences(array $prefarray, $user = null)

Example function description.

unset_user_preference($name, $user = null)

Example function description.

set_user_preference($name, $value, $user = null)

Example function description.

Preference API Usage

Title for the example goes here

Description of the example:

shortexamplecode();

See also