backup MDL-23362 added grade_settings to backup and restore
[moodle.git] / blocks / community / block_community.php
CommitLineData
07ab0c80 1<?PHP
e6c2edbf 2
07ab0c80 3// This file is part of Moodle - http://moodle.org/
4//
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.
9//
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.
14//
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/>.
17
18/*
19 * @package blocks
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
24 *
25 * The community block
e6c2edbf 26 */
07ab0c80 27
07ab0c80 28class block_community extends block_list {
29 function init() {
30 $this->title = get_string('pluginname', 'block_community');
07ab0c80 31 }
32
6585e9f8
MD
33 function user_can_addto($page) {
34 // Don't allow people to add the block if they can't even use it
e6c2edbf 35 if (!has_capability('moodle/community:add',
8cbe03ee 36 get_context_instance(CONTEXT_COURSE, $page->course->id))) {
6585e9f8
MD
37 return false;
38 }
e6c2edbf 39
9358f71f 40 return parent::user_can_addto($page);
6585e9f8
MD
41 }
42
43 function user_can_edit() {
44 // Don't allow people to edit the block if they can't even use it
e6c2edbf 45 if (!has_capability('moodle/community:add',
46 get_context_instance(CONTEXT_COURSE, $this->page->course->id))) {
6585e9f8
MD
47 return false;
48 }
029a3117 49 return parent::user_can_edit();
6585e9f8
MD
50 }
51
07ab0c80 52 function get_content() {
07ab0c80 53 global $CFG, $OUTPUT, $USER;
6585e9f8 54
e6c2edbf 55 if (!has_capability('moodle/community:add',
56 get_context_instance(CONTEXT_COURSE, $this->page->course->id))
755f96f8 57 or $this->content !== NULL) {
602efb3b
MD
58 return $this->content;
59 }
60
07ab0c80 61 $this->content = new stdClass();
62 $this->content->items = array();
63 $this->content->icons = array();
64 $this->content->footer = '';
65
602efb3b
MD
66 if (!isloggedin()) {
67 return $this->content;
68 }
710363c9
RW
69
70 $icon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/group'),
e6c2edbf 71 'class' => 'icon', 'alt' => get_string('addcourse', 'block_community')));
b48c4478 72 $addcourseurl = new moodle_url('/blocks/community/communitycourse.php',
e6c2edbf 73 array('add' => true, 'courseid' => $this->page->course->id));
74 $searchlink = html_writer::tag('a', $icon . '&nbsp;' . get_string('addcourse', 'block_community'),
75 array('href' => $addcourseurl->out(false)));
f5747998 76 $this->content->items[] = $searchlink;
07ab0c80 77
1c2b7a90 78 require_once($CFG->dirroot . '/blocks/community/locallib.php');
79 $communitymanager = new block_community_manager();
80 $courses = $communitymanager->block_community_get_courses($USER->id);
bfe600c3 81 if ($courses) {
f5747998 82 $this->content->items[] = html_writer::empty_tag('hr');
bfe600c3
MD
83 $this->content->icons[] = '';
84 $this->content->items[] = get_string('mycommunities', 'block_community');
85 $this->content->icons[] = '';
86 foreach ($courses as $course) {
87 //delete link
8571833f 88 $deleteicon = html_writer::empty_tag('img',
e6c2edbf 89 array('src' => $OUTPUT->pix_url('i/cross_red_small'),
90 'alt' => get_string('removecommunitycourse', 'block_community')));
b48c4478 91 $deleteurl = new moodle_url('/blocks/community/communitycourse.php',
e6c2edbf 92 array('remove' => true,
93 'courseid' => $this->page->course->id,
94 'communityid' => $course->id, 'sesskey' => sesskey()));
bfe600c3 95 $deleteatag = html_writer::tag('a', $deleteicon, array('href' => $deleteurl));
276f590e 96
f5747998 97 $courselink = html_writer::tag('a', $course->coursename,
e6c2edbf 98 array('href' => $course->courseurl));
99 $this->content->items[] = $courselink . $deleteatag;
bfe600c3
MD
100 $this->content->icons[] = '';
101 }
07ab0c80 102 }
103
104 return $this->content;
105 }
106
07ab0c80 107}
108