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 * Course category proxy. 19 * 20 * @package core_calendar 21 * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace core_calendar\local\event\proxies; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 /** 30 * Course category proxy. 31 * 32 * This returns an instance of a coursecat rather than a stdClass. 33 * 34 * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class coursecat_proxy implements proxy_interface { 38 /** 39 * @var int $id The ID of the database record. 40 */ 41 protected $id; 42 43 /** 44 * @var \stdClass $base Base class to get members from. 45 */ 46 protected $base; 47 48 /** 49 * @var \core_course_category $category The proxied instance. 50 */ 51 protected $category; 52 53 /** 54 * coursecat_proxy constructor. 55 * 56 * @param int $id The ID of the record in the database. 57 */ 58 public function __construct($id) { 59 $this->id = $id; 60 $this->base = (object) [ 61 'id' => $id, 62 ]; 63 } 64 65 /** 66 * Retrieve a member of the proxied class. 67 * 68 * @param string $member The name of the member to retrieve 69 * @return mixed The member. 70 */ 71 public function get($member) { 72 if ($this->base && property_exists($this->base, $member)) { 73 return $this->base->{$member}; 74 } 75 76 return $this->get_proxied_instance()->{$member}; 77 } 78 79 /** 80 * Get the full instance of the proxied class. 81 * 82 * @return \core_course_category 83 */ 84 public function get_proxied_instance() : \core_course_category { 85 if (!$this->category) { 86 $this->category = \core_course_category::get($this->id, IGNORE_MISSING, true); 87 } 88 return $this->category; 89 } 90 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body