mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
community block MDL-24011 fix two context related issues with community block
This commit is contained in:
parent
d7ba102bcf
commit
e6c2edbf7c
1 changed files with 20 additions and 14 deletions
|
@ -1,4 +1,5 @@
|
|||
<?PHP
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
|
@ -22,7 +23,7 @@
|
|||
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
|
||||
*
|
||||
* The community block
|
||||
*/
|
||||
*/
|
||||
|
||||
class block_community extends block_list {
|
||||
function init() {
|
||||
|
@ -31,16 +32,18 @@ class block_community extends block_list {
|
|||
|
||||
function user_can_addto($page) {
|
||||
// Don't allow people to add the block if they can't even use it
|
||||
if (!has_capability('moodle/community:add', get_context_instance(CONTEXT_SYSTEM))) { // Should be page context?
|
||||
if (!has_capability('moodle/community:add',
|
||||
get_context_instance(CONTEXT_COURSE, $this->page->course->id))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return parent::user_can_addto($page);
|
||||
}
|
||||
|
||||
function user_can_edit() {
|
||||
// Don't allow people to edit the block if they can't even use it
|
||||
if (!has_capability('moodle/community:add', get_context_instance(CONTEXT_SYSTEM))) { // Should be page context?
|
||||
if (!has_capability('moodle/community:add',
|
||||
get_context_instance(CONTEXT_COURSE, $this->page->course->id))) {
|
||||
return false;
|
||||
}
|
||||
return parent::user_can_edit();
|
||||
|
@ -49,7 +52,8 @@ class block_community extends block_list {
|
|||
function get_content() {
|
||||
global $CFG, $OUTPUT, $USER;
|
||||
|
||||
if (!has_capability('moodle/community:add', get_context_instance(CONTEXT_SYSTEM)) // Should be page context?
|
||||
if (!has_capability('moodle/community:add',
|
||||
get_context_instance(CONTEXT_COURSE, $this->page->course->id))
|
||||
or $this->content !== NULL) {
|
||||
return $this->content;
|
||||
}
|
||||
|
@ -64,11 +68,11 @@ class block_community extends block_list {
|
|||
}
|
||||
|
||||
$icon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/group'),
|
||||
'class' => 'icon', 'alt' => get_string('addcourse', 'block_community')));
|
||||
'class' => 'icon', 'alt' => get_string('addcourse', 'block_community')));
|
||||
$addcourseurl = new moodle_url('/blocks/community/communitycourse.php',
|
||||
array('add' => true, 'courseid' => $this->page->course->id));
|
||||
$searchlink = html_writer::tag('a', $icon .' '.get_string('addcourse', 'block_community'),
|
||||
array('href' => $addcourseurl->out(false)));
|
||||
array('add' => true, 'courseid' => $this->page->course->id));
|
||||
$searchlink = html_writer::tag('a', $icon . ' ' . get_string('addcourse', 'block_community'),
|
||||
array('href' => $addcourseurl->out(false)));
|
||||
$this->content->items[] = $searchlink;
|
||||
|
||||
require_once($CFG->dirroot . '/blocks/community/locallib.php');
|
||||
|
@ -82,15 +86,17 @@ class block_community extends block_list {
|
|||
foreach ($courses as $course) {
|
||||
//delete link
|
||||
$deleteicon = html_writer::empty_tag('img',
|
||||
array('src' => $OUTPUT->pix_url('i/cross_red_small'),
|
||||
'alt' => get_string('removecommunitycourse', 'block_community')));
|
||||
array('src' => $OUTPUT->pix_url('i/cross_red_small'),
|
||||
'alt' => get_string('removecommunitycourse', 'block_community')));
|
||||
$deleteurl = new moodle_url('/blocks/community/communitycourse.php',
|
||||
array('remove'=>true, 'communityid'=> $course->id, 'sesskey' => sesskey()));
|
||||
array('remove' => true,
|
||||
'courseid' => $this->page->course->id,
|
||||
'communityid' => $course->id, 'sesskey' => sesskey()));
|
||||
$deleteatag = html_writer::tag('a', $deleteicon, array('href' => $deleteurl));
|
||||
|
||||
$courselink = html_writer::tag('a', $course->coursename,
|
||||
array('href' => $course->courseurl));
|
||||
$this->content->items[] = $courselink .$deleteatag;
|
||||
array('href' => $course->courseurl));
|
||||
$this->content->items[] = $courselink . $deleteatag;
|
||||
$this->content->icons[] = '';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue