community block MDL-24011 fix two context related issues with community block

This commit is contained in:
jerome mouneyrac 2010-09-08 02:06:43 +00:00
parent d7ba102bcf
commit e6c2edbf7c

View file

@ -1,4 +1,5 @@
<?PHP <?PHP
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -31,7 +32,8 @@ class block_community extends block_list {
function user_can_addto($page) { function user_can_addto($page) {
// Don't allow people to add the block if they can't even use it // 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 false;
} }
@ -40,7 +42,8 @@ class block_community extends block_list {
function user_can_edit() { function user_can_edit() {
// Don't allow people to edit the block if they can't even use it // 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 false;
} }
return parent::user_can_edit(); return parent::user_can_edit();
@ -49,7 +52,8 @@ class block_community extends block_list {
function get_content() { function get_content() {
global $CFG, $OUTPUT, $USER; 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) { or $this->content !== NULL) {
return $this->content; return $this->content;
} }
@ -85,7 +89,9 @@ class block_community extends block_list {
array('src' => $OUTPUT->pix_url('i/cross_red_small'), array('src' => $OUTPUT->pix_url('i/cross_red_small'),
'alt' => get_string('removecommunitycourse', 'block_community'))); 'alt' => get_string('removecommunitycourse', 'block_community')));
$deleteurl = new moodle_url('/blocks/community/communitycourse.php', $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)); $deleteatag = html_writer::tag('a', $deleteicon, array('href' => $deleteurl));
$courselink = html_writer::tag('a', $course->coursename, $courselink = html_writer::tag('a', $course->coursename,