protected function get_listing_my_unified()

in lib.php [577:650]


    protected function get_listing_my_unified($path = '') {
        global $USER;

        $path = (empty($path)) ? '/' : $path;
        $caller = '/repository_office365::get_listing_my_unified';

        $list = [];

        $unified = $this->get_unified_apiclient();
        $realpath = $path;

        // Generate path.
        $strmyfiles = get_string('myfiles', 'repository_office365');
        $breadcrumb = [['name' => $this->name, 'path' => '/'], ['name' => $strmyfiles, 'path' => '/my/']];

        if ($this->path_is_upload($path) === true) {
            $realpath = substr($path, 0, -strlen('/upload/'));
        } else {
            try {
                $o365userid = utils::get_o365_userid($USER->id);

                $filesresults = $unified->get_user_files($realpath, $o365userid);
                $contents = $filesresults['value'];
                while (!empty($filesresults['@odata.nextLink'])) {
                    $nextlink = parse_url($filesresults['@odata.nextLink']);
                    if (isset($nextlink['query'])) {
                        $query = [];
                        parse_str($nextlink['query'], $query);
                        if (isset($query['$skiptoken'])) {
                            $filesresults = $unified->get_user_files($realpath, $o365userid, $query['$skiptoken']);
                            $contents = array_merge($contents, $filesresults['value']);
                        }
                    }
                }

                $list = $this->contents_api_response_to_list($contents, $realpath, 'unified');
            } catch (\Exception $e) {
                $errmsg = 'Exception when retrieving personal onedrive files for folder';
                $debugdata = [
                    'fullpath' => $path,
                    'message' => $e->getMessage(),
                ];
                utils::debug($errmsg, $caller, $debugdata);
                return [[], $breadcrumb];
            }
        }

        if ($realpath !== '/') {
            $o365userid = utils::get_o365_userid($USER->id);
            $metadata = $unified->get_file_metadata($realpath, $o365userid);
            if (!empty($metadata['parentReference']) && !empty($metadata['parentReference']['path'])) {
                $parentrefpath = substr($metadata['parentReference']['path']
                  , (strpos($metadata['parentReference']['path'], ':') + 1));
                $cache = \cache::make('repository_office365', 'unifiedfolderids');
                $result = $cache->set($parentrefpath.'/'.$metadata['name'], $metadata['id']);
                if (!empty($parentrefpath)) {
                    $parentrefpath = explode('/', trim($parentrefpath, '/'));
                    $currentfullpath = '';
                    foreach ($parentrefpath as $folder) {
                        $currentfullpath .= '/'.$folder;
                        $folderid = $cache->get($currentfullpath);
                        $breadcrumb[] = ['name' => $folder, 'path' => '/my/'.$folderid];
                    }
                }
            }
            $breadcrumb[] = ['name' => $metadata['name'], 'path' => '/my/'.$metadata['id']];
        }

        if ($this->path_is_upload($path) === true) {
            $breadcrumb[] = ['name' => get_string('upload', 'repository_office365'), 'path' => '/my/'.$metadata['id'].'/upload/'];
        }

        return [$list, $breadcrumb];
    }