Ejemplo n.º 1
0
 /**
  * post_config
  * 
  * @access  public
  * @return  Response (json, html)
  */
 public function post_config($name = null)
 {
     $this->api_accept_formats = array('json', 'html');
     $this->controller_common_api(function () use($name) {
         if (!is_null(Input::post('name'))) {
             $name = Input::post('name');
         }
         $value = Input::post('value');
         self::check_name_format_for_update_config($name);
         $this->check_response_format_for_update_config($name);
         $this->response_body['message'] = self::get_success_message($name);
         $this->response_body['errors']['message_default'] = self::get_error_message_default($name);
         $member_id = (int) $this->u->id;
         if (!($member_config = Model_MemberConfig::get_one4member_id_and_name($member_id, $name))) {
             $member_config = Model_MemberConfig::forge();
             $member_config->member_id = $member_id;
             $member_config->name = $name;
         }
         $current_value = isset($member_config->value) ? $member_config->value : null;
         $value = self::validate_posted_value($name, $current_value);
         $member_config->value = $value;
         \DB::start_transaction();
         $member_config->save();
         \DB::commit_transaction();
         $response_body = self::get_response_for_update_config($name, array('id' => $member_id, $name => $value));
         $this->response_body = $this->format == 'html' ? $response_body : array('html' => $response_body, 'message' => sprintf('%sを%sしました。', term('site.display', 'site.setting'), term('form.update')));
     });
 }
Ejemplo n.º 2
0
 public static function save($member_id, Validation $val, $posted_values)
 {
     $field_names = Form_Util::get_field_names($val);
     foreach ($field_names as $name) {
         $member_config = Model_MemberConfig::get_one4member_id_and_name($member_id, $name);
         if ($member_config && $member_config->value == $posted_values[$name]) {
             continue;
         }
         if (!$member_config) {
             $member_config = Model_MemberConfig::forge();
         }
         $member_config->member_id = $member_id;
         $member_config->name = $name;
         $member_config->value = $posted_values[$name];
         $member_config->save();
     }
 }