Файловый менеджер - Редактировать - /home/harasnat/www/mf/renderer.php.tar
Назад
home/harasnat/www/learning/admin/renderer.php 0000604 00000275524 15062104310 0015332 0 ustar 00 <?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Standard HTML output renderer for core_admin subsystem. * * @package core * @subpackage admin * @copyright 2011 David Mudrak <david@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class core_admin_renderer extends plugin_renderer_base { /** * Display the 'Do you acknowledge the terms of the GPL' page. The first page * during install. * @return string HTML to output. */ public function install_licence_page() { global $CFG; $output = ''; $copyrightnotice = text_to_html(get_string('gpl3')); $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack $continue = new single_button(new moodle_url($this->page->url, array( 'lang' => $CFG->lang, 'agreelicense' => 1)), get_string('continue'), 'get'); $output .= $this->header(); $output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment'); $output .= $this->heading(get_string('copyrightnotice')); $output .= $this->box($copyrightnotice, 'copyrightnotice'); $output .= html_writer::empty_tag('br'); $output .= $this->confirm(get_string('doyouagree'), $continue, "https://moodledev.io/general/license"); $output .= $this->footer(); return $output; } /** * Display page explaining proper upgrade process, * there can not be any PHP file leftovers... * * @return string HTML to output. */ public function upgrade_stale_php_files_page() { $output = ''; $output .= $this->header(); $output .= $this->heading(get_string('upgradestalefiles', 'admin')); $output .= $this->box_start('generalbox', 'notice'); $output .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN); $output .= html_writer::empty_tag('br'); $output .= html_writer::tag('div', $this->single_button($this->page->url, get_string('reload'), 'get'), array('class' => 'buttons')); $output .= $this->box_end(); $output .= $this->footer(); return $output; } /** * Display the 'environment check' page that is displayed during install. * @param int $maturity * @param boolean $envstatus final result of the check (true/false) * @param array $environment_results array of results gathered * @param string $release moodle release * @return string HTML to output. */ public function install_environment_page($maturity, $envstatus, $environment_results, $release) { global $CFG; $output = ''; $output .= $this->header(); $output .= $this->maturity_warning($maturity); $output .= $this->heading("Moodle $release"); $output .= $this->release_notes_link(); $output .= $this->environment_check_table($envstatus, $environment_results); if (!$envstatus) { $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('agreelicense' => 1, 'lang' => $CFG->lang))); } else { $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess'); $output .= $this->continue_button(new moodle_url($this->page->url, array( 'agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang))); } $output .= $this->footer(); return $output; } /** * Displays the list of plugins with unsatisfied dependencies * * @param double|string|int $version Moodle on-disk version * @param array $failed list of plugins with unsatisfied dependecies * @param moodle_url $reloadurl URL of the page to recheck the dependencies * @return string HTML */ public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) { $output = ''; $output .= $this->header(); $output .= $this->heading(get_string('pluginscheck', 'admin')); $output .= $this->warning(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed))))); $output .= $this->plugins_check_table(core_plugin_manager::instance(), $version, array('xdep' => true)); $output .= $this->warning(get_string('pluginschecktodo', 'admin')); $output .= $this->continue_button($reloadurl); $output .= $this->footer(); return $output; } /** * Display the 'You are about to upgrade Moodle' page. The first page * during upgrade. * @param string $strnewversion * @param int $maturity * @param string $testsite * @return string HTML to output. */ public function upgrade_confirm_page($strnewversion, $maturity, $testsite) { $output = ''; $continueurl = new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0)); $continue = new single_button($continueurl, get_string('continue'), 'get'); $cancelurl = new moodle_url('/admin/index.php'); $output .= $this->header(); $output .= $this->maturity_warning($maturity); $output .= $this->test_site_warning($testsite); $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continue, $cancelurl); $output .= $this->footer(); return $output; } /** * Display the environment page during the upgrade process. * @param string $release * @param boolean $envstatus final result of env check (true/false) * @param array $environment_results array of results gathered * @return string HTML to output. */ public function upgrade_environment_page($release, $envstatus, $environment_results) { global $CFG; $output = ''; $output .= $this->header(); $output .= $this->heading("Moodle $release"); $output .= $this->release_notes_link(); $output .= $this->environment_check_table($envstatus, $environment_results); if (!$envstatus) { $output .= $this->upgrade_reload(new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0))); } else { $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess'); if (empty($CFG->skiplangupgrade) and current_language() !== 'en') { $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice'); } $output .= $this->continue_button(new moodle_url($this->page->url, array( 'confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0))); } $output .= $this->footer(); return $output; } /** * Display the upgrade page that lists all the plugins that require attention. * @param core_plugin_manager $pluginman provides information about the plugins. * @param \core\update\checker $checker provides information about available updates. * @param int $version the version of the Moodle code from version.php. * @param bool $showallplugins * @param moodle_url $reloadurl * @param moodle_url $continueurl * @return string HTML to output. */ public function upgrade_plugin_check_page(core_plugin_manager $pluginman, \core\update\checker $checker, $version, $showallplugins, $reloadurl, $continueurl) { $output = ''; $output .= $this->header(); $output .= $this->box_start('generalbox', 'plugins-check-page'); $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'), array('class' => 'page-description')); $output .= $this->check_for_updates_button($checker, $reloadurl); $output .= $this->missing_dependencies($pluginman); $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins)); $output .= $this->box_end(); $output .= $this->upgrade_reload($reloadurl); if ($pluginman->some_plugins_updatable()) { $output .= $this->container_start('upgradepluginsinfo'); $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin')); $output .= $this->container_end(); } $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get', single_button::BUTTON_PRIMARY); $button->class = 'continuebutton'; $output .= $this->render($button); $output .= $this->footer(); return $output; } /** * Display a page to confirm plugin installation cancelation. * * @param array $abortable list of \core\update\plugininfo * @param moodle_url $continue * @return string */ public function upgrade_confirm_abort_install_page(array $abortable, moodle_url $continue) { $pluginman = core_plugin_manager::instance(); if (empty($abortable)) { // The UI should not allow this. throw new moodle_exception('err_no_plugin_install_abortable', 'core_plugin'); } $out = $this->output->header(); $out .= $this->output->heading(get_string('cancelinstallhead', 'core_plugin'), 3); $out .= $this->output->container(get_string('cancelinstallinfo', 'core_plugin'), 'cancelinstallinfo'); foreach ($abortable as $pluginfo) { $out .= $this->output->heading($pluginfo->displayname.' ('.$pluginfo->component.')', 4); $out .= $this->output->container(get_string('cancelinstallinfodir', 'core_plugin', $pluginfo->rootdir)); if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) { $out .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype), 'alert alert-warning mt-2'); } } $out .= $this->plugins_management_confirm_buttons($continue, $this->page->url); $out .= $this->output->footer(); return $out; } /** * Display the admin notifications page. * @param int $maturity * @param bool $insecuredataroot warn dataroot is invalid * @param bool $errorsdisplayed warn invalid dispaly error setting * @param bool $cronoverdue warn cron not running * @param bool $dbproblems warn db has problems * @param bool $maintenancemode warn in maintenance mode * @param bool $buggyiconvnomb warn iconv problems * @param array|null $availableupdates array of \core\update\info objects or null * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown) * @param string[] $cachewarnings An array containing warnings from the Cache API. * @param array $eventshandlers Events 1 API handlers. * @param bool $themedesignermode Warn about the theme designer mode. * @param bool $devlibdir Warn about development libs directory presence. * @param bool $mobileconfigured Whether the mobile web services have been enabled * @param bool $overridetossl Whether or not ssl is being forced. * @param bool $invalidforgottenpasswordurl Whether the forgotten password URL does not link to a valid URL. * @param bool $croninfrequent If true, warn that cron hasn't run in the past few minutes * @param bool $showcampaigncontent Whether the campaign content should be visible or not. * @param bool $showfeedbackencouragement Whether the feedback encouragement content should be displayed or not. * @param bool $showservicesandsupport Whether the services and support content should be displayed or not. * @param string $xmlrpcwarning XML-RPC deprecation warning message. * * @return string HTML to output. */ public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0, $themedesignermode = false, $devlibdir = false, $mobileconfigured = false, $overridetossl = false, $invalidforgottenpasswordurl = false, $croninfrequent = false, $showcampaigncontent = false, bool $showfeedbackencouragement = false, bool $showservicesandsupport = false, $xmlrpcwarning = '') { global $CFG; $output = ''; $output .= $this->header(); $output .= $this->output->heading(get_string('notifications', 'admin')); $output .= $this->maturity_info($maturity); $output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : ''; $output .= $this->insecure_dataroot_warning($insecuredataroot); $output .= $this->development_libs_directories_warning($devlibdir); $output .= $this->themedesignermode_warning($themedesignermode); $output .= $this->display_errors_warning($errorsdisplayed); $output .= $this->buggy_iconv_warning($buggyiconvnomb); $output .= $this->cron_overdue_warning($cronoverdue); $output .= $this->cron_infrequent_warning($croninfrequent); $output .= $this->db_problems($dbproblems); $output .= $this->maintenance_mode_warning($maintenancemode); $output .= $this->overridetossl_warning($overridetossl); $output .= $this->cache_warnings($cachewarnings); $output .= $this->events_handlers($eventshandlers); $output .= $this->registration_warning($registered); $output .= $this->mobile_configuration_warning($mobileconfigured); $output .= $this->forgotten_password_url_warning($invalidforgottenpasswordurl); $output .= $this->mnet_deprecation_warning($xmlrpcwarning); $output .= $this->userfeedback_encouragement($showfeedbackencouragement); $output .= $this->services_and_support_content($showservicesandsupport); $output .= $this->campaign_content($showcampaigncontent); ////////////////////////////////////////////////////////////////////////////////////////////////// //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE /// $output .= $this->moodle_copyright(); ////////////////////////////////////////////////////////////////////////////////////////////////// $output .= $this->footer(); return $output; } /** * Display the plugin management page (admin/plugins.php). * * The filtering options array may contain following items: * bool contribonly - show only contributed extensions * bool updatesonly - show only plugins with an available update * * @param core_plugin_manager $pluginman * @param \core\update\checker $checker * @param array $options filtering options * @return string HTML to output. */ public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) { $output = ''; $output .= $this->header(); $output .= $this->heading(get_string('pluginsoverview', 'core_admin')); $output .= $this->check_for_updates_button($checker, $this->page->url); $output .= $this->plugins_overview_panel($pluginman, $options); $output .= $this->plugins_control_panel($pluginman, $options); $output .= $this->footer(); return $output; } /** * Renders a button to fetch for available updates. * * @param \core\update\checker $checker * @param moodle_url $reloadurl * @return string HTML */ public function check_for_updates_button(\core\update\checker $checker, $reloadurl) { $output = ''; if ($checker->enabled()) { $output .= $this->container_start('checkforupdates mb-4'); $output .= $this->single_button( new moodle_url($reloadurl, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin') ); if ($timefetched = $checker->get_last_timefetched()) { $timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig')); $output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched), 'lasttimefetched small text-muted mt-1'); } $output .= $this->container_end(); } return $output; } /** * Display a page to confirm the plugin uninstallation. * * @param core_plugin_manager $pluginman * @param \core\plugininfo\base $pluginfo * @param moodle_url $continueurl URL to continue after confirmation * @param moodle_url $cancelurl URL to to go if cancelled * @return string */ public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) { $output = ''; $pluginname = $pluginman->plugin_name($pluginfo->component); $confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>'; if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) { $confirm .= $extraconfirm; } $output .= $this->output->header(); $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname))); $output .= $this->output->confirm($confirm, $continueurl, $cancelurl); $output .= $this->output->footer(); return $output; } /** * Display a page with results of plugin uninstallation and offer removal of plugin files. * * @param core_plugin_manager $pluginman * @param \core\plugininfo\base $pluginfo * @param progress_trace_buffer $progress * @param moodle_url $continueurl URL to continue to remove the plugin folder * @return string */ public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress, moodle_url $continueurl) { $output = ''; $pluginname = $pluginman->plugin_name($pluginfo->component); // Do not show navigation here, they must click one of the buttons. $this->page->set_pagelayout('maintenance'); $this->page->set_cacheable(false); $output .= $this->output->header(); $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname))); $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage'); $confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin', array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm'); if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) { $confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype), 'alert alert-warning mt-2'); } // After any uninstall we must execute full upgrade to finish the cleanup! $output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php')); $output .= $this->output->footer(); return $output; } /** * Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually. * * @param core_plugin_manager $pluginman * @param \core\plugininfo\base $pluginfo * @param progress_trace_buffer $progress * @return string */ public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) { $output = ''; $pluginname = $pluginfo->component; $output .= $this->output->header(); $output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname))); $output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage'); $output .= $this->output->box(get_string('uninstalldelete', 'core_plugin', array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete'); $output .= $this->output->continue_button(new moodle_url('/admin/index.php')); $output .= $this->output->footer(); return $output; } /** * Display the plugin management page (admin/environment.php). * @param array $versions * @param string $version * @param boolean $envstatus final result of env check (true/false) * @param array $environment_results array of results gathered * @return string HTML to output. */ public function environment_check_page($versions, $version, $envstatus, $environment_results) { $output = ''; $output .= $this->header(); // Print the component download link $output .= html_writer::tag('div', html_writer::link( new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())), get_string('updatecomponent', 'admin')), array('class' => 'reportlink')); // Heading. $output .= $this->heading(get_string('environment', 'admin')); // Box with info and a menu to choose the version. $output .= $this->box_start(); $output .= html_writer::tag('div', get_string('adminhelpenvironment')); $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null); $select->label = get_string('moodleversion'); $output .= $this->render($select); $output .= $this->box_end(); // The results $output .= $this->environment_check_table($envstatus, $environment_results); $output .= $this->footer(); return $output; } /** * Output a warning message, of the type that appears on the admin notifications page. * @param string $message the message to display. * @param string $type type class * @return string HTML to output. */ protected function warning($message, $type = 'warning') { return $this->box($message, 'generalbox alert alert-' . $type); } /** * Render an appropriate message if dataroot is insecure. * @param bool $insecuredataroot * @return string HTML to output. */ protected function insecure_dataroot_warning($insecuredataroot) { global $CFG; if ($insecuredataroot == INSECURE_DATAROOT_WARNING) { return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot)); } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) { return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'danger'); } else { return ''; } } /** * Render a warning that a directory with development libs is present. * * @param bool $devlibdir True if the warning should be displayed. * @return string */ protected function development_libs_directories_warning($devlibdir) { if ($devlibdir) { $moreinfo = new moodle_url('/report/security/index.php'); $warning = get_string('devlibdirpresent', 'core_admin', ['moreinfourl' => $moreinfo->out()]); return $this->warning($warning, 'danger'); } else { return ''; } } /** * Render an appropriate message if dataroot is insecure. * @param bool $errorsdisplayed * @return string HTML to output. */ protected function display_errors_warning($errorsdisplayed) { if (!$errorsdisplayed) { return ''; } return $this->warning(get_string('displayerrorswarning', 'admin')); } /** * Render an appropriate message if themdesignermode is enabled. * @param bool $themedesignermode true if enabled * @return string HTML to output. */ protected function themedesignermode_warning($themedesignermode) { if (!$themedesignermode) { return ''; } return $this->warning(get_string('themedesignermodewarning', 'admin')); } /** * Render an appropriate message if iconv is buggy and mbstring missing. * @param bool $buggyiconvnomb * @return string HTML to output. */ protected function buggy_iconv_warning($buggyiconvnomb) { if (!$buggyiconvnomb) { return ''; } return $this->warning(get_string('warningiconvbuggy', 'admin')); } /** * Render an appropriate message if cron has not been run recently. * @param bool $cronoverdue * @return string HTML to output. */ public function cron_overdue_warning($cronoverdue) { global $CFG; if (!$cronoverdue) { return ''; } $check = new \tool_task\check\cronrunning(); $result = $check->get_result(); return $this->warning($result->get_summary() . ' ' . $this->help_icon('cron', 'admin')); } /** * Render an appropriate message if cron is not being run frequently (recommended every minute). * * @param bool $croninfrequent * @return string HTML to output. */ public function cron_infrequent_warning(bool $croninfrequent) : string { global $CFG; if (!$croninfrequent) { return ''; } $check = new \tool_task\check\cronrunning(); $result = $check->get_result(); return $this->warning($result->get_summary() . ' ' . $this->help_icon('cron', 'admin')); } /** * Render an appropriate message if there are any problems with the DB set-up. * @param bool $dbproblems * @return string HTML to output. */ public function db_problems($dbproblems) { if (!$dbproblems) { return ''; } return $this->warning($dbproblems); } /** * Renders cache warnings if there are any. * * @param string[] $cachewarnings * @return string */ public function cache_warnings(array $cachewarnings) { if (!count($cachewarnings)) { return ''; } return join("\n", array_map(array($this, 'warning'), $cachewarnings)); } /** * Renders events 1 API handlers warning. * * @param array $eventshandlers * @return string */ public function events_handlers($eventshandlers) { if ($eventshandlers) { $components = ''; foreach ($eventshandlers as $eventhandler) { $components .= $eventhandler->component . ', '; } $components = rtrim($components, ', '); return $this->warning(get_string('eventshandlersinuse', 'admin', $components)); } } /** * Render an appropriate message if the site in in maintenance mode. * @param bool $maintenancemode * @return string HTML to output. */ public function maintenance_mode_warning($maintenancemode) { if (!$maintenancemode) { return ''; } $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode')); $url = $url->out(); // get_string() does not support objects in params return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url)); } /** * Render a warning that ssl is forced because the site was on loginhttps. * * @param bool $overridetossl Whether or not ssl is being forced. * @return string */ protected function overridetossl_warning($overridetossl) { if (!$overridetossl) { return ''; } $warning = get_string('overridetossl', 'core_admin'); return $this->warning($warning, 'warning'); } /** * Display a warning about installing development code if necesary. * @param int $maturity * @return string HTML to output. */ protected function maturity_warning($maturity) { if ($maturity == MATURITY_STABLE) { return ''; // No worries. } $maturitylevel = get_string('maturity' . $maturity, 'admin'); return $this->warning( $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) . $this->container($this->doc_link('admin/versions', get_string('morehelp'))), 'danger'); } /* * If necessary, displays a warning about upgrading a test site. * * @param string $testsite * @return string HTML */ protected function test_site_warning($testsite) { if (!$testsite) { return ''; } $warning = (get_string('testsiteupgradewarning', 'admin', $testsite)); return $this->warning($warning, 'danger'); } /** * Output the copyright notice. * @return string HTML to output. */ protected function moodle_copyright() { global $CFG; ////////////////////////////////////////////////////////////////////////////////////////////////// //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE /// $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '. '<a href="https://moodledev.io/general/releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'. 'Copyright © 1999 onwards, Martin Dougiamas<br />'. 'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'. '<a href="https://moodledev.io/general/license">GNU Public License</a>'; ////////////////////////////////////////////////////////////////////////////////////////////////// return $this->box($copyrighttext, 'copyright'); } /** * Display a warning about installing development code if necesary. * @param int $maturity * @return string HTML to output. */ protected function maturity_info($maturity) { if ($maturity == MATURITY_STABLE) { return ''; // No worries. } $level = 'warning'; if ($maturity == MATURITY_ALPHA) { $level = 'danger'; } $maturitylevel = get_string('maturity' . $maturity, 'admin'); $warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel); $warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp')); return $this->warning($warningtext, $level); } /** * Displays the info about available Moodle core and plugin updates * * The structure of the $updates param has changed since 2.4. It contains not only updates * for the core itself, but also for all other installed plugins. * * @param array|null $updates array of (string)component => array of \core\update\info objects or null * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown) * @return string */ protected function available_updates($updates, $fetch) { $updateinfo = ''; $someupdateavailable = false; if (is_array($updates)) { if (is_array($updates['core'])) { $someupdateavailable = true; $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3); foreach ($updates['core'] as $update) { $updateinfo .= $this->moodle_available_update_info($update); } $updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'), array('class' => 'updateavailablerecommendation')); } unset($updates['core']); // If something has left in the $updates array now, it is updates for plugins. if (!empty($updates)) { $someupdateavailable = true; $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3); $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1)); $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin', array('url' => $pluginsoverviewurl->out()))); } } if (!$someupdateavailable) { $now = time(); if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) { $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3); } } $updateinfo .= $this->container_start('checkforupdates mt-1'); $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0)); $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin')); if ($fetch) { $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin', userdate($fetch, get_string('strftimedatetime', 'core_langconfig')))); } $updateinfo .= $this->container_end(); return $this->warning($updateinfo); } /** * Display a warning about not being registered on Moodle.org if necesary. * * @param boolean $registered true if the site is registered on Moodle.org * @return string HTML to output. */ protected function registration_warning($registered) { if (!$registered && site_is_public()) { if (has_capability('moodle/site:config', context_system::instance())) { $registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'), get_string('register', 'admin')); $str = 'registrationwarning'; } else { $registerbutton = ''; $str = 'registrationwarningcontactadmin'; } return $this->warning( get_string($str, 'admin') . ' ' . $this->help_icon('registration', 'admin') . $registerbutton , 'error alert alert-danger'); } return ''; } /** * Return an admin page warning if site is not registered with moodle.org * * @return string */ public function warn_if_not_registered() { return $this->registration_warning(\core\hub\registration::is_registered()); } /** * Display a warning about the Mobile Web Services being disabled. * * @param boolean $mobileconfigured true if mobile web services are enabled * @return string HTML to output. */ protected function mobile_configuration_warning($mobileconfigured) { $output = ''; if (!$mobileconfigured) { $settingslink = new moodle_url('/admin/settings.php', ['section' => 'mobilesettings']); $configurebutton = $this->single_button($settingslink, get_string('enablemobilewebservice', 'admin')); $output .= $this->warning(get_string('mobilenotconfiguredwarning', 'admin') . ' ' . $configurebutton); } return $output; } /** * Display campaign content. * * @param bool $showcampaigncontent Whether the campaign content should be visible or not. * @return string the campaign content raw html. */ protected function campaign_content(bool $showcampaigncontent): string { if (!$showcampaigncontent) { return ''; } $lang = current_language(); $url = "https://campaign.moodle.org/current/lms/{$lang}/install/"; $params = [ 'url' => $url, 'iframeid' => 'campaign-content', 'title' => get_string('campaign', 'admin'), ]; return $this->render_from_template('core/external_content_banner', $params); } /** * Display services and support content. * * @param bool $showservicesandsupport Whether the services and support content should be visible or not. * @return string the campaign content raw html. */ protected function services_and_support_content(bool $showservicesandsupport): string { if (!$showservicesandsupport) { return ''; } $lang = current_language(); $url = "https://campaign.moodle.org/current/lms/{$lang}/servicesandsupport/"; $params = [ 'url' => $url, 'iframeid' => 'services-support-content', 'title' => get_string('supportandservices', 'admin'), ]; return $this->render_from_template('core/external_content_banner', $params); } /** * Display a warning about the forgotten password URL not linking to a valid URL. * * @param boolean $invalidforgottenpasswordurl true if the forgotten password URL is not valid * @return string HTML to output. */ protected function forgotten_password_url_warning($invalidforgottenpasswordurl) { $output = ''; if ($invalidforgottenpasswordurl) { $settingslink = new moodle_url('/admin/settings.php', ['section' => 'manageauths']); $configurebutton = $this->single_button($settingslink, get_string('check', 'moodle')); $output .= $this->warning(get_string('invalidforgottenpasswordurl', 'admin') . ' ' . $configurebutton, 'error alert alert-danger'); } return $output; } /** * Helper method to render the information about the available Moodle update * * @param \core\update\info $updateinfo information about the available Moodle core update */ protected function moodle_available_update_info(\core\update\info $updateinfo) { $boxclasses = 'moodleupdateinfo mb-2'; $info = array(); if (isset($updateinfo->release)) { $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release), array('class' => 'info release')); } if (isset($updateinfo->version)) { $info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version), array('class' => 'info version')); } if (isset($updateinfo->maturity)) { $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'), array('class' => 'info maturity')); $boxclasses .= ' maturity'.$updateinfo->maturity; } if (isset($updateinfo->download)) { $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download btn btn-secondary')); } if (isset($updateinfo->url)) { $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'), array('class' => 'info more')); } $box = $this->output->container_start($boxclasses); $box .= $this->output->container(implode(html_writer::tag('span', ' | ', array('class' => 'separator')), $info), ''); $box .= $this->output->container_end(); return $box; } /** * Display a link to the release notes. * @return string HTML to output. */ protected function release_notes_link() { $releasenoteslink = get_string('releasenoteslink', 'admin', 'https://moodledev.io/general/releases'); $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack return $this->box($releasenoteslink, 'generalbox alert alert-info'); } /** * Display the reload link that appears on several upgrade/install pages. * @return string HTML to output. */ function upgrade_reload($url) { return html_writer::empty_tag('br') . html_writer::tag('div', html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) . get_string('reload'), array('title' => get_string('reload'))), array('class' => 'continuebutton')) . html_writer::empty_tag('br'); } /** * Displays all known plugins and information about their installation or upgrade * * This default implementation renders all plugins into one big table. The rendering * options support: * (bool)full = false: whether to display up-to-date plugins, too * (bool)xdep = false: display the plugins with unsatisified dependecies only * * @param core_plugin_manager $pluginman provides information about the plugins. * @param int $version the version of the Moodle code from version.php. * @param array $options rendering options * @return string HTML code */ public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) { global $CFG; $plugininfo = $pluginman->get_plugins(); if (empty($plugininfo)) { return ''; } $options['full'] = isset($options['full']) ? (bool)$options['full'] : false; $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false; $table = new html_table(); $table->id = 'plugins-check'; $table->head = array( get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'), get_string('versiondb', 'core_plugin'), get_string('versiondisk', 'core_plugin'), get_string('requires', 'core_plugin'), get_string('source', 'core_plugin').' / '.get_string('status', 'core_plugin'), ); $table->colclasses = array( 'displayname', 'versiondb', 'versiondisk', 'requires', 'status', ); $table->data = array(); // Number of displayed plugins per type. $numdisplayed = array(); // Number of plugins known to the plugin manager. $sumtotal = 0; // Number of plugins requiring attention. $sumattention = 0; // List of all components we can cancel installation of. $installabortable = $pluginman->list_cancellable_installations(); // List of all components we can cancel upgrade of. $upgradeabortable = $pluginman->list_restorable_archives(); foreach ($plugininfo as $type => $plugins) { $header = new html_table_cell($pluginman->plugintype_name_plural($type)); $header->header = true; $header->colspan = count($table->head); $header = new html_table_row(array($header)); $header->attributes['class'] = 'plugintypeheader type-' . $type; $numdisplayed[$type] = 0; if (empty($plugins) and $options['full']) { $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin')); $msg->colspan = count($table->head); $row = new html_table_row(array($msg)); $row->attributes['class'] .= 'msg msg-noneinstalled'; $table->data[] = $header; $table->data[] = $row; continue; } $plugintyperows = array(); foreach ($plugins as $name => $plugin) { $component = "{$plugin->type}_{$plugin->name}"; $sumtotal++; $row = new html_table_row(); $row->attributes['class'] = "type-{$plugin->type} name-{$component}"; $iconidentifier = 'icon'; if ($plugin->type === 'mod') { $iconidentifier = 'monologo'; } if ($this->page->theme->resolve_image_location($iconidentifier, $component, null)) { $icon = $this->output->pix_icon($iconidentifier, '', $component, [ 'class' => 'smallicon pluginicon', ]); } else { $icon = ''; } $displayname = new html_table_cell( $icon. html_writer::span($plugin->displayname, 'pluginname'). html_writer::div($plugin->get_dir(), 'plugindir text-muted small') ); $versiondb = new html_table_cell($plugin->versiondb); $versiondisk = new html_table_cell($plugin->versiondisk); if ($isstandard = $plugin->is_standard()) { $row->attributes['class'] .= ' standard'; $sourcelabel = html_writer::span(get_string('sourcestd', 'core_plugin'), 'sourcetext badge badge-secondary'); } else { $row->attributes['class'] .= ' extension'; $sourcelabel = html_writer::span(get_string('sourceext', 'core_plugin'), 'sourcetext badge badge-info'); } $coredependency = $plugin->is_core_dependency_satisfied($version); $incompatibledependency = $plugin->is_core_compatible_satisfied($CFG->branch); $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins()); $dependenciesok = $coredependency && $otherpluginsdependencies && $incompatibledependency; $statuscode = $plugin->get_status(); $row->attributes['class'] .= ' status-' . $statuscode; $statusclass = 'statustext badge '; switch ($statuscode) { case core_plugin_manager::PLUGIN_STATUS_NEW: $statusclass .= $dependenciesok ? 'badge-success' : 'badge-warning'; break; case core_plugin_manager::PLUGIN_STATUS_UPGRADE: $statusclass .= $dependenciesok ? 'badge-info' : 'badge-warning'; break; case core_plugin_manager::PLUGIN_STATUS_MISSING: case core_plugin_manager::PLUGIN_STATUS_DOWNGRADE: case core_plugin_manager::PLUGIN_STATUS_DELETE: $statusclass .= 'badge-danger'; break; case core_plugin_manager::PLUGIN_STATUS_NODB: case core_plugin_manager::PLUGIN_STATUS_UPTODATE: $statusclass .= $dependenciesok ? 'badge-light' : 'badge-warning'; break; } $status = html_writer::span(get_string('status_' . $statuscode, 'core_plugin'), $statusclass); if (!empty($installabortable[$plugin->component])) { $status .= $this->output->single_button( new moodle_url($this->page->url, array('abortinstall' => $plugin->component, 'confirmplugincheck' => 0)), get_string('cancelinstallone', 'core_plugin'), 'post', array('class' => 'actionbutton cancelinstallone d-block mt-1') ); } if (!empty($upgradeabortable[$plugin->component])) { $status .= $this->output->single_button( new moodle_url($this->page->url, array('abortupgrade' => $plugin->component)), get_string('cancelupgradeone', 'core_plugin'), 'post', array('class' => 'actionbutton cancelupgradeone d-block mt-1') ); } $availableupdates = $plugin->available_updates(); if (!empty($availableupdates)) { foreach ($availableupdates as $availableupdate) { $status .= $this->plugin_available_update_info($pluginman, $availableupdate); } } $status = new html_table_cell($sourcelabel.' '.$status); if ($plugin->pluginsupported != null) { $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version, $CFG->branch)); } else { $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version)); } $statusisboring = in_array($statuscode, array( core_plugin_manager::PLUGIN_STATUS_NODB, core_plugin_manager::PLUGIN_STATUS_UPTODATE)); if ($options['xdep']) { // we want to see only plugins with failed dependencies if ($dependenciesok) { continue; } } else if ($statusisboring and $dependenciesok and empty($availableupdates)) { // no change is going to happen to the plugin - display it only // if the user wants to see the full list if (empty($options['full'])) { continue; } } else { $sumattention++; } // The plugin should be displayed. $numdisplayed[$type]++; $row->cells = array($displayname, $versiondb, $versiondisk, $requires, $status); $plugintyperows[] = $row; } if (empty($numdisplayed[$type]) and empty($options['full'])) { continue; } $table->data[] = $header; $table->data = array_merge($table->data, $plugintyperows); } // Total number of displayed plugins. $sumdisplayed = array_sum($numdisplayed); if ($options['xdep']) { // At the plugins dependencies check page, display the table only. return html_writer::table($table); } $out = $this->output->container_start('', 'plugins-check-info'); if ($sumdisplayed == 0) { $out .= $this->output->heading(get_string('pluginchecknone', 'core_plugin')); } else { if (empty($options['full'])) { $out .= $this->output->heading(get_string('plugincheckattention', 'core_plugin')); } else { $out .= $this->output->heading(get_string('plugincheckall', 'core_plugin')); } } $out .= $this->output->container_start('actions mb-2'); $installableupdates = $pluginman->filter_installable($pluginman->available_updates()); if ($installableupdates) { $out .= $this->output->single_button( new moodle_url($this->page->url, array('installupdatex' => 1)), get_string('updateavailableinstallall', 'core_admin', count($installableupdates)), 'post', array('class' => 'singlebutton updateavailableinstallall mr-1') ); } if ($installabortable) { $out .= $this->output->single_button( new moodle_url($this->page->url, array('abortinstallx' => 1, 'confirmplugincheck' => 0)), get_string('cancelinstallall', 'core_plugin', count($installabortable)), 'post', array('class' => 'singlebutton cancelinstallall mr-1') ); } if ($upgradeabortable) { $out .= $this->output->single_button( new moodle_url($this->page->url, array('abortupgradex' => 1)), get_string('cancelupgradeall', 'core_plugin', count($upgradeabortable)), 'post', array('class' => 'singlebutton cancelupgradeall mr-1') ); } $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 0)), get_string('plugincheckattention', 'core_plugin')).' '.html_writer::span($sumattention, 'badge badge-light'), 'btn btn-link mr-1'); $out .= html_writer::div(html_writer::link(new moodle_url($this->page->url, array('showallplugins' => 1)), get_string('plugincheckall', 'core_plugin')).' '.html_writer::span($sumtotal, 'badge badge-light'), 'btn btn-link mr-1'); $out .= $this->output->container_end(); // End of .actions container. $out .= $this->output->container_end(); // End of #plugins-check-info container. if ($sumdisplayed > 0 or $options['full']) { $out .= html_writer::table($table); } return $out; } /** * Display the continue / cancel widgets for the plugins management pages. * * @param null|moodle_url $continue URL for the continue button, should it be displayed * @param null|moodle_url $cancel URL for the cancel link, defaults to the current page * @return string HTML */ public function plugins_management_confirm_buttons(moodle_url $continue=null, moodle_url $cancel=null) { $out = html_writer::start_div('plugins-management-confirm-buttons'); if (!empty($continue)) { $out .= $this->output->single_button($continue, get_string('continue'), 'post', array('class' => 'continue')); } if (empty($cancel)) { $cancel = $this->page->url; } $out .= html_writer::div(html_writer::link($cancel, get_string('cancel')), 'cancel'); return $out; } /** * Displays the information about missing dependencies * * @param core_plugin_manager $pluginman * @return string */ protected function missing_dependencies(core_plugin_manager $pluginman) { $dependencies = $pluginman->missing_dependencies(); if (empty($dependencies)) { return ''; } $available = array(); $unavailable = array(); $unknown = array(); foreach ($dependencies as $component => $remoteinfo) { if ($remoteinfo === false) { // The required version is not available. Let us check if there // is at least some version in the plugins directory. $remoteinfoanyversion = $pluginman->get_remote_plugin_info($component, ANY_VERSION, false); if ($remoteinfoanyversion === false) { $unknown[$component] = $component; } else { $unavailable[$component] = $remoteinfoanyversion; } } else { $available[$component] = $remoteinfo; } } $out = $this->output->container_start('plugins-check-dependencies mb-4'); if ($unavailable or $unknown) { $out .= $this->output->heading(get_string('misdepsunavail', 'core_plugin')); if ($unknown) { $out .= $this->output->render((new \core\output\notification(get_string('misdepsunknownlist', 'core_plugin', implode(', ', $unknown))))->set_show_closebutton(false)); } if ($unavailable) { $unavailablelist = array(); foreach ($unavailable as $component => $remoteinfoanyversion) { $unavailablelistitem = html_writer::link('https://moodle.org/plugins/view.php?plugin='.$component, '<strong>'.$remoteinfoanyversion->name.'</strong>'); if ($remoteinfoanyversion->version) { $unavailablelistitem .= ' ('.$component.' > '.$remoteinfoanyversion->version->version.')'; } else { $unavailablelistitem .= ' ('.$component.')'; } $unavailablelist[] = $unavailablelistitem; } $out .= $this->output->render((new \core\output\notification(get_string('misdepsunavaillist', 'core_plugin', implode(', ', $unavailablelist))))->set_show_closebutton(false)); } $out .= $this->output->container_start('plugins-check-dependencies-actions mb-4'); $out .= ' '.html_writer::link(new moodle_url('/admin/tool/installaddon/'), get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-secondary')); $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container. } if ($available) { $out .= $this->output->heading(get_string('misdepsavail', 'core_plugin')); $out .= $this->output->container_start('plugins-check-dependencies-actions mb-2'); $installable = $pluginman->filter_installable($available); if ($installable) { $out .= $this->output->single_button( new moodle_url($this->page->url, array('installdepx' => 1)), get_string('dependencyinstallmissing', 'core_plugin', count($installable)), 'post', array('class' => 'singlebutton dependencyinstallmissing d-inline-block mr-1') ); } $out .= html_writer::div(html_writer::link(new moodle_url('/admin/tool/installaddon/'), get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-link')), 'dependencyuploadmissing d-inline-block mr-1'); $out .= $this->output->container_end(); // End of .plugins-check-dependencies-actions container. $out .= $this->available_missing_dependencies_list($pluginman, $available); } $out .= $this->output->container_end(); // End of .plugins-check-dependencies container. return $out; } /** * Displays the list if available missing dependencies. * * @param core_plugin_manager $pluginman * @param array $dependencies * @return string */ protected function available_missing_dependencies_list(core_plugin_manager $pluginman, array $dependencies) { global $CFG; $table = new html_table(); $table->id = 'plugins-check-available-dependencies'; $table->head = array( get_string('displayname', 'core_plugin'), get_string('release', 'core_plugin'), get_string('version', 'core_plugin'), get_string('supportedmoodleversions', 'core_plugin'), get_string('info', 'core'), ); $table->colclasses = array('displayname', 'release', 'version', 'supportedmoodleversions', 'info'); $table->data = array(); foreach ($dependencies as $plugin) { $supportedmoodles = array(); foreach ($plugin->version->supportedmoodles as $moodle) { if ($CFG->branch == str_replace('.', '', $moodle->release)) { $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-success'); } else { $supportedmoodles[] = html_writer::span($moodle->release, 'badge badge-light'); } } $requriedby = $pluginman->other_plugins_that_require($plugin->component); if ($requriedby) { foreach ($requriedby as $ix => $val) { $inf = $pluginman->get_plugin_info($val); if ($inf) { $requriedby[$ix] = $inf->displayname.' ('.$inf->component.')'; } } $info = html_writer::div( get_string('requiredby', 'core_plugin', implode(', ', $requriedby)), 'requiredby mb-1' ); } else { $info = ''; } $info .= $this->output->container_start('actions'); $info .= html_writer::div( html_writer::link('https://moodle.org/plugins/view.php?plugin='.$plugin->component, get_string('misdepinfoplugin', 'core_plugin')), 'misdepinfoplugin d-inline-block mr-3 mb-1' ); $info .= html_writer::div( html_writer::link('https://moodle.org/plugins/pluginversion.php?id='.$plugin->version->id, get_string('misdepinfoversion', 'core_plugin')), 'misdepinfoversion d-inline-block mr-3 mb-1' ); $info .= html_writer::div(html_writer::link($plugin->version->downloadurl, get_string('download')), 'misdepdownload d-inline-block mr-3 mb-1'); if ($pluginman->is_remote_plugin_installable($plugin->component, $plugin->version->version, $reason)) { $info .= $this->output->single_button( new moodle_url($this->page->url, array('installdep' => $plugin->component)), get_string('dependencyinstall', 'core_plugin'), 'post', array('class' => 'singlebutton dependencyinstall mr-3 mb-1') ); } else { $reasonhelp = $this->info_remote_plugin_not_installable($reason); if ($reasonhelp) { $info .= html_writer::div($reasonhelp, 'reasonhelp dependencyinstall d-inline-block mr-3 mb-1'); } } $info .= $this->output->container_end(); // End of .actions container. $table->data[] = array( html_writer::div($plugin->name, 'name').' '.html_writer::div($plugin->component, 'component text-muted small'), $plugin->version->release, $plugin->version->version, implode(' ', $supportedmoodles), $info ); } return html_writer::table($table); } /** * Explain why {@link core_plugin_manager::is_remote_plugin_installable()} returned false. * * @param string $reason the reason code as returned by the plugin manager * @return string */ protected function info_remote_plugin_not_installable($reason) { if ($reason === 'notwritableplugintype' or $reason === 'notwritableplugin') { return $this->output->help_icon('notwritable', 'core_plugin', get_string('notwritable', 'core_plugin')); } if ($reason === 'remoteunavailable') { return $this->output->help_icon('notdownloadable', 'core_plugin', get_string('notdownloadable', 'core_plugin')); } return false; } /** * Formats the information that needs to go in the 'Requires' column. * @param \core\plugininfo\base $plugin the plugin we are rendering the row for. * @param core_plugin_manager $pluginman provides data on all the plugins. * @param string $version * @param int $branch the current Moodle branch * @return string HTML code */ protected function required_column(\core\plugininfo\base $plugin, core_plugin_manager $pluginman, $version, $branch = null) { $requires = array(); $displayuploadlink = false; $displayupdateslink = false; $requirements = $pluginman->resolve_requirements($plugin, $version, $branch); foreach ($requirements as $reqname => $reqinfo) { if ($reqname === 'core') { if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) { $class = 'requires-ok text-muted'; $label = ''; } else { $class = 'requires-failed'; $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger'); } if ($branch != null && !$plugin->is_core_compatible_satisfied($branch)) { $requires[] = html_writer::tag('li', html_writer::span(get_string('incompatibleversion', 'core_plugin', $branch), 'dep dep-core'). ' '.$label, array('class' => $class)); } else if ($branch != null && $plugin->pluginsupported != null) { $requires[] = html_writer::tag('li', html_writer::span(get_string('moodlebranch', 'core_plugin', array('min' => $plugin->pluginsupported[0], 'max' => $plugin->pluginsupported[1])), 'dep dep-core'). ' '.$label, array('class' => $class)); } else if ($reqinfo->reqver != ANY_VERSION) { $requires[] = html_writer::tag('li', html_writer::span(get_string('moodleversion', 'core_plugin', $plugin->versionrequires), 'dep dep-core'). ' '.$label, array('class' => $class)); } } else { $actions = array(); if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OK) { $label = ''; $class = 'requires-ok text-muted'; } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_MISSING) { if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) { $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-warning'); $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning'); $class = 'requires-failed requires-missing requires-available'; $actions[] = html_writer::link( new moodle_url('https://moodle.org/plugins/view.php', array('plugin' => $reqname)), get_string('misdepinfoplugin', 'core_plugin') ); } else { $label = html_writer::span(get_string('dependencymissing', 'core_plugin'), 'badge badge-danger'); $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'), 'badge badge-danger'); $class = 'requires-failed requires-missing requires-unavailable'; } $displayuploadlink = true; } else if ($reqinfo->status == $pluginman::REQUIREMENT_STATUS_OUTDATED) { if ($reqinfo->availability == $pluginman::REQUIREMENT_AVAILABLE) { $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-warning'); $label .= ' '.html_writer::span(get_string('dependencyavailable', 'core_plugin'), 'badge badge-warning'); $class = 'requires-failed requires-outdated requires-available'; $displayupdateslink = true; } else { $label = html_writer::span(get_string('dependencyfails', 'core_plugin'), 'badge badge-danger'); $label .= ' '.html_writer::span(get_string('dependencyunavailable', 'core_plugin'), 'badge badge-danger'); $class = 'requires-failed requires-outdated requires-unavailable'; } $displayuploadlink = true; } if ($reqinfo->reqver != ANY_VERSION) { $str = 'otherpluginversion'; } else { $str = 'otherplugin'; } $requires[] = html_writer::tag('li', html_writer::span( get_string($str, 'core_plugin', array('component' => $reqname, 'version' => $reqinfo->reqver)), 'dep dep-plugin').' '.$label.' '.html_writer::span(implode(' | ', $actions), 'actions'), array('class' => $class) ); } } if (!$requires) { return ''; } $out = html_writer::tag('ul', implode("\n", $requires), array('class' => 'm-0')); if ($displayuploadlink) { $out .= html_writer::div( html_writer::link( new moodle_url('/admin/tool/installaddon/'), get_string('dependencyuploadmissing', 'core_plugin'), array('class' => 'btn btn-secondary btn-sm m-1') ), 'dependencyuploadmissing' ); } if ($displayupdateslink) { $out .= html_writer::div( html_writer::link( new moodle_url($this->page->url, array('sesskey' => sesskey(), 'fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'), array('class' => 'btn btn-secondary btn-sm m-1') ), 'checkforupdates' ); } // Check if supports is present, and $branch is not in, only if $incompatible check was ok. if ($plugin->pluginsupported != null && $class == 'requires-ok' && $branch != null) { if ($pluginman->check_explicitly_supported($plugin, $branch) == $pluginman::VERSION_NOT_SUPPORTED) { $out .= html_writer::div(get_string('notsupported', 'core_plugin', $branch)); } } return $out; } /** * Prints an overview about the plugins - number of installed, number of extensions etc. * * @param core_plugin_manager $pluginman provides information about the plugins * @param array $options filtering options * @return string as usually */ public function plugins_overview_panel(core_plugin_manager $pluginman, array $options = array()) { $plugininfo = $pluginman->get_plugins(); $numtotal = $numextension = $numupdatable = $numinstallable = 0; foreach ($plugininfo as $type => $plugins) { foreach ($plugins as $name => $plugin) { if ($res = $plugin->available_updates()) { $numupdatable++; foreach ($res as $updateinfo) { if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) { $numinstallable++; break; } } } if ($plugin->get_status() === core_plugin_manager::PLUGIN_STATUS_MISSING) { continue; } $numtotal++; if (!$plugin->is_standard()) { $numextension++; } } } $infoall = html_writer::link( new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 0)), get_string('overviewall', 'core_plugin'), array('title' => get_string('filterall', 'core_plugin')) ).' '.html_writer::span($numtotal, 'badge number number-all'); $infoext = html_writer::link( new moodle_url($this->page->url, array('contribonly' => 1, 'updatesonly' => 0)), get_string('overviewext', 'core_plugin'), array('title' => get_string('filtercontribonly', 'core_plugin')) ).' '.html_writer::span($numextension, 'badge number number-additional'); if ($numupdatable) { $infoupdatable = html_writer::link( new moodle_url($this->page->url, array('contribonly' => 0, 'updatesonly' => 1)), get_string('overviewupdatable', 'core_plugin'), array('title' => get_string('filterupdatesonly', 'core_plugin')) ).' '.html_writer::span($numupdatable, 'badge badge-info number number-updatable'); } else { // No updates, or the notifications disabled. $infoupdatable = ''; } $out = html_writer::start_div('', array('id' => 'plugins-overview-panel')); if (!empty($options['updatesonly'])) { $out .= $this->output->heading(get_string('overviewupdatable', 'core_plugin'), 3); } else if (!empty($options['contribonly'])) { $out .= $this->output->heading(get_string('overviewext', 'core_plugin'), 3); } if ($numinstallable) { $out .= $this->output->single_button( new moodle_url($this->page->url, array('installupdatex' => 1)), get_string('updateavailableinstallall', 'core_admin', $numinstallable), 'post', array('class' => 'singlebutton updateavailableinstallall') ); } $out .= html_writer::div($infoall, 'info info-all'). html_writer::div($infoext, 'info info-ext'). html_writer::div($infoupdatable, 'info info-updatable'); $out .= html_writer::end_div(); // End of #plugins-overview-panel block. return $out; } /** * Displays all known plugins and links to manage them * * This default implementation renders all plugins into one big table. * * @param core_plugin_manager $pluginman provides information about the plugins. * @param array $options filtering options * @return string HTML code */ public function plugins_control_panel(core_plugin_manager $pluginman, array $options = array()) { $plugininfo = $pluginman->get_plugins(); // Filter the list of plugins according the options. if (!empty($options['updatesonly'])) { $updateable = array(); foreach ($plugininfo as $plugintype => $pluginnames) { foreach ($pluginnames as $pluginname => $pluginfo) { $pluginavailableupdates = $pluginfo->available_updates(); if (!empty($pluginavailableupdates)) { foreach ($pluginavailableupdates as $pluginavailableupdate) { $updateable[$plugintype][$pluginname] = $pluginfo; } } } } $plugininfo = $updateable; } if (!empty($options['contribonly'])) { $contribs = array(); foreach ($plugininfo as $plugintype => $pluginnames) { foreach ($pluginnames as $pluginname => $pluginfo) { if (!$pluginfo->is_standard()) { $contribs[$plugintype][$pluginname] = $pluginfo; } } } $plugininfo = $contribs; } if (empty($plugininfo)) { return ''; } $table = new html_table(); $table->id = 'plugins-control-panel'; $table->head = array( get_string('displayname', 'core_plugin'), get_string('version', 'core_plugin'), get_string('availability', 'core_plugin'), get_string('actions', 'core_plugin'), get_string('notes','core_plugin'), ); $table->headspan = array(1, 1, 1, 2, 1); $table->colclasses = array( 'pluginname', 'version', 'availability', 'settings', 'uninstall', 'notes' ); foreach ($plugininfo as $type => $plugins) { $heading = $pluginman->plugintype_name_plural($type); $pluginclass = core_plugin_manager::resolve_plugininfo_class($type); if ($manageurl = $pluginclass::get_manage_url()) { $heading .= $this->output->action_icon($manageurl, new pix_icon('i/settings', get_string('settings', 'core_plugin'))); } $header = new html_table_cell(html_writer::tag('span', $heading, array('id'=>'plugin_type_cell_'.$type))); $header->header = true; $header->colspan = array_sum($table->headspan); $header = new html_table_row(array($header)); $header->attributes['class'] = 'plugintypeheader type-' . $type; $table->data[] = $header; if (empty($plugins)) { $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin')); $msg->colspan = array_sum($table->headspan); $row = new html_table_row(array($msg)); $row->attributes['class'] .= 'msg msg-noneinstalled'; $table->data[] = $row; continue; } foreach ($plugins as $name => $plugin) { $component = "{$plugin->type}_{$plugin->name}"; $row = new html_table_row(); $row->attributes['class'] = "type-{$plugin->type} name-{$component}"; $iconidentifier = 'icon'; if ($plugin->type === 'mod') { $iconidentifier = 'monologo'; } if ($this->page->theme->resolve_image_location($iconidentifier, $component, null)) { $icon = $this->output->pix_icon($iconidentifier, '', $component, [ 'class' => 'icon pluginicon', ]); } else { $icon = $this->output->spacer(); } $status = $plugin->get_status(); $row->attributes['class'] .= ' status-'.$status; $pluginname = html_writer::tag('div', $icon.$plugin->displayname, array('class' => 'displayname')). html_writer::tag('div', $plugin->component, array('class' => 'componentname')); $pluginname = new html_table_cell($pluginname); $version = html_writer::div($plugin->versiondb, 'versionnumber'); if ((string)$plugin->release !== '') { $version = html_writer::div($plugin->release, 'release').$version; } $version = new html_table_cell($version); $isenabled = $plugin->is_enabled(); if (is_null($isenabled)) { $availability = new html_table_cell(''); } else if ($isenabled) { $row->attributes['class'] .= ' enabled'; $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin')); } else { $row->attributes['class'] .= ' disabled'; $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin')); } $settingsurl = $plugin->get_settings_url(); if (!is_null($settingsurl)) { $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings')); } else { $settings = ''; } $settings = new html_table_cell($settings); if ($uninstallurl = $pluginman->get_uninstall_url($plugin->component, 'overview')) { $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin')); } else { $uninstall = ''; } $uninstall = new html_table_cell($uninstall); if ($plugin->is_standard()) { $row->attributes['class'] .= ' standard'; $source = ''; } else { $row->attributes['class'] .= ' extension'; $source = html_writer::div(get_string('sourceext', 'core_plugin'), 'source badge badge-info'); } if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) { $msg = html_writer::div(get_string('status_missing', 'core_plugin'), 'statusmsg badge badge-danger'); } else if ($status === core_plugin_manager::PLUGIN_STATUS_NEW) { $msg = html_writer::div(get_string('status_new', 'core_plugin'), 'statusmsg badge badge-success'); } else { $msg = ''; } $requriedby = $pluginman->other_plugins_that_require($plugin->component); if ($requriedby) { $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)), array('class' => 'requiredby')); } else { $requiredby = ''; } $updateinfo = ''; if (is_array($plugin->available_updates())) { foreach ($plugin->available_updates() as $availableupdate) { $updateinfo .= $this->plugin_available_update_info($pluginman, $availableupdate); } } $notes = new html_table_cell($source.$msg.$requiredby.$updateinfo); $row->cells = array( $pluginname, $version, $availability, $settings, $uninstall, $notes ); $table->data[] = $row; } } return html_writer::table($table); } /** * Helper method to render the information about the available plugin update * * @param core_plugin_manager $pluginman plugin manager instance * @param \core\update\info $updateinfo information about the available update for the plugin */ protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) { $boxclasses = 'pluginupdateinfo'; $info = array(); if (isset($updateinfo->release)) { $info[] = html_writer::div( get_string('updateavailable_release', 'core_plugin', $updateinfo->release), 'info release' ); } if (isset($updateinfo->maturity)) { $info[] = html_writer::div( get_string('maturity'.$updateinfo->maturity, 'core_admin'), 'info maturity' ); $boxclasses .= ' maturity'.$updateinfo->maturity; } if (isset($updateinfo->download)) { $info[] = html_writer::div( html_writer::link($updateinfo->download, get_string('download')), 'info download' ); } if (isset($updateinfo->url)) { $info[] = html_writer::div( html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')), 'info more' ); } $box = html_writer::start_div($boxclasses); $box .= html_writer::div( get_string('updateavailable', 'core_plugin', $updateinfo->version), 'version' ); $box .= html_writer::div( implode(html_writer::span(' ', 'separator'), $info), 'infos' ); if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason, false)) { $box .= $this->output->single_button( new moodle_url($this->page->url, array('installupdate' => $updateinfo->component, 'installupdateversion' => $updateinfo->version)), get_string('updateavailableinstall', 'core_admin'), 'post', array('class' => 'singlebutton updateavailableinstall') ); } else { $reasonhelp = $this->info_remote_plugin_not_installable($reason); if ($reasonhelp) { $box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall'); } } $box .= html_writer::end_div(); return $box; } /** * This function will render one beautiful table with all the environmental * configuration and how it suits Moodle needs. * * @param boolean $result final result of the check (true/false) * @param environment_results[] $environment_results array of results gathered * @return string HTML to output. */ public function environment_check_table($result, $environment_results) { global $CFG; // Table headers $servertable = new html_table();//table for server checks $servertable->head = array( get_string('name'), get_string('info'), get_string('report'), get_string('plugin'), get_string('status'), ); $servertable->colclasses = array('centeralign name', 'centeralign info', 'leftalign report', 'leftalign plugin', 'centeralign status'); $servertable->attributes['class'] = 'admintable environmenttable generaltable table-sm'; $servertable->id = 'serverstatus'; $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array()); $othertable = new html_table();//table for custom checks $othertable->head = array( get_string('info'), get_string('report'), get_string('plugin'), get_string('status'), ); $othertable->colclasses = array('aligncenter info', 'alignleft report', 'alignleft plugin', 'aligncenter status'); $othertable->attributes['class'] = 'admintable environmenttable generaltable table-sm'; $othertable->id = 'otherserverstatus'; $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array()); // Iterate over each environment_result $continue = true; foreach ($environment_results as $environment_result) { $errorline = false; $warningline = false; $stringtouse = ''; if ($continue) { $type = $environment_result->getPart(); $info = $environment_result->getInfo(); $status = $environment_result->getStatus(); $plugin = $environment_result->getPluginName(); $error_code = $environment_result->getErrorCode(); // Process Report field $rec = new stdClass(); // Something has gone wrong at parsing time if ($error_code) { $stringtouse = 'environmentxmlerror'; $rec->error_code = $error_code; $status = get_string('error'); $errorline = true; $continue = false; } if ($continue) { if ($rec->needed = $environment_result->getNeededVersion()) { // We are comparing versions $rec->current = $environment_result->getCurrentVersion(); if ($environment_result->getLevel() == 'required') { $stringtouse = 'environmentrequireversion'; } else { $stringtouse = 'environmentrecommendversion'; } } else if ($environment_result->getPart() == 'custom_check') { // We are checking installed & enabled things if ($environment_result->getLevel() == 'required') { $stringtouse = 'environmentrequirecustomcheck'; } else { $stringtouse = 'environmentrecommendcustomcheck'; } } else if ($environment_result->getPart() == 'php_setting') { if ($status) { $stringtouse = 'environmentsettingok'; } else if ($environment_result->getLevel() == 'required') { $stringtouse = 'environmentmustfixsetting'; } else { $stringtouse = 'environmentshouldfixsetting'; } } else { if ($environment_result->getLevel() == 'required') { $stringtouse = 'environmentrequireinstall'; } else { $stringtouse = 'environmentrecommendinstall'; } } // Calculate the status value if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning) $status = get_string('bypassed'); $warningline = true; } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error) $status = get_string('restricted'); $errorline = true; } else { if ($status) { //Handle ok result (ok) $status = get_string('statusok'); } else { if ($environment_result->getLevel() == 'optional') {//Handle check result (warning) $status = get_string('check'); $warningline = true; } else { //Handle error result (error) $status = get_string('check'); $errorline = true; } } } } // Build the text $linkparts = array(); $linkparts[] = 'admin/environment'; $linkparts[] = $type; if (!empty($info)){ $linkparts[] = $info; } // Plugin environments do not have docs pages yet. if (empty($CFG->docroot) or $environment_result->plugin) { $report = get_string($stringtouse, 'admin', $rec); } else { $report = $this->doc_link(join('/', $linkparts), get_string($stringtouse, 'admin', $rec), true); } // Enclose report text in div so feedback text will be displayed underneath it. $report = html_writer::div($report); // Format error or warning line if ($errorline) { $messagetype = 'error'; $statusclass = 'badge-danger'; } else if ($warningline) { $messagetype = 'warn'; $statusclass = 'badge-warning'; } else { $messagetype = 'ok'; $statusclass = 'badge-success'; } $status = html_writer::span($status, 'badge ' . $statusclass); // Here we'll store all the feedback found $feedbacktext = ''; // Append the feedback if there is some $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype); //Append the bypass if there is some $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn'); //Append the restrict if there is some $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error'); $report .= $feedbacktext; // Add the row to the table if ($environment_result->getPart() == 'custom_check'){ $otherdata[$messagetype][] = array ($info, $report, $plugin, $status); } else { $serverdata[$messagetype][] = array ($type, $info, $report, $plugin, $status); } } } //put errors first in $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']); $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']); // Print table $output = ''; $output .= $this->heading(get_string('serverchecks', 'admin')); $output .= html_writer::table($servertable); if (count($othertable->data)){ $output .= $this->heading(get_string('customcheck', 'admin')); $output .= html_writer::table($othertable); } // Finally, if any error has happened, print the summary box if (!$result) { $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox'); } return $output; } /** * Render a simple page for providing the upgrade key. * * @param moodle_url|string $url * @return string */ public function upgradekey_form_page($url) { $output = ''; $output .= $this->header(); $output .= $this->container_start('upgradekeyreq'); $output .= $this->heading(get_string('upgradekeyreq', 'core_admin')); $output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url)); $output .= html_writer::empty_tag('input', [ 'name' => 'upgradekey', 'type' => 'password', 'class' => 'form-control w-auto', ]); $output .= html_writer::empty_tag('input', [ 'type' => 'submit', 'value' => get_string('submit'), 'class' => 'btn btn-primary mt-3', ]); $output .= html_writer::end_tag('form'); $output .= $this->container_end(); $output .= $this->footer(); return $output; } /** * Display message about the benefits of registering on Moodle.org * * @return string */ public function moodleorg_registration_message() { $out = format_text(get_string('registerwithmoodleorginfo', 'core_hub'), FORMAT_MARKDOWN); $out .= html_writer::link( new moodle_url('/admin/settings.php', ['section' => 'moodleservices']), $this->output->pix_icon('i/info', '').' '.get_string('registerwithmoodleorginfoapp', 'core_hub'), ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href'] ); $out .= html_writer::link( HUB_MOODLEORGHUBURL, $this->output->pix_icon('i/stats', '').' '.get_string('registerwithmoodleorginfostats', 'core_hub'), ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href'] ); $out .= html_writer::link( HUB_MOODLEORGHUBURL.'/sites', $this->output->pix_icon('i/location', '').' '.get_string('registerwithmoodleorginfosites', 'core_hub'), ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href'] ); return $this->output->box($out); } /** * Display message about benefits of enabling the user feedback feature. * * @param bool $showfeedbackencouragement Whether the encouragement content should be displayed or not * @return string */ protected function userfeedback_encouragement(bool $showfeedbackencouragement): string { $output = ''; if ($showfeedbackencouragement) { $settingslink = new moodle_url('/admin/settings.php', ['section' => 'userfeedback']); $output .= $this->warning(get_string('userfeedbackencouragement', 'admin', $settingslink->out()), 'info'); } return $output; } /** * Display a warning about the deprecation of Mnet. * * @param string $xmlrpcwarning The warning message * @return string HTML to output. */ protected function mnet_deprecation_warning($xmlrpcwarning) { if (empty($xmlrpcwarning)) { return ''; } return $this->warning($xmlrpcwarning); } } home/harasnat/www/learning/calendar/renderer.php 0000604 00000045047 15062106652 0016021 0 ustar 00 <?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * This file contains the renderers for the calendar within Moodle * * @copyright 2010 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @package calendar */ if (!defined('MOODLE_INTERNAL')) { die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page } /** * The primary renderer for the calendar. */ class core_calendar_renderer extends plugin_renderer_base { /** * Starts the standard layout for the page * * @return string */ public function start_layout() { return html_writer::start_tag('div', ['data-region' => 'calendar', 'class' => 'maincalendar']); } /** * Creates the remainder of the layout * * @return string */ public function complete_layout() { return html_writer::end_tag('div'); } /** * Produces the content for the three months block (pretend block) * * This includes the previous month, the current month, and the next month * * @deprecated since 4.0 MDL-72810. * @todo MDL-73117 This will be deleted in Moodle 4.4. * * @param calendar_information $calendar * @return string */ public function fake_block_threemonths(calendar_information $calendar) { debugging('This method is no longer used as the three month calendar block has been removed', DEBUG_DEVELOPER); // Get the calendar type we are using. $calendartype = \core_calendar\type_factory::get_calendar_instance(); $time = $calendartype->timestamp_to_date_array($calendar->time); $current = $calendar->time; $prevmonthyear = $calendartype->get_prev_month($time['year'], $time['mon']); $prev = $calendartype->convert_to_timestamp( $prevmonthyear[1], $prevmonthyear[0], 1 ); $nextmonthyear = $calendartype->get_next_month($time['year'], $time['mon']); $next = $calendartype->convert_to_timestamp( $nextmonthyear[1], $nextmonthyear[0], 1 ); $content = ''; // Previous. $calendar->set_time($prev); list($previousmonth, ) = calendar_get_view($calendar, 'minithree', false, true); // Current month. $calendar->set_time($current); list($currentmonth, ) = calendar_get_view($calendar, 'minithree', false, true); // Next month. $calendar->set_time($next); list($nextmonth, ) = calendar_get_view($calendar, 'minithree', false, true); // Reset the time back. $calendar->set_time($current); $data = (object) [ 'previousmonth' => $previousmonth, 'currentmonth' => $currentmonth, 'nextmonth' => $nextmonth, ]; $template = 'core_calendar/calendar_threemonth'; $content .= $this->render_from_template($template, $data); return $content; } /** * Adds a pretent calendar block * * @param block_contents $bc * @param mixed $pos BLOCK_POS_RIGHT | BLOCK_POS_LEFT */ public function add_pretend_calendar_block(block_contents $bc, $pos=BLOCK_POS_RIGHT) { $this->page->blocks->add_fake_block($bc, $pos); } /** * Creates a button to add a new event. * * @param int $courseid * @param int $unused1 * @param int $unused2 * @param int $unused3 * @param int $unused4 * @return string */ public function add_event_button($courseid, $unused1 = null, $unused2 = null, $unused3 = null, $unused4 = null) { $data = [ 'contextid' => (\context_course::instance($courseid))->id, ]; return $this->render_from_template('core_calendar/add_event_button', $data); } /** * Displays an event * * @deprecated since 3.9 * * @param calendar_event $event * @param bool $showactions * @return string */ public function event(calendar_event $event, $showactions=true) { global $CFG; debugging('This function is no longer used', DEBUG_DEVELOPER); $event = calendar_add_event_metadata($event); $context = $event->context; $output = ''; $output .= $this->output->box_start('card-header clearfix'); if (calendar_edit_event_allowed($event) && $showactions) { if (calendar_delete_event_allowed($event)) { $editlink = new moodle_url(CALENDAR_URL.'event.php', array('action' => 'edit', 'id' => $event->id)); $deletelink = new moodle_url(CALENDAR_URL.'delete.php', array('id' => $event->id)); if (!empty($event->calendarcourseid)) { $editlink->param('course', $event->calendarcourseid); $deletelink->param('course', $event->calendarcourseid); } } else { $params = array('update' => $event->cmid, 'return' => true, 'sesskey' => sesskey()); $editlink = new moodle_url('/course/mod.php', $params); $deletelink = null; } $commands = html_writer::start_tag('div', array('class' => 'commands float-sm-right')); $commands .= html_writer::start_tag('a', array('href' => $editlink)); $str = get_string('tt_editevent', 'calendar'); $commands .= $this->output->pix_icon('t/edit', $str); $commands .= html_writer::end_tag('a'); if ($deletelink != null) { $commands .= html_writer::start_tag('a', array('href' => $deletelink)); $str = get_string('tt_deleteevent', 'calendar'); $commands .= $this->output->pix_icon('t/delete', $str); $commands .= html_writer::end_tag('a'); } $commands .= html_writer::end_tag('div'); $output .= $commands; } if (!empty($event->icon)) { $output .= $event->icon; } else { $output .= $this->output->spacer(array('height' => 16, 'width' => 16)); } if (!empty($event->referer)) { $output .= $this->output->heading($event->referer, 3, array('class' => 'referer')); } else { $output .= $this->output->heading( format_string($event->name, false, array('context' => $context)), 3, array('class' => 'name d-inline-block') ); } // Show subscription source if needed. if (!empty($event->subscription) && $CFG->calendar_showicalsource) { if (!empty($event->subscription->url)) { $source = html_writer::link($event->subscription->url, get_string('subscriptionsource', 'calendar', $event->subscription->name)); } else { // File based ical. $source = get_string('subscriptionsource', 'calendar', $event->subscription->name); } $output .= html_writer::tag('div', $source, array('class' => 'subscription')); } if (!empty($event->courselink)) { $output .= html_writer::tag('div', $event->courselink); } if (!empty($event->time)) { $output .= html_writer::tag('span', $event->time, array('class' => 'date float-sm-right mr-1')); } else { $attrs = array('class' => 'date float-sm-right mr-1'); $output .= html_writer::tag('span', calendar_time_representation($event->timestart), $attrs); } if (!empty($event->actionurl)) { $actionlink = html_writer::link(new moodle_url($event->actionurl), $event->actionname); $output .= html_writer::tag('div', $actionlink, ['class' => 'action']); } $output .= $this->output->box_end(); $eventdetailshtml = ''; $eventdetailsclasses = ''; $eventdetailshtml .= format_text($event->description, $event->format, array('context' => $context)); $eventdetailsclasses .= 'description card-block'; if (isset($event->cssclass)) { $eventdetailsclasses .= ' '.$event->cssclass; } if (!empty($eventdetailshtml)) { $output .= html_writer::tag('div', $eventdetailshtml, array('class' => $eventdetailsclasses)); } $eventhtml = html_writer::tag('div', $output, array('class' => 'card')); return html_writer::tag('div', $eventhtml, array('class' => 'event', 'id' => 'event_' . $event->id)); } /** * Displays a course filter selector * * @param moodle_url $returnurl The URL that the user should be taken too upon selecting a course. * @param string $label The label to use for the course select. * @param int $courseid The id of the course to be selected. * @param int|null $calendarinstanceid The instance ID of the calendar we're generating this course filter for. * @return string */ public function course_filter_selector(moodle_url $returnurl, $label = null, $courseid = null, int $calendarinstanceid = null) { global $CFG, $DB; if (!isloggedin() or isguestuser()) { return ''; } $contextrecords = []; $courses = calendar_get_default_courses($courseid, 'id, shortname'); if (!empty($courses) && count($courses) > CONTEXT_CACHE_MAX_SIZE) { // We need to pull the context records from the DB to preload them // below. The calendar_get_default_courses code will actually preload // the contexts itself however the context cache is capped to a certain // amount before it starts recycling. Unfortunately that starts to happen // quite a bit if a user has access to a large number of courses (e.g. admin). // So in order to avoid hitting the DB for each context as we loop below we // can load all of the context records and add them to the cache just in time. $courseids = array_map(function($c) { return $c->id; }, $courses); list($insql, $params) = $DB->get_in_or_equal($courseids); $contextsql = "SELECT ctx.instanceid, " . context_helper::get_preload_record_columns_sql('ctx') . " FROM {context} ctx WHERE ctx.contextlevel = ? AND ctx.instanceid $insql"; array_unshift($params, CONTEXT_COURSE); $contextrecords = $DB->get_records_sql($contextsql, $params); } unset($courses[SITEID]); $courseoptions = array(); $courseoptions[SITEID] = get_string('fulllistofcourses'); foreach ($courses as $course) { if (isset($contextrecords[$course->id])) { context_helper::preload_from_record($contextrecords[$course->id]); } $coursecontext = context_course::instance($course->id); $courseoptions[$course->id] = format_string($course->shortname, true, array('context' => $coursecontext)); } if ($courseid) { $selected = $courseid; } else if ($this->page->course->id !== SITEID) { $selected = $this->page->course->id; } else { $selected = ''; } $courseurl = new moodle_url($returnurl); $courseurl->remove_params('course'); $labelattributes = []; if (empty($label)) { $label = get_string('listofcourses'); $labelattributes['class'] = 'sr-only'; } $filterid = 'calendar-course-filter'; if ($calendarinstanceid) { $filterid .= "-$calendarinstanceid"; } $select = html_writer::label($label, $filterid, false, $labelattributes); $select .= html_writer::select($courseoptions, 'course', $selected, false, ['class' => 'cal_courses_flt ml-1 mr-auto', 'id' => $filterid]); return $select; } /** * Render the subscriptions header * * @return string */ public function render_subscriptions_header(): string { $importcalendarbutton = new single_button(new moodle_url('/calendar/import.php', calendar_get_export_import_link_params()), get_string('importcalendar', 'calendar'), 'get', single_button::BUTTON_PRIMARY); $importcalendarbutton->class .= ' float-sm-right float-right'; $exportcalendarbutton = new single_button(new moodle_url('/calendar/export.php', calendar_get_export_import_link_params()), get_string('exportcalendar', 'calendar'), 'get', single_button::BUTTON_PRIMARY); $exportcalendarbutton->class .= ' float-sm-right float-right'; $output = $this->output->heading(get_string('managesubscriptions', 'calendar')); $output .= html_writer::start_div('header d-flex flex-wrap mt-5'); $headerattr = [ 'class' => 'mr-auto', 'aria-describedby' => 'subscription_details_table', ]; $output .= html_writer::tag('h3', get_string('yoursubscriptions', 'calendar'), $headerattr); $output .= $this->output->render($importcalendarbutton); $output .= $this->output->render($exportcalendarbutton); $output .= html_writer::end_div(); return $output; } /** * Render the subscriptions blank state appearance * * @return string */ public function render_no_calendar_subscriptions(): string { $output = html_writer::start_div('mt-5'); $importlink = html_writer::link((new moodle_url('/calendar/import.php', calendar_get_export_import_link_params()))->out(), get_string('importcalendarexternal', 'calendar')); $output .= get_string('nocalendarsubscriptions', 'calendar', $importlink); $output .= html_writer::end_div(); return $output; } /** * Renders a table containing information about calendar subscriptions. * * @param int $unused * @param array $subscriptions * @param string $unused2 * @return string */ public function subscription_details($unused, $subscriptions, $unused2 = '') { $table = new html_table(); $table->head = array( get_string('colcalendar', 'calendar'), get_string('collastupdated', 'calendar'), get_string('eventkind', 'calendar'), get_string('colpoll', 'calendar'), get_string('colactions', 'calendar') ); $table->data = array(); $table->id = 'subscription_details_table'; if (empty($subscriptions)) { $cell = new html_table_cell(get_string('nocalendarsubscriptions', 'calendar')); $cell->colspan = 5; $table->data[] = new html_table_row(array($cell)); } $strnever = new lang_string('never', 'calendar'); foreach ($subscriptions as $sub) { $label = $sub->name; if (!empty($sub->url)) { $label = html_writer::link($sub->url, $label); } if (empty($sub->lastupdated)) { $lastupdated = $strnever->out(); } else { $lastupdated = userdate($sub->lastupdated, get_string('strftimedatetimeshort', 'langconfig')); } $type = $sub->eventtype . 'events'; $calendarname = new html_table_cell($label); $calendarname->header = true; $tablerow = new html_table_row(array( $calendarname, new html_table_cell($lastupdated), new html_table_cell(get_string($type, 'calendar')), new html_table_cell($this->render_subscription_update_interval($sub)), new html_table_cell($this->subscription_action_links()) )); $tablerow->attributes += [ 'data-subid' => $sub->id, 'data-subname' => $sub->name ]; $table->data[] = $tablerow; } $out = $this->output->box_start('generalbox calendarsubs'); $out .= html_writer::table($table); $out .= $this->output->box_end(); $this->page->requires->js_call_amd('core_calendar/manage_subscriptions', 'init'); return $out; } /** * Render subscription update interval form. * * @param stdClass $subscription * @return string */ protected function render_subscription_update_interval(stdClass $subscription): string { if (empty($subscription->url)) { return ''; } $tmpl = new \core_calendar\output\refreshintervalcollection($subscription); return $this->output->render_from_template('core/inplace_editable', $tmpl->export_for_template($this->output)); } /** * Creates a form to perform actions on a given subscription. * * @return string */ protected function subscription_action_links(): string { $html = html_writer::start_tag('div', array('class' => 'btn-group float-left')); $html .= html_writer::span(html_writer::link('#', get_string('delete'), ['data-action' => 'delete-subscription']), ''); $html .= html_writer::end_tag('div'); return $html; } /** * Render the event filter region. * * @return string */ public function event_filter() { $data = [ 'eventtypes' => calendar_get_filter_types(), ]; return $this->render_from_template('core_calendar/event_filter', $data); } /** * Render the calendar import result. * * @param array $result Import result * @return string|null */ public function render_import_result(array $result): ?string { $data = [ 'eventsimported' => $result['eventsimported'], 'eventsskipped' => $result['eventsskipped'], 'eventsupdated' => $result['eventsupdated'], 'eventsdeleted' => $result['eventsdeleted'], 'haserror' => $result['haserror'], 'errors' => $result['errors'] ]; return $this->render_from_template('core_calendar/subscription_update_result', $data); } } home/harasnat/www/learning/course/renderer.php 0000604 00000311071 15062125005 0015532 0 ustar 00 <?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Renderer for use with the course section and all the goodness that falls * within it. * * This renderer should contain methods useful to courses, and categories. * * @package moodlecore * @copyright 2010 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * The core course renderer * * Can be retrieved with the following: * $renderer = $PAGE->get_renderer('core','course'); */ class core_course_renderer extends plugin_renderer_base { const COURSECAT_SHOW_COURSES_NONE = 0; /* do not show courses at all */ const COURSECAT_SHOW_COURSES_COUNT = 5; /* do not show courses but show number of courses next to category name */ const COURSECAT_SHOW_COURSES_COLLAPSED = 10; const COURSECAT_SHOW_COURSES_AUTO = 15; /* will choose between collapsed and expanded automatically */ const COURSECAT_SHOW_COURSES_EXPANDED = 20; const COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT = 30; const COURSECAT_TYPE_CATEGORY = 0; const COURSECAT_TYPE_COURSE = 1; /** * A cache of strings * @var stdClass */ protected $strings; /** * Whether a category content is being initially rendered with children. This is mainly used by the * core_course_renderer::corsecat_tree() to render the appropriate action for the Expand/Collapse all link on * page load. * @var bool */ protected $categoryexpandedonload = false; /** * Override the constructor so that we can initialise the string cache * * @param moodle_page $page * @param string $target */ public function __construct(moodle_page $page, $target) { $this->strings = new stdClass; $courseid = $page->course->id; parent::__construct($page, $target); } /** * @deprecated since 3.2 */ protected function add_modchoosertoggle() { throw new coding_exception('core_course_renderer::add_modchoosertoggle() can not be used anymore.'); } /** * Renders course info box. * * @param stdClass $course * @return string */ public function course_info_box(stdClass $course) { $content = ''; $content .= $this->output->box_start('generalbox info'); $chelper = new coursecat_helper(); $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED); $content .= $this->coursecat_coursebox($chelper, $course); $content .= $this->output->box_end(); return $content; } /** * Renderers a structured array of courses and categories into a nice XHTML tree structure. * * @deprecated since 2.5 * * @param array $ignored argument ignored * @return string */ public final function course_category_tree(array $ignored) { debugging('Function core_course_renderer::course_category_tree() is deprecated, please use frontpage_combo_list()', DEBUG_DEVELOPER); return $this->frontpage_combo_list(); } /** * Renderers a category for use with course_category_tree * * @deprecated since 2.5 * * @param array $category * @param int $depth * @return string */ protected final function course_category_tree_category(stdClass $category, $depth=1) { debugging('Function core_course_renderer::course_category_tree_category() is deprecated', DEBUG_DEVELOPER); return ''; } /** * Render a modchooser. * * @param renderable $modchooser The chooser. * @return string */ public function render_modchooser(renderable $modchooser) { return $this->render_from_template('core_course/modchooser', $modchooser->export_for_template($this)); } /** * @deprecated since 3.9 */ public function course_modchooser() { throw new coding_exception('course_modchooser() can not be used anymore, please use course_activitychooser() instead.'); } /** * Build the HTML for the module chooser javascript popup. * * @param int $courseid The course id to fetch modules for. * @return string */ public function course_activitychooser($courseid) { if (!$this->page->requires->should_create_one_time_item_now('core_course_modchooser')) { return ''; } // Build an object of config settings that we can then hook into in the Activity Chooser. $chooserconfig = (object) [ 'tabmode' => get_config('core', 'activitychoosertabmode'), ]; $this->page->requires->js_call_amd('core_course/activitychooser', 'init', [$courseid, $chooserconfig]); return ''; } /** * Build the HTML for a specified set of modules * * @param array $modules A set of modules as used by the * course_modchooser_module function * @return string The composed HTML for the module */ protected function course_modchooser_module_types($modules) { debugging('Method core_course_renderer::course_modchooser_module_types() is deprecated, ' . 'see core_course_renderer::render_modchooser().', DEBUG_DEVELOPER); return ''; } /** * Return the HTML for the specified module adding any required classes * * @param object $module An object containing the title, and link. An * icon, and help text may optionally be specified. If the module * contains subtypes in the types option, then these will also be * displayed. * @param array $classes Additional classes to add to the encompassing * div element * @return string The composed HTML for the module */ protected function course_modchooser_module($module, $classes = array('option')) { debugging('Method core_course_renderer::course_modchooser_module() is deprecated, ' . 'see core_course_renderer::render_modchooser().', DEBUG_DEVELOPER); return ''; } protected function course_modchooser_title($title, $identifier = null) { debugging('Method core_course_renderer::course_modchooser_title() is deprecated, ' . 'see core_course_renderer::render_modchooser().', DEBUG_DEVELOPER); return ''; } /** * Renders HTML for displaying the sequence of course module editing buttons * * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more. * * @see course_get_cm_edit_actions() * * @param action_link[] $actions Array of action_link objects * @param cm_info $mod The module we are displaying actions for. * @param array $displayoptions additional display options: * ownerselector => A JS/CSS selector that can be used to find an cm node. * If specified the owning node will be given the class 'action-menu-shown' when the action * menu is being displayed. * donotenhance => If set to true the action menu that gets displayed won't be enhanced by JS. * @return string */ public function course_section_cm_edit_actions($actions, cm_info $mod = null, $displayoptions = array()) { global $CFG; debugging( 'course_section_cm_edit_actions is deprecated. Use core_courseformat\\output\\local\\content\\cm\\controlmenu instead.', DEBUG_DEVELOPER ); if (empty($actions)) { return ''; } if (isset($displayoptions['ownerselector'])) { $ownerselector = $displayoptions['ownerselector']; } else if ($mod) { $ownerselector = '#module-'.$mod->id; } else { debugging('You should upgrade your call to '.__FUNCTION__.' and provide $mod', DEBUG_DEVELOPER); $ownerselector = 'li.activity'; } $menu = new action_menu(); $menu->set_owner_selector($ownerselector); $menu->set_menu_trigger(get_string('edit')); foreach ($actions as $action) { if ($action instanceof action_menu_link) { $action->add_class('cm-edit-action'); } $menu->add($action); } $menu->attributes['class'] .= ' section-cm-edit-actions commands'; // Prioritise the menu ahead of all other actions. $menu->prioritise = true; return $this->render($menu); } /** * Renders HTML for the menus to add activities and resources to the current course * * Renders the ajax control (the link which when clicked produces the activity chooser modal). No noscript fallback. * * @param stdClass $course * @param int $section relative section number (field course_sections.section) * @param int $sectionreturn The section to link back to * @param array $displayoptions additional display options, for example blocks add * option 'inblock' => true, suggesting to display controls vertically * @return string */ function course_section_add_cm_control($course, $section, $sectionreturn = null, $displayoptions = array()) { // Check to see if user can add menus. if (!has_capability('moodle/course:manageactivities', context_course::instance($course->id)) || !$this->page->user_is_editing()) { return ''; } $data = [ 'sectionid' => $section, 'sectionreturn' => $sectionreturn ]; $ajaxcontrol = $this->render_from_template('course/activitychooserbutton', $data); // Load the JS for the modal. $this->course_activitychooser($course->id); return $ajaxcontrol; } /** * Renders html to display a course search form * * @param string $value default value to populate the search field * @return string */ public function course_search_form($value = '') { $data = [ 'action' => \core_search\manager::get_course_search_url(), 'btnclass' => 'btn-primary', 'inputname' => 'q', 'searchstring' => get_string('searchcourses'), 'hiddenfields' => (object) ['name' => 'areaids', 'value' => 'core_course-course'], 'query' => $value ]; return $this->render_from_template('core/search_input', $data); } /** * @deprecated since Moodle 3.11 */ public function course_section_cm_completion() { throw new coding_exception(__FUNCTION__ . ' is deprecated. Use the activity_completion output component instead.'); } /** * Checks if course module has any conditions that may make it unavailable for * all or some of the students * * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more. * * @param cm_info $mod * @return bool */ public function is_cm_conditionally_hidden(cm_info $mod) { global $CFG; debugging( 'is_cm_conditionally_hidden is deprecated. Use \core_availability\info_module::is_available_for_all instead', DEBUG_DEVELOPER ); $conditionalhidden = false; if (!empty($CFG->enableavailability)) { $info = new \core_availability\info_module($mod); $conditionalhidden = !$info->is_available_for_all(); } return $conditionalhidden; } /** * Renders html to display a name with the link to the course module on a course page * * If module is unavailable for user but still needs to be displayed * in the list, just the name is returned without a link * * Note, that for course modules that never have separate pages (i.e. labels) * this function return an empty string * * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more. * * @param cm_info $mod * @param array $displayoptions * @return string */ public function course_section_cm_name(cm_info $mod, $displayoptions = array()) { debugging( 'course_section_cm_name is deprecated. Use core_courseformat\\output\\local\\content\\cm\\cmname class instead.', DEBUG_DEVELOPER ); if (!$mod->is_visible_on_course_page() || !$mod->url) { // Nothing to be displayed to the user. return ''; } list($linkclasses, $textclasses) = $this->course_section_cm_classes($mod); $groupinglabel = $mod->get_grouping_label($textclasses); // Render element that allows to edit activity name inline. $format = course_get_format($mod->course); $cmnameclass = $format->get_output_classname('content\\cm\\cmname'); // Mod inplace name editable. $cmname = new $cmnameclass( $format, $mod->get_section_info(), $mod, null, $displayoptions ); $renderer = $format->get_renderer($this->page); return $renderer->render($cmname) . $groupinglabel; } /** * Returns the CSS classes for the activity name/content * * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more. * * For items which are hidden, unavailable or stealth but should be displayed * to current user ($mod->is_visible_on_course_page()), we show those as dimmed. * Students will also see as dimmed activities names that are not yet available * but should still be displayed (without link) with availability info. * * @param cm_info $mod * @return array array of two elements ($linkclasses, $textclasses) */ protected function course_section_cm_classes(cm_info $mod) { debugging( 'course_section_cm_classes is deprecated. Now it is part of core_courseformat\\output\\local\\content\\cm ', DEBUG_DEVELOPER ); $format = course_get_format($mod->course); $cmclass = $format->get_output_classname('content\\cm'); $cmoutput = new $cmclass( $format, $mod->get_section_info(), $mod, ); return [ $cmoutput->get_link_classes(), $cmoutput->get_text_classes(), ]; } /** * Renders html to display a name with the link to the course module on a course page * * If module is unavailable for user but still needs to be displayed * in the list, just the name is returned without a link * * Note, that for course modules that never have separate pages (i.e. labels) * this function return an empty string * * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more. * * @param cm_info $mod * @param array $displayoptions * @return string */ public function course_section_cm_name_title(cm_info $mod, $displayoptions = array()) { debugging( 'course_section_cm_name_title is deprecated. Use core_courseformat\\output\\local\\cm\\title class instead.', DEBUG_DEVELOPER ); $output = ''; $url = $mod->url; if (!$mod->is_visible_on_course_page() || !$url) { // Nothing to be displayed to the user. return $output; } //Accessibility: for files get description via icon, this is very ugly hack! $instancename = $mod->get_formatted_name(); $altname = $mod->modfullname; // Avoid unnecessary duplication: if e.g. a forum name already // includes the word forum (or Forum, etc) then it is unhelpful // to include that in the accessible description that is added. if (false !== strpos(core_text::strtolower($instancename), core_text::strtolower($altname))) { $altname = ''; } // File type after name, for alphabetic lists (screen reader). if ($altname) { $altname = get_accesshide(' '.$altname); } list($linkclasses, $textclasses) = $this->course_section_cm_classes($mod); // Get on-click attribute value if specified and decode the onclick - it // has already been encoded for display (puke). $onclick = htmlspecialchars_decode($mod->onclick, ENT_QUOTES); // Display link itself. $instancename = html_writer::tag('span', $instancename . $altname, ['class' => 'instancename ml-1']); $imageicon = html_writer::empty_tag('img', ['src' => $mod->get_icon_url(), 'class' => 'activityicon', 'alt' => '', 'role' => 'presentation', 'aria-hidden' => 'true']); $imageicon = html_writer::tag('span', $imageicon, ['class' => 'activityiconcontainer courseicon']); $activitylink = $imageicon . $instancename; if ($mod->uservisible) { $output .= html_writer::link($url, $activitylink, array('class' => 'aalink' . $linkclasses, 'onclick' => $onclick)); } else { // We may be displaying this just in order to show information // about visibility, without the actual link ($mod->is_visible_on_course_page()). $output .= html_writer::tag('div', $activitylink, array('class' => $textclasses)); } return $output; } /** * Renders html to display the module content on the course page (i.e. text of the labels) * * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more. * * @param cm_info $mod * @param array $displayoptions * @return string */ public function course_section_cm_text(cm_info $mod, $displayoptions = array()) { debugging( 'course_section_cm_text is deprecated. Now it is part of core_courseformat\\output\\local\\content\\cm ', DEBUG_DEVELOPER ); $output = ''; if (!$mod->is_visible_on_course_page()) { // nothing to be displayed to the user return $output; } $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)); list($linkclasses, $textclasses) = $this->course_section_cm_classes($mod); if ($mod->url && $mod->uservisible) { if ($content) { // If specified, display extra content after link. $output = html_writer::tag('div', $content, array('class' => trim('contentafterlink ' . $textclasses))); } } else { $groupinglabel = $mod->get_grouping_label($textclasses); // No link, so display only content. $output = html_writer::tag('div', $content . $groupinglabel, array('class' => 'contentwithoutlink ' . $textclasses)); } return $output; } /** * Displays availability info for a course section or course module * * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more. * @param string $text * @param string $additionalclasses * @return string */ public function availability_info($text, $additionalclasses = '') { debugging( 'availability_info is deprecated. Use core_courseformat\\output\\local\\content\\section\\availability instead', DEBUG_DEVELOPER ); $data = ['text' => $text, 'classes' => $additionalclasses]; $additionalclasses = array_filter(explode(' ', $additionalclasses)); if (in_array('ishidden', $additionalclasses)) { $data['ishidden'] = 1; } else if (in_array('isstealth', $additionalclasses)) { $data['isstealth'] = 1; } else if (in_array('isrestricted', $additionalclasses)) { $data['isrestricted'] = 1; if (in_array('isfullinfo', $additionalclasses)) { $data['isfullinfo'] = 1; } } return $this->render_from_template('core/availability_info', $data); } /** * Renders HTML to show course module availability information (for someone who isn't allowed * to see the activity itself, or for staff) * * @deprecated since Moodle 4.0 MDL-72656 - please do not use this function any more. * @param cm_info $mod * @param array $displayoptions * @return string */ public function course_section_cm_availability(cm_info $mod, $displayoptions = array()) { debugging( 'course_section_cm_availability is deprecated. Use core_courseformat\\output\\local\\content\\cm\\availability instead', DEBUG_DEVELOPER ); $format = course_get_format($mod->course); $availabilityclass = $format->get_output_classname('content\\cm\\availability'); $availability = new $availabilityclass( $format, $mod->get_section_info(), $mod, ); $renderer = $format->get_renderer($this->page); return $renderer->render($availability); } /** * Renders HTML to display one course module for display within a section. * * @deprecated since 4.0 - use core_course output components or course_format::course_section_updated_cm_item instead. * * This function calls: * {@link core_course_renderer::course_section_cm()} * * @param stdClass $course * @param completion_info $completioninfo * @param cm_info $mod * @param int|null $sectionreturn * @param array $displayoptions * @return String */ public function course_section_cm_list_item($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = []) { debugging( 'course_section_cm_list_item is deprecated. Use renderer course_section_updated_cm_item instead', DEBUG_DEVELOPER ); $output = ''; if ($modulehtml = $this->course_section_cm($course, $completioninfo, $mod, $sectionreturn, $displayoptions)) { $modclasses = 'activity ' . $mod->modname . ' modtype_' . $mod->modname . ' ' . $mod->extraclasses; $output .= html_writer::tag('li', $modulehtml, array('class' => $modclasses, 'id' => 'module-' . $mod->id)); } return $output; } /** * Renders HTML to display one course module in a course section * * This includes link, content, availability, completion info and additional information * that module type wants to display (i.e. number of unread forum posts) * * @deprecated since 4.0 MDL-72656 - use core_course output components instead. * * @param stdClass $course * @param completion_info $completioninfo * @param cm_info $mod * @param int|null $sectionreturn * @param array $displayoptions * @return string */ public function course_section_cm($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = []) { debugging( 'course_section_cm is deprecated. Use core_courseformat\\output\\content\\cm output class instead.', DEBUG_DEVELOPER ); if (!$mod->is_visible_on_course_page()) { return ''; } $format = course_get_format($course); $modinfo = $format->get_modinfo(); // Output renderers works only with real section_info objects. if ($sectionreturn) { $format->set_section_number($sectionreturn); } $section = $modinfo->get_section_info($format->get_section_number()); $cmclass = $format->get_output_classname('content\\cm'); $cm = new $cmclass($format, $section, $mod, $displayoptions); // The course outputs works with format renderers, not with course renderers. $renderer = $format->get_renderer($this->page); $data = $cm->export_for_template($renderer); return $this->output->render_from_template('core_courseformat/local/content/cm', $data); } /** * Message displayed to the user when they try to access unavailable activity following URL * * This method is a very simplified version of {@link course_section_cm()} to be part of the error * notification only. It also does not check if module is visible on course page or not. * * The message will be displayed inside notification! * * @param cm_info $cm * @return string */ public function course_section_cm_unavailable_error_message(cm_info $cm) { if ($cm->uservisible) { return null; } if (!$cm->availableinfo) { return get_string('activityiscurrentlyhidden'); } $altname = get_accesshide(' ' . $cm->modfullname); $name = html_writer::empty_tag('img', array('src' => $cm->get_icon_url(), 'class' => 'iconlarge activityicon', 'alt' => ' ', 'role' => 'presentation')) . html_writer::tag('span', ' '.$cm->get_formatted_name() . $altname, array('class' => 'instancename')); $formattedinfo = \core_availability\info::format_info($cm->availableinfo, $cm->get_course()); return html_writer::div($name, 'activityinstance-error') . html_writer::div($formattedinfo, 'availabilityinfo-error'); } /** * Renders HTML to display a list of course modules in a course section * Also displays "move here" controls in Javascript-disabled mode. * * @deprecated since 4.0 MDL-72656 - use core_course output components instead. * * This function calls {@link core_course_renderer::course_section_cm()} * * @param stdClass $course course object * @param int|stdClass|section_info $section relative section number or section object * @param int $sectionreturn section number to return to * @param int $displayoptions * @return void */ public function course_section_cm_list($course, $section, $sectionreturn = null, $displayoptions = []) { global $USER; debugging('course_section_cm_list is deprecated. Use core_courseformat\\output\\local\\content\\section\\cmlist '. 'classes instead.', DEBUG_DEVELOPER); $output = ''; $format = course_get_format($course); $modinfo = $format->get_modinfo(); if (is_object($section)) { $section = $modinfo->get_section_info($section->section); } else { $section = $modinfo->get_section_info($section); } $completioninfo = new completion_info($course); // check if we are currently in the process of moving a module with JavaScript disabled $ismoving = $format->show_editor() && ismoving($course->id); if ($ismoving) { $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); } // Get the list of modules visible to user (excluding the module being moved if there is one) $moduleshtml = []; if (!empty($modinfo->sections[$section->section])) { foreach ($modinfo->sections[$section->section] as $modnumber) { $mod = $modinfo->cms[$modnumber]; if ($ismoving and $mod->id == $USER->activitycopy) { // do not display moving mod continue; } if ($modulehtml = $this->course_section_cm_list_item($course, $completioninfo, $mod, $sectionreturn, $displayoptions)) { $moduleshtml[$modnumber] = $modulehtml; } } } $sectionoutput = ''; if (!empty($moduleshtml) || $ismoving) { foreach ($moduleshtml as $modnumber => $modulehtml) { if ($ismoving) { $movingurl = new moodle_url('/course/mod.php', array('moveto' => $modnumber, 'sesskey' => sesskey())); $sectionoutput .= html_writer::tag('li', html_writer::link($movingurl, '', array('title' => $strmovefull, 'class' => 'movehere')), array('class' => 'movehere')); } $sectionoutput .= $modulehtml; } if ($ismoving) { $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey())); $sectionoutput .= html_writer::tag('li', html_writer::link($movingurl, '', array('title' => $strmovefull, 'class' => 'movehere')), array('class' => 'movehere')); } } // Always output the section module list. $output .= html_writer::tag('ul', $sectionoutput, array('class' => 'section img-text')); return $output; } /** * Displays a custom list of courses with paging bar if necessary * * If $paginationurl is specified but $totalcount is not, the link 'View more' * appears under the list. * * If both $paginationurl and $totalcount are specified, and $totalcount is * bigger than count($courses), a paging bar is displayed above and under the * courses list. * * @param array $courses array of course records (or instances of core_course_list_element) to show on this page * @param bool $showcategoryname whether to add category name to the course description * @param string $additionalclasses additional CSS classes to add to the div.courses * @param moodle_url $paginationurl url to view more or url to form links to the other pages in paging bar * @param int $totalcount total number of courses on all pages, if omitted $paginationurl will be displayed as 'View more' link * @param int $page current page number (defaults to 0 referring to the first page) * @param int $perpage number of records per page (defaults to $CFG->coursesperpage) * @return string */ public function courses_list($courses, $showcategoryname = false, $additionalclasses = null, $paginationurl = null, $totalcount = null, $page = 0, $perpage = null) { global $CFG; // create instance of coursecat_helper to pass display options to function rendering courses list $chelper = new coursecat_helper(); if ($showcategoryname) { $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT); } else { $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED); } if ($totalcount !== null && $paginationurl !== null) { // add options to display pagination if ($perpage === null) { $perpage = $CFG->coursesperpage; } $chelper->set_courses_display_options(array( 'limit' => $perpage, 'offset' => ((int)$page) * $perpage, 'paginationurl' => $paginationurl, )); } else if ($paginationurl !== null) { // add options to display 'View more' link $chelper->set_courses_display_options(array('viewmoreurl' => $paginationurl)); $totalcount = count($courses) + 1; // has to be bigger than count($courses) otherwise link will not be displayed } $chelper->set_attributes(array('class' => $additionalclasses)); $content = $this->coursecat_courses($chelper, $courses, $totalcount); return $content; } /** * Returns HTML to display course name. * * @param coursecat_helper $chelper * @param core_course_list_element $course * @return string */ protected function course_name(coursecat_helper $chelper, core_course_list_element $course): string { $content = ''; if ($chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_EXPANDED) { $nametag = 'h3'; } else { $nametag = 'div'; } $coursename = $chelper->get_course_formatted_name($course); $coursenamelink = html_writer::link(new moodle_url('/course/view.php', ['id' => $course->id]), $coursename, ['class' => $course->visible ? 'aalink' : 'aalink dimmed']); $content .= html_writer::tag($nametag, $coursenamelink, ['class' => 'coursename']); // If we display course in collapsed form but the course has summary or course contacts, display the link to the info page. $content .= html_writer::start_tag('div', ['class' => 'moreinfo']); if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) { if ($course->has_summary() || $course->has_course_contacts() || $course->has_course_overviewfiles() || $course->has_custom_fields()) { $url = new moodle_url('/course/info.php', ['id' => $course->id]); $image = $this->output->pix_icon('i/info', $this->strings->summary); $content .= html_writer::link($url, $image, ['title' => $this->strings->summary]); // Make sure JS file to expand course content is included. $this->coursecat_include_js(); } } $content .= html_writer::end_tag('div'); return $content; } /** * Returns HTML to display course enrolment icons. * * @param core_course_list_element $course * @return string */ protected function course_enrolment_icons(core_course_list_element $course): string { $content = ''; if ($icons = enrol_get_course_info_icons($course)) { $content .= html_writer::start_tag('div', ['class' => 'enrolmenticons']); foreach ($icons as $icon) { $content .= $this->render($icon); } $content .= html_writer::end_tag('div'); } return $content; } /** * Displays one course in the list of courses. * * This is an internal function, to display an information about just one course * please use {@link core_course_renderer::course_info_box()} * * @param coursecat_helper $chelper various display options * @param core_course_list_element|stdClass $course * @param string $additionalclasses additional classes to add to the main <div> tag (usually * depend on the course position in list - first/last/even/odd) * @return string */ protected function coursecat_coursebox(coursecat_helper $chelper, $course, $additionalclasses = '') { if (!isset($this->strings->summary)) { $this->strings->summary = get_string('summary'); } if ($chelper->get_show_courses() <= self::COURSECAT_SHOW_COURSES_COUNT) { return ''; } if ($course instanceof stdClass) { $course = new core_course_list_element($course); } $content = ''; $classes = trim('coursebox clearfix '. $additionalclasses); if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) { $classes .= ' collapsed'; } // .coursebox $content .= html_writer::start_tag('div', array( 'class' => $classes, 'data-courseid' => $course->id, 'data-type' => self::COURSECAT_TYPE_COURSE, )); $content .= html_writer::start_tag('div', array('class' => 'info')); $content .= $this->course_name($chelper, $course); $content .= $this->course_enrolment_icons($course); $content .= html_writer::end_tag('div'); $content .= html_writer::start_tag('div', array('class' => 'content')); $content .= $this->coursecat_coursebox_content($chelper, $course); $content .= html_writer::end_tag('div'); $content .= html_writer::end_tag('div'); // .coursebox return $content; } /** * Returns HTML to display course summary. * * @param coursecat_helper $chelper * @param core_course_list_element $course * @return string */ protected function course_summary(coursecat_helper $chelper, core_course_list_element $course): string { $content = ''; if ($course->has_summary()) { $content .= html_writer::start_tag('div', ['class' => 'summary']); $content .= $chelper->get_course_formatted_summary($course, array('overflowdiv' => true, 'noclean' => true, 'para' => false)); $content .= html_writer::end_tag('div'); } return $content; } /** * Returns HTML to display course contacts. * * @param core_course_list_element $course * @return string */ protected function course_contacts(core_course_list_element $course) { $content = ''; if ($course->has_course_contacts()) { $content .= html_writer::start_tag('ul', ['class' => 'teachers']); foreach ($course->get_course_contacts() as $coursecontact) { $rolenames = array_map(function ($role) { return $role->displayname; }, $coursecontact['roles']); $name = html_writer::tag('span', implode(", ", $rolenames).': ', ['class' => 'font-weight-bold']); $name .= html_writer::link( \core_user::get_profile_url($coursecontact['user'], context_system::instance()), $coursecontact['username'] ); $content .= html_writer::tag('li', $name); } $content .= html_writer::end_tag('ul'); } return $content; } /** * Returns HTML to display course overview files. * * @param core_course_list_element $course * @return string */ protected function course_overview_files(core_course_list_element $course): string { global $CFG; $contentimages = $contentfiles = ''; foreach ($course->get_course_overviewfiles() as $file) { $isimage = $file->is_valid_image(); $url = moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage); if ($isimage) { $contentimages .= html_writer::tag('div', html_writer::empty_tag('img', ['src' => $url, 'alt' => '']), ['class' => 'courseimage']); } else { $image = $this->output->pix_icon(file_file_icon($file), $file->get_filename(), 'moodle'); $filename = html_writer::tag('span', $image, ['class' => 'fp-icon']). html_writer::tag('span', $file->get_filename(), ['class' => 'fp-filename']); $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), ['class' => 'coursefile fp-filename-icon text-break']); } } return $contentimages . $contentfiles; } /** * Returns HTML to display course category name. * * @param coursecat_helper $chelper * @param core_course_list_element $course * @return string */ protected function course_category_name(coursecat_helper $chelper, core_course_list_element $course): string { $content = ''; // Display course category if necessary (for example in search results). if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) { if ($cat = core_course_category::get($course->category, IGNORE_MISSING)) { $content .= html_writer::start_tag('div', ['class' => 'coursecat']); $content .= html_writer::tag('span', get_string('category').': ', ['class' => 'font-weight-bold']); $content .= html_writer::link(new moodle_url('/course/index.php', ['categoryid' => $cat->id]), $cat->get_formatted_name(), ['class' => $cat->visible ? '' : 'dimmed']); $content .= html_writer::end_tag('div'); } } return $content; } /** * Returns HTML to display course custom fields. * * @param core_course_list_element $course * @return string */ protected function course_custom_fields(core_course_list_element $course): string { $content = ''; if ($course->has_custom_fields()) { $handler = core_course\customfield\course_handler::create(); $customfields = $handler->display_custom_fields_data($course->get_custom_fields()); $content .= \html_writer::tag('div', $customfields, ['class' => 'customfields-container']); } return $content; } /** * Returns HTML to display course content (summary, course contacts and optionally category name) * * This method is called from coursecat_coursebox() and may be re-used in AJAX * * @param coursecat_helper $chelper various display options * @param stdClass|core_course_list_element $course * @return string */ protected function coursecat_coursebox_content(coursecat_helper $chelper, $course) { if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) { return ''; } if ($course instanceof stdClass) { $course = new core_course_list_element($course); } $content = \html_writer::start_tag('div', ['class' => 'd-flex']); $content .= $this->course_overview_files($course); $content .= \html_writer::start_tag('div', ['class' => 'flex-grow-1']); $content .= $this->course_summary($chelper, $course); $content .= $this->course_contacts($course); $content .= $this->course_category_name($chelper, $course); $content .= $this->course_custom_fields($course); $content .= \html_writer::end_tag('div'); $content .= \html_writer::end_tag('div'); return $content; } /** * Renders the list of courses * * This is internal function, please use {@link core_course_renderer::courses_list()} or another public * method from outside of the class * * If list of courses is specified in $courses; the argument $chelper is only used * to retrieve display options and attributes, only methods get_show_courses(), * get_courses_display_option() and get_and_erase_attributes() are called. * * @param coursecat_helper $chelper various display options * @param array $courses the list of courses to display * @param int|null $totalcount total number of courses (affects display mode if it is AUTO or pagination if applicable), * defaulted to count($courses) * @return string */ protected function coursecat_courses(coursecat_helper $chelper, $courses, $totalcount = null) { global $CFG; if ($totalcount === null) { $totalcount = count($courses); } if (!$totalcount) { // Courses count is cached during courses retrieval. return ''; } if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO) { // In 'auto' course display mode we analyse if number of courses is more or less than $CFG->courseswithsummarieslimit if ($totalcount <= $CFG->courseswithsummarieslimit) { $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED); } else { $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED); } } // prepare content of paging bar if it is needed $paginationurl = $chelper->get_courses_display_option('paginationurl'); $paginationallowall = $chelper->get_courses_display_option('paginationallowall'); if ($totalcount > count($courses)) { // there are more results that can fit on one page if ($paginationurl) { // the option paginationurl was specified, display pagingbar $perpage = $chelper->get_courses_display_option('limit', $CFG->coursesperpage); $page = $chelper->get_courses_display_option('offset') / $perpage; $pagingbar = $this->paging_bar($totalcount, $page, $perpage, $paginationurl->out(false, array('perpage' => $perpage))); if ($paginationallowall) { $pagingbar .= html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => 'all')), get_string('showall', '', $totalcount)), array('class' => 'paging paging-showall')); } } else if ($viewmoreurl = $chelper->get_courses_display_option('viewmoreurl')) { // the option for 'View more' link was specified, display more link $viewmoretext = $chelper->get_courses_display_option('viewmoretext', new lang_string('viewmore')); $morelink = html_writer::tag( 'div', html_writer::link($viewmoreurl, $viewmoretext, ['class' => 'btn btn-secondary']), ['class' => 'paging paging-morelink'] ); } } else if (($totalcount > $CFG->coursesperpage) && $paginationurl && $paginationallowall) { // there are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode $pagingbar = html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => $CFG->coursesperpage)), get_string('showperpage', '', $CFG->coursesperpage)), array('class' => 'paging paging-showperpage')); } // display list of courses $attributes = $chelper->get_and_erase_attributes('courses'); $content = html_writer::start_tag('div', $attributes); if (!empty($pagingbar)) { $content .= $pagingbar; } $coursecount = 0; foreach ($courses as $course) { $coursecount ++; $classes = ($coursecount%2) ? 'odd' : 'even'; if ($coursecount == 1) { $classes .= ' first'; } if ($coursecount >= count($courses)) { $classes .= ' last'; } $content .= $this->coursecat_coursebox($chelper, $course, $classes); } if (!empty($pagingbar)) { $content .= $pagingbar; } if (!empty($morelink)) { $content .= $morelink; } $content .= html_writer::end_tag('div'); // .courses return $content; } /** * Renders the list of subcategories in a category * * @param coursecat_helper $chelper various display options * @param core_course_category $coursecat * @param int $depth depth of the category in the current tree * @return string */ protected function coursecat_subcategories(coursecat_helper $chelper, $coursecat, $depth) { global $CFG; $subcategories = array(); if (!$chelper->get_categories_display_option('nodisplay')) { $subcategories = $coursecat->get_children($chelper->get_categories_display_options()); } $totalcount = $coursecat->get_children_count(); if (!$totalcount) { // Note that we call core_course_category::get_children_count() AFTER core_course_category::get_children() // to avoid extra DB requests. // Categories count is cached during children categories retrieval. return ''; } // prepare content of paging bar or more link if it is needed $paginationurl = $chelper->get_categories_display_option('paginationurl'); $paginationallowall = $chelper->get_categories_display_option('paginationallowall'); if ($totalcount > count($subcategories)) { if ($paginationurl) { // the option 'paginationurl was specified, display pagingbar $perpage = $chelper->get_categories_display_option('limit', $CFG->coursesperpage); $page = $chelper->get_categories_display_option('offset') / $perpage; $pagingbar = $this->paging_bar($totalcount, $page, $perpage, $paginationurl->out(false, array('perpage' => $perpage))); if ($paginationallowall) { $pagingbar .= html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => 'all')), get_string('showall', '', $totalcount)), array('class' => 'paging paging-showall')); } } else if ($viewmoreurl = $chelper->get_categories_display_option('viewmoreurl')) { // the option 'viewmoreurl' was specified, display more link (if it is link to category view page, add category id) if ($viewmoreurl->compare(new moodle_url('/course/index.php'), URL_MATCH_BASE)) { $viewmoreurl->param('categoryid', $coursecat->id); } $viewmoretext = $chelper->get_categories_display_option('viewmoretext', new lang_string('viewmore')); $morelink = html_writer::tag('div', html_writer::link($viewmoreurl, $viewmoretext), array('class' => 'paging paging-morelink')); } } else if (($totalcount > $CFG->coursesperpage) && $paginationurl && $paginationallowall) { // there are more than one page of results and we are in 'view all' mode, suggest to go back to paginated view mode $pagingbar = html_writer::tag('div', html_writer::link($paginationurl->out(false, array('perpage' => $CFG->coursesperpage)), get_string('showperpage', '', $CFG->coursesperpage)), array('class' => 'paging paging-showperpage')); } // display list of subcategories $content = html_writer::start_tag('div', array('class' => 'subcategories')); if (!empty($pagingbar)) { $content .= $pagingbar; } foreach ($subcategories as $subcategory) { $content .= $this->coursecat_category($chelper, $subcategory, $depth + 1); } if (!empty($pagingbar)) { $content .= $pagingbar; } if (!empty($morelink)) { $content .= $morelink; } $content .= html_writer::end_tag('div'); return $content; } /** * Make sure that javascript file for AJAX expanding of courses and categories content is included */ protected function coursecat_include_js() { if (!$this->page->requires->should_create_one_time_item_now('core_course_categoryexpanderjsinit')) { return; } // We must only load this module once. $this->page->requires->yui_module('moodle-course-categoryexpander', 'Y.Moodle.course.categoryexpander.init'); } /** * Returns HTML to display the subcategories and courses in the given category * * This method is re-used by AJAX to expand content of not loaded category * * @param coursecat_helper $chelper various display options * @param core_course_category $coursecat * @param int $depth depth of the category in the current tree * @return string */ protected function coursecat_category_content(coursecat_helper $chelper, $coursecat, $depth) { $content = ''; // Subcategories $content .= $this->coursecat_subcategories($chelper, $coursecat, $depth); // AUTO show courses: Courses will be shown expanded if this is not nested category, // and number of courses no bigger than $CFG->courseswithsummarieslimit. $showcoursesauto = $chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_AUTO; if ($showcoursesauto && $depth) { // this is definitely collapsed mode $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_COLLAPSED); } // Courses if ($chelper->get_show_courses() > core_course_renderer::COURSECAT_SHOW_COURSES_COUNT) { $courses = array(); if (!$chelper->get_courses_display_option('nodisplay')) { $courses = $coursecat->get_courses($chelper->get_courses_display_options()); } if ($viewmoreurl = $chelper->get_courses_display_option('viewmoreurl')) { // the option for 'View more' link was specified, display more link (if it is link to category view page, add category id) if ($viewmoreurl->compare(new moodle_url('/course/index.php'), URL_MATCH_BASE)) { $chelper->set_courses_display_option('viewmoreurl', new moodle_url($viewmoreurl, array('categoryid' => $coursecat->id))); } } $content .= $this->coursecat_courses($chelper, $courses, $coursecat->get_courses_count()); } if ($showcoursesauto) { // restore the show_courses back to AUTO $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_AUTO); } return $content; } /** * Returns HTML to display a course category as a part of a tree * * This is an internal function, to display a particular category and all its contents * use {@link core_course_renderer::course_category()} * * @param coursecat_helper $chelper various display options * @param core_course_category $coursecat * @param int $depth depth of this category in the current tree * @return string */ protected function coursecat_category(coursecat_helper $chelper, $coursecat, $depth) { // open category tag $classes = array('category'); if (empty($coursecat->visible)) { $classes[] = 'dimmed_category'; } if ($chelper->get_subcat_depth() > 0 && $depth >= $chelper->get_subcat_depth()) { // do not load content $categorycontent = ''; $classes[] = 'notloaded'; if ($coursecat->get_children_count() || ($chelper->get_show_courses() >= self::COURSECAT_SHOW_COURSES_COLLAPSED && $coursecat->get_courses_count())) { $classes[] = 'with_children'; $classes[] = 'collapsed'; } } else { // load category content $categorycontent = $this->coursecat_category_content($chelper, $coursecat, $depth); $classes[] = 'loaded'; if (!empty($categorycontent)) { $classes[] = 'with_children'; // Category content loaded with children. $this->categoryexpandedonload = true; } } // Make sure JS file to expand category content is included. $this->coursecat_include_js(); $content = html_writer::start_tag('div', array( 'class' => join(' ', $classes), 'data-categoryid' => $coursecat->id, 'data-depth' => $depth, 'data-showcourses' => $chelper->get_show_courses(), 'data-type' => self::COURSECAT_TYPE_CATEGORY, )); // category name $categoryname = $coursecat->get_formatted_name(); $categoryname = html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $coursecat->id)), $categoryname); if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_COUNT && ($coursescount = $coursecat->get_courses_count())) { $categoryname .= html_writer::tag('span', ' ('. $coursescount.')', array('title' => get_string('numberofcourses'), 'class' => 'numberofcourse')); } $content .= html_writer::start_tag('div', array('class' => 'info')); $content .= html_writer::tag(($depth > 1) ? 'h4' : 'h3', $categoryname, array('class' => 'categoryname aabtn')); $content .= html_writer::end_tag('div'); // .info // add category content to the output $content .= html_writer::tag('div', $categorycontent, array('class' => 'content')); $content .= html_writer::end_tag('div'); // .category // Return the course category tree HTML return $content; } /** * Returns HTML to display a tree of subcategories and courses in the given category * * @param coursecat_helper $chelper various display options * @param core_course_category $coursecat top category (this category's name and description will NOT be added to the tree) * @return string */ protected function coursecat_tree(coursecat_helper $chelper, $coursecat) { // Reset the category expanded flag for this course category tree first. $this->categoryexpandedonload = false; $categorycontent = $this->coursecat_category_content($chelper, $coursecat, 0); if (empty($categorycontent)) { return ''; } // Start content generation $content = ''; $attributes = $chelper->get_and_erase_attributes('course_category_tree clearfix'); $content .= html_writer::start_tag('div', $attributes); if ($coursecat->get_children_count()) { $classes = array( 'collapseexpand', 'aabtn' ); // Check if the category content contains subcategories with children's content loaded. if ($this->categoryexpandedonload) { $classes[] = 'collapse-all'; $linkname = get_string('collapseall'); } else { $linkname = get_string('expandall'); } // Only show the collapse/expand if there are children to expand. $content .= html_writer::start_tag('div', array('class' => 'collapsible-actions')); $content .= html_writer::link('#', $linkname, array('class' => implode(' ', $classes))); $content .= html_writer::end_tag('div'); $this->page->requires->strings_for_js(array('collapseall', 'expandall'), 'moodle'); } $content .= html_writer::tag('div', $categorycontent, array('class' => 'content')); $content .= html_writer::end_tag('div'); // .course_category_tree return $content; } /** * Renders HTML to display particular course category - list of it's subcategories and courses * * Invoked from /course/index.php * * @param int|stdClass|core_course_category $category */ public function course_category($category) { global $CFG; $usertop = core_course_category::user_top(); if (empty($category)) { $coursecat = $usertop; } else if (is_object($category) && $category instanceof core_course_category) { $coursecat = $category; } else { $coursecat = core_course_category::get(is_object($category) ? $category->id : $category); } $site = get_site(); $actionbar = new \core_course\output\category_action_bar($this->page, $coursecat); $output = $this->render_from_template('core_course/category_actionbar', $actionbar->export_for_template($this)); if (core_course_category::is_simple_site()) { // There is only one category in the system, do not display link to it. $strfulllistofcourses = get_string('fulllistofcourses'); $this->page->set_title($strfulllistofcourses); } else if (!$coursecat->id || !$coursecat->is_uservisible()) { $strcategories = get_string('categories'); $this->page->set_title($strcategories); } else { $strfulllistofcourses = get_string('fulllistofcourses'); $this->page->set_title($strfulllistofcourses); } // Print current category description $chelper = new coursecat_helper(); if ($description = $chelper->get_category_formatted_description($coursecat)) { $output .= $this->box($description, array('class' => 'generalbox info')); } // Prepare parameters for courses and categories lists in the tree $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_AUTO) ->set_attributes(array('class' => 'category-browse category-browse-'.$coursecat->id)); $coursedisplayoptions = array(); $catdisplayoptions = array(); $browse = optional_param('browse', null, PARAM_ALPHA); $perpage = optional_param('perpage', $CFG->coursesperpage, PARAM_INT); $page = optional_param('page', 0, PARAM_INT); $baseurl = new moodle_url('/course/index.php'); if ($coursecat->id) { $baseurl->param('categoryid', $coursecat->id); } if ($perpage != $CFG->coursesperpage) { $baseurl->param('perpage', $perpage); } $coursedisplayoptions['limit'] = $perpage; $catdisplayoptions['limit'] = $perpage; if ($browse === 'courses' || !$coursecat->get_children_count()) { $coursedisplayoptions['offset'] = $page * $perpage; $coursedisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'courses')); $catdisplayoptions['nodisplay'] = true; $catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories')); $catdisplayoptions['viewmoretext'] = new lang_string('viewallsubcategories'); } else if ($browse === 'categories' || !$coursecat->get_courses_count()) { $coursedisplayoptions['nodisplay'] = true; $catdisplayoptions['offset'] = $page * $perpage; $catdisplayoptions['paginationurl'] = new moodle_url($baseurl, array('browse' => 'categories')); $coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses')); $coursedisplayoptions['viewmoretext'] = new lang_string('viewallcourses'); } else { // we have a category that has both subcategories and courses, display pagination separately $coursedisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'courses', 'page' => 1)); $catdisplayoptions['viewmoreurl'] = new moodle_url($baseurl, array('browse' => 'categories', 'page' => 1)); } $chelper->set_courses_display_options($coursedisplayoptions)->set_categories_display_options($catdisplayoptions); // Display course category tree. $output .= $this->coursecat_tree($chelper, $coursecat); return $output; } /** * Serves requests to /course/category.ajax.php * * In this renderer implementation it may expand the category content or * course content. * * @return string * @throws coding_exception */ public function coursecat_ajax() { global $DB, $CFG; $type = required_param('type', PARAM_INT); if ($type === self::COURSECAT_TYPE_CATEGORY) { // This is a request for a category list of some kind. $categoryid = required_param('categoryid', PARAM_INT); $showcourses = required_param('showcourses', PARAM_INT); $depth = required_param('depth', PARAM_INT); $category = core_course_category::get($categoryid); $chelper = new coursecat_helper(); $baseurl = new moodle_url('/course/index.php', array('categoryid' => $categoryid)); $coursedisplayoptions = array( 'limit' => $CFG->coursesperpage, 'viewmoreurl' => new moodle_url($baseurl, array('browse' => 'courses', 'page' => 1)) ); $catdisplayoptions = array( 'limit' => $CFG->coursesperpage, 'viewmoreurl' => new moodle_url($baseurl, array('browse' => 'categories', 'page' => 1)) ); $chelper->set_show_courses($showcourses)-> set_courses_display_options($coursedisplayoptions)-> set_categories_display_options($catdisplayoptions); return $this->coursecat_category_content($chelper, $category, $depth); } else if ($type === self::COURSECAT_TYPE_COURSE) { // This is a request for the course information. $courseid = required_param('courseid', PARAM_INT); $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); $chelper = new coursecat_helper(); $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED); return $this->coursecat_coursebox_content($chelper, $course); } else { throw new coding_exception('Invalid request type'); } } /** * Renders html to display search result page * * @param array $searchcriteria may contain elements: search, blocklist, modulelist, tagid * @return string */ public function search_courses($searchcriteria) { global $CFG; $content = ''; $search = ''; if (!empty($searchcriteria['search'])) { $search = $searchcriteria['search']; } $content .= $this->course_search_form($search); if (!empty($searchcriteria)) { // print search results $displayoptions = array('sort' => array('displayname' => 1)); // take the current page and number of results per page from query $perpage = optional_param('perpage', 0, PARAM_RAW); if ($perpage !== 'all') { $displayoptions['limit'] = ((int)$perpage <= 0) ? $CFG->coursesperpage : (int)$perpage; $page = optional_param('page', 0, PARAM_INT); $displayoptions['offset'] = $displayoptions['limit'] * $page; } // options 'paginationurl' and 'paginationallowall' are only used in method coursecat_courses() $displayoptions['paginationurl'] = new moodle_url('/course/search.php', $searchcriteria); $displayoptions['paginationallowall'] = true; // allow adding link 'View all' $class = 'course-search-result'; foreach ($searchcriteria as $key => $value) { if (!empty($value)) { $class .= ' course-search-result-'. $key; } } $chelper = new coursecat_helper(); $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT)-> set_courses_display_options($displayoptions)-> set_search_criteria($searchcriteria)-> set_attributes(array('class' => $class)); $courses = core_course_category::search_courses($searchcriteria, $chelper->get_courses_display_options()); $totalcount = core_course_category::search_courses_count($searchcriteria); $courseslist = $this->coursecat_courses($chelper, $courses, $totalcount); if (!$totalcount) { if (!empty($searchcriteria['search'])) { $content .= $this->heading(get_string('nocoursesfound', '', $searchcriteria['search'])); } else { $content .= $this->heading(get_string('novalidcourses')); } } else { $content .= $this->heading(get_string('searchresults'). ": $totalcount"); $content .= $courseslist; } } return $content; } /** * Renders html to print list of courses tagged with particular tag * * @param int $tagid id of the tag * @param bool $exclusivemode if set to true it means that no other entities tagged with this tag * are displayed on the page and the per-page limit may be bigger * @param int $fromctx context id where the link was displayed, may be used by callbacks * to display items in the same context first * @param int $ctx context id where to search for records * @param bool $rec search in subcontexts as well * @param array $displayoptions * @return string empty string if no courses are marked with this tag or rendered list of courses */ public function tagged_courses($tagid, $exclusivemode = true, $ctx = 0, $rec = true, $displayoptions = null) { global $CFG; if (empty($displayoptions)) { $displayoptions = array(); } $showcategories = !core_course_category::is_simple_site(); $displayoptions += array('limit' => $CFG->coursesperpage, 'offset' => 0); $chelper = new coursecat_helper(); $searchcriteria = array('tagid' => $tagid, 'ctx' => $ctx, 'rec' => $rec); $chelper->set_show_courses($showcategories ? self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT : self::COURSECAT_SHOW_COURSES_EXPANDED)-> set_search_criteria($searchcriteria)-> set_courses_display_options($displayoptions)-> set_attributes(array('class' => 'course-search-result course-search-result-tagid')); // (we set the same css class as in search results by tagid) if ($totalcount = core_course_category::search_courses_count($searchcriteria)) { $courses = core_course_category::search_courses($searchcriteria, $chelper->get_courses_display_options()); if ($exclusivemode) { return $this->coursecat_courses($chelper, $courses, $totalcount); } else { $tagfeed = new core_tag\output\tagfeed(); $img = $this->output->pix_icon('i/course', ''); foreach ($courses as $course) { $url = course_get_url($course); $imgwithlink = html_writer::link($url, $img); $coursename = html_writer::link($url, $course->get_formatted_name()); $details = ''; if ($showcategories && ($cat = core_course_category::get($course->category, IGNORE_MISSING))) { $details = get_string('category').': '. html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)), $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed')); } $tagfeed->add($imgwithlink, $coursename, $details); } return $this->output->render_from_template('core_tag/tagfeed', $tagfeed->export_for_template($this->output)); } } return ''; } /** * Returns HTML to display one remote course * * @param stdClass $course remote course information, contains properties: id, remoteid, shortname, fullname, hostid, summary, summaryformat, cat_name, hostname * @return string */ protected function frontpage_remote_course(stdClass $course) { $url = new moodle_url('/auth/mnet/jump.php', array( 'hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='. $course->remoteid )); $output = ''; $output .= html_writer::start_tag('div', array('class' => 'coursebox remotecoursebox clearfix')); $output .= html_writer::start_tag('div', array('class' => 'info')); $output .= html_writer::start_tag('h3', array('class' => 'coursename')); $output .= html_writer::link($url, format_string($course->fullname), array('title' => get_string('entercourse'))); $output .= html_writer::end_tag('h3'); // .name $output .= html_writer::tag('div', '', array('class' => 'moreinfo')); $output .= html_writer::end_tag('div'); // .info $output .= html_writer::start_tag('div', array('class' => 'content')); $output .= html_writer::start_tag('div', array('class' => 'summary')); $options = new stdClass(); $options->noclean = true; $options->para = false; $options->overflowdiv = true; $output .= format_text($course->summary, $course->summaryformat, $options); $output .= html_writer::end_tag('div'); // .summary $addinfo = format_string($course->hostname) . ' : ' . format_string($course->cat_name) . ' : ' . format_string($course->shortname); $output .= html_writer::tag('div', $addinfo, array('class' => 'remotecourseinfo')); $output .= html_writer::end_tag('div'); // .content $output .= html_writer::end_tag('div'); // .coursebox return $output; } /** * Returns HTML to display one remote host * * @param array $host host information, contains properties: name, url, count * @return string */ protected function frontpage_remote_host($host) { $output = ''; $output .= html_writer::start_tag('div', array('class' => 'coursebox remotehost clearfix')); $output .= html_writer::start_tag('div', array('class' => 'info')); $output .= html_writer::start_tag('h3', array('class' => 'name')); $output .= html_writer::link($host['url'], s($host['name']), array('title' => s($host['name']))); $output .= html_writer::end_tag('h3'); // .name $output .= html_writer::tag('div', '', array('class' => 'moreinfo')); $output .= html_writer::end_tag('div'); // .info $output .= html_writer::start_tag('div', array('class' => 'content')); $output .= html_writer::start_tag('div', array('class' => 'summary')); $output .= $host['count'] . ' ' . get_string('courses'); $output .= html_writer::end_tag('div'); // .content $output .= html_writer::end_tag('div'); // .coursebox return $output; } /** * Returns HTML to print list of courses user is enrolled to for the frontpage * * Also lists remote courses or remote hosts if MNET authorisation is used * * @return string */ public function frontpage_my_courses() { global $USER, $CFG, $DB; if (!isloggedin() or isguestuser()) { return ''; } $output = ''; $courses = enrol_get_my_courses('summary, summaryformat'); $rhosts = array(); $rcourses = array(); if (!empty($CFG->mnet_dispatcher_mode) && $CFG->mnet_dispatcher_mode==='strict') { $rcourses = get_my_remotecourses($USER->id); $rhosts = get_my_remotehosts(); } if (!empty($courses) || !empty($rcourses) || !empty($rhosts)) { $chelper = new coursecat_helper(); $totalcount = count($courses); if (count($courses) > $CFG->frontpagecourselimit) { // There are more enrolled courses than we can display, display link to 'My courses'. $courses = array_slice($courses, 0, $CFG->frontpagecourselimit, true); $chelper->set_courses_display_options(array( 'viewmoreurl' => new moodle_url('/my/courses.php'), 'viewmoretext' => new lang_string('mycourses') )); } else if (core_course_category::top()->is_uservisible()) { // All enrolled courses are displayed, display link to 'All courses' if there are more courses in system. $chelper->set_courses_display_options(array( 'viewmoreurl' => new moodle_url('/course/index.php'), 'viewmoretext' => new lang_string('fulllistofcourses') )); $totalcount = $DB->count_records('course') - 1; } $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)-> set_attributes(array('class' => 'frontpage-course-list-enrolled')); $output .= $this->coursecat_courses($chelper, $courses, $totalcount); // MNET if (!empty($rcourses)) { // at the IDP, we know of all the remote courses $output .= html_writer::start_tag('div', array('class' => 'courses')); foreach ($rcourses as $course) { $output .= $this->frontpage_remote_course($course); } $output .= html_writer::end_tag('div'); // .courses } elseif (!empty($rhosts)) { // non-IDP, we know of all the remote servers, but not courses $output .= html_writer::start_tag('div', array('class' => 'courses')); foreach ($rhosts as $host) { $output .= $this->frontpage_remote_host($host); } $output .= html_writer::end_tag('div'); // .courses } } return $output; } /** * Returns HTML to print list of available courses for the frontpage * * @return string */ public function frontpage_available_courses() { global $CFG; $chelper = new coursecat_helper(); $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)-> set_courses_display_options(array( 'recursive' => true, 'limit' => $CFG->frontpagecourselimit, 'viewmoreurl' => new moodle_url('/course/index.php'), 'viewmoretext' => new lang_string('fulllistofcourses'))); $chelper->set_attributes(array('class' => 'frontpage-course-list-all')); $courses = core_course_category::top()->get_courses($chelper->get_courses_display_options()); $totalcount = core_course_category::top()->get_courses_count($chelper->get_courses_display_options()); if (!$totalcount && !$this->page->user_is_editing() && has_capability('moodle/course:create', context_system::instance())) { // Print link to create a new course, for the 1st available category. return $this->add_new_course_button(); } return $this->coursecat_courses($chelper, $courses, $totalcount); } /** * Returns HTML to the "add new course" button for the page * * @return string */ public function add_new_course_button() { global $CFG; // Print link to create a new course, for the 1st available category. $output = $this->container_start('buttons'); $url = new moodle_url('/course/edit.php', array('category' => $CFG->defaultrequestcategory, 'returnto' => 'topcat')); $output .= $this->single_button($url, get_string('addnewcourse'), 'get'); $output .= $this->container_end('buttons'); return $output; } /** * Returns HTML to print tree with course categories and courses for the frontpage * * @return string */ public function frontpage_combo_list() { global $CFG; // TODO MDL-10965 improve. $tree = core_course_category::top(); if (!$tree->get_children_count()) { return ''; } $chelper = new coursecat_helper(); $chelper->set_subcat_depth($CFG->maxcategorydepth)-> set_categories_display_options(array( 'limit' => $CFG->coursesperpage, 'viewmoreurl' => new moodle_url('/course/index.php', array('browse' => 'categories', 'page' => 1)) ))-> set_courses_display_options(array( 'limit' => $CFG->coursesperpage, 'viewmoreurl' => new moodle_url('/course/index.php', array('browse' => 'courses', 'page' => 1)) ))-> set_attributes(array('class' => 'frontpage-category-combo')); return $this->coursecat_tree($chelper, $tree); } /** * Returns HTML to print tree of course categories (with number of courses) for the frontpage * * @return string */ public function frontpage_categories_list() { global $CFG; // TODO MDL-10965 improve. $tree = core_course_category::top(); if (!$tree->get_children_count()) { return ''; } $chelper = new coursecat_helper(); $chelper->set_subcat_depth($CFG->maxcategorydepth)-> set_show_courses(self::COURSECAT_SHOW_COURSES_COUNT)-> set_categories_display_options(array( 'limit' => $CFG->coursesperpage, 'viewmoreurl' => new moodle_url('/course/index.php', array('browse' => 'categories', 'page' => 1)) ))-> set_attributes(array('class' => 'frontpage-category-names')); return $this->coursecat_tree($chelper, $tree); } /** * Renders the activity information. * * Defer to template. * * @deprecated since Moodle 4.3 MDL-78744 * @todo MDL-78926 This method will be deleted in Moodle 4.7 * @param \core_course\output\activity_information $page * @return string html for the page */ public function render_activity_information(\core_course\output\activity_information $page) { debugging('render_activity_information method is deprecated.', DEBUG_DEVELOPER); $data = $page->export_for_template($this->output); return $this->output->render_from_template('core_course/activity_info', $data); } /** * Renders the activity navigation. * * Defer to template. * * @param \core_course\output\activity_navigation $page * @return string html for the page */ public function render_activity_navigation(\core_course\output\activity_navigation $page) { $data = $page->export_for_template($this->output); return $this->output->render_from_template('core_course/activity_navigation', $data); } /** * Display waiting information about backup size during uploading backup process * @param object $backupfile the backup stored_file * @return $html string */ public function sendingbackupinfo($backupfile) { $sizeinfo = new stdClass(); $sizeinfo->total = number_format($backupfile->get_filesize() / 1000000, 2); $html = html_writer::tag('div', get_string('sendingsize', 'hub', $sizeinfo), array('class' => 'courseuploadtextinfo')); return $html; } /** * Hub information (logo - name - description - link) * @param object $hubinfo * @return string html code */ public function hubinfo($hubinfo) { $screenshothtml = html_writer::empty_tag('img', array('src' => $hubinfo['imgurl'], 'alt' => $hubinfo['name'])); $hubdescription = html_writer::tag('div', $screenshothtml, array('class' => 'hubscreenshot')); $hubdescription .= html_writer::tag('a', $hubinfo['name'], array('class' => 'hublink', 'href' => $hubinfo['url'], 'onclick' => 'this.target="_blank"')); $hubdescription .= html_writer::tag('div', format_text($hubinfo['description'], FORMAT_PLAIN), array('class' => 'hubdescription')); $hubdescription = html_writer::tag('div', $hubdescription, array('class' => 'hubinfo clearfix')); return $hubdescription; } /** * Output frontpage summary text and frontpage modules (stored as section 1 in site course) * * This may be disabled in settings * * @return string */ public function frontpage_section1() { global $SITE, $USER; $output = ''; $editing = $this->page->user_is_editing(); if ($editing) { // Make sure section with number 1 exists. course_create_sections_if_missing($SITE, 1); } $modinfo = get_fast_modinfo($SITE); $section = $modinfo->get_section_info(1); if (($section && (!empty($modinfo->sections[1]) or !empty($section->summary))) or $editing) { $format = course_get_format($SITE); $frontpageclass = $format->get_output_classname('content\\frontpagesection'); $frontpagesection = new $frontpageclass($format, $section); // The course outputs works with format renderers, not with course renderers. $renderer = $format->get_renderer($this->page); $output .= $renderer->render($frontpagesection); } return $output; } /** * Output news for the frontpage (extract from site-wide news forum) * * @param stdClass $forum record from db table 'forum' that represents the site news forum * @return string */ protected function frontpage_news($forum) { global $CFG, $SITE, $SESSION, $USER; require_once($CFG->dirroot .'/mod/forum/lib.php'); $output = ''; if (isloggedin()) { $SESSION->fromdiscussion = $CFG->wwwroot; $subtext = ''; if (\mod_forum\subscriptions::is_subscribed($USER->id, $forum)) { if (!\mod_forum\subscriptions::is_forcesubscribed($forum)) { $subtext = get_string('unsubscribe', 'forum'); } } else { $subtext = get_string('subscribe', 'forum'); } $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $forum->id, 'sesskey' => sesskey())); $output .= html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink')); } $coursemodule = get_coursemodule_from_instance('forum', $forum->id); $context = context_module::instance($coursemodule->id); $entityfactory = mod_forum\local\container::get_entity_factory(); $forumentity = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $SITE); $rendererfactory = mod_forum\local\container::get_renderer_factory(); $discussionsrenderer = $rendererfactory->get_frontpage_news_discussion_list_renderer($forumentity); $cm = \cm_info::create($coursemodule); return $output . $discussionsrenderer->render($USER, $cm, null, null, 0, $SITE->newsitems); } /** * Renders part of frontpage with a skip link (i.e. "My courses", "Site news", etc.) * * @param string $skipdivid * @param string $contentsdivid * @param string $header Header of the part * @param string $contents Contents of the part * @return string */ protected function frontpage_part($skipdivid, $contentsdivid, $header, $contents) { if (strval($contents) === '') { return ''; } $output = html_writer::link('#' . $skipdivid, get_string('skipa', 'access', core_text::strtolower(strip_tags($header))), array('class' => 'skip-block skip aabtn')); // Wrap frontpage part in div container. $output .= html_writer::start_tag('div', array('id' => $contentsdivid)); $output .= $this->heading($header); $output .= $contents; // End frontpage part div container. $output .= html_writer::end_tag('div'); $output .= html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => $skipdivid)); return $output; } /** * Outputs contents for frontpage as configured in $CFG->frontpage or $CFG->frontpageloggedin * * @return string */ public function frontpage() { global $CFG, $SITE; $output = ''; if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) { $frontpagelayout = $CFG->frontpageloggedin; } else { $frontpagelayout = $CFG->frontpage; } foreach (explode(',', $frontpagelayout) as $v) { switch ($v) { // Display the main part of the front page. case FRONTPAGENEWS: if ($SITE->newsitems) { // Print forums only when needed. require_once($CFG->dirroot .'/mod/forum/lib.php'); if (($newsforum = forum_get_course_forum($SITE->id, 'news')) && ($forumcontents = $this->frontpage_news($newsforum))) { $newsforumcm = get_fast_modinfo($SITE)->instances['forum'][$newsforum->id]; $output .= $this->frontpage_part('skipsitenews', 'site-news-forum', $newsforumcm->get_formatted_name(), $forumcontents); } } break; case FRONTPAGEENROLLEDCOURSELIST: $mycourseshtml = $this->frontpage_my_courses(); if (!empty($mycourseshtml)) { $output .= $this->frontpage_part('skipmycourses', 'frontpage-course-list', get_string('mycourses'), $mycourseshtml); } break; case FRONTPAGEALLCOURSELIST: $availablecourseshtml = $this->frontpage_available_courses(); $output .= $this->frontpage_part('skipavailablecourses', 'frontpage-available-course-list', get_string('availablecourses'), $availablecourseshtml); break; case FRONTPAGECATEGORYNAMES: $output .= $this->frontpage_part('skipcategories', 'frontpage-category-names', get_string('categories'), $this->frontpage_categories_list()); break; case FRONTPAGECATEGORYCOMBO: $output .= $this->frontpage_part('skipcourses', 'frontpage-category-combo', get_string('courses'), $this->frontpage_combo_list()); break; case FRONTPAGECOURSESEARCH: $output .= $this->box($this->course_search_form(''), 'd-flex justify-content-center'); break; } $output .= '<br />'; } return $output; } } /** * Class storing display options and functions to help display course category and/or courses lists * * This is a wrapper for core_course_category objects that also stores display options * and functions to retrieve sorted and paginated lists of categories/courses. * * If theme overrides methods in core_course_renderers that access this class * it may as well not use this class at all or extend it. * * @package core * @copyright 2013 Marina Glancy * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class coursecat_helper { /** @var string [none, collapsed, expanded] how (if) display courses list */ protected $showcourses = 10; /* core_course_renderer::COURSECAT_SHOW_COURSES_COLLAPSED */ /** @var int depth to expand subcategories in the tree (deeper subcategories will be loaded by AJAX or proceed to category page by clicking on category name) */ protected $subcatdepth = 1; /** @var array options to display courses list */ protected $coursesdisplayoptions = array(); /** @var array options to display subcategories list */ protected $categoriesdisplayoptions = array(); /** @var array additional HTML attributes */ protected $attributes = array(); /** @var array search criteria if the list is a search result */ protected $searchcriteria = null; /** * Sets how (if) to show the courses - none, collapsed, expanded, etc. * * @param int $showcourses SHOW_COURSES_NONE, SHOW_COURSES_COLLAPSED, SHOW_COURSES_EXPANDED, etc. * @return coursecat_helper */ public function set_show_courses($showcourses) { $this->showcourses = $showcourses; // Automatically set the options to preload summary and coursecontacts for core_course_category::get_courses() // and core_course_category::search_courses(). $this->coursesdisplayoptions['summary'] = $showcourses >= core_course_renderer::COURSECAT_SHOW_COURSES_AUTO; $this->coursesdisplayoptions['coursecontacts'] = $showcourses >= core_course_renderer::COURSECAT_SHOW_COURSES_EXPANDED; $this->coursesdisplayoptions['customfields'] = $showcourses >= core_course_renderer::COURSECAT_SHOW_COURSES_COLLAPSED; return $this; } /** * Returns how (if) to show the courses - none, collapsed, expanded, etc. * * @return int - COURSECAT_SHOW_COURSES_NONE, COURSECAT_SHOW_COURSES_COLLAPSED, COURSECAT_SHOW_COURSES_EXPANDED, etc. */ public function get_show_courses() { return $this->showcourses; } /** * Sets the maximum depth to expand subcategories in the tree * * deeper subcategories may be loaded by AJAX or proceed to category page by clicking on category name * * @param int $subcatdepth * @return coursecat_helper */ public function set_subcat_depth($subcatdepth) { $this->subcatdepth = $subcatdepth; return $this; } /** * Returns the maximum depth to expand subcategories in the tree * * deeper subcategories may be loaded by AJAX or proceed to category page by clicking on category name * * @return int */ public function get_subcat_depth() { return $this->subcatdepth; } /** * Sets options to display list of courses * * Options are later submitted as argument to core_course_category::get_courses() and/or core_course_category::search_courses() * * Options that core_course_category::get_courses() accept: * - recursive - return courses from subcategories as well. Use with care, * this may be a huge list! * - summary - preloads fields 'summary' and 'summaryformat' * - coursecontacts - preloads course contacts * - customfields - preloads custom fields data * - isenrolled - preloads indication whether this user is enrolled in the course * - sort - list of fields to sort. Example * array('idnumber' => 1, 'shortname' => 1, 'id' => -1) * will sort by idnumber asc, shortname asc and id desc. * Default: array('sortorder' => 1) * Only cached fields may be used for sorting! * - offset * - limit - maximum number of children to return, 0 or null for no limit * * Options summary and coursecontacts are filled automatically in the set_show_courses() * * Also renderer can set here any additional options it wants to pass between renderer functions. * * @param array $options * @return coursecat_helper */ public function set_courses_display_options($options) { $this->coursesdisplayoptions = $options; $this->set_show_courses($this->showcourses); // this will calculate special display options return $this; } /** * Sets one option to display list of courses * * @see coursecat_helper::set_courses_display_options() * * @param string $key * @param mixed $value * @return coursecat_helper */ public function set_courses_display_option($key, $value) { $this->coursesdisplayoptions[$key] = $value; return $this; } /** * Return the specified option to display list of courses * * @param string $optionname option name * @param mixed $defaultvalue default value for option if it is not specified * @return mixed */ public function get_courses_display_option($optionname, $defaultvalue = null) { if (array_key_exists($optionname, $this->coursesdisplayoptions)) { return $this->coursesdisplayoptions[$optionname]; } else { return $defaultvalue; } } /** * Returns all options to display the courses * * This array is usually passed to {@link core_course_category::get_courses()} or * {@link core_course_category::search_courses()} * * @return array */ public function get_courses_display_options() { return $this->coursesdisplayoptions; } /** * Sets options to display list of subcategories * * Options 'sort', 'offset' and 'limit' are passed to core_course_category::get_children(). * Any other options may be used by renderer functions * * @param array $options * @return coursecat_helper */ public function set_categories_display_options($options) { $this->categoriesdisplayoptions = $options; return $this; } /** * Return the specified option to display list of subcategories * * @param string $optionname option name * @param mixed $defaultvalue default value for option if it is not specified * @return mixed */ public function get_categories_display_option($optionname, $defaultvalue = null) { if (array_key_exists($optionname, $this->categoriesdisplayoptions)) { return $this->categoriesdisplayoptions[$optionname]; } else { return $defaultvalue; } } /** * Returns all options to display list of subcategories * * This array is usually passed to {@link core_course_category::get_children()} * * @return array */ public function get_categories_display_options() { return $this->categoriesdisplayoptions; } /** * Sets additional general options to pass between renderer functions, usually HTML attributes * * @param array $attributes * @return coursecat_helper */ public function set_attributes($attributes) { $this->attributes = $attributes; return $this; } /** * Return all attributes and erases them so they are not applied again * * @param string $classname adds additional class name to the beginning of $attributes['class'] * @return array */ public function get_and_erase_attributes($classname) { $attributes = $this->attributes; $this->attributes = array(); if (empty($attributes['class'])) { $attributes['class'] = ''; } $attributes['class'] = $classname . ' '. $attributes['class']; return $attributes; } /** * Sets the search criteria if the course is a search result * * Search string will be used to highlight terms in course name and description * * @param array $searchcriteria * @return coursecat_helper */ public function set_search_criteria($searchcriteria) { $this->searchcriteria = $searchcriteria; return $this; } /** * Returns formatted and filtered description of the given category * * @param core_course_category $coursecat category * @param stdClass|array $options format options, by default [noclean,overflowdiv], * if context is not specified it will be added automatically * @return string|null */ public function get_category_formatted_description($coursecat, $options = null) { if ($coursecat->id && $coursecat->is_uservisible() && !empty($coursecat->description)) { if (!isset($coursecat->descriptionformat)) { $descriptionformat = FORMAT_MOODLE; } else { $descriptionformat = $coursecat->descriptionformat; } if ($options === null) { $options = array('noclean' => true, 'overflowdiv' => true); } else { $options = (array)$options; } $context = context_coursecat::instance($coursecat->id); if (!isset($options['context'])) { $options['context'] = $context; } $text = file_rewrite_pluginfile_urls($coursecat->description, 'pluginfile.php', $context->id, 'coursecat', 'description', null); return format_text($text, $descriptionformat, $options); } return null; } /** * Returns given course's summary with proper embedded files urls and formatted * * @param core_course_list_element $course * @param array|stdClass $options additional formatting options * @return string */ public function get_course_formatted_summary($course, $options = array()) { global $CFG; require_once($CFG->libdir. '/filelib.php'); if (!$course->has_summary()) { return ''; } $options = (array)$options; $context = context_course::instance($course->id); if (!isset($options['context'])) { // TODO see MDL-38521 // option 1 (current), page context - no code required // option 2, system context // $options['context'] = context_system::instance(); // option 3, course context: // $options['context'] = $context; // option 4, course category context: // $options['context'] = $context->get_parent_context(); } $summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', null); $summary = format_text($summary, $course->summaryformat, $options, $course->id); if (!empty($this->searchcriteria['search'])) { $summary = highlight($this->searchcriteria['search'], $summary); } return $summary; } /** * Returns course name as it is configured to appear in courses lists formatted to course context * * @param core_course_list_element $course * @param array|stdClass $options additional formatting options * @return string */ public function get_course_formatted_name($course, $options = array()) { $options = (array)$options; if (!isset($options['context'])) { $options['context'] = context_course::instance($course->id); } $name = format_string(get_course_display_name_for_list($course), true, $options); if (!empty($this->searchcriteria['search'])) { $name = highlight($this->searchcriteria['search'], $name); } return $name; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.33 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка