Additional Data saving

ajnos

Member
I've added some extrafields to some forms.

What's the best way, to save the data with the datamanger?

Wouldn't it be good to have a event listener before, which sends $userInput $this->_input as reference, so we can add the own fields?
$writer->bulkSet($userInput);
Admincontroller_user
PHP:
/**
  * Inserts a new user or updates an existing one.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionSave()
 {
  $this->_assertPostOnly();
  $userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT);
  if ($userId)
  {
   $user = $this->_getUserOrError($userId);
   $this->getHelper('Admin')->checkSuperAdminEdit($user);
  }
  $userInput = $this->_input->filter(array(
   // essentials
   'username'               => XenForo_Input::STRING,
   'email'                  => XenForo_Input::STRING,
   'user_group_id'          => XenForo_Input::UINT,
   'user_state'             => XenForo_Input::STRING,
   'is_discouraged'         => XenForo_Input::UINT,
   // personal details
   'gender'                 => XenForo_Input::STRING,
   'dob_day'                => XenForo_Input::UINT,
   'dob_month'              => XenForo_Input::UINT,
   'dob_year'               => XenForo_Input::UINT,
   'location'               => XenForo_Input::STRING,
   'occupation'             => XenForo_Input::STRING,
   // profile info
   'custom_title'           => XenForo_Input::STRING,
   'homepage'               => XenForo_Input::STRING,
   'about'                  => XenForo_Input::STRING,
   'signature'              => XenForo_Input::STRING,
   'message_count'          => XenForo_Input::UINT,
   'like_count'             => XenForo_Input::UINT,
   'trophy_points'          => XenForo_Input::UINT,
   // preferences
   'style_id'               => XenForo_Input::UINT,
   'language_id'            => XenForo_Input::UINT,
   'timezone'               => XenForo_Input::STRING,
   'content_show_signature' => XenForo_Input::UINT,
   'enable_rte'             => XenForo_Input::UINT,
   // privacy
   'visible'                 => XenForo_Input::UINT,
   'receive_admin_email'     => XenForo_Input::UINT,
   'show_dob_date'           => XenForo_Input::UINT,
   'show_dob_year'           => XenForo_Input::UINT,
   'allow_view_profile'      => XenForo_Input::STRING,
   'allow_post_profile'      => XenForo_Input::STRING,
   'allow_send_personal_conversation' => XenForo_Input::STRING,
   'allow_view_identities'   => XenForo_Input::STRING,
   'allow_receive_news_feed' => XenForo_Input::STRING,
  ));
  $secondaryGroupIds = $this->_input->filterSingle('secondary_group_ids', XenForo_Input::UINT, array('array' => true));
  $userInput['about'] = XenForo_Helper_String::autoLinkBbCode($userInput['about']);
  if ($this->_input->filterSingle('clear_status', XenForo_Input::UINT))
  {
   //TODO: clear status
  }
  $identities = $this->_input->filterSingle('identity', XenForo_Input::STRING, array('array' => true));
  foreach ($identities AS $_key => $_value)
  {
   if ($_value === '')
   {
    unset($identities[$_key]);
   }
  }
  /* @var $writer XenForo_DataWriter_User */
  $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
  if ($userId)
  {
   $writer->setExistingData($userId);
  }
  $writer->setOption(XenForo_DataWriter_User::OPTION_ADMIN_EDIT, true);
  $writer->bulkSet($userInput);
  $writer->setIdentities($identities);
  $writer->setSecondaryGroups($secondaryGroupIds);
  $password = $this->_input->filterSingle('password', XenForo_Input::STRING);
  if ($password !== '')
  {
   $writer->setPassword($password);
  }
  $writer->save();
  $userId = $writer->get('user_id');
  // TODO: redirect to previous search if possible?
  return $this->responseRedirect(
   XenForo_ControllerResponse_Redirect::SUCCESS,
   XenForo_Link::buildAdminLink('users/search', null, array('last_user_id' => $userId)) . $this->getLastHash($userId)
  );
 }
 
Top Bottom