mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
MDL-45758 tool_monitor: Create a subscription instance class
Original issue - MDL-46241
This commit is contained in:
parent
3870ad7a2f
commit
3432c96d3a
96
admin/tool/monitor/classes/subscription.php
Normal file
96
admin/tool/monitor/classes/subscription.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Class represents a single subscription.
|
||||
*
|
||||
* @package tool_monitor
|
||||
* @copyright 2014 onwards Ankit Agarwal <ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_monitor;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class represents a single subscription instance (i.e with all the subscription info).
|
||||
*
|
||||
* @since Moodle 2.8
|
||||
* @package tool_monitor
|
||||
* @copyright 2014 onwards Ankit Agarwal <ankit.agrr@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class subscription {
|
||||
use helper_trait;
|
||||
/**
|
||||
* @var \stdClass
|
||||
*/
|
||||
protected $subscription;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* use {@link \tool_monitor\subscription_manager::get_subscription} to get an instance instead of directly calling this method.
|
||||
*
|
||||
* @param \stdClass $subscription
|
||||
*/
|
||||
public function __construct($subscription) {
|
||||
$this->subscription = $subscription;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic get method.
|
||||
*
|
||||
* @param string $prop property to get.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \coding_exception
|
||||
*/
|
||||
public function __get($prop) {
|
||||
if (property_exists($this->subscription, $prop)) {
|
||||
return $this->subscription->$prop;
|
||||
}
|
||||
throw new \coding_exception('Property "' . $prop . '" doesn\'t exist');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a human readable name for instances associated with this subscription.
|
||||
*
|
||||
* @return string
|
||||
* @throws \coding_exception
|
||||
*/
|
||||
public function get_instance_name() {
|
||||
if ($this->plugin === 'core') {
|
||||
$string = get_string('allevents', 'tool_monitor');
|
||||
} else {
|
||||
if ($this->cmid == 0) {
|
||||
$string = get_string('allmodules', 'tool_monitor');
|
||||
} else {
|
||||
$cms = get_fast_modinfo($this->courseid);
|
||||
$cms = $cms->get_cms();
|
||||
if (isset($cms[$this->cmid])) {
|
||||
$string = $cms[$this->cmid]->get_formatted_name(); // Instance name.
|
||||
} else {
|
||||
// Something is wrong, instance is not present anymore.
|
||||
$string = get_string('invalidmodule', 'tool_monitor');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ $string['defaultmessagetpl'] = 'Rule "{rulename}" has happened. You can find fur
|
||||
$string['eventnotfound'] = 'Event not found';
|
||||
$string['errorincorrectevent'] = 'Please select an event related to the selected plugin';
|
||||
$string['frequency'] = 'Frequency';
|
||||
$string['freqdesc'] = '{$a->freq} times in {$a->mins} minutes';
|
||||
$string['invalidmodule'] = 'Invalid module';
|
||||
$string['manage'] = 'Manage';
|
||||
$string['managesubscriptions'] = 'Manage subscriptions';
|
||||
$string['managerules'] = 'Manage rules';
|
||||
|
Loading…
x
Reference in New Issue
Block a user