本文整理汇总了PHP中RainLab\User\Models\User::find方法的典型用法代码示例。如果您正苦于以下问题:PHP User::find方法的具体用法?PHP User::find怎么用?PHP User::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RainLab\User\Models\User
的用法示例。
在下文中一共展示了User::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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];
}
示例2: __construct
public function __construct()
{
parent::__construct();
BackendMenu::setContext('Klubitus.Calendar', 'calendar', 'import');
SettingsManager::setContext('Klubitus.Calendar', 'settings');
$this->vars['importEnabled'] = $this->importEnabled = (bool) CalendarSettings::get('facebook_import_enabled');
$this->vars['importUrl'] = $this->importUrl = CalendarSettings::get('facebook_import_url');
$this->vars['importUser'] = $this->importUser = UserModel::find(CalendarSettings::get('facebook_import_user_id'));
}
示例3: getUserAttribute
public function getUserAttribute()
{
$user_name = '';
if (isset($this->attribute['user_id'])) {
$user = User::find($this->attribute['user_id']);
$user_name = $user->name;
}
return $user_name;
}
示例4: 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;
}
示例5: get_user_charge_money
public static function get_user_charge_money($user_id = 0)
{
if (!$user_id) {
return 0;
}
$user = User::find($user_id);
$money_account = $user->money_charge - $user->money_spent;
if ($money_account > 0) {
return $money_account;
} else {
return 0;
}
}
示例6: onTransferPassword
public function onTransferPassword($recordId = null)
{
if (!$recordId or !post('sourceId')) {
return null;
}
$userTo = user::find($recordId);
$userFrom = user::find(post('sourceId'));
if (!$userTo or !$userFrom) {
return null;
}
$userTo->setPasswordAttribute($userFrom->password);
$userTo->forceSave();
return ['#layout-flash-messages' => '<p data-control="flash-message" class="flash-message success" data-interval="5">The password for ' . $userTo->name . ' ' . $userTo->surname . ' has been updated to match the source user password.</p>'];
}
示例7: onRun
public function onRun()
{
$userPermision = $this->property('permission');
if ($userPermision) {
if (!UserGroup::can($userPermision)) {
return;
}
}
$person = user::find(intval($this->property('SLSlug')));
if ($person) {
$filename = $person->surname . '_' . $person->name . '.vcf';
return response($this->renderPartial('@vcard', ['person' => $person]))->header('Content-Type', 'text/directory')->header('Content-Disposition', 'attachment; filename=' . $filename)->header('Pragma', 'public');
}
}
示例8: can
public static function can($permissions)
{
$account = new Account();
$permissions = !is_array($permissions) ? [$permissions] : $permissions;
if (Auth::check()) {
$roles = json_decode(User::find($account->user()->id)->groups);
foreach ($roles as $role) {
foreach (UserGroup::find($role->id)->perms as $perm) {
if (in_array($perm->name, $permissions)) {
return true;
}
}
}
}
}
示例9: pdf
public function pdf($id)
{
$user = User::find($id);
if (!$user) {
throw new ApplicationException('User not found.');
}
$templateCode = Config::get('vojtasvoboda.userexportpdf::config.template', 'rainlab::user');
$data = ['user' => $user];
$filename = Str::slug($user->name . '-' . $user->username) . ".pdf";
try {
return PDF::loadTemplate($templateCode, $data)->download($filename);
} catch (Exception $e) {
throw new ApplicationException($e->getMessage());
}
}
示例10: index_onDelete
/**
* Deleted checked users.
*/
public function index_onDelete()
{
if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
foreach ($checkedIds as $userId) {
if (!($user = User::find($userId))) {
continue;
}
$user->delete();
}
Flash::success(Lang::get('rainlab.user::lang.users.delete_selected_success'));
} else {
Flash::error(Lang::get('rainlab.user::lang.users.delete_selected_empty'));
}
return $this->listRefresh();
}
示例11: oneUser
public function oneUser($id)
{
$this->page['person'] = $this->person = user::find($id);
$this->page['avatarThumb'] = $this->person->getAvatarThumb(200);
$this->page['epsettings'] = ExtendedInfo::loadSettings($this->person);
//$this->page['hint'] = count($this->page['epsettings']);
}
示例12: redeemByGet
/**
* @SWG\Definition(
* definition="response.redeem",
* required={"data"},
* @SWG\Property(
* property="data",
* type="object",
* ref="#/definitions/redeem.payload"
* )
* )
*
* @SWG\Definition(
* definition="redeem.payload",
* required={"success", "message", "user"},
* @SWG\Property(
* property="success",
* type="boolean"
* ),
* @SWG\Property(
* property="message",
* type="string"
* ),
* @SWG\Property(
* property="user",
* type="object",
* ref="#/definitions/user.info.points"
* )
* )
*
*
* @SWG\GET(
* path="rewards/redeem/{reward}/user/{user}",
* description="Redeem user points for rewards",
* summary="Redeem a reward",
* tags={ "rewards"},
*
* @SWG\Parameter(
* description="ID of reward to redeem",
* format="int64",
* in="path",
* name="reward",
* required=true,
* type="integer"
* ),
* @SWG\Parameter(
* description="ID of user",
* format="int64",
* in="path",
* name="user",
* required=true,
* type="integer"
* ),
* @SWG\Response(
* response=200,
* description="Unsuccessful response",
* @SWG\Schema(ref="#/definitions/response.redeem")
* ),
* @SWG\Response(
* response=201,
* description="Successful response",
* @SWG\Schema(ref="#/definitions/response.redeem")
* ),
* @SWG\Response(
* response=500,
* description="Unexpected error",
* @SWG\Schema(ref="#/definitions/error500")
* ),
* @SWG\Response(
* response=404,
* description="User not found",
* @SWG\Schema(ref="#/definitions/UserError404")
* )
* )
*/
public function redeemByGet($rewardId, $userId)
{
if (is_null($user = User::find($userId))) {
return Response::api()->errorNotFound('User not found');
}
if (is_null($reward = Reward::find($rewardId))) {
return Response::api()->errorNotFound('Reward not found');
}
RewardManager::redeem($rewardId, $user);
// Check if redeem was successful
$message = Session::pull('rewardMessage');
$type = $message ? 'info' : 'error';
$success = true;
$httpCode = 201;
if ($type == 'error') {
$success = false;
$httpCode = 200;
$message = Session::pull('rewardError');
}
// Get common user points format via UserProfileTransformer
$userTransformer = new UserProfileTransformer();
$points = $userTransformer->getUserPoints($user);
$payload = ['data' => ['success' => $success, 'message' => $message, 'user' => ['id' => $user->getKey(), 'points' => $points]]];
return Response::api()->setStatusCode($httpCode)->withArray($payload);
}
示例13: onRemoveMember
/**
* Ajax handler for removing members
*/
public function onRemoveMember()
{
// refresh current step
$this->currentStep = self::STEP_MEMBERS;
if (($memberId = post('memberId')) != '' && ($groupId = post('groupId')) != '') {
$user = User::find($memberId);
if ($user) {
if ($group = $this->getGroup($groupId)) {
// remove from group
$group->removeUser($user);
// Refresh current groupid
$this->currentGroupId = $groupId;
// Updated list of users and other vars
$this->prepareVars();
$message = Lang::get('dma.friends::lang.groups.memberRemoved');
Flash::info($message);
}
} else {
$message = Lang::get('dma.friends::lang.exceptions.userNotFound');
Flash::info($message);
}
}
}
示例14: rate
public function rate($rating)
{
$user = User::find($this->user_id);
$this->rating = $rating;
$user->touch();
}
示例15: indexByTypeAndUser
/**
* Return activity metadata by the given user filtered
* by activities types
* @param string $types comma separted strings
* @param string $user
* @return Response
*/
public function indexByTypeAndUser($types = null, $userId = null)
{
// Apply query filters and sort parameters
$query = $this->applyFilters();
if (!is_null($userId)) {
if (is_null($user = User::find($userId))) {
return Response::api()->errorNotFound('User not found');
}
// Filter query by user
$query = $query->where('user_id', $user->getKey());
}
// Filter by activity type
$types = !is_null($types) ? explode(',', $types) : $types;
if (!is_null($types)) {
$query = $query->whereHas('activity', function ($q) use($types) {
$q->whereIn('activity_type', $types);
});
}
return $this->paginateResult($query);
}