/** * Extracts the model's fields (except the key and those handled by * Observers) from the $post_data and returns an array of name => value pairs * * @param Array $post_data The post data, usually $this->input->post() when called from the controller * * @return Array An array of name => value pairs containing the data for the model's fields */ public function prep_data($post_data) { $data = parent::prep_data($post_data); if (!empty($post_data['timezones'])) { $data['timezone'] = $post_data['timezones']; } if (!empty($post_data['password'])) { $data['password'] = $post_data['password']; } if ($data['display_name'] === '') { unset($data['display_name']); } if (isset($post_data['restore']) && $post_data['restore']) { $data['deleted'] = 0; } if (isset($post_data['unban']) && $post_data['unban']) { $data['banned'] = 0; } if (isset($post_data['activate']) && $post_data['activate']) { $data['active'] = 1; } elseif (isset($post_data['deactivate']) && $post_data['deactivate']) { $data['active'] = 0; } return $data; }
/** * Extracts the model's fields (except the key and those handled by observers) * from the $post_data and returns an array of name => value pairs. * * @param array $post_data The post data, usually $this->input->post() when * called from the controller. * * @return array An array of name => value pairs containing the prepared data * for the model's fields. */ public function prep_data($post_data) { // Take advantage of BF_Model's prep_data() method. $data = parent::prep_data($post_data); // Special handling of the data specific to the User_model. // Only set 'timezone' if one was selected from the 'timezones' select. if (!empty($post_data['timezones'])) { $data['timezone'] = $post_data['timezones']; } // Only set 'password' if a value was provided (so the user's profile can // be updated without changing the password). if (!empty($post_data['password'])) { $data['password'] = $post_data['password']; } if ($data['display_name'] === '') { unset($data['display_name']); } // Convert actions to the proper values. if (isset($post_data['restore']) && $post_data['restore']) { // 'restore': unset the soft-delete flag. $data['deleted'] = 0; } if (isset($post_data['unban']) && $post_data['unban']) { // 'unban': unset the banned flag. $data['banned'] = 0; } if (isset($post_data['activate']) && $post_data['activate']) { // 'activate': set the 'active' flag. $data['active'] = 1; } elseif (isset($post_data['deactivate']) && $post_data['deactivate']) { // 'deactivate': unset the 'active' flag. $data['active'] = 0; } return $data; }