[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  <?php
   2  
   3  ///////////////////////////////////////////////////////////////////////////
   4  //                                                                       //
   5  // This file is part of Moodle - http://moodle.org/                      //
   6  // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
   7  //                                                                       //
   8  // Moodle is free software: you can redistribute it and/or modify        //
   9  // it under the terms of the GNU General Public License as published by  //
  10  // the Free Software Foundation, either version 3 of the License, or     //
  11  // (at your option) any later version.                                   //
  12  //                                                                       //
  13  // Moodle is distributed in the hope that it will be useful,             //
  14  // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
  15  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
  16  // GNU General Public License for more details.                          //
  17  //                                                                       //
  18  // You should have received a copy of the GNU General Public License     //
  19  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.       //
  20  //                                                                       //
  21  ///////////////////////////////////////////////////////////////////////////
  22  
  23  /**
  24   * Block community renderer.
  25   * @package   block_community
  26   * @copyright 2010 Moodle Pty Ltd (http://moodle.com)
  27   * @author    Jerome Mouneyrac
  28   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  class block_community_renderer extends plugin_renderer_base {
  31  
  32      public function restore_confirmation_box($filename, $context) {
  33          $restoreurl = new moodle_url('/backup/restore.php',
  34                          array('filename' => $filename . ".mbz", 'contextid' => $context->id));
  35          $searchurl = new moodle_url('/blocks/community/communitycourse.php',
  36                          array('add' => 1, 'courseid' => $context->instanceid,
  37                              'cancelrestore' => 1, 'sesskey' => sesskey(),
  38                              'filename' => $filename));
  39          $formrestore = new single_button($restoreurl,
  40                          get_string('dorestore', 'block_community'));
  41          $formsearch = new single_button($searchurl,
  42                          get_string('donotrestore', 'block_community'));
  43          return $this->output->confirm(get_string('restorecourseinfo', 'block_community'),
  44                  $formrestore, $formsearch);
  45      }
  46  
  47      /**
  48       * Display remove community success message and a button to be redirected to te referer page
  49       * @param moodle_url $url the page to be redirected to
  50       * @return string html
  51       */
  52      public function remove_success(moodle_url $url) {
  53          $html = $this->output->notification(get_string('communityremoved', 'hub'),
  54                      'notifysuccess');
  55          $continuebutton = new single_button($url,
  56                          get_string('continue', 'block_community'));
  57          $html .= html_writer::tag('div', $this->output->render($continuebutton),
  58                  array('class' => 'continuebutton'));
  59          return $html;
  60      }
  61  
  62      /**
  63       * Display add community course success message and a button to be redirected to te referer page
  64       * @param moodle_url $url the page to be redirected to
  65       * @return string html
  66       */
  67      public function save_link_success(moodle_url $url) {
  68          $html = $this->output->notification(get_string('addedtoblock', 'block_community'),
  69                      'notifysuccess');
  70          $continuebutton = new single_button($url,
  71                          get_string('continue', 'block_community'));
  72          $html .= html_writer::tag('div', $this->output->render($continuebutton),
  73                  array('class' => 'continuebutton'));
  74          return $html;
  75      }
  76  
  77      /**
  78       * The 'Next'/'more course result' link for a courses search
  79       * @param array $data - the form parameter to execute the search on more result
  80       * @return string html code
  81       */
  82      public function next_button($data) {
  83          $nextlink = html_writer::tag('a', get_string('next', 'block_community'),
  84                  array('href' => new moodle_url('', $data)));
  85          return html_writer::tag('div', $nextlink, array( 'class' => 'nextlink'));
  86      }
  87  
  88      /**
  89       * Display a list of courses
  90       * @param array $courses
  91       * @param boolean $withwriteaccess
  92       * @param int $contextcourseid context course id
  93       * @return string
  94       */
  95      public function course_list($courses, $huburl, $contextcourseid) {
  96          global $CFG;
  97  
  98          $renderedhtml = '';
  99  
 100          if (empty($courses)) {
 101              if (isset($courses)) {
 102                  $renderedhtml .= get_string('nocourse', 'block_community');
 103              }
 104          } else {
 105              $courseiteration = 0;
 106              foreach ($courses as $course) {
 107                  $course = (object) $course;
 108                  $courseiteration = $courseiteration + 1;
 109  
 110                  //create visit link html
 111                  if (!empty($course->courseurl)) {
 112                      $courseurl = new moodle_url($course->courseurl);
 113                      $linktext = get_string('visitsite', 'block_community');
 114                  } else {
 115                      $courseurl = new moodle_url($course->demourl);
 116                      $linktext = get_string('visitdemo', 'block_community');
 117                  }
 118  
 119                  $visitlinkhtml = html_writer::tag('a', $linktext,
 120                                  array('href' => $courseurl, 'class' => 'hubcoursedownload',
 121                                      'onclick' => 'this.target="_blank"'));
 122  
 123                  //create title html
 124                  $coursename = html_writer::tag('h3', $course->fullname,
 125                                  array('class' => 'hubcoursetitle'));
 126                  $coursenamehtml = html_writer::tag('div', $coursename,
 127                          array('class' => 'hubcoursetitlepanel'));
 128  
 129                  // create screenshots html
 130                  $screenshothtml = '';
 131                  if (!empty($course->screenshots)) {
 132                      $baseurl = new moodle_url($huburl . '/local/hub/webservice/download.php',
 133                                      array('courseid' => $course->id,
 134                                          'filetype' => HUB_SCREENSHOT_FILE_TYPE));
 135                      $screenshothtml = html_writer::empty_tag('img',
 136                          array('src' => $baseurl, 'alt' => $course->fullname));
 137                  }
 138                  $coursescreenshot = html_writer::tag('div', $screenshothtml,
 139                                  array('class' => 'coursescreenshot',
 140                                      'id' => 'image-' . $course->id));
 141  
 142                  //create description html
 143                  $deschtml = html_writer::tag('div', $course->description,
 144                                  array('class' => 'hubcoursedescription'));
 145  
 146                  //create users related information html
 147                  $courseuserinfo = get_string('userinfo', 'block_community', $course);
 148                  if ($course->contributornames) {
 149                      $courseuserinfo .= ' - ' . get_string('contributors', 'block_community',
 150                                      $course->contributornames);
 151                  }
 152                  $courseuserinfohtml = html_writer::tag('div', $courseuserinfo,
 153                                  array('class' => 'hubcourseuserinfo'));
 154  
 155                  //create course content related information html
 156                  $course->subject = get_string($course->subject, 'edufields');
 157                  $course->audience = get_string('audience' . $course->audience, 'hub');
 158                  $course->educationallevel = get_string('edulevel' . $course->educationallevel, 'hub');
 159                  $coursecontentinfo = '';
 160                  if (empty($course->coverage)) {
 161                      $course->coverage = '';
 162                  } else {
 163                      $coursecontentinfo .= get_string('coverage', 'block_community', $course->coverage);
 164                      $coursecontentinfo .= ' - ';
 165                  }
 166                  $coursecontentinfo .= get_string('contentinfo', 'block_community', $course);
 167                  $coursecontentinfohtml = html_writer::tag('div', $coursecontentinfo,
 168                                  array('class' => 'hubcoursecontentinfo'));
 169  
 170                  ///create course file related information html
 171                  //language
 172                  if (!empty($course->language)) {
 173                      $languages = get_string_manager()->get_list_of_languages();
 174                      $course->lang = $languages[$course->language];
 175                  } else {
 176                      $course->lang = '';
 177                  }
 178                  //licence
 179                  require_once($CFG->libdir . "/licenselib.php");
 180                  $licensemanager = new license_manager();
 181                  $licenses = $licensemanager->get_licenses();
 182                  foreach ($licenses as $license) {
 183                      if ($license->shortname == $course->licenceshortname) {
 184                          $course->license = $license->fullname;
 185                      }
 186                  }
 187                  $course->timeupdated = userdate($course->timemodified);
 188                  $coursefileinfo = get_string('fileinfo', 'block_community', $course);
 189                  $coursefileinfohtml = html_writer::tag('div', $coursefileinfo,
 190                                  array('class' => 'hubcoursefileinfo'));
 191  
 192  
 193  
 194                  //Create course content html
 195                  $blocks = core_component::get_plugin_list('block');
 196                  $activities = core_component::get_plugin_list('mod');
 197                  if (!empty($course->contents)) {
 198                      $activitieshtml = '';
 199                      $blockhtml = '';
 200                      foreach ($course->contents as $content) {
 201                          $content = (object) $content;
 202                          if ($content->moduletype == 'block') {
 203                              if (!empty($blockhtml)) {
 204                                  $blockhtml .= ' - ';
 205                              }
 206                              if (array_key_exists($content->modulename, $blocks)) {
 207                                  $blockname = get_string('pluginname', 'block_' . $content->modulename);
 208                              } else {
 209                                  $blockname = $content->modulename;
 210                              }
 211                              $blockhtml .= $blockname . " (" . $content->contentcount . ")";
 212                          } else {
 213                              if (!empty($activitieshtml)) {
 214                                  $activitieshtml .= ' - ';
 215                              }
 216                              if (array_key_exists($content->modulename, $activities)) {
 217                                  $activityname = get_string('modulename', $content->modulename);
 218                              } else {
 219                                  $activityname = $content->modulename;
 220                              }
 221                              $activitieshtml .= $activityname . " (" . $content->contentcount . ")";
 222                          }
 223                      }
 224  
 225                      $blocksandactivities = html_writer::tag('div',
 226                                      get_string('activities', 'block_community') . " : " . $activitieshtml);
 227  
 228                      //Uncomment following lines to display blocks information
 229  //                    $blocksandactivities .= html_writer::tag('span',
 230  //                                    get_string('blocks', 'block_community') . " : " . $blockhtml);
 231                  }
 232  
 233                  //Create outcomes html
 234                  $outcomes= '';
 235                  if (!empty($course->outcomes)) {
 236                      foreach ($course->outcomes as $outcome) {
 237                          if (!empty($outcomes)) {
 238                              $outcomes .= ', ';
 239                          }
 240                          $outcomes .= $outcome['fullname'];
 241                      }
 242                      $outcomes = get_string('outcomes', 'block_community',
 243                              $outcomes);
 244                  }
 245                  $outcomeshtml = html_writer::tag('div', $outcomes, array('class' => 'hubcourseoutcomes'));
 246  
 247                  //create additional information html
 248                  $additionaldesc = $courseuserinfohtml . $coursecontentinfohtml
 249                          . $coursefileinfohtml . $blocksandactivities . $outcomeshtml;
 250                  $additionaldeschtml = html_writer::tag('div', $additionaldesc,
 251                                  array('class' => 'additionaldesc'));
 252  
 253                  //Create add button html
 254                  $addbuttonhtml = "";
 255                  if ($course->enrollable) {
 256                      $params = array('sesskey' => sesskey(), 'add' => 1, 'confirmed' => 1,
 257                          'coursefullname' => $course->fullname, 'courseurl' => $courseurl,
 258                          'coursedescription' => $course->description,
 259                          'courseid' => $contextcourseid);
 260                      $addurl = new moodle_url("/blocks/community/communitycourse.php", $params);
 261                      $addbuttonhtml = html_writer::tag('a',
 262                                      get_string('addtocommunityblock', 'block_community'),
 263                                      array('href' => $addurl, 'class' => 'centeredbutton, hubcoursedownload'));
 264                  }
 265  
 266                  //create download button html
 267                  $downloadbuttonhtml = "";
 268                  if (!$course->enrollable) {
 269                      $params = array('sesskey' => sesskey(), 'download' => 1, 'confirmed' => 1,
 270                          'remotemoodleurl' => $CFG->wwwroot, 'courseid' => $contextcourseid,
 271                          'downloadcourseid' => $course->id, 'huburl' => $huburl,
 272                          'coursefullname' => $course->fullname, 'backupsize' => $course->backupsize);
 273                      $downloadurl = new moodle_url("/blocks/community/communitycourse.php", $params);
 274                      $downloadbuttonhtml = html_writer::tag('a', get_string('install', 'block_community'),
 275                                      array('href' => $downloadurl, 'class' => 'centeredbutton, hubcoursedownload'));
 276                  }
 277  
 278                  //Create rating html
 279                  $rating = html_writer::tag('div', get_string('noratings', 'block_community'),
 280                                  array('class' => 'norating'));
 281                  if (!empty($course->rating)) {
 282                      $course->rating = (object) $course->rating;
 283                      if ($course->rating->count > 0) {
 284  
 285                          //calculate size of the rating star
 286                          $starimagesize = 20; //in px
 287                          $numberofstars = 5;
 288                          $size = ($course->rating->aggregate / $course->rating->scaleid)
 289                                  * $numberofstars * $starimagesize;
 290                          $rating = html_writer::tag('li', '',
 291                                          array('class' => 'current-rating',
 292                                              'style' => 'width:' . $size . 'px;'));
 293  
 294                          $rating = html_writer::tag('ul', $rating,
 295                                          array('class' => 'star-rating clearfix'));
 296                          $rating .= html_writer::tag('div', ' (' . $course->rating->count . ')',
 297                                          array('class' => 'ratingcount clearfix'));
 298                      }
 299                  }
 300  
 301  
 302                  //Create comments html
 303                  $coursecomments = html_writer::tag('div', get_string('nocomments', 'block_community'),
 304                                  array('class' => 'nocomments'));
 305                  $commentcount = 0;
 306                  if (!empty($course->comments)) {
 307                      //display only if there is some comment if there is some comment
 308                      $commentcount = count($course->comments);
 309                      $coursecomments = html_writer::tag('div',
 310                                      get_string('comments', 'block_community', $commentcount),
 311                                      array('class' => 'commenttitle'));
 312  
 313                      foreach ($course->comments as $comment) {
 314                          $commentator = html_writer::tag('div',
 315                                          $comment['commentator'],
 316                                          array('class' => 'hubcommentator'));
 317                          $commentdate = html_writer::tag('div',
 318                                          ' - ' . userdate($comment['date'], '%e/%m/%y'),
 319                                          array('class' => 'hubcommentdate clearfix'));
 320  
 321                          $commenttext = html_writer::tag('div',
 322                                          $comment['comment'],
 323                                          array('class' => 'hubcommenttext'));
 324  
 325                          $coursecomments .= html_writer::tag('div',
 326                                          $commentator . $commentdate . $commenttext,
 327                                          array('class' => 'hubcomment'));
 328                      }
 329                      $coursecommenticon = html_writer::tag('div',
 330                                      get_string('comments', 'block_community', $commentcount),
 331                                      array('class' => 'hubcoursecomments',
 332                                          'id' => 'comments-' . $course->id));
 333                      $coursecomments = $coursecommenticon . html_writer::tag('div',
 334                                      $coursecomments,
 335                                      array('class' => 'yui3-overlay-loading',
 336                                          'id' => 'commentoverlay-' . $course->id));
 337                  }
 338  
 339                  //link rate and comment
 340                  $rateandcomment = html_writer::tag('div',
 341                                  html_writer::tag('a', get_string('rateandcomment', 'block_community'),
 342                                          array('href' => new moodle_url($huburl,
 343                                                      array('courseid' => $course->id, 'mustbelogged' => true)),
 344                                              'onclick' => 'this.target="_blank"')),
 345                                  array('class' => 'hubrateandcomment'));
 346  
 347                  //the main DIV tags
 348                  $buttonsdiv = html_writer::tag('div',
 349                                  $addbuttonhtml . $downloadbuttonhtml . $visitlinkhtml,
 350                                  array('class' => 'courseoperations'));
 351                  $screenshotbuttonsdiv = html_writer::tag('div',
 352                                  $coursescreenshot . $buttonsdiv,
 353                                  array('class' => 'courselinks'));
 354  
 355                  $coursedescdiv = html_writer::tag('div',
 356                                  $deschtml . $additionaldeschtml
 357                                  . $rating . $coursecomments . $rateandcomment,
 358                                  array('class' => 'coursedescription'));
 359                  $coursehtml =
 360                          $coursenamehtml . html_writer::tag('div',
 361                                  $coursedescdiv . $screenshotbuttonsdiv,
 362                                  array('class' => 'hubcourseinfo clearfix'));
 363  
 364                  $renderedhtml .=html_writer::tag('div', $coursehtml,
 365                                  array('class' => 'fullhubcourse clearfix'));
 366              }
 367  
 368              $renderedhtml = html_writer::tag('div', $renderedhtml,
 369                              array('class' => 'hubcourseresult'));
 370          }
 371  
 372          return $renderedhtml;
 373      }
 374  
 375  }


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