MDL-45895 user: Scaffold of the new preferences page
Part of MDL-45774
This commit is contained in:
committed by
Adrian Greeve
parent
b6c42eb0f0
commit
0e8418a8de
@@ -75,6 +75,7 @@ $string['cannoteditcomment'] = 'This comment is not yours to edit!';
|
||||
$string['cannoteditcommentexpired'] = 'You can\'t edit this. The time has expired!';
|
||||
$string['cannoteditpostorblog'] = 'You cannot post or edit blogs';
|
||||
$string['cannoteditsiteform'] = 'You cannot edit the site course using this form';
|
||||
$string['cannotedituserpreferences'] = 'Cannot edit this user\'s preferences';
|
||||
$string['cannotedityourprofile'] = 'Sorry, you cannot edit own profile';
|
||||
$string['cannotexecduringupgrade'] = 'Cannot be executed during upgrade';
|
||||
$string['cannotfindcategory'] = 'Cannot find category record from database by ID - {$a}';
|
||||
|
||||
@@ -3596,3 +3596,62 @@ class action_menu_link_secondary extends action_menu_link {
|
||||
parent::__construct($url, $icon, $text, false, $attributes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a set of preferences groups.
|
||||
*
|
||||
* @package core
|
||||
* @category output
|
||||
* @copyright 2015 Frédéric Massart - FMCorz.net
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class preferences_groups implements renderable {
|
||||
|
||||
/**
|
||||
* Array of preferences_group.
|
||||
* @var array
|
||||
*/
|
||||
public $groups;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param array $groups of preferences_group
|
||||
*/
|
||||
public function __construct($groups) {
|
||||
$this->groups = $groups;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a group of preferences page link.
|
||||
*
|
||||
* @package core
|
||||
* @category output
|
||||
* @copyright 2015 Frédéric Massart - FMCorz.net
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class preferences_group implements renderable {
|
||||
|
||||
/**
|
||||
* Title of the group.
|
||||
* @var string
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* Array of navigation_node.
|
||||
* @var array
|
||||
*/
|
||||
public $nodes;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param string $title The title.
|
||||
* @param array $nodes of navigation_node.
|
||||
*/
|
||||
public function __construct($title, $nodes) {
|
||||
$this->title = $title;
|
||||
$this->nodes = $nodes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3946,6 +3946,58 @@ EOD;
|
||||
public function favicon() {
|
||||
return $this->pix_url('favicon', 'theme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders preferences groups.
|
||||
*
|
||||
* @param preferences_groups $renderable The renderable
|
||||
* @return string The output.
|
||||
*/
|
||||
public function render_preferences_groups(preferences_groups $renderable) {
|
||||
$html = '';
|
||||
$html .= html_writer::start_tag('div', array('class' => 'span12 preferences-groups'));
|
||||
$i = 0;
|
||||
$open = false;
|
||||
foreach ($renderable->groups as $group) {
|
||||
if ($i == 0 || $i % 3 == 0) {
|
||||
if ($open) {
|
||||
$html .= html_writer::end_tag('div');
|
||||
}
|
||||
$html .= html_writer::start_tag('div', array('class' => 'row'));
|
||||
$open = true;
|
||||
}
|
||||
$html .= $this->render($group);
|
||||
$i++;
|
||||
}
|
||||
|
||||
$html .= html_writer::end_tag('div');
|
||||
|
||||
$html .= html_writer::end_tag('ul');
|
||||
$html .= html_writer::end_tag('div');
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders preferences group.
|
||||
*
|
||||
* @param preferences_group $renderable The renderable
|
||||
* @return string The output.
|
||||
*/
|
||||
public function render_preferences_group(preferences_group $renderable) {
|
||||
$html = '';
|
||||
$html .= html_writer::start_tag('div', array('class' => 'span4 preferences-group'));
|
||||
$html .= $this->heading($renderable->title, 3);
|
||||
$html .= html_writer::start_tag('ul');
|
||||
foreach ($renderable->nodes as $node) {
|
||||
if ($node->has_children()) {
|
||||
debugging('Preferences nodes do not support children', DEBUG_DEVELOPER);
|
||||
}
|
||||
$html .= html_writer::tag('li', $this->render($node));
|
||||
}
|
||||
$html .= html_writer::end_tag('ul');
|
||||
$html .= html_writer::end_tag('div');
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -226,3 +226,17 @@
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
|
||||
/** Preferences page */
|
||||
.preferences-group {
|
||||
ul {
|
||||
list-style: none;
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
.dir-rtl {
|
||||
.preferences-group {
|
||||
float: right;
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,82 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* My preferences.
|
||||
*
|
||||
* @package core_user
|
||||
* @copyright 2015 Frédéric Massart - FMCorz.net
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/../config.php');
|
||||
require_once($CFG->libdir . '/navigationlib.php');
|
||||
|
||||
require_login(null, false);
|
||||
if (isguestuser()) {
|
||||
throw new require_login_exception();
|
||||
}
|
||||
|
||||
$userid = optional_param('userid', $USER->id, PARAM_INT);
|
||||
$currentuser = $userid == $USER->id;
|
||||
|
||||
// Only administrators can access another user's preferences.
|
||||
if (!$currentuser && !is_siteadmin($USER)) {
|
||||
throw new moodle_exception('cannotedituserpreferences', 'error');
|
||||
}
|
||||
|
||||
// Check that the user is a valid user.
|
||||
$user = core_user::get_user($userid);
|
||||
if (!$user || !core_user::is_real_user($userid)) {
|
||||
throw new moodle_exception('invaliduser', 'error');
|
||||
}
|
||||
|
||||
$PAGE->set_context(context_user::instance($userid));
|
||||
$PAGE->set_url('/user/preferences.php', array('userid' => $userid));
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_pagetype('user-preferences');
|
||||
|
||||
if (!$currentuser) {
|
||||
$PAGE->set_title(fullname($user));
|
||||
$PAGE->set_heading(fullname($user));
|
||||
|
||||
$PAGE->navigation->extend_for_user($user);
|
||||
$settings = $PAGE->settingsnav->get('userviewingsettings' . $user->id);
|
||||
} else {
|
||||
$PAGE->set_title(get_string('preferences'));
|
||||
$PAGE->set_heading(get_string('preferences'));
|
||||
|
||||
$settings = $PAGE->settingsnav->get('usercurrentsettings');
|
||||
}
|
||||
|
||||
// Identifying the nodes.
|
||||
$groups = array();
|
||||
$orphans = array();
|
||||
foreach ($settings->children as $setting) {
|
||||
if ($setting->has_children()) {
|
||||
$groups[] = new preferences_group($setting->get_content(), $setting->children);
|
||||
} else {
|
||||
$orphans[] = $setting;
|
||||
}
|
||||
}
|
||||
if (!empty($orphans)) {
|
||||
$groups[] = new preferences_group(get_string('miscellaneous'), $orphans);
|
||||
}
|
||||
$preferences = new preferences_groups($groups);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->render($preferences);
|
||||
echo $OUTPUT->footer();
|
||||
Reference in New Issue
Block a user