Updated the HEAD build version to 20100908
[moodle.git] / blocks / community / block_community.php
CommitLineData
07ab0c80 1<?PHP
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/*
18 * @package blocks
19 * @subpackage community
20 * @author Jerome Mouneyrac <jerome@mouneyrac.com>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
22 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
23 *
24 * The community block
25*/
26
07ab0c80 27class block_community extends block_list {
28 function init() {
29 $this->title = get_string('pluginname', 'block_community');
07ab0c80 30 }
31
6585e9f8
MD
32 function user_can_addto($page) {
33 // Don't allow people to add the block if they can't even use it
34 if (!has_capability('moodle/community:add', get_context_instance(CONTEXT_SYSTEM))) { // Should be page context?
35 return false;
36 }
9358f71f 37
38 return parent::user_can_addto($page);
6585e9f8
MD
39 }
40
41 function user_can_edit() {
42 // Don't allow people to edit the block if they can't even use it
43 if (!has_capability('moodle/community:add', get_context_instance(CONTEXT_SYSTEM))) { // Should be page context?
44 return false;
45 }
029a3117 46 return parent::user_can_edit();
6585e9f8
MD
47 }
48
07ab0c80 49 function get_content() {
07ab0c80 50 global $CFG, $OUTPUT, $USER;
6585e9f8
MD
51
52 if (!has_capability('moodle/community:add', get_context_instance(CONTEXT_SYSTEM)) // Should be page context?
755f96f8 53 or $this->content !== NULL) {
602efb3b
MD
54 return $this->content;
55 }
56
07ab0c80 57 $this->content = new stdClass();
58 $this->content->items = array();
59 $this->content->icons = array();
60 $this->content->footer = '';
61
602efb3b
MD
62 if (!isloggedin()) {
63 return $this->content;
64 }
710363c9
RW
65
66 $icon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/group'),
67 'class' => 'icon', 'alt' => get_string('addcourse', 'block_community')));
b48c4478 68 $addcourseurl = new moodle_url('/blocks/community/communitycourse.php',
69 array('add' => true, 'courseid' => $this->page->course->id));
710363c9 70 $searchlink = html_writer::tag('a', $icon .'&nbsp;'.get_string('addcourse', 'block_community'),
b48c4478 71 array('href' => $addcourseurl->out(false)));
f5747998 72 $this->content->items[] = $searchlink;
07ab0c80 73
1c2b7a90 74 require_once($CFG->dirroot . '/blocks/community/locallib.php');
75 $communitymanager = new block_community_manager();
76 $courses = $communitymanager->block_community_get_courses($USER->id);
bfe600c3 77 if ($courses) {
f5747998 78 $this->content->items[] = html_writer::empty_tag('hr');
bfe600c3
MD
79 $this->content->icons[] = '';
80 $this->content->items[] = get_string('mycommunities', 'block_community');
81 $this->content->icons[] = '';
82 foreach ($courses as $course) {
83 //delete link
8571833f
PS
84 $deleteicon = html_writer::empty_tag('img',
85 array('src' => $OUTPUT->pix_url('i/cross_red_small'),
f5747998 86 'alt' => get_string('removecommunitycourse', 'block_community')));
b48c4478 87 $deleteurl = new moodle_url('/blocks/community/communitycourse.php',
bfe600c3
MD
88 array('remove'=>true, 'communityid'=> $course->id, 'sesskey' => sesskey()));
89 $deleteatag = html_writer::tag('a', $deleteicon, array('href' => $deleteurl));
276f590e 90
f5747998 91 $courselink = html_writer::tag('a', $course->coursename,
92 array('href' => $course->courseurl));
93 $this->content->items[] = $courselink .$deleteatag;
bfe600c3
MD
94 $this->content->icons[] = '';
95 }
07ab0c80 96 }
97
98 return $this->content;
99 }
100
07ab0c80 101}
102