protected static function validate_database($databaseid) {
        global $DB;

        // Request and permission validation.
        $database = $DB->get_record('data', array('id' => $databaseid), '*', MUST_EXIST);
        list($course, $cm) = get_course_and_cm_from_instance($database, 'data');

        $context = context_module::instance($cm->id);
        self::validate_context($context);
        require_capability('mod/data:viewentry', $context);

        return array($database, $course, $cm, $context);
    }