[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/blocks/community/ -> block_community.php (source)

   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 block_community
  19   * @author     Jerome Mouneyrac <jerome@mouneyrac.com>
  20   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
  21   * @copyright  (C) 1999 onwards Martin Dougiamas  http://dougiamas.com
  22   *
  23   * The community block
  24   */
  25  
  26  class block_community extends block_list {
  27  
  28      function init() {
  29          $this->title = get_string('pluginname', 'block_community');
  30      }
  31  
  32      function user_can_addto($page) {
  33          // Don't allow people to add the block if they can't even use it
  34          if (!has_capability('moodle/community:add', $page->context)) {
  35              return false;
  36          }
  37  
  38          return parent::user_can_addto($page);
  39      }
  40  
  41      function user_can_edit() {
  42          // Don't allow people to edit the block if they can't even use it
  43          if (!has_capability('moodle/community:add',
  44                          context::instance_by_id($this->instance->parentcontextid))) {
  45              return false;
  46          }
  47          return parent::user_can_edit();
  48      }
  49  
  50      function get_content() {
  51          global $CFG, $OUTPUT, $USER;
  52  
  53          $coursecontext = context::instance_by_id($this->instance->parentcontextid);
  54  
  55          if (!has_capability('moodle/community:add', $coursecontext)
  56                  or $this->content !== NULL) {
  57              return $this->content;
  58          }
  59  
  60          $this->content = new stdClass();
  61          $this->content->items = array();
  62          $this->content->icons = array();
  63          $this->content->footer = '';
  64  
  65          if (!isloggedin()) {
  66              return $this->content;
  67          }
  68  
  69          $icon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/group'),
  70                      'class' => 'icon', 'alt' => ""));
  71          $addcourseurl = new moodle_url('/blocks/community/communitycourse.php',
  72                          array('add' => true, 'courseid' => $this->page->course->id));
  73          $searchlink = html_writer::tag('a', $icon . get_string('addcourse', 'block_community'),
  74                          array('href' => $addcourseurl->out(false)));
  75          $this->content->items[] = $searchlink;
  76  
  77          require_once($CFG->dirroot . '/blocks/community/locallib.php');
  78          $communitymanager = new block_community_manager();
  79          $courses = $communitymanager->block_community_get_courses($USER->id);
  80          if ($courses) {
  81              $this->content->items[] = html_writer::empty_tag('hr');
  82              $this->content->icons[] = '';
  83              $this->content->items[] = get_string('mycommunities', 'block_community');
  84              $this->content->icons[] = '';
  85              foreach ($courses as $course) {
  86                  //delete link
  87                  $deleteicon = html_writer::empty_tag('img',
  88                                  array('src' => $OUTPUT->pix_url('t/delete'),
  89                                      'alt' => get_string('removecommunitycourse', 'block_community')));
  90                  $deleteurl = new moodle_url('/blocks/community/communitycourse.php',
  91                                  array('remove' => true,
  92                                      'courseid' => $this->page->course->id,
  93                                      'communityid' => $course->id, 'sesskey' => sesskey()));
  94                  $deleteatag = html_writer::tag('a', $deleteicon, array('href' => $deleteurl));
  95  
  96                  $courselink = html_writer::tag('a', $course->coursename,
  97                                  array('href' => $course->courseurl));
  98                  $this->content->items[] = $courselink . ' ' . $deleteatag;
  99                  $this->content->icons[] = '';
 100              }
 101          }
 102  
 103          return $this->content;
 104      }
 105  
 106  }
 107  


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1