<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class prepare_main_data
{

    public function prepare($form_name, $set_default_values = true)
    {
        $ci = & get_instance();
        $data = [
            'sex'       => $ci->{$form_name}->get_value('sex'),
            'phone'     => (string) $ci->{$form_name}->get_value('phone'),
            'subscribe' => !empty($ci->{$form_name}->get_value('subscribe'))
        ];

        if ($set_default_values) {
            $data['login'] = $ci->{$form_name}->get_value('email');
            $data['email'] = $ci->{$form_name}->get_value('email');
            $data['password'] = $ci->rt_user->password_hash($ci->{$form_name}->get_value('password'));
            $data['registered'] = date('Y-m-d H:i:s');
            $data['id_acl_role'] = $ci->config->item('registered_user_default_role_id');
        }

        return $data;
    }

}
