MDL-31830 course: fixed interface issues with limited user

* Navigation/settings now show best available option.
* Resorting categories works now for limited access user.
* Display of up and down arrows corrected.
* Checkboxes no longer displayed if an action can't be performed.
This commit is contained in:
Sam Hemelryk 2013-10-03 10:28:58 +13:00
parent f454e3247d
commit b488058f7d
8 changed files with 73 additions and 18 deletions

View File

@ -124,9 +124,7 @@ class core_course_management_renderer extends plugin_renderer_base {
$html = html_writer::start_div('category-listing');
$html .= html_writer::tag('h3', get_string('categories'));
if ($category !== null) {
$html .= $this->category_listing_actions($category);
}
$html .= $this->category_listing_actions($category);
$html .= html_writer::start_tag('ul', array('class' => 'ml'));
foreach ($listing as $listitem) {
// Render each category in the listing.
@ -176,6 +174,12 @@ class core_course_management_renderer extends plugin_renderer_base {
$text = $category->get_formatted_name();
$courseicon = $this->output->pix_icon('i/course', get_string('courses'));
$bcatinput = array('type' => 'checkbox', 'name' => 'bcat[]', 'value' => $category->id, 'class' => 'bulk-action-checkbox');
if (!$category->can_resort_subcategories() && !$category->has_manage_capability()) {
// Very very hardcoded here.
$bcatinput['style'] = 'visibility:hidden';
}
$viewcaturl = new moodle_url('/course/management.php', array('categoryid' => $category->id));
if ($isexpanded) {
$icon = $this->output->pix_icon('t/switch_minus', get_string('collapse'), 'moodle', array('class' => 'tree-icon'));
@ -187,6 +191,8 @@ class core_course_management_renderer extends plugin_renderer_base {
$icon = $this->output->pix_icon('i/navigationitem', '', 'moodle', array('class' => 'tree-icon'));
$icon = html_writer::link($viewcaturl, $icon, array('class' => 'float-left'));
}
$actions = \core_course\management\helper::get_category_listitem_actions($category);
$hasactions = !empty($actions);
$html = html_writer::start_tag('li', $attributes);
$html .= html_writer::start_div('clearfix');
@ -194,9 +200,15 @@ class core_course_management_renderer extends plugin_renderer_base {
$html .= html_writer::empty_tag('input', $bcatinput).' ';
$html .= html_writer::end_div();
$html .= $icon;
$html .= html_writer::link($viewcaturl, $text, array('class' => 'float-left categoryname'));
if ($hasactions) {
$html .= html_writer::link($viewcaturl, $text, array('class' => 'float-left categoryname'));
} else {
$html .= html_writer::link($viewcaturl, $text, array('class' => 'float-left categoryname without-actions'));
}
$html .= html_writer::start_div('float-right');
$html .= $this->category_listitem_actions($category);
if ($hasactions) {
$html .= $this->category_listitem_actions($category, $actions);
}
$html .= html_writer::span($category->coursecount.$courseicon, 'course-count dimmed');
$html .= html_writer::end_div();
$html .= html_writer::end_div();
@ -228,10 +240,13 @@ class core_course_management_renderer extends plugin_renderer_base {
* @param coursecat $category
* @return string
*/
public function category_listing_actions(coursecat $category) {
public function category_listing_actions(coursecat $category = null) {
$actions = array();
$createtoplevel = coursecat::can_create_top_level_category();
$createsubcategory = $category->can_create_subcategory();
$createsubcategory = $category && $category->can_create_subcategory();
if ($category === null) {
$category = coursecat::get(0);
}
$hasitems = false;
if ($createtoplevel || $createsubcategory) {
@ -279,7 +294,11 @@ class core_course_management_renderer extends plugin_renderer_base {
get_string('resortbyidnumber')
)
));
$menu->actiontext = get_string('resortcategories');
if ($category->id === 0) {
$menu->actiontext = get_string('resortcategories');
} else {
$menu->actiontext = get_string('resortsubcategories');
}
$menu->actionicon = new pix_icon('t/sort', ' ', 'moodle', array('class' => 'iconsmall'));
$actions[] = $this->render($menu);
}
@ -295,11 +314,14 @@ class core_course_management_renderer extends plugin_renderer_base {
* @param coursecat $category
* @return string
*/
public function category_listitem_actions(coursecat $category) {
public function category_listitem_actions(coursecat $category, array $actions = null) {
if ($actions === null) {
$actions = \core_course\management\helper::get_category_listitem_actions($category);
}
$menu = new action_menu();
$menu->attributes['class'] .= ' category-item-actions item-actions';
$hasitems = false;
foreach (\core_course\management\helper::get_category_listitem_actions($category) as $key => $action) {
foreach ($actions as $key => $action) {
$hasitems = true;
$menu->add(new action_menu_link(
$action['url'],

View File

@ -45,16 +45,19 @@ if ($issearching) {
$url = new moodle_url('/course/management.php');
navigation_node::override_active_url($url);
$systemcontext = $context = context_system::instance();
if ($courseid) {
$record = get_course($courseid);
$course = new course_in_list($record);
$category = coursecat::get($course->category);
$categoryid = $category->id;
$context = context_coursecat::instance($category->id);
$url->param('courseid', $course->id);
} else if ($categoryid) {
$courseid = null;
$course = null;
$category = coursecat::get($categoryid);
$context = context_coursecat::instance($category->id);
$url->param('categoryid', $category->id);
} else {
$course = null;
@ -64,6 +67,7 @@ if ($courseid) {
if ($viewmode === 'default') {
$viewmode = 'categories';
}
$context = $systemcontext;
}
if ($page !== 0) {
$url->param('page', $page);
@ -81,8 +85,7 @@ if ($modulelist !== '') {
$url->param('modulelist', $search);
}
$context = context_system::instance();
$title = format_string($SITE->fullname, true, array('context' => $context));
$title = format_string($SITE->fullname, true, array('context' => $systemcontext));
$PAGE->set_context($context);
$PAGE->set_url($url);
@ -90,7 +93,23 @@ $PAGE->set_pagelayout('admin');
$PAGE->set_title($title);
$PAGE->set_heading($title);
if (!$issearching && $category !== null) {
// If the user poses any of these capabilities then they will be able to see the admin
// tree and the management link within it.
// This is the most accurate form of navigation.
$capabilities = array(
'moodle/site:config',
'moodle/backup:backupcourse',
'moodle/category:manage',
'moodle/course:create',
'moodle/site:approvecourse'
);
if ($category && !has_any_capability($capabilities, $systemcontext)) {
// If the user doesn't poses any of these system capabilities then we're going to trigger
// the page to set the specific category being viewed.
// This will at least give the page some relevant navigation.
$PAGE->set_category_by_id($category->id);
navigation_node::override_active_url(new moodle_url('/course/management.php', array('categoryid' => $category->id)));
} else if (!$issearching && $category !== null) {
$parents = coursecat::get_many($category->get_parents());
foreach ($parents as $parent) {
$PAGE->navbar->add($parent->get_formatted_name());
@ -102,6 +121,7 @@ if (!$issearching && $category !== null) {
}
}
// This is a system level page that operates on other contexts.
require_login();
$notificationspass = array();
@ -128,7 +148,8 @@ if ($action !== false && confirm_sesskey()) {
switch ($action) {
case 'resortcategories' :
$sort = required_param('resort', PARAM_ALPHA);
\core_course\management\helper::action_category_resort_subcategories(coursecat::get(0), $sort);
$cattosort = coursecat::get((int)optional_param('categoryid', 0, PARAM_INT));
$redirectback = \core_course\management\helper::action_category_resort_subcategories($cattosort, $sort);
break;
case 'resortcourses' :
// They must have specified a category.
@ -289,6 +310,11 @@ if ($action !== false && confirm_sesskey()) {
\core_course\management\helper::action_category_resort_subcategories($cat, $sort, false);
}
coursecat::resort_categories_cleanup();
if ($category === null && count($categoryids) === 1) {
// They're bulk sorting just a single category and they've not selected a category.
// Lets for convenience sake auto-select the category that has been resorted for them.
redirect(new moodle_url($PAGE->url, array('categoryid' => reset($categoryids))));
}
}
}
if ($redirectback) {

View File

@ -1438,6 +1438,7 @@ $string['resetstatus'] = 'Status';
$string['resettask'] = 'Task';
$string['resettodefaults'] = 'Reset to defaults';
$string['resortcategories'] = 'Re-sort categories';
$string['resortsubcategories'] = 'Re-sort subcategories';
$string['resortcourses'] = 'Re-sort courses';
$string['resortcoursesbyname'] = 'Re-sort courses by name';
$string['resortbyname'] = 'By name';

View File

@ -1101,7 +1101,7 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
*
* @return bool
*/
protected static function has_manage_capability_on_any() {
public static function has_manage_capability_on_any() {
global $DB;
if (!isloggedin() || isguestuser()) {
return false;

View File

@ -4191,9 +4191,8 @@ class settings_navigation extends navigation_node {
$categorynode = $this->add($this->context->get_context_name(), null, null, null, 'categorysettings');
$categorynode->force_open();
$onmanagepage = $this->page->url->compare(new moodle_url('/course/management.php'), URL_MATCH_BASE);
if (can_edit_in_category($this->context->instanceid) && !$onmanagepage) {
if (can_edit_in_category($this->context->instanceid)) {
$url = new moodle_url('/course/management.php', array('categoryid' => $this->context->instanceid));
$editstring = get_string('managecategorythis');
$categorynode->add($editstring, $url, self::TYPE_SETTING, null, null, new pix_icon('i/edit', ''));

View File

@ -293,6 +293,8 @@ input.titleeditor { width: 330px; vertical-align: text-bottom; }
#course-category-listings .listitem:first-child > div .item-actions .action-moveup,
#course-category-listings .listitem:last-child > div .item-actions .action-movedown {display: none;}
#course-category-listings .listitem > div a.without-actions {color: #333;}
#course-listing li > div {padding-left:1em;}
#course-category-listings .detail-pair {border-bottom:1px solid #e1e1e8;margin:0 1em;}

View File

@ -611,6 +611,8 @@ span.editinstructions {
padding:0.3em;
}
/**
* Course management page
* Palette
@ -778,6 +780,9 @@ span.editinstructions {
display:inline;
}
}
.without-actions {
color: #333;
}
}
// The category or course is hidden.
&[data-visible="0"] {

File diff suppressed because one or more lines are too long