protected function generate_rating_settings_object($options) {

        if (!isset($options->context)) {
            throw new coding_exception('The context option is a required option when generating a rating settings object.');
        }
        if (!isset($options->component)) {
            throw new coding_exception('The component option is now a required option when generating a rating settings object.');
        }
        if (!isset($options->ratingarea)) {
            throw new coding_exception('The ratingarea option is now a required option when generating a rating settings object.');
        }
        if (!isset($options->aggregate)) {
            throw new coding_exception('The aggregate option is now a required option when generating a rating settings object.');
        }
        if (!isset($options->scaleid)) {
            throw new coding_exception('The scaleid option is now a required option when generating a rating settings object.');
        }

        // Settings that are common to all ratings objects in this context.
        $settings = new stdClass;
        $settings->scale             = $this->generate_rating_scale_object($options->scaleid); // The scale to use now.
        $settings->aggregationmethod = $options->aggregate;
        $settings->assesstimestart   = null;
        $settings->assesstimefinish  = null;

        // Collect options into the settings object.
        if (!empty($options->assesstimestart)) {
            $settings->assesstimestart = $options->assesstimestart;
        }
        if (!empty($options->assesstimefinish)) {
            $settings->assesstimefinish = $options->assesstimefinish;
        }
        if (!empty($options->returnurl)) {
            $settings->returnurl = $options->returnurl;
        }

        // Check site capabilities.
        $settings->permissions = new stdClass;
        // Can view the aggregate of ratings of their own items.
        $settings->permissions->view    = has_capability('moodle/rating:view', $options->context);
        // Can view the aggregate of ratings of other people's items.
        $settings->permissions->viewany = has_capability('moodle/rating:viewany', $options->context);
        // Can view individual ratings.
        $settings->permissions->viewall = has_capability('moodle/rating:viewall', $options->context);
        // Can submit ratings.
        $settings->permissions->rate    = has_capability('moodle/rating:rate', $options->context);

        // Check module capabilities
        // This is mostly for backwards compatability with old modules that previously implemented their own ratings.
        $pluginpermissionsarray = $this->get_plugin_permissions_array($options->context->id,
                                                                      $options->component,
                                                                      $options->ratingarea);
        $settings->pluginpermissions = new stdClass;
        $settings->pluginpermissions->view    = $pluginpermissionsarray['view'];
        $settings->pluginpermissions->viewany = $pluginpermissionsarray['viewany'];
        $settings->pluginpermissions->viewall = $pluginpermissionsarray['viewall'];
        $settings->pluginpermissions->rate    = $pluginpermissionsarray['rate'];

        return $settings;
    }