protected function render_onenote()

in block_microsoft.php [538:602]


    protected function render_onenote() {
        global $USER;

        if (empty($this->globalconfig->settings_showonenotenotebook)) {
            return '';
        }

        if (!class_exists('\local_onenote\api\base')) {
            $url = new moodle_url('https://www.office.com/launch/onenote');
            $stropennotebook = get_string('linkonenote', 'block_microsoft');
            $linkattrs = [
                'onclick' => 'window.open(this.href,\'_blank\'); return false;',
                'class' => 'servicelink block_microsoft_onenote',
            ];
            return html_writer::link($url->out(false), $stropennotebook, $linkattrs);
        }

        $action = optional_param('action', '', PARAM_TEXT);
        try {
            $onenoteapi = \local_onenote\api\base::getinstance();
            $output = '';
            if ($onenoteapi->is_logged_in()) {
                // Add the "save to onenote" button if we are on an assignment page.
                $onassignpage = ($this->page->cm
                  && $this->page->cm->modname == 'assign'
                  && $action == 'editsubmission') ? true : false;
                if ($onassignpage === true && $onenoteapi->is_student($this->page->cm->id, $USER->id)) {
                    $workstr = get_string('workonthis', 'block_microsoft');
                    $output .= $onenoteapi->render_action_button($workstr, $this->page->cm->id).'<br /><br />';
                }
                // Find moodle notebook, create if not found.
                $moodlenotebook = null;

                $cache = cache::make('block_microsoft', 'onenotenotebook');
                $moodlenotebook = $cache->get($USER->id);
                if (empty($moodlenotebook)) {
                    $moodlenotebook = $this->get_onenote_notebook($onenoteapi);
                    $result = $cache->set($USER->id, $moodlenotebook);
                }

                if (!empty($moodlenotebook)) {
                    $url = new moodle_url($moodlenotebook['url']);
                    $stropennotebook = get_string('linkonenote', 'block_microsoft');
                    $linkattrs = [
                        'onclick' => 'window.open(this.href,\'_blank\'); return false;',
                        'class' => 'servicelink block_microsoft_onenote',
                    ];
                    $output .= html_writer::link($url->out(false), $stropennotebook, $linkattrs);
                } else {
                    $output .= get_string('error_nomoodlenotebook', 'block_microsoft');
                }
            } else {
                if (\local_o365\utils::is_configured_msaccount()) {
                    $output .= $this->render_signin_widget($onenoteapi->get_login_url());
                }
            }
            return $output;
        } catch (\Exception $e) {
            if (class_exists('\local_o365\utils')) {
                \local_o365\utils::debug($e->getMessage(), 'block_microsoft', $e);
            }
            return '<span class="block_microsoft_onenote servicelink">'.get_string('linkonenote_unavailable', 'block_microsoft')
                    .'<br /><small>'.get_string('contactadmin', 'block_microsoft').'</small></span>';
        }
    }