forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-58110 core_calendar: Add proxy for modules
Modules associated with an event are stored in the event table as the module's name and instance number not the actual ID of the instance in the modules table. So to lazy load them we need a proxy that uses the module name and instance rather than the ID. Part of MDL-55611 epic.
- Loading branch information
1 parent
55b36b1
commit e798fa7
Showing
8 changed files
with
394 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Course module stdClass proxy. | ||
* | ||
* @package core_calendar | ||
* @copyright 2017 Cameron Ball <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace core_calendar\local\event\proxies; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use core_calendar\local\interfaces\proxy_interface; | ||
use core_calendar\local\event\exceptions\member_does_not_exist_exception; | ||
|
||
/** | ||
* Course module stdClass proxy. | ||
* | ||
* This implementation differs from the regular std_proxy in that it takes | ||
* a module name and instance instead of an id to construct the proxied class. | ||
* | ||
* This is needed as the event table does not store the id of course modules | ||
* instead it stores the module name and instance. | ||
* | ||
* @copyright 2017 Cameron Ball <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class module_std_proxy extends std_proxy implements proxy_interface { | ||
public function __construct($modulename, $instance, callable $callback, \stdClass $base = null) { | ||
$this->modulename = $modulename; | ||
$this->instance = $instance; | ||
$this->callbackargs = [$modulename, $instance]; | ||
$this->callback = $callback; | ||
$this->base = $base = is_null($base) ? new \stdClass() : $base; | ||
$this->base->modulename = $modulename; | ||
$this->base->instance = $instance; | ||
} | ||
|
||
public function get_id() { | ||
return $this->get_proxied_instance()->id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.