Repository plugins: Difference between revisions
No edit summary |
mNo edit summary |
||
Line 9: | Line 9: | ||
==How it works== | ==How it works== | ||
== | ==APIs for File picker== | ||
===Methods you *MUST* override=== | |||
====__construct==== | |||
You may initialize you plugin here, such as: | |||
1) Get options from database | |||
2) Get user name and password from HTTP POST. | |||
== | ====get_listing==== | ||
This function will return a list of files, the list must be a array like this: | |||
<code php> | |||
$list = array( | |||
'path'=>'/var/repo/', | |||
'manage'=>'http://webmgr.moodle.com', | |||
array('title'=>'filename1', 'date'=>'01/01/2009', 'size'=>'10MB', 'source'=>'http://www.moodle.com/dl.rar'), | |||
array('title'=>'folder', 'date'=>'01/01/2009', 'size'=>'0', 'children'=>array()) | |||
); | |||
</code> | |||
The full specification: | |||
* array( | |||
* 'path' => (string) path for the current folder | |||
* 'dynload' => (bool) use dynamic loading, | |||
* 'manage' => (string) link to file manager, | |||
* 'nologin' => (bool) requires login, | |||
* 'nosearch' => (bool) no search link, | |||
* 'search_result' => (bool) this list is a searching result, | |||
* 'upload' => array( // upload manager | |||
* 'name' => (string) label of the form element, | |||
* 'id' => (string) id of the form element | |||
* ), | |||
* 'list' => array( | |||
* array( // file | |||
* 'title' => (string) file name, | |||
* 'date' => (string) file last modification time, usually userdate(...), | |||
* 'size' => (int) file size, | |||
* 'thumbnail' => (string) url to thumbnail for the file, | |||
* 'source' => plugin-dependent unique path to the file (id, url, path, etc.), | |||
* 'url'=> the accessible url of file | |||
* ), | |||
* array( // folder - same as file, but no 'source'. | |||
* 'title' => (string) folder name, | |||
* 'path' => (string) path to this folder | |||
* 'date' => (string) folder last modification time, usually userdate(...), | |||
* 'size' => 0, | |||
* 'thumbnail' => (string) url to thumbnail for the folder, | |||
* 'children' => array( // an empty folder needs to have 'children' defined, but empty. | |||
* // content (files and folders) | |||
* ) | |||
* ), | |||
* ) | |||
* ) | |||
===Methods you can override=== | |||
====print_login==== | |||
This function will help to print a login form, for ajax file picker, this function will return a | |||
PHP array to define this form. | |||
<code php> | |||
public function print_login(){ | |||
if ($this->options['ajax']) { | |||
$user_field->label = get_string('username', 'repository_boxnet').': '; | |||
$user_field->id = 'box_username'; | |||
$user_field->type = 'text'; | |||
$user_field->name = 'boxusername'; | |||
$user_field->value = $ret->username; | |||
$passwd_field->label = get_string('password', 'repository_boxnet').': '; | |||
$passwd_field->id = 'box_password'; | |||
$passwd_field->type = 'password'; | |||
$passwd_field->name = 'boxpassword'; | |||
$ret = array(); | |||
$ret['login'] = array($user_field, $passwd_field); | |||
return $ret; | |||
} | |||
} | |||
</code> | |||
This will help to generate a form by file picker which contains user name and password input elements. | |||
If your plugin don't require logging in, you don't need to override it, it will call get_listing to list files automatically by default. | |||
====check_login==== | |||
This function will return a boolean value to tell moodle whether the user has logged in. | |||
By default, this function will return true. | |||
====logout==== | |||
When user clicked logout button in file picker, this function will be called, you may clean up session or disconnect connection with remote server here. | |||
====global_search==== | |||
Moodle Repository API supports global search, this function will return a boolean value to tell Moodle if this plugin is ready to search, by default, it will return false, you need to override it to enable global search. | |||
====print_search==== | |||
When user clicked search button on file picker, this function will be called to return a search form, by default, it will create a form with single search bar, you can override it to create a advanced search form. | |||
====search==== | |||
This function will do the searching job, you can obtain the POST parameters from the from the form you created in print_search function | |||
This function will return a file list exactly like the one from get_listing. | |||
====get_file==== | |||
When user clicked "Get" button to transfer the file, this function will be called, basically, it will download a file to Moodle, you can override it to modify the file then move to a proper location. | |||
====get_name==== | |||
This function will return the name of the repository instance | |||
==APIs for Administration== | |||
==Officially supported repository plugins list== | |||
See: | |||
http://tracker.moodle.org/browse/MDL-16543 | |||
== Standard repository plugins == | == Standard repository plugins == |
Revision as of 05:23, 17 September 2008
Audience:
- Plug-in Developer
Related Documents:
How it works
APIs for File picker
Methods you *MUST* override
__construct
You may initialize you plugin here, such as: 1) Get options from database 2) Get user name and password from HTTP POST.
get_listing
This function will return a list of files, the list must be a array like this:
$list = array(
'path'=>'/var/repo/',
'manage'=>'http://webmgr.moodle.com',
array('title'=>'filename1', 'date'=>'01/01/2009', 'size'=>'10MB', 'source'=>'http://www.moodle.com/dl.rar'),
array('title'=>'folder', 'date'=>'01/01/2009', 'size'=>'0', 'children'=>array())
);
The full specification:
* array( * 'path' => (string) path for the current folder * 'dynload' => (bool) use dynamic loading, * 'manage' => (string) link to file manager, * 'nologin' => (bool) requires login, * 'nosearch' => (bool) no search link, * 'search_result' => (bool) this list is a searching result, * 'upload' => array( // upload manager * 'name' => (string) label of the form element, * 'id' => (string) id of the form element * ), * 'list' => array( * array( // file * 'title' => (string) file name, * 'date' => (string) file last modification time, usually userdate(...), * 'size' => (int) file size, * 'thumbnail' => (string) url to thumbnail for the file, * 'source' => plugin-dependent unique path to the file (id, url, path, etc.), * 'url'=> the accessible url of file * ), * array( // folder - same as file, but no 'source'. * 'title' => (string) folder name, * 'path' => (string) path to this folder * 'date' => (string) folder last modification time, usually userdate(...), * 'size' => 0, * 'thumbnail' => (string) url to thumbnail for the folder, * 'children' => array( // an empty folder needs to have 'children' defined, but empty. * // content (files and folders) * ) * ), * ) * )
Methods you can override
print_login
This function will help to print a login form, for ajax file picker, this function will return a
PHP array to define this form.
public function print_login(){
if ($this->options['ajax']) {
$user_field->label = get_string('username', 'repository_boxnet').': ';
$user_field->id = 'box_username';
$user_field->type = 'text';
$user_field->name = 'boxusername';
$user_field->value = $ret->username;
$passwd_field->label = get_string('password', 'repository_boxnet').': ';
$passwd_field->id = 'box_password';
$passwd_field->type = 'password';
$passwd_field->name = 'boxpassword';
$ret = array();
$ret['login'] = array($user_field, $passwd_field);
return $ret;
}
}
This will help to generate a form by file picker which contains user name and password input elements.
If your plugin don't require logging in, you don't need to override it, it will call get_listing to list files automatically by default.
check_login
This function will return a boolean value to tell moodle whether the user has logged in. By default, this function will return true.
logout
When user clicked logout button in file picker, this function will be called, you may clean up session or disconnect connection with remote server here.
global_search
Moodle Repository API supports global search, this function will return a boolean value to tell Moodle if this plugin is ready to search, by default, it will return false, you need to override it to enable global search.
print_search
When user clicked search button on file picker, this function will be called to return a search form, by default, it will create a form with single search bar, you can override it to create a advanced search form.
search
This function will do the searching job, you can obtain the POST parameters from the from the form you created in print_search function This function will return a file list exactly like the one from get_listing.
get_file
When user clicked "Get" button to transfer the file, this function will be called, basically, it will download a file to Moodle, you can override it to modify the file then move to a proper location.
get_name
This function will return the name of the repository instance
APIs for Administration
Officially supported repository plugins list
See: http://tracker.moodle.org/browse/MDL-16543
Standard repository plugins
This is the functional specification list of the officially supported repository plugins. For each plugins, the two mains part we are interesting in are:
- How do I administrate the plugin ( Repository Administration Specification - UC001-3)
- How do I setup an account for this repository ( Repository Interface for Moodle/Course/User)