Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/blocks/community/block_community.php
Go to the documentation of this file.
00001 <?PHP
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 /*
00019  * @package    blocks
00020  * @subpackage community
00021  * @author     Jerome Mouneyrac <jerome@mouneyrac.com>
00022  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
00023  * @copyright  (C) 1999 onwards Martin Dougiamas  http://dougiamas.com
00024  *
00025  * The community block
00026  */
00027 
00028 class block_community extends block_list {
00029 
00030     function init() {
00031         $this->title = get_string('pluginname', 'block_community');
00032     }
00033 
00034     function user_can_addto($page) {
00035         // Don't allow people to add the block if they can't even use it
00036         if (!has_capability('moodle/community:add', $page->context)) {
00037             return false;
00038         }
00039 
00040         return parent::user_can_addto($page);
00041     }
00042 
00043     function user_can_edit() {
00044         // Don't allow people to edit the block if they can't even use it
00045         if (!has_capability('moodle/community:add',
00046                         get_context_instance_by_id($this->instance->parentcontextid))) {
00047             return false;
00048         }
00049         return parent::user_can_edit();
00050     }
00051 
00052     function get_content() {
00053         global $CFG, $OUTPUT, $USER;
00054 
00055         $coursecontext = get_context_instance_by_id($this->instance->parentcontextid);
00056 
00057         if (!has_capability('moodle/community:add', $coursecontext)
00058                 or $this->content !== NULL) {
00059             return $this->content;
00060         }
00061 
00062         $this->content = new stdClass();
00063         $this->content->items = array();
00064         $this->content->icons = array();
00065         $this->content->footer = '';
00066 
00067         if (!isloggedin()) {
00068             return $this->content;
00069         }
00070 
00071         $icon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/group'),
00072                     'class' => 'icon', 'alt' => get_string('addcourse', 'block_community')));
00073         $addcourseurl = new moodle_url('/blocks/community/communitycourse.php',
00074                         array('add' => true, 'courseid' => $coursecontext->instanceid));
00075         $searchlink = html_writer::tag('a', $icon . '&nbsp;' . get_string('addcourse', 'block_community'),
00076                         array('href' => $addcourseurl->out(false)));
00077         $this->content->items[] = $searchlink;
00078 
00079         require_once($CFG->dirroot . '/blocks/community/locallib.php');
00080         $communitymanager = new block_community_manager();
00081         $courses = $communitymanager->block_community_get_courses($USER->id);
00082         if ($courses) {
00083             $this->content->items[] = html_writer::empty_tag('hr');
00084             $this->content->icons[] = '';
00085             $this->content->items[] = get_string('mycommunities', 'block_community');
00086             $this->content->icons[] = '';
00087             foreach ($courses as $course) {
00088                 //delete link
00089                 $deleteicon = html_writer::empty_tag('img',
00090                                 array('src' => $OUTPUT->pix_url('t/delete'),
00091                                     'alt' => get_string('removecommunitycourse', 'block_community')));
00092                 $deleteurl = new moodle_url('/blocks/community/communitycourse.php',
00093                                 array('remove' => true,
00094                                     'courseid' => $coursecontext->instanceid,
00095                                     'communityid' => $course->id, 'sesskey' => sesskey()));
00096                 $deleteatag = html_writer::tag('a', $deleteicon, array('href' => $deleteurl));
00097 
00098                 $courselink = html_writer::tag('a', $course->coursename,
00099                                 array('href' => $course->courseurl));
00100                 $this->content->items[] = $courselink . ' ' . $deleteatag;
00101                 $this->content->icons[] = '';
00102             }
00103         }
00104 
00105         return $this->content;
00106     }
00107 
00108 }
00109 
 All Data Structures Namespaces Files Functions Variables Enumerations