Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 39 and 400] [Versions 400 and 402] [Versions 400 and 403]

This plugin is used to access Google Drive.

Copyright: 2009 Dan Poltawski <talktodan@gmail.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1224 lines (50 kb)
Included or required:0 times
Referenced: 2 times
Includes or requires: 0 files

Defines 1 class


Class: repository_googledocs  - X-Ref

Google Docs Plugin

__construct($repositoryid, $context = SYSCONTEXTID, $options = array()   X-Ref
Constructor.

return: void
param: int $repositoryid repository instance id.
param: int|stdClass $context a context id or context object.
param: array $options repository options.
param: int $readonly indicate this repo is readonly or not.

get_user_oauth_client($overrideurl = false)   X-Ref
Get a cached user authenticated oauth client.

return: \core\oauth2\client
param: moodle_url $overrideurl - Use this url instead of the repo callback.

check_login()   X-Ref
Checks whether the user is authenticate or not.

return: bool true when logged in.

print_login()   X-Ref
Print or return the login form.

return: void|array for ajax.

print_login_popup($attr = null)   X-Ref
Print the login in a popup.

param: array|null $attr Custom attributes to be applied to popup div.

build_breadcrumb($path)   X-Ref
Build the breadcrumb from a path.

return: array containing name and path of each crumb.
param: string $path to create a breadcrumb from.

build_node_path($id, $name = '', $root = '')   X-Ref
Generates a safe path to a node.

Typically, a node will be id|Name of the node.

return: string path to the node.
param: string $id of the node.
param: string $name of the node, will be URL encoded.
param: string $root to append the node on, must be a result of this function.

explode_node_path($node)   X-Ref
Returns information about a node in a path.

return: array about the node.
param: string $node to extrat information from.

get_listing($path='', $page = '')   X-Ref
List the files and folders.

return: array of result.
param: string $path path to browse.
param: string $page page to browse.

search($searchtext, $page = 0)   X-Ref
Search throughout the Google Drive.

return: array of results.
param: string $searchtext text to search for.
param: int $page search page.

query($q, $path = null, $page = 0)   X-Ref
Query Google Drive for files and folders using a search query.

Documentation about the query format can be found here:
https://developers.google.com/drive/search-parameters

This returns a list of files and folders with their details as they should be
formatted and returned by functions such as get_listing() or search().

return: array of files and folders.
param: string $q search query as expected by the Google API.
param: string $path parent path of the current files, will not be used for the query.
param: int $page page.

logout()   X-Ref
Logout.

return: string

get_file($reference, $filename = '')   X-Ref
Get a file.

return: string JSON encoded array of information about the file.
param: string $reference reference of the file.
param: string $file name to save the file to.

get_file_reference($source)   X-Ref
Prepare file reference information.

We are using this method to clean up the source to make sure that it
is a valid source.

return: string file reference.
param: string $source of the file.

supported_filetypes()   X-Ref
What kind of files will be in this repository?

return: array return '*' means this repository support any files, otherwise

supported_returntypes()   X-Ref
Tells how the file can be picked from this repository.

return: int

default_returntype()   X-Ref
Which return type should be selected by default.

return: int

get_type_option_names()   X-Ref
Return names of the general options.
By default: no general option name.

return: array

callback()   X-Ref
Store the access token.


send_file($storedfile, $lifetime=null , $filter=0, $forcedownload=false, array $options = null)   X-Ref
Repository method to serve the referenced file

param: stored_file $storedfile the file that contains the reference
param: int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime)
param: int $filter 0 (default)=no filtering, 1=all files, 2=html files only
param: bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
param: array $options additional options affecting the file serving

folder_exists_in_folder(\repository_googledocs\rest $client, $foldername, $parentid)   X-Ref
See if a folder exists within a folder

return: string|boolean The file id if it exists or false.
param: \repository_googledocs\rest $client Authenticated client.
param: string $foldername The folder we are looking for.
param: string $parentid The parent folder we are looking in.

create_folder_in_folder(\repository_googledocs\rest $client, $foldername, $parentid)   X-Ref
Create a folder within a folder

return: string The file id of the new folder.
param: \repository_googledocs\rest $client Authenticated client.
param: string $foldername The folder we are creating.
param: string $parentid The parent folder we are creating in.

get_file_summary(\repository_googledocs\rest $client, $fileid)   X-Ref
Get simple file info for humans.

return: stdClass
param: \repository_googledocs\rest $client Authenticated client.
param: string $fileid The file we are querying.

copy_file(\repository_googledocs\rest $client, $fileid, $name)   X-Ref
Copy a file and return the new file details. A side effect of the copy
is that the owner will be the account authenticated with this oauth client.

return: stdClass file details.
param: \repository_googledocs\rest $client Authenticated client.
param: string $fileid The file we are copying.
param: string $name The original filename (don't change it).

add_temp_writer_to_file(\repository_googledocs\rest $client, $fileid, $email)   X-Ref
Add a writer to the permissions on the file (temporary).

return: boolean
param: \repository_googledocs\rest $client Authenticated client.
param: string $fileid The file we are updating.
param: string $email The email of the writer account to add.

add_writer_to_file(\repository_googledocs\rest $client, $fileid, $email)   X-Ref
Add a writer to the permissions on the file.

return: boolean
param: \repository_googledocs\rest $client Authenticated client.
param: string $fileid The file we are updating.
param: string $email The email of the writer account to add.

move_file_from_root_to_folder(\repository_googledocs\rest $client, $fileid, $folderid)   X-Ref
Move from root to folder

return: boolean
param: \repository_googledocs\rest $client Authenticated client.
param: string $fileid The file we are updating.
param: string $folderid The id of the folder we are moving to

prevent_writers_from_sharing_file(\repository_googledocs\rest $client, $fileid)   X-Ref
Prevent writers from sharing.

return: boolean
param: \repository_googledocs\rest $client Authenticated client.
param: string $fileid The file we are updating.

set_file_sharing_anyone_with_link_can_read(\repository_googledocs\rest $client, $fileid)   X-Ref
Allow anyone with the link to read the file.

return: boolean
param: \repository_googledocs\rest $client Authenticated client.
param: string $fileid The file we are updating.

reference_file_selected($reference, $context, $component, $filearea, $itemid)   X-Ref
Called when a file is selected as a "link".
Invoked at MOODLE/repository/repository_ajax.php

This is called at the point the reference files are being copied from the draft area to the real area
(when the file has really really been selected.

return: string updated reference (final one before it's saved to db).
param: string $reference this reference is generated by
param: context $context the target context for this new file.
param: string $component the target component for this new file.
param: string $filearea the target filearea for this new file.
param: string $itemid the target itemid for this new file.

get_reference_details($reference, $filestatus = 0)   X-Ref
Get human readable file info from a the reference.

param: string $reference
param: int $filestatus

type_config_form($mform, $classname = 'repository')   X-Ref
Edit/Create Admin Settings Moodle form.

param: moodleform $mform Moodle form (passed by reference).
param: string $classname repository class name.

repository_googledocs_oauth2_system_scopes(\core\oauth2\issuer $issuer)   X-Ref
Callback to get the required scopes for system account.

return: string
param: \core\oauth2\issuer $issuer