[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/user/classes/output/myprofile/ -> renderer.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   * myprofile renderer.
  19   *
  20   * @package    core_user
  21   * @copyright  2015 onwards Ankit Agarwal <ankit.agrr@gmail.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_user\output\myprofile;
  26  defined('MOODLE_INTERNAL') || die;
  27  /**
  28   * Report log renderer's for printing reports.
  29   *
  30   * @since      Moodle 2.9
  31   * @package    core_user
  32   * @copyright  2015 onwards Ankit Agarwal <ankit.agrr@gmail.com>
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class renderer extends \plugin_renderer_base {
  36      /**
  37       * Render the whole tree.
  38       *
  39       * @param tree $tree
  40       *
  41       * @return string
  42       */
  43      public function render_tree(tree $tree) {
  44          $return = \html_writer::start_tag('div', array('class' => 'profile_tree'));
  45          $categories = $tree->categories;
  46          foreach ($categories as $category) {
  47              $return .= $this->render($category);
  48          }
  49          $return .= \html_writer::end_tag('div');
  50          return $return;
  51      }
  52  
  53      /**
  54       * Render a category.
  55       *
  56       * @param category $category
  57       *
  58       * @return string
  59       */
  60      public function render_category(category $category) {
  61          $classes = $category->classes;
  62          if (empty($classes)) {
  63              $return = \html_writer::start_tag('section', array('class' => 'node_category'));
  64          } else {
  65              $return = \html_writer::start_tag('section', array('class' => 'node_category ' . $classes));
  66          }
  67          $return .= \html_writer::tag('h3', $category->title);
  68          $nodes = $category->nodes;
  69          if (empty($nodes)) {
  70              // No nodes, nothing to render.
  71              return '';
  72          }
  73          $return .= \html_writer::start_tag('ul');
  74          foreach ($nodes as $node) {
  75              $return .= $this->render($node);
  76          }
  77          $return .= \html_writer::end_tag('ul');
  78          $return .= \html_writer::end_tag('section');
  79          return $return;
  80      }
  81  
  82      /**
  83       * Render a node.
  84       *
  85       * @param node $node
  86       *
  87       * @return string
  88       */
  89      public function render_node(node $node) {
  90          $return = '';
  91          if (is_object($node->url)) {
  92              $header = \html_writer::link($node->url, $node->title);
  93          } else {
  94              $header = $node->title;
  95          }
  96          $icon = $node->icon;
  97          if (!empty($icon)) {
  98              $header .= $this->render($icon);
  99          }
 100          $content = $node->content;
 101          $classes = $node->classes;
 102          if (!empty($content)) {
 103              // There is some content to display below this make this a header.
 104              $return = \html_writer::tag('dt', $header);
 105              $return .= \html_writer::tag('dd', $content);
 106  
 107              $return = \html_writer::tag('dl', $return);
 108              if ($classes) {
 109                  $return = \html_writer::tag('li', $return, array('class' => 'contentnode ' . $classes));
 110              } else {
 111                  $return = \html_writer::tag('li', $return, array('class' => 'contentnode'));
 112              }
 113          } else {
 114              $return = \html_writer::span($header);
 115              $return = \html_writer::tag('li', $return, array('class' => $classes));
 116          }
 117  
 118          return $return;
 119      }
 120  }


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