Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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.
13
//
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/>.
16
 
17
namespace repository_googledocs\local\browser;
18
 
19
use repository_googledocs\googledocs_content;
20
use repository_googledocs\helper;
21
 
22
/**
23
 * Utility class for browsing the content within the googledocs repository root.
24
 *
25
 * This class is responsible for generating the content that would be displayed in the googledocs repository root.
26
 *
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
30
 */
31
class googledocs_root_content extends googledocs_content {
32
 
33
    /**
34
     * Returns all relevant contents based on the given path or search query.
35
     *
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.
38
     *
39
     * @param string $query The search query
40
     * @return array The array containing the contents
41
     */
42
    protected function get_contents(string $query): array {
43
        // Add 'My drive' folder into the displayed contents.
44
        $contents = [
45
            (object)[
46
                'id' => \repository_googledocs::MY_DRIVE_ROOT_ID,
47
                'name' => get_string('mydrive', 'repository_googledocs'),
48
                'mimeType' => 'application/vnd.google-apps.folder',
49
                'modifiedTime' => '',
50
            ],
51
        ];
52
 
53
        // If shared drives exists, include 'Shared drives' folder to the displayed contents.
54
        $response = helper::request($this->service, 'shared_drives_list', []);
55
 
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',
61
                'modifiedTime' => '',
62
            ];
63
        }
64
 
65
        return $contents;
66
    }
67
}