Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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   * Defines a node in my profile page navigation.
  19   *
  20   * @package   core_user
  21   * @copyright 2015 onwards Ankit Agarwal
  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  /**
  29   * Defines a node in my profile page navigation.
  30   *
  31   * @since     Moodle 2.9
  32   * @package   core_user
  33   * @copyright 2015 onwards Ankit Agarwal
  34   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class node implements \renderable {
  37      /**
  38       * @var string Name of parent category.
  39       */
  40      private $parentcat;
  41  
  42      /**
  43       * @var string Name of this node.
  44       */
  45      private $name;
  46  
  47      /**
  48       * @var string Name of the node after which this node should appear.
  49       */
  50      private $after;
  51  
  52      /**
  53       * @var string Title of this node.
  54       */
  55      private $title;
  56  
  57      /**
  58       * @var string|\moodle_url Url that this node should link to.
  59       */
  60      private $url;
  61  
  62      /**
  63       * @var string Content to display under this node.
  64       */
  65      private $content;
  66  
  67      /**
  68       * @var string|\pix_icon Icon for this node.
  69       */
  70      private $icon;
  71  
  72      /**
  73       * @var string HTML class attribute for this node. Classes should be separated by a space, e.g. 'class1 class2'
  74       */
  75      private $classes;
  76  
  77      /**
  78       * @var array list of properties accessible via __get.
  79       */
  80      private $properties = array('parentcat', 'after', 'name', 'title', 'url', 'content', 'icon', 'classes');
  81  
  82      /**
  83       * Constructor for the node.
  84       *
  85       * @param string $parentcat Name of parent category.
  86       * @param string $name Name of this node.
  87       * @param string $title Title of this node.
  88       * @param null|string $after Name of the node after which this node should appear.
  89       * @param null|string|\moodle_url $url Url that this node should link to.
  90       * @param null|string $content Content to display under this node.
  91       * @param null|string|\pix_icon $icon Icon for this node.
  92       * @param null|string $classes a list of css classes.
  93       */
  94      public function __construct($parentcat, $name, $title, $after = null, $url = null, $content = null, $icon = null,
  95                                  $classes = null) {
  96          $this->parentcat = $parentcat;
  97          $this->after = $after;
  98          $this->name = $name;
  99          $this->title = $title;
 100          $this->url = is_null($url) ? null : new \moodle_url($url);
 101          $this->content = $content;
 102          $this->icon = $icon;
 103          $this->classes = $classes;
 104      }
 105  
 106      /**
 107       * Magic get method.
 108       *
 109       * @param string $prop property to get.
 110       *
 111       * @return mixed
 112       * @throws \coding_exception
 113       */
 114      public function __get($prop) {
 115          if (in_array($prop, $this->properties)) {
 116              return $this->$prop;
 117          }
 118          throw new \coding_exception('Property "' . $prop . '" doesn\'t exist');
 119      }
 120  }