本文整理汇总了PHP中RainLab\User\Models\User类的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addUserActivity
/**
* Add activity metadata
*
* @param User $user
* @param Activity $activity
* @param array $data key-value pair data to store
* @param array $exclude When given exclude keys to be stored in the database
*/
public static function addUserActivity(User $user, Activity $activity, array $data, array $exclude = [])
{
$rows = [];
$exclude = array_map('strtolower', $exclude);
// Create a session_id.
// Session_id is use for easily identify groups of metadata
$hashids = new Hashids('dma.activity.metadata', 6);
$user_id = $user->getKey();
$activity_id = $activity->getKey();
// Add unixtime and microseconds to avoid session_id collisions
$micro = microtime(true);
$unixtime = floor($micro);
$milseconds = floor(($micro - $unixtime) * pow(10, 8));
// Create session_id
$session_id = $hashids->encode($user_id, $activity_id, $unixtime, $milseconds);
// Current date and time
$now = date('Y-m-d H:i:s');
foreach ($data as $key => $value) {
$key = strtolower($key);
if (!in_array($key, $exclude)) {
$row = ['session_id' => $session_id, 'user_id' => $user_id, 'activity_id' => $activity_id, 'key' => $key, 'value' => $value, 'created_at' => $now, 'updated_at' => $now];
$rows[] = $row;
}
}
if (count($row) > 0) {
static::insert($rows);
}
}
示例2: importData
public function importData($results, $sessionKey = null)
{
foreach ($results as $row => $data) {
$data += ['is_activated' => true];
if (empty($data['username'])) {
$data['username'] = $data['email'];
}
if (empty($data['password'])) {
$data['password'] = $data['username'];
}
if (empty($data['password_confirmation'])) {
$data['password_confirmation'] = $data['password'];
}
try {
$user = new User();
$user->fill($data);
// try to find avatar
$avatar = $this->findAvatar($data['username']);
if ($avatar) {
$user->avatar = $avatar;
}
// save user
$user->save();
// activate user
$user->attemptActivation($user->activation_code);
$this->logCreated();
} catch (\Exception $ex) {
$this->logError($row, $ex->getMessage());
}
}
}
示例3: getFromUser
/**
* Automatically creates a metadata entry for a user if not one already.
* @param RainLab\User\Models\User $user
* @return DMA\Friends\Models\Usermeta
*/
public static function getFromUser($user = null)
{
if (!$user) {
return null;
}
if (!$user->metadata) {
$meta = new static();
User::find($user->getKey())->metadata()->save($meta);
$user = User::find($user->getKey());
}
return $user->metadata;
}
示例4: onStart
public function onStart()
{
$user_id = $this->param('id');
$user_id = $user_id == 'default' ? 1 : $user_id;
$this['cur_id'] = $user_id;
$this['cur_user'] = User::findOrFail($user_id);
}
示例5: boot
public function boot()
{
User::extend(function ($model) {
$model->hasOne['forum_member'] = ['RainLab\\Forum\\Models\\Member'];
$model->bindEvent('model.beforeDelete', function () use($model) {
$model->forum_member && $model->forum_member->delete();
});
});
UsersController::extendFormFields(function ($widget, $model, $context) {
// Prevent extending of related form instead of the intended User form
if (!$widget->model instanceof \RainLab\User\Models\User) {
return;
}
if ($context != 'update') {
return;
}
if (!Member::getFromUser($model)) {
return;
}
$widget->addFields(['forum_member[username]' => ['label' => 'rainlab.forum::lang.settings.username', 'tab' => 'Forum', 'comment' => 'rainlab.forum::lang.settings.username_comment'], 'forum_member[is_moderator]' => ['label' => 'rainlab.forum::lang.settings.moderator', 'type' => 'checkbox', 'tab' => 'Forum', 'span' => 'auto', 'comment' => 'rainlab.forum::lang.settings.moderator_comment'], 'forum_member[is_banned]' => ['label' => 'rainlab.forum::lang.settings.banned', 'type' => 'checkbox', 'tab' => 'Forum', 'span' => 'auto', 'comment' => 'rainlab.forum::lang.settings.banned_comment']], 'primary');
});
UsersController::extendListColumns(function ($widget, $model) {
if (!$model instanceof \RainLab\User\Models\User) {
return;
}
$widget->addColumns(['forum_member_username' => ['label' => 'rainlab.forum::lang.settings.forum_username', 'relation' => 'forum_member', 'select' => 'username', 'searchable' => false]]);
});
}
示例6: boot
public function boot()
{
User::extend(function ($model) {
$model->hasMany['flynsarmy_sociallogin_providers'] = ['Flynsarmy\\SocialLogin\\Models\\Provider'];
});
Event::listen('backend.form.extendFields', function (Form $form) {
if (!$form->getController() instanceof \System\Controllers\Settings) {
return;
}
if (!$form->model instanceof \Flynsarmy\SocialLogin\Models\Settings) {
return;
}
foreach (ProviderManager::instance()->listProviders() as $class => $details) {
$classObj = $class::instance();
$classObj->extendSettingsForm($form);
}
});
Event::listen('backend.form.extendFields', function ($widget) {
if (!$widget->getController() instanceof \RainLab\User\Controllers\Users) {
return;
}
if ($widget->getContext() != 'update') {
return;
}
$widget->addFields(['flynsarmy_sociallogin_providers' => ['label' => 'Social Providers', 'type' => 'Flynsarmy\\SocialLogin\\FormWidgets\\LoginProviders']], 'secondary');
});
}
示例7: loadData
protected function loadData()
{
$days = $this->property('days');
if (!$days) {
throw new ApplicationException('Invalid days value: ' . $days);
}
// all accesses for last month
$items = User::where('created_at', '>=', Carbon::now()->subDays($days)->format('Y-m-d'))->get();
// parse data
$all = [];
foreach ($items as $item) {
// date
$timestamp = strtotime($item->created_at) * 1000;
$day = Carbon::createFromFormat('Y-m-d H:i:s', $item->created_at)->format('Y-m-d');
if (isset($all[$day])) {
$all[$day][1]++;
} else {
$all[$day] = [$timestamp, 1];
}
}
// count all
$all_render = [];
foreach ($all as $a) {
$all_render[] = [$a[0], $a[1]];
}
return $all_render;
}
示例8: boot
public function boot()
{
// Alias
$alias = AliasLoader::getInstance();
$alias->alias('Carbon', '\\Carbon\\Carbon');
// $alias->alias('DB', '\Barryvdh\Debugbar\Facade');
$alias->alias('CW', '\\Clockwork\\Support\\Laravel\\Facade');
// User model extend
UserModel::extend(function ($model) {
$model->addFillable(['phone', 'patronymic']);
$model->hasOne['profile'] = ['Abnmt\\MRC\\Models\\Profile'];
$model->hasMany['orders'] = ['Abnmt\\MRC\\Models\\Order'];
$model->hasMany['userevents'] = ['Abnmt\\MRC\\Models\\UserEvent'];
$model->hasManyThrough['courses'] = ['Abnmt\\MRC\\Models\\Event', 'through' => 'Abnmt\\MRC\\Models\\UserEvent'];
$model->hasManyThrough['events'] = ['Abnmt\\MRC\\Models\\Event', 'through' => 'Abnmt\\MRC\\Models\\UserEvent'];
});
// User controller extend Form
UsersController::extendFormFields(function ($widget) {
// $configFile = __DIR__ . '/config/profile_fields.yaml';
// $config = Yaml::parse(File::get($configFile));
$config = ['phone' => ['label' => 'Телефон', 'span' => 'auto'], 'patronymic' => ['label' => 'Отчество', 'span' => 'auto']];
$widget->addFields($config);
});
// User controller extend List
UsersController::extendListColumns(function ($list, $model) {
if (!$model instanceof UserModel) {
return;
}
$config = ['surname' => ['label' => 'Фамилия'], 'patronymic' => ['label' => 'Отчество'], 'phone' => ['label' => 'Телефон']];
$list->addColumns($config);
});
}
示例9: fire
/**
* Execute the console command.
* @throws Exception
*/
public function fire()
{
$login = $this->argument('login');
if ($this->rainlab) {
$rainlab = (bool) $this->option('rainlab');
} else {
$rainlab = false;
}
if ($rainlab) {
$user = \RainLab\User\Models\User::where('email', '=', $login)->orWhere('username', '=', $login)->first();
} else {
$user = User::whereLogin($login)->first();
}
if (!$user) {
return $this->error('User not found');
}
$password = $this->option('password');
if ($rainlab) {
$login = 'RainLab.User => ' . $login;
} else {
$login = 'Backend.User => ' . $login;
}
if ($password == null) {
$password = $this->ask('Set password for ' . $login . ' (or press Enter to skip)');
}
if ($password == null) {
$password = Str::random(5);
}
$user->update(['password' => $password, 'password_confirmation' => $password]);
$message = "\n -> new password for " . $login . ": ";
$this->comment($message . $password);
return;
}
示例10: boot
public function boot()
{
UserModel::extend(function ($model) {
$model->hasOne['profile'] = ['KurtJensen\\Profile\\Models\\Profile', 'key' => 'user_id', 'otherKey' => 'id'];
});
UsersController::extendFormFields(function ($form, $model, $context) {
if (!$model instanceof UserModel) {
return;
}
if (!$model->exists) {
return;
}
if ($form->getContext() != 'update') {
return;
}
if (!ProfileModel::getFromUser($form->model)) {
return;
}
// Flash::success($model->profile->created_at);
// Ensure that a profile model always exists
ProfileModel::getFromUser($model);
$groupsField = $form->getField('groups');
$form->removeField('groups');
$form->addTabFields(['primary_usergroup' => ['label' => 'Primary User Group', 'comment' => 'Set the primary group association for this user.', 'tab' => 'rainlab.user::lang.user.account', 'type' => 'dropdown', 'options' => $this->getPrimaryUsergroupOptions()], 'groups' => ['label' => 'Groups/Roles', 'tab' => 'rainlab.user::lang.user.account', 'type' => 'relation', 'emptyOption' => 'There are no user groups available.'], 'profile[per_text_1]' => ['label' => Settings::get('per_label_1', 'Place of Birth'), 'comment' => Settings::get('per_desc_1', 'The town you were born in.'), 'tab' => 'Personal', 'type' => Settings::get('per_typ_1', 'text'), 'options' => ['test' => 'test', 'test2' => 'test2', 'custom' => 'custom']], 'profile[per_text_2]' => ['label' => Settings::get('per_label_2', 'Favorite Activity'), 'comment' => Settings::get('per_desc_2', 'The thing you like to do most.'), 'tab' => 'Personal', 'type' => Settings::get('per_typ_2', 'text')], 'profile[per_text_3]' => ['label' => Settings::get('per_label_3', 'About Me'), 'comment' => Settings::get('per_desc_3', 'All about you.'), 'tab' => 'Personal', 'type' => Settings::get('per_typ_3', 'textarea')], 'profile[per_text_4]' => ['label' => Settings::get('per_label_4', 'Hobbies'), 'comment' => Settings::get('per_desc_4', 'How you invest in your free time.'), 'tab' => 'Personal', 'type' => Settings::get('per_typ_4', 'textarea')], 'profile[pro_text_1]' => ['label' => Settings::get('pro_label_1', 'Position'), 'comment' => Settings::get('pro_desc_1', 'Your current job title.'), 'tab' => 'Professional', 'type' => Settings::get('pro_typ_1', 'text')], 'profile[pro_text_2]' => ['label' => Settings::get('pro_label_2', 'Assignment'), 'comment' => Settings::get('pro_desc_2', 'Where are you working now.'), 'tab' => 'Professional', 'type' => Settings::get('pro_typ_2', 'text')], 'profile[pro_text_3]' => ['label' => Settings::get('pro_label_3', 'Accomplishments'), 'comment' => Settings::get('pro_desc_3', 'The positive things you have done so far.'), 'tab' => 'Professional', 'type' => Settings::get('pro_typ_3', 'textarea')], 'profile[pro_text_4]' => ['label' => Settings::get('pro_label_4', 'Future Goals'), 'comment' => Settings::get('pro_desc_4', 'The things you want to accomplish in the next year or more.'), 'tab' => 'Professional', 'type' => Settings::get('pro_typ_4', 'textarea')]]);
});
Event::listen('backend.menu.extendItems', function ($manager) {
$manager->addSideMenuItems('RainLab.User', 'user', ['merge' => ['label' => 'Merge', 'icon' => 'icon-exchange', 'code' => 'merge', 'owner' => 'RainLab.User', 'url' => Backend::url('kurtjensen/profile/merge'), 'permissions' => ['kurtjensen.profile.merge']]]);
});
}
示例11: render
/**
* {@inheritDoc}
*/
public function render()
{
$limit = $this->property('limit');
$users = User::orderBy('points_today', 'DESC')->take($limit)->get();
$this->vars['users'] = $users;
return $this->makePartial('widget');
}
示例12: postValidPincode
public function postValidPincode()
{
if (!Auth::check()) {
return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'require_signin')), 500);
}
if (!Input::has('pincode')) {
return;
}
$rules = array('pincode' => 'required|alpha_num|size:4');
if ($response = self::valid($rules)) {
return Response::json($response);
}
//$phone_number = Input::get('phone_number');
$user_id = Auth::getUser()->id;
$pincode = Input::get('pincode');
// Get pincode inactive
$check = Pincode::getLastPincodeInActive($user_id, $pincode);
if ($check && !empty($check->phone_number)) {
// Exists pincode inactive in db
if (Pincode::ActivePincode($check->phone_number)) {
// Update user has actived
$user = User::where('id', $user_id)->update(array('is_validated' => 1, 'phone_number' => $check->phone_number));
if (isset($user->errors)) {
return Response::json(response_message(400, $user->errors()->first()), 400);
}
}
return Response::json(response_message(200));
} else {
return Response::json(response_message(1006));
}
}
示例13: onRun
public function onRun()
{
$users = User::with(['metadata' => function ($query) {
$query->where('current_member', '!=', Usermeta::IS_STAFF);
}])->orderBy('points_today', 'desc')->take(10)->get();
$this->page['users'] = $users;
}
示例14: exportData
public function exportData($columns, $sessionKey = null)
{
$users = User::all();
$users->each(function ($user) use($columns) {
$user->addVisible($columns);
});
return $users->toArray();
}
示例15: loadData
protected function loadData()
{
$days = $this->property('days');
if (!$days) {
throw new ApplicationException('Invalid days value: ' . $days);
}
// all accesses for last month
$items = AccessLog::where('created_at', '>=', Carbon::now()->subDays($days)->format('Y-m-d'))->get();
// parse data
$all = [];
$users = [];
$user_rows = [];
foreach ($items as $item) {
// user
$user_id = $item->user_id ? $item->user_id : 0;
$users[$user_id] = $user_id > 0 ? User::find($user_id) : $this->getDeletedFakeUser();
// date
$timestamp = strtotime($item->created_at) * 1000;
$day = Carbon::createFromFormat('Y-m-d H:i:s', $item->created_at)->format('Y-m-d');
if (isset($user_rows[$user_id][$day])) {
$user_rows[$user_id][$day][1]++;
} else {
$user_rows[$user_id][$day] = [$timestamp, 1];
}
// init empty day
if (!isset($all[$day])) {
$all[$day] = ['timestamp' => $timestamp, 'date' => $day, 'count' => 0];
}
// increase count
$all[$day]['count']++;
}
// we need at least two days, to display chart
if (sizeof($all) == 1) {
$day = reset($all);
$date = Carbon::createFromFormat('Y-m-d', $day['date'])->subDays(1);
$dateFormated = $date->format('Y-m-d');
$all[$dateFormated] = ['timestamp' => $date->timestamp * 1000, 'date' => $dateFormated, 'count' => 0];
}
// transform user line to json
foreach ($user_rows as $key => $user_row) {
$rows = [];
foreach ($user_row as $row) {
$rows[] = [$row[0], $row[1]];
}
// we need at least two days, to display chart
if (sizeof($rows) == 1) {
$first = reset($rows);
$rows[] = [$first[0] - 86400000, 0];
}
$user_rows[$key] = $rows;
}
// count all
$all_render = [];
foreach ($all as $a) {
$all_render[] = [$a['timestamp'], $a['count']];
}
return ['all' => $all_render, 'user_rows' => $user_rows, 'users' => $users];
}