MDL-36110 - Blocks - Community finder icon alt attribute is now empty
[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 {
0bb7789a 29
07ab0c80 30 function init() {
31 $this->title = get_string('pluginname', 'block_community');
07ab0c80 32 }
33
6585e9f8
MD
34 function user_can_addto($page) {
35 // Don't allow people to add the block if they can't even use it
0bb7789a 36 if (!has_capability('moodle/community:add', $page->context)) {
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
0bb7789a 45 if (!has_capability('moodle/community:add',
46 get_context_instance_by_id($this->instance->parentcontextid))) {
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
0bb7789a 55 $coursecontext = get_context_instance_by_id($this->instance->parentcontextid);
56
57 if (!has_capability('moodle/community:add', $coursecontext)
755f96f8 58 or $this->content !== NULL) {
602efb3b
MD
59 return $this->content;
60 }
61
07ab0c80 62 $this->content = new stdClass();
63 $this->content->items = array();
64 $this->content->icons = array();
65 $this->content->footer = '';
66
602efb3b
MD
67 if (!isloggedin()) {
68 return $this->content;
69 }
710363c9
RW
70
71 $icon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/group'),
e0971d8b 72 'class' => 'icon', 'alt' => ""));
b48c4478 73 $addcourseurl = new moodle_url('/blocks/community/communitycourse.php',
98814390 74 array('add' => true, 'courseid' => $this->page->course->id));
e6c2edbf 75 $searchlink = html_writer::tag('a', $icon . '&nbsp;' . get_string('addcourse', 'block_community'),
76 array('href' => $addcourseurl->out(false)));
f5747998 77 $this->content->items[] = $searchlink;
07ab0c80 78
1c2b7a90 79 require_once($CFG->dirroot . '/blocks/community/locallib.php');
80 $communitymanager = new block_community_manager();
81 $courses = $communitymanager->block_community_get_courses($USER->id);
bfe600c3 82 if ($courses) {
f5747998 83 $this->content->items[] = html_writer::empty_tag('hr');
bfe600c3
MD
84 $this->content->icons[] = '';
85 $this->content->items[] = get_string('mycommunities', 'block_community');
86 $this->content->icons[] = '';
87 foreach ($courses as $course) {
88 //delete link
8571833f 89 $deleteicon = html_writer::empty_tag('img',
c37d631f 90 array('src' => $OUTPUT->pix_url('t/delete'),
e6c2edbf 91 'alt' => get_string('removecommunitycourse', 'block_community')));
b48c4478 92 $deleteurl = new moodle_url('/blocks/community/communitycourse.php',
e6c2edbf 93 array('remove' => true,
98814390 94 'courseid' => $this->page->course->id,
e6c2edbf 95 'communityid' => $course->id, 'sesskey' => sesskey()));
bfe600c3 96 $deleteatag = html_writer::tag('a', $deleteicon, array('href' => $deleteurl));
276f590e 97
f5747998 98 $courselink = html_writer::tag('a', $course->coursename,
e6c2edbf 99 array('href' => $course->courseurl));
c37d631f 100 $this->content->items[] = $courselink . ' ' . $deleteatag;
bfe600c3
MD
101 $this->content->icons[] = '';
102 }
07ab0c80 103 }
104
105 return $this->content;
106 }
107
07ab0c80 108}
109