本文整理汇总了PHP中RainLab\User\Models\User::state方法的典型用法代码示例。如果您正苦于以下问题:PHP User::state方法的具体用法?PHP User::state怎么用?PHP User::state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RainLab\User\Models\User
的用法示例。
在下文中一共展示了User::state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateMetadata
/**
* Updates and save the metadata for a user object
*/
public function updateMetadata(OctoberUser $user, $wordpressId)
{
$metadata = $this->db->table('wp_usermeta')->where('user_id', $wordpressId)->get();
// Organize the metadata for mapping to user fields
$data = ['phone' => '', 'street_address' => '', 'city' => '', 'state' => '', 'zip' => '', 'first_name' => '', 'last_name' => '', '_badgeos_points' => '', 'email_optin' => false, 'current_member' => false, 'current_member_number' => ''];
foreach ($metadata as $mdata) {
$data[$mdata->meta_key] = $mdata->meta_value;
}
$user->phone = $data['phone'];
$user->street_addr = $data['street_address'];
$user->city = $data['city'];
$user->zip = $data['zip'];
$user->points = $data['_badgeos_points'];
// Ensures that we have a barcode id for the user
if (empty($user->barcode_id)) {
$user->barcode_id = $user->name;
}
// Populate state and country objects
if (!empty($data['state'])) {
$state = State::where('code', strtoupper($data['state']))->first();
if (!$state) {
$state = State::where('name', $data['state'])->first();
}
if ($state) {
$user->state()->associate($state);
$user->country()->associate(Country::find($state->country_id));
}
}
$metadata = new Usermeta();
$metadata->first_name = $data['first_name'];
$metadata->last_name = $data['last_name'];
$metadata->email_optin = $data['email_optin'];
$metadata->current_member = $data['current_member'];
$metadata->current_member_number = $data['current_member_number'];
try {
$user->forceSave();
$user->metadata()->delete();
$user->metadata()->save($metadata);
} catch (Exception $e) {
var_dump($e);
}
}