コード例 #1
0
ファイル: rule_manager_test.php プロジェクト: evltuma/moodle
 /**
  * Test get_rule method.
  */
 public function test_get_rule()
 {
     $this->setAdminUser();
     $this->resetAfterTest(true);
     $monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor');
     $rule = $monitorgenerator->create_rule();
     $rules1 = \tool_monitor\rule_manager::get_rule($rule->id);
     $this->assertInstanceOf('tool_monitor\\rule', $rules1);
     $this->assertEquals($rules1, $rule);
 }
コード例 #2
0
ファイル: renderable.php プロジェクト: HuiChangZhai/moodle
 /**
  * Returns the string to display for the help icon.
  *
  * @param string $type the type we are displaying the help icon for (either rule or subscription).
  * @param int $id the id of the type.
  * @param boolean $ajax Whether this help is called from an AJAX script.
  *      This is used to influence text formatting and determines which format to output the doclink in.
  * @return string|object|array $a An object, string or number that can be used within translation strings
  */
 public static function get_help_string_parameters($type, $id, $ajax = false)
 {
     if ($type == 'rule') {
         $rule = \tool_monitor\rule_manager::get_rule($id);
         $langstring = new \stdClass();
         $langstring->eventname = $rule->get_event_name();
         $langstring->eventcomponent = $rule->get_plugin_name();
         $langstring->frequency = $rule->frequency;
         $langstring->minutes = $rule->timewindow / MINSECS;
         return get_formatted_help_string('rulehelp', 'tool_monitor', $ajax, $langstring);
     }
     // Must be a subscription.
     $sub = \tool_monitor\subscription_manager::get_subscription($id);
     $langstring = new \stdClass();
     $langstring->eventname = $sub->get_event_name();
     $langstring->moduleinstance = $sub->get_instance_name();
     $langstring->frequency = $sub->frequency;
     $langstring->minutes = $sub->timewindow / MINSECS;
     return get_formatted_help_string('subhelp', 'tool_monitor', $ajax, $langstring);
 }
コード例 #3
0
ファイル: help_ajax.php プロジェクト: HuiChangZhai/moodle
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Displays help via AJAX call.
 *
 * @copyright 2014 Mark Nelson <*****@*****.**>
 * @package tool_monitor
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('NO_MOODLE_COOKIES', true);
define('AJAX_SCRIPT', true);
require_once '../../../config.php';
$type = required_param('type', PARAM_ALPHA);
$id = required_param('id', PARAM_INT);
$lang = optional_param('lang', 'en', PARAM_LANG);
// We don't actually modify the session here as we have NO_MOODLE_COOKIES set.
$SESSION->lang = $lang;
$PAGE->set_url('/admin/tool/monitor/help_ajax.php');
if ($type == 'rule') {
    $item = \tool_monitor\rule_manager::get_rule($id);
} else {
    // Must be a subscription.
    $item = \tool_monitor\subscription_manager::get_subscription($id);
}
if ($item->courseid) {
    $PAGE->set_context(context_course::instance($item->courseid));
} else {
    // Must be system context.
    $PAGE->set_context(context_system::instance());
}
echo json_encode(tool_monitor\output\helpicon\renderable::get_help_string_parameters($type, $id, true));
コード例 #4
0
ファイル: managerules.php プロジェクト: pzhu2004/moodle
if (!empty($action) && $action == 'changestatus') {
    require_sesskey();
    require_capability('tool/monitor:managetool', context_system::instance());
    // Toggle status of the plugin.
    set_config('enablemonitor', $status, 'tool_monitor');
    redirect(new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => 0)));
}
// Copy/delete rule if needed.
if (!empty($action) && $ruleid) {
    require_sesskey();
    // If the rule does not exist, then redirect back as the rule must have already been deleted.
    if (!($rule = $DB->get_record('tool_monitor_rules', array('id' => $ruleid), '*', IGNORE_MISSING))) {
        redirect(new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => $courseid)));
    }
    echo $OUTPUT->header();
    $rule = \tool_monitor\rule_manager::get_rule($rule);
    switch ($action) {
        case 'copy':
            // No need to check for capability here as it is done at the start of the page.
            $rule->duplicate_rule($courseid);
            echo $OUTPUT->notification(get_string('rulecopysuccess', 'tool_monitor'), 'notifysuccess');
            break;
        case 'delete':
            if ($rule->can_manage_rule()) {
                $confirmurl = new moodle_url($CFG->wwwroot . '/admin/tool/monitor/managerules.php', array('ruleid' => $ruleid, 'courseid' => $courseid, 'action' => 'delete', 'confirm' => true, 'sesskey' => sesskey()));
                $cancelurl = new moodle_url($CFG->wwwroot . '/admin/tool/monitor/managerules.php', array('courseid' => $courseid));
                if ($confirm) {
                    $rule->delete_rule();
                    echo $OUTPUT->notification(get_string('ruledeletesuccess', 'tool_monitor'), 'notifysuccess');
                } else {
                    $strconfirm = get_string('ruleareyousure', 'tool_monitor', $rule->get_name($context));
コード例 #5
0
ファイル: edit.php プロジェクト: alanaipe2015/moodle
$eventlist = tool_monitor\eventlist::get_all_eventlist(true);
$pluginlist = tool_monitor\eventlist::get_plugin_list();
$eventlist = array_merge(array('' => get_string('choosedots')), $eventlist);
$pluginlist = array_merge(array('' => get_string('choosedots')), $pluginlist);
// Set up the yui module.
$PAGE->requires->yui_module('moodle-tool_monitor-dropdown', 'Y.M.tool_monitor.DropDown.init', array(array('eventlist' => $eventlist)));
// Site level report.
if (empty($courseid)) {
    admin_externalpage_setup('toolmonitorrules', '', null, '', array('pagelayout' => 'report'));
} else {
    // Course level report.
    $PAGE->navigation->override_active_url($manageurl);
}
// Mform setup.
if (!empty($ruleid)) {
    $rule = \tool_monitor\rule_manager::get_rule($ruleid)->get_mform_set_data();
    $rule->minutes = $rule->timewindow / MINSECS;
    $subscriptioncount = \tool_monitor\subscription_manager::count_rule_subscriptions($ruleid);
} else {
    $rule = new stdClass();
    $subscriptioncount = 0;
}
$mform = new tool_monitor\rule_form(null, array('eventlist' => $eventlist, 'pluginlist' => $pluginlist, 'rule' => $rule, 'courseid' => $courseid, 'subscriptioncount' => $subscriptioncount));
if ($mform->is_cancelled()) {
    redirect(new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => $courseid)));
    exit;
}
if ($mformdata = $mform->get_data()) {
    $rule = \tool_monitor\rule_manager::clean_ruledata_form($mformdata);
    if (empty($rule->id)) {
        \tool_monitor\rule_manager::add_rule($rule);