3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * @subpackage community
21 * @author Jerome Mouneyrac <jerome@mouneyrac.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
23 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
28 class block_community
extends block_list
{
31 $this->title
= get_string('pluginname', 'block_community');
34 function user_can_addto($page) {
35 // Don't allow people to add the block if they can't even use it
36 if (!has_capability('moodle/community:add', $page->context
)) {
40 return parent
::user_can_addto($page);
43 function user_can_edit() {
44 // Don't allow people to edit the block if they can't even use it
45 if (!has_capability('moodle/community:add',
46 get_context_instance_by_id($this->instance
->parentcontextid
))) {
49 return parent
::user_can_edit();
52 function get_content() {
53 global $CFG, $OUTPUT, $USER;
55 $coursecontext = get_context_instance_by_id($this->instance
->parentcontextid
);
57 if (!has_capability('moodle/community:add', $coursecontext)
58 or $this->content
!== NULL) {
59 return $this->content
;
62 $this->content
= new stdClass();
63 $this->content
->items
= array();
64 $this->content
->icons
= array();
65 $this->content
->footer
= '';
68 return $this->content
;
71 $icon = html_writer
::empty_tag('img', array('src' => $OUTPUT->pix_url('i/group'),
72 'class' => 'icon', 'alt' => get_string('addcourse', 'block_community')));
73 $addcourseurl = new moodle_url('/blocks/community/communitycourse.php',
74 array('add' => true, 'courseid' => $coursecontext->instanceid
));
75 $searchlink = html_writer
::tag('a', $icon . ' ' . get_string('addcourse', 'block_community'),
76 array('href' => $addcourseurl->out(false)));
77 $this->content
->items
[] = $searchlink;
79 require_once($CFG->dirroot
. '/blocks/community/locallib.php');
80 $communitymanager = new block_community_manager();
81 $courses = $communitymanager->block_community_get_courses($USER->id
);
83 $this->content
->items
[] = html_writer
::empty_tag('hr');
84 $this->content
->icons
[] = '';
85 $this->content
->items
[] = get_string('mycommunities', 'block_community');
86 $this->content
->icons
[] = '';
87 foreach ($courses as $course) {
89 $deleteicon = html_writer
::empty_tag('img',
90 array('src' => $OUTPUT->pix_url('t/delete'),
91 'alt' => get_string('removecommunitycourse', 'block_community')));
92 $deleteurl = new moodle_url('/blocks/community/communitycourse.php',
93 array('remove' => true,
94 'courseid' => $coursecontext->instanceid
,
95 'communityid' => $course->id
, 'sesskey' => sesskey()));
96 $deleteatag = html_writer
::tag('a', $deleteicon, array('href' => $deleteurl));
98 $courselink = html_writer
::tag('a', $course->coursename
,
99 array('href' => $course->courseurl
));
100 $this->content
->items
[] = $courselink . ' ' . $deleteatag;
101 $this->content
->icons
[] = '';
105 return $this->content
;