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


PHP User::getKey方法代码示例

本文整理汇总了PHP中RainLab\User\Models\User::getKey方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getKey方法的具体用法?PHP User::getKey怎么用?PHP User::getKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RainLab\User\Models\User的用法示例。


在下文中一共展示了User::getKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
     }
 }
开发者ID:janusnic,项目名称:OctoberFriends,代码行数:36,代码来源:ActivityMetadata.php

示例2: 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

示例3: uploadAvatarFromString

 /**
  * Upload Avatar from Base64 encoded image
  * 
  * @param \RainLab\User\Models\User $user
  * @param string $source
  * string contend of an image on Base64 enconding 
  */
 public static function uploadAvatarFromString($user, $source)
 {
     $dst = '/tmp/avatar_' . $user->getKey() . '_' . uniqid();
     FileHelper::put($dst, base64_decode($source));
     $validImage = true;
     try {
         // Validated is a JPG or PNG
         $imageType = exif_imagetype($dst);
         $validImage = in_array($imageType, [IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF]);
         // Validated is not bigger that xx by xx
         if ($validImage) {
             // Test if image is corrupted if OctoberCMS Resizer can open it
             // is more likely the image is ok
             Resizer::open($dst);
             // Test image dimensions
             list($width, $height, $type, $attr) = getimagesize($dst);
             $validImage = $width <= 400 && $height <= 400;
         }
         // Add right file extension to the upload file
         if ($validImage) {
             // Save image with correct image extension
             $extension = [IMAGETYPE_JPEG => 'jpg', IMAGETYPE_PNG => 'png', IMAGETYPE_GIF => 'gif'][$imageType];
             $newDst = $dst . '.' . $extension;
             rename($dst, $newDst);
             $dst = $newDst;
         }
     } catch (\Exception $e) {
         $validImage = false;
     }
     if (!$validImage) {
         throw new \Exception('Must be a valid JPG, GIF or PNG. And not bigger that 400x400 pixels.');
     }
     $file = new File();
     $file->data = $dst;
     $file->is_public = true;
     $file->save();
     if ($file) {
         $user->avatar()->add($file);
     }
 }
开发者ID:janusnic,项目名称:OctoberFriends,代码行数:47,代码来源:UserExtend.php

示例4: scopeHasMetadataValue

 /**
  * Query scope to filter activity metadata by the given key and value
  * @param mixed $query
  * @param RainLab\User\Models\User $user
  * @param DMA\Friends\Models\Activity $activity
  * @param string $key
  * @param string $value
  */
 public function scopeHasMetadataValue($query, $user, $activity, $key, $value)
 {
     return self::where('user_id', $user->getKey())->where('activity_id', $activity->getKey())->where('key', $key)->where('value', $value);
 }
开发者ID:janusnic,项目名称:OctoberFriends,代码行数:12,代码来源:ActivityMetadata.php


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