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