2 // This file is part of Moodle - http://moodle.org/
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.
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
;
23 * Utility class for browsing the content within the googledocs repository root.
25 * This class is responsible for generating the content that would be displayed in the googledocs repository root.
27 * @package repository_googledocs
28 * @copyright 2021 Mihail Geshoski <mihail@moodle.com>
29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 class googledocs_root_content
extends googledocs_content
{
34 * Returns all relevant contents based on the given path or search query.
36 * The method predefines the content which will be displayed in the repository root level. Currently,
37 * only the folders representing 'My drives' and 'Shared drives' will be displayed in the root level.
39 * @param string $query The search query
40 * @return array The array containing the contents
42 protected function get_contents(string $query): array {
43 // Add 'My drive' folder into the displayed contents.
46 'id' => \repository_googledocs
::MY_DRIVE_ROOT_ID
,
47 'name' => get_string('mydrive', 'repository_googledocs'),
48 'mimeType' => 'application/vnd.google-apps.folder',
53 // If shared drives exists, include 'Shared drives' folder to the displayed contents.
54 $response = helper
::request($this->service
, 'shared_drives_list', []);
56 if (!empty($response->drives
)) {
57 $contents[] = (object)[
58 'id' => \repository_googledocs
::SHARED_DRIVES_ROOT_ID
,
59 'name' => get_string('shareddrives', 'repository_googledocs'),
60 'mimeType' => 'application/vnd.google-apps.folder',