Bumping HEAD to today
[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;
37
602efb3b
MD
38 if ($this->content !== NULL) {
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
07ab0c80 51 $this->content->items[] = '<a href='.$CFG->wwwroot.'/blocks/community/communitycourse.php?add=true>'.get_string('addcourse', 'block_community').'</a>';
52 $this->content->icons[] = '<img src="'.$OUTPUT->pix_url('i/group') . '" class="icon" alt="" />';
53
54 $community = new community();
55 $courses = $community->get_community_courses($USER->id);
bfe600c3
MD
56 if ($courses) {
57 $this->content->items[] = '<hr />';
58 $this->content->icons[] = '';
59 $this->content->items[] = get_string('mycommunities', 'block_community');
60 $this->content->icons[] = '';
61 foreach ($courses as $course) {
62 //delete link
63 $deleteicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/cross_red_small')));
64 $deleteurl = new moodle_url($CFG->wwwroot.'/blocks/community/communitycourse.php',
65 array('remove'=>true, 'communityid'=> $course->id, 'sesskey' => sesskey()));
66 $deleteatag = html_writer::tag('a', $deleteicon, array('href' => $deleteurl));
276f590e 67
bfe600c3 68 $this->content->items[] = '<a href='.$course->courseurl.'>'.$course->coursename.'</a> ' .
276f590e 69 $deleteatag;
bfe600c3
MD
70 $this->content->icons[] = '';
71 }
07ab0c80 72 }
73
74 return $this->content;
75 }
76
77 function applicable_formats() {
78 return array('all' => true);
79 }
80
81}
82