MDL-61768 repository_googledocs: Support shared drives
[moodle.git] / repository / googledocs / classes / local / browser / googledocs_shared_drives_content.php
blob2c7e8fdf3ada00a663ae96441d666c7e65406bde
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 namespace repository_googledocs\local\browser;
19 use repository_googledocs\googledocs_content;
20 use repository_googledocs\helper;
22 /**
23 * Utility class for browsing the content within the googledocs repository shared drives root.
25 * This class is responsible for generating the content that would be displayed in the googledocs repository
26 * shared drives root.
28 * @package repository_googledocs
29 * @copyright 2021 Mihail Geshoski <mihail@moodle.com>
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 class googledocs_shared_drives_content extends googledocs_content {
34 /**
35 * Returns all relevant contents based on the given path or search query.
37 * The method generates the content which will be displayed in the repository shared drives root level.
38 * All existing shared drives will be fetched through an API call and presented as folders.
40 * @param string $query The search query
41 * @return array The array containing the contents
43 protected function get_contents(string $query): array {
44 // Make an API request to get all existing shared drives.
45 $response = helper::request($this->service, 'shared_drives_list', []);
46 // If shared drives exist, create folder for each shared drive.
47 if ($shareddrives = $response->drives) {
48 return array_map(function($shareddrive) {
49 return (object)[
50 'id' => $shareddrive->id,
51 'name' => $shareddrive->name,
52 'mimeType' => 'application/vnd.google-apps.folder',
53 'modifiedTime' => '',
55 }, $shareddrives);
58 return [];