forked from moodle-an-hochschulen/moodle-theme_boost_union
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
414 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?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/>. | ||
|
||
namespace theme_boost_union; | ||
|
||
/** | ||
* Theme Boost Union - External admin settings page which can be placed within a tab | ||
* | ||
* @package theme_boost_union | ||
* @copyright 2024 Alexander Bias, lern.link GmbH <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Class admin_externalpage_in_tab. | ||
* | ||
* @package theme_boost_union | ||
* @copyright 2024 Alexander Bias, lern.link GmbH <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class admin_externalpage_in_tab extends \admin_externalpage { | ||
/** | ||
* Dummy function just to make /admin/settings.php happy. | ||
* It returns just an empty string. | ||
* | ||
* @return string | ||
*/ | ||
public function output_html() { | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?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/>. | ||
|
||
namespace theme_boost_union; | ||
|
||
use moodle_url; | ||
use tabobject; | ||
use tabtree; | ||
|
||
/** | ||
* Theme Boost Union - Tabs to be shown within an external admin settings page | ||
* | ||
* @package theme_boost_union | ||
* @copyright 2024 Alexander Bias, lern.link GmbH <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Class admin_externalpage_tabs. | ||
* | ||
* @package theme_boost_union | ||
* @copyright 2024 Alexander Bias, lern.link GmbH <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class admin_externalpage_tabs { | ||
|
||
/** | ||
* @var array Holds the tabs in this tab tree. | ||
*/ | ||
private $tabs; | ||
|
||
|
||
/** | ||
* Create a tab tree. | ||
* | ||
* @return void | ||
*/ | ||
public function _construct() { | ||
// Initialize the tab tree. | ||
$this->tabs = []; | ||
} | ||
|
||
/** | ||
* Add a tab to the tab tree. | ||
* | ||
* @param string $name The (internal) tab name. | ||
* @param moodle_url $url The tab URL. | ||
* @param string $label The tab label. | ||
* @return void | ||
*/ | ||
public function add_tab(string $name, moodle_url $url, string $label) { | ||
// Create a new tab. | ||
$newtab = new tabobject($name, $url, $label); | ||
|
||
// Add the tab to the tab tree. | ||
$this->tabs[] = $newtab; | ||
} | ||
|
||
/** | ||
* Render the tab tree. | ||
* | ||
* @param string $selected The selected tab's name. | ||
* @return string The rendered tab tree. | ||
*/ | ||
public function render_tabtree(string $selected) { | ||
global $OUTPUT; | ||
|
||
// Make a tabtree object from the added tabs. | ||
$tabtree = new tabtree($this->tabs, $selected); | ||
|
||
// Render and return the tab tree. | ||
return $OUTPUT->render($tabtree); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?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/>. | ||
|
||
namespace theme_boost_union; | ||
|
||
/** | ||
* Theme Boost Union - Admin settings page with tabs as well as external pages within a tab | ||
* | ||
* @package theme_boost_union | ||
* @copyright 2024 Alexander Bias, lern.link GmbH <[email protected]> | ||
* based on code 2016 Ryan Wyllie in class theme_boost_admin_settingspage_tabs | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Class admin_settingspage_tabs_with_external. | ||
* | ||
* This class is copied and modified from /theme/boost/classes/admin_settingspage_tabs.php | ||
* | ||
* @package theme_boost_union | ||
* @copyright 2024 Alexander Bias, lern.link GmbH <[email protected]> | ||
* based on code 2016 Ryan Wyllie in class theme_boost_admin_settingspage_tabs | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class admin_settingspage_tabs_with_external extends \theme_boost_admin_settingspage_tabs { | ||
/** | ||
* Add the page. | ||
* | ||
* This function is amended with a switch for the external tabs. | ||
* | ||
* @param $tab object A tab. | ||
*/ | ||
public function add($tab) { | ||
// If the tab is an external page, add it as external tab. | ||
if ($tab instanceof \admin_externalpage) { | ||
return $this->add_external_tab($tab); | ||
|
||
// Otherwise, fall back to normal mode. | ||
} else { | ||
return $this->add_tab($tab); | ||
} | ||
} | ||
|
||
/** | ||
* Add an external tab. | ||
* | ||
* @param \admin_externalpage $tab An external tab. | ||
*/ | ||
private function add_external_tab(\admin_externalpage $tab) { | ||
$this->tabs[] = $tab; | ||
return true; | ||
} | ||
|
||
/** | ||
* Generate the HTML output. | ||
* | ||
* This function is amended with a switch for the external tabs. | ||
* | ||
* @return string | ||
*/ | ||
public function output_html() { | ||
global $OUTPUT; | ||
|
||
$activetab = optional_param('activetab', '', PARAM_TEXT); | ||
$context = array('tabs' => array()); | ||
$havesetactive = false; | ||
|
||
foreach ($this->get_tabs() as $tab) { | ||
$active = false; | ||
|
||
// Default to first tab it not told otherwise. | ||
if (empty($activetab) && !$havesetactive) { | ||
$active = true; | ||
$havesetactive = true; | ||
} else if ($activetab === $tab->name) { | ||
$active = true; | ||
} | ||
|
||
$newtab = array( | ||
'name' => $tab->name, | ||
'displayname' => $tab->visiblename, | ||
'html' => $tab->output_html(), | ||
'active' => $active, | ||
); | ||
// If the tab is an external page. | ||
if ($tab instanceof \admin_externalpage) { | ||
// Add a flag for the mustache template. | ||
$newtab['externaltab'] = true; | ||
// And change the name (which is used as link in the mustache template) | ||
// to hold the full URL of the external page.. | ||
$externalname = new \moodle_url('/theme/boost_union/snippets/overview.php'); | ||
$newtab['name'] = $externalname->out(); | ||
} | ||
$context['tabs'][] = $newtab; | ||
} | ||
|
||
if (empty($context['tabs'])) { | ||
return ''; | ||
} | ||
|
||
return $OUTPUT->render_from_template('theme_boost/admin_setting_tabs', $context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.