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
// 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,7 +32,8 @@ 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;
}
@ -40,7 +42,8 @@ class block_community extends block_list {
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;
}
@ -67,7 +71,7 @@ class block_community extends block_list {
'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 .'&nbsp;'.get_string('addcourse', 'block_community'),
$searchlink = html_writer::tag('a', $icon . '&nbsp;' . get_string('addcourse', 'block_community'),
array('href' => $addcourseurl->out(false)));
$this->content->items[] = $searchlink;
@ -85,12 +89,14 @@ class block_community extends block_list {
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;
$this->content->items[] = $courselink . $deleteatag;
$this->content->icons[] = '';
}
}