Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]

   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   * Social activities block.
  19   *
  20   * @package    block_social_activities
  21   * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  class block_social_activities extends block_list {
  26      function init(){
  27          $this->title = get_string('pluginname', 'block_social_activities');
  28      }
  29  
  30      function applicable_formats() {
  31          return array('course-view-social' => true);
  32      }
  33  
  34      function get_content() {
  35          global $USER, $CFG, $DB, $OUTPUT;
  36  
  37          if ($this->content !== NULL) {
  38              return $this->content;
  39          }
  40  
  41          $this->content = new stdClass();
  42          $this->content->items = array();
  43          $this->content->icons = array();
  44          $this->content->footer = '';
  45  
  46          if (empty($this->instance)) {
  47              return $this->content;
  48          }
  49  
  50          $course = $this->page->course;
  51          $format = course_get_format($course);
  52          $courserenderer = $format->get_renderer($this->page);
  53  
  54          require_once($CFG->dirroot.'/course/lib.php');
  55  
  56          $context = context_course::instance($course->id);
  57          $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
  58          $modinfo = get_fast_modinfo($course);
  59  
  60          // Output classes.
  61          $cmnameclass = $format->get_output_classname('content\\cm\\cmname');
  62          $controlmenuclass = $format->get_output_classname('content\\cm\\controlmenu');
  63  
  64          $badgeattributes = [
  65              'class' => 'badge badge-pill badge-warning mt-2',
  66              'data-region' => 'visibility'
  67          ];
  68  
  69          // Extra fast view mode.
  70          if (!$isediting) {
  71              if (!empty($modinfo->sections[0])) {
  72                  foreach($modinfo->sections[0] as $cmid) {
  73                      $cm = $modinfo->cms[$cmid];
  74                      if (!$cm->uservisible || !$cm->is_visible_on_course_page()) {
  75                          continue;
  76                      }
  77  
  78                      $badges = '';
  79                      if (!$cm->visible) {
  80                          $badges = html_writer::tag(
  81                              'span',
  82                              get_string('hiddenfromstudents'),
  83                              $badgeattributes
  84                          );
  85                      }
  86  
  87                      if ($cm->is_stealth()) {
  88                          $badges = html_writer::tag(
  89                              'span',
  90                              get_string('hiddenoncoursepage'),
  91                              $badgeattributes
  92                          );
  93                      }
  94  
  95                      if (!$cm->url) {
  96                          $activitybasis = html_writer::div(
  97                              $cm->get_formatted_content(['overflowdiv' => true, 'noclean' => true]),
  98                              'activity-basis d-flex align-items-center'
  99                          );
 100                          $content = html_writer::div(
 101                              $activitybasis . $badges,
 102                              'contentwithoutlink activity-item activity',
 103                              ['data-activityname' => $cm->name]
 104                          );
 105                          $this->content->items[] = $content;
 106                          $this->content->icons[] = '';
 107                      } else {
 108                          $cmname = new $cmnameclass($format, $cm->get_section_info(), $cm);
 109                          $activitybasis = html_writer::div(
 110                              $courserenderer->render($cmname),
 111                              'activity-basis d-flex align-items-center');
 112                          $content = html_writer::div(
 113                              $activitybasis . $badges,
 114                              'activity-item activity',
 115                              ['data-activityname' => $cm->name]
 116                          );
 117                          $this->content->items[] = $content;
 118                      }
 119                  }
 120              }
 121              return $this->content;
 122          }
 123  
 124          // Slow & hacky editing mode.
 125          $ismoving = ismoving($course->id);
 126          $section = $modinfo->get_section_info(0);
 127  
 128          if ($ismoving) {
 129              $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
 130              $strcancel= get_string('cancel');
 131          } else {
 132              $strmove = get_string('move');
 133          }
 134  
 135          if ($ismoving) {
 136              $this->content->icons[] = '&nbsp;' . $OUTPUT->pix_icon('t/move', get_string('move'));
 137              $cancelurl = new moodle_url('/course/mod.php', array('cancelcopy' => 'true', 'sesskey' => sesskey()));
 138              $this->content->items[] = $USER->activitycopyname . '&nbsp;(<a href="' . $cancelurl . '">' . $strcancel . '</a>)';
 139          }
 140  
 141          if (!empty($modinfo->sections[0])) {
 142              foreach ($modinfo->sections[0] as $modnumber) {
 143                  $mod = $modinfo->cms[$modnumber];
 144                  if (!$mod->uservisible || !$mod->is_visible_on_course_page()) {
 145                      continue;
 146                  }
 147                  if (!$ismoving) {
 148  
 149                      $controlmenu = new $controlmenuclass(
 150                          $format,
 151                          $mod->get_section_info(),
 152                          $mod,
 153                          ['disableindentation' => true]
 154                      );
 155  
 156                      $menu = $controlmenu->get_action_menu($OUTPUT);
 157  
 158                      // Add a move primary action.
 159                      $moveaction = html_writer::link(
 160                          new moodle_url('/course/mod.php', ['sesskey' => sesskey(), 'copy' => $mod->id]),
 161                          $OUTPUT->pix_icon('i/dragdrop', $strmove),
 162                          ['class' => 'editing_move_activity']
 163                      );
 164  
 165                      $editbuttons = html_writer::tag('div',
 166                          $courserenderer->render($controlmenu),
 167                          ['class' => 'buttons activity-actions ml-auto']
 168                      );
 169                  } else {
 170                      $editbuttons = '';
 171                      $moveaction = '';
 172                  }
 173                  if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $mod->context)) {
 174                      if ($ismoving) {
 175                          if ($mod->id == $USER->activitycopy) {
 176                              continue;
 177                          }
 178                          $movingurl = new moodle_url('/course/mod.php', array('moveto' => $mod->id, 'sesskey' => sesskey()));
 179                          $this->content->items[] = html_writer::link($movingurl, '', array('title' => $strmovefull,
 180                              'class' => 'movehere'));
 181                          $this->content->icons[] = '';
 182                      }
 183  
 184                      $badges = '';
 185                      if (!$mod->visible) {
 186                          $badges = html_writer::tag(
 187                              'span',
 188                              get_string('hiddenfromstudents'),
 189                              $badgeattributes
 190                          );
 191                      }
 192  
 193                      if ($mod->is_stealth()) {
 194                          $badges = html_writer::tag(
 195                              'span',
 196                              get_string('hiddenoncoursepage'),
 197                              $badgeattributes
 198                          );
 199                      }
 200  
 201                      if (!$mod->url) {
 202                          $activitybasis = html_writer::div(
 203                              $mod->get_formatted_content(['overflowdiv' => true, 'noclean' => true]) .
 204                              $editbuttons,
 205                              'activity-basis d-flex align-items-center');
 206                          $content = html_writer::div(
 207                              $moveaction .
 208                              $activitybasis .
 209                              $badges,
 210                              'contentwithoutlink activity-item activity',
 211                              ['data-activityname' => $mod->name]
 212                          );
 213                          $this->content->items[] = $content;
 214                          $this->content->icons[] = '';
 215                      } else {
 216                          $cmname = new $cmnameclass($format, $mod->get_section_info(), $mod);
 217                          $activitybasis = html_writer::div(
 218                              $courserenderer->render($cmname) .
 219                              $editbuttons,
 220                              'activity-basis d-flex align-items-center');
 221                          $content = html_writer::div(
 222                              $moveaction .
 223                              $activitybasis .
 224                              $badges,
 225                              'activity-item activity',
 226                              ['data-activityname' => $mod->name]
 227                          );
 228                          $this->content->items[] = $content;
 229                      }
 230                  }
 231              }
 232          }
 233  
 234          if ($ismoving) {
 235              $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey()));
 236              $this->content->items[] = html_writer::link($movingurl, '', array('title' => $strmovefull, 'class' => 'movehere'));
 237              $this->content->icons[] = '';
 238          }
 239  
 240          $this->content->footer = $courserenderer->course_section_add_cm_control($course,
 241                  0, null, array('inblock' => true));
 242  
 243          return $this->content;
 244      }
 245  }