public static function get_rules_by_courseid($courseid, $limitfrom = 0, $limitto = 0, $includesite = true) {
        global $DB;

        $select = 'courseid = ?';
        $params = array();
        $params[] = $courseid;
        if ($includesite) {
            $select .= ' OR courseid = ?';
            $params[] = 0;
        }
        $orderby = 'courseid DESC, name ASC';

        return self::get_instances($DB->get_records_select('tool_monitor_rules', $select, $params, $orderby,
                '*', $limitfrom, $limitto));
    }