public static function clean_ruledata_form($mformdata) {
        global $USER;

        $rule = new \stdClass();
        if (!empty($mformdata->ruleid)) {
            $rule->id = $mformdata->ruleid;
        }
        $rule->userid = empty($mformdata->userid) ? $USER->id : $mformdata->userid;
        $rule->courseid = $mformdata->courseid;
        $rule->name = $mformdata->name;
        $rule->plugin = $mformdata->plugin;
        $rule->eventname = $mformdata->eventname;
        $rule->description = $mformdata->description['text'];
        $rule->descriptionformat = $mformdata->description['format'];
        $rule->frequency = $mformdata->frequency;
        $rule->timewindow = $mformdata->minutes * MINSECS;
        $rule->template = $mformdata->template['text'];
        $rule->templateformat = $mformdata->template['format'];

        return $rule;
    }