当前位置: 首页>>代码示例>>PHP>>正文


PHP User::find方法代码示例

本文整理汇总了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];
 }
开发者ID:vojtasvoboda,项目名称:oc-useraccesslog-plugin,代码行数:58,代码来源:AccessLogChartLine.php

示例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'));
 }
开发者ID:anqqa,项目名称:oc-calendar-plugin,代码行数:9,代码来源:Import.php

示例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;
 }
开发者ID:httvncoder,项目名称:151722441,代码行数:9,代码来源:Report.php

示例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;
 }
开发者ID:janusnic,项目名称:OctoberFriends,代码行数:17,代码来源:Usermeta.php

示例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;
     }
 }
开发者ID:httvncoder,项目名称:151722441,代码行数:13,代码来源:Money.php

示例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>'];
 }
开发者ID:aydancoskun,项目名称:octobercms,代码行数:14,代码来源:Merge.php

示例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');
     }
 }
开发者ID:aydancoskun,项目名称:octobercms,代码行数:14,代码来源:VCard.php

示例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;
                 }
             }
         }
     }
 }
开发者ID:janusnic,项目名称:OctoberCMS,代码行数:15,代码来源:UserGroup.php

示例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());
     }
 }
开发者ID:vojtasvoboda,项目名称:oc-userexportpdf-plugin,代码行数:15,代码来源:PdfExportBehavior.php

示例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();
 }
开发者ID:idxos,项目名称:portfolio,代码行数:18,代码来源:Users.php

示例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']);
 }
开发者ID:aydancoskun,项目名称:octobercms,代码行数:7,代码来源:UserList.php

示例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);
 }
开发者ID:janusnic,项目名称:OctoberFriends,代码行数:99,代码来源:RewardResource.php

示例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);
         }
     }
 }
开发者ID:janusnic,项目名称:OctoberFriends,代码行数:26,代码来源:GroupManager.php

示例14: rate

 public function rate($rating)
 {
     $user = User::find($this->user_id);
     $this->rating = $rating;
     $user->touch();
 }
开发者ID:janusnic,项目名称:ActivityFields,代码行数:6,代码来源:Rating.php

示例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);
 }
开发者ID:janusnic,项目名称:OctoberFriends,代码行数:27,代码来源:ActivityMetadataResource.php


注:本文中的RainLab\User\Models\User::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。