Bumped to Preview Release 4
[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');
30 $this->version = 2010042701;
31 }
32
33 function get_content() {
07ab0c80 34 global $CFG, $OUTPUT, $USER;
755f96f8 35 if (!has_capability('moodle/community:add', get_context_instance(CONTEXT_USER, $USER->id))
36 or $this->content !== NULL) {
602efb3b
MD
37 return $this->content;
38 }
39
07ab0c80 40 $this->content = new stdClass();
41 $this->content->items = array();
42 $this->content->icons = array();
43 $this->content->footer = '';
44
602efb3b
MD
45 if (!isloggedin()) {
46 return $this->content;
47 }
276f590e 48
f5747998 49 $searchlink = html_writer::tag('a', get_string('addcourse', 'block_community'),
50 array('href' => $CFG->wwwroot.'/blocks/community/communitycourse.php?add=true'));
51 $this->content->items[] = $searchlink;
52 $icon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/group'),
53 'class' => 'icon', 'alt' => get_string('addcourse', 'block_community')));
54 $this->content->icons[] = $icon;
07ab0c80 55
1c2b7a90 56 require_once($CFG->dirroot . '/blocks/community/locallib.php');
57 $communitymanager = new block_community_manager();
58 $courses = $communitymanager->block_community_get_courses($USER->id);
bfe600c3 59 if ($courses) {
f5747998 60 $this->content->items[] = html_writer::empty_tag('hr');
bfe600c3
MD
61 $this->content->icons[] = '';
62 $this->content->items[] = get_string('mycommunities', 'block_community');
63 $this->content->icons[] = '';
64 foreach ($courses as $course) {
65 //delete link
f5747998 66 $deleteicon = html_writer::empty_tag('img',
67 array('src' => $OUTPUT->pix_url('i/cross_red_small'),
68 'alt' => get_string('removecommunitycourse', 'block_community')));
bfe600c3
MD
69 $deleteurl = new moodle_url($CFG->wwwroot.'/blocks/community/communitycourse.php',
70 array('remove'=>true, 'communityid'=> $course->id, 'sesskey' => sesskey()));
71 $deleteatag = html_writer::tag('a', $deleteicon, array('href' => $deleteurl));
276f590e 72
f5747998 73 $courselink = html_writer::tag('a', $course->coursename,
74 array('href' => $course->courseurl));
75 $this->content->items[] = $courselink .$deleteatag;
bfe600c3
MD
76 $this->content->icons[] = '';
77 }
07ab0c80 78 }
79
80 return $this->content;
81 }
82
07ab0c80 83}
84