2013-07-25 23:33:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Entities;
|
|
|
|
|
2013-07-27 02:15:07 +02:00
|
|
|
use Cover;
|
|
|
|
use Gravatar;
|
2013-07-25 23:33:04 +02:00
|
|
|
use Illuminate\Auth\UserInterface;
|
|
|
|
use Illuminate\Auth\Reminders\RemindableInterface;
|
2013-08-29 05:19:24 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2013-07-28 20:50:02 +02:00
|
|
|
use Illuminate\Support\Facades\URL;
|
2013-07-28 23:51:35 +02:00
|
|
|
use Illuminate\Support\Str;
|
2013-07-28 20:50:02 +02:00
|
|
|
use Ratchet\Wamp\Exception;
|
2013-07-25 23:33:04 +02:00
|
|
|
|
|
|
|
class User extends \Eloquent implements UserInterface, RemindableInterface {
|
|
|
|
protected $table = 'users';
|
|
|
|
protected $hidden = ['password_hash', 'password_salt', 'bio'];
|
|
|
|
|
2013-08-29 05:19:24 +02:00
|
|
|
public function scopeUserDetails($query) {
|
|
|
|
if (Auth::check()) {
|
|
|
|
$query->with(['users' => function($query) {
|
|
|
|
$query->whereUserId(Auth::user()->id);
|
|
|
|
}]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return !$query;
|
|
|
|
}
|
|
|
|
|
2013-07-27 02:15:07 +02:00
|
|
|
public function avatar() {
|
|
|
|
return $this->belongsTo('Entities\Image');
|
|
|
|
}
|
|
|
|
|
2013-08-29 05:19:24 +02:00
|
|
|
public function users() {
|
|
|
|
return $this->hasMany('Entities\ResourceUser', 'artist_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function comments() {
|
|
|
|
return $this->hasMany('Entities\Comment', 'profile_id')->orderBy('created_at', 'desc');
|
2013-08-01 10:57:08 +02:00
|
|
|
}
|
|
|
|
|
2013-07-28 23:51:35 +02:00
|
|
|
public function getUrlAttribute() {
|
|
|
|
return URL::to('/' . $this->slug);
|
|
|
|
}
|
|
|
|
|
2013-08-29 05:19:24 +02:00
|
|
|
public function getMessageUrlAttribute() {
|
|
|
|
return 'http://mlpforums.com/index.php?app=members&module=messaging§ion=send&do=form&fromMemberID='.$this->id;
|
|
|
|
}
|
|
|
|
|
2013-07-25 23:33:04 +02:00
|
|
|
public function getAuthIdentifier() {
|
|
|
|
return $this->getKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAuthPassword() {
|
|
|
|
return $this->password_hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getReminderEmail() {
|
|
|
|
return $this->email;
|
|
|
|
}
|
2013-07-27 02:15:07 +02:00
|
|
|
|
2013-09-24 08:27:13 +02:00
|
|
|
public function setDisplayNameAttribute($value) {
|
2013-07-28 23:51:35 +02:00
|
|
|
$this->attributes['display_name'] = $value;
|
|
|
|
$this->attributes['slug'] = Str::slug($value);
|
|
|
|
}
|
|
|
|
|
2013-07-28 20:50:02 +02:00
|
|
|
public function getAvatarUrl($type = Image::NORMAL) {
|
2013-07-27 02:15:07 +02:00
|
|
|
if (!$this->uses_gravatar)
|
2013-08-19 05:39:29 +02:00
|
|
|
return $this->avatar->getUrl($type);
|
2013-07-27 02:15:07 +02:00
|
|
|
|
|
|
|
$email = $this->gravatar;
|
|
|
|
if (!strlen($email))
|
|
|
|
$email = $this->email;
|
|
|
|
|
|
|
|
return Gravatar::getUrl($email, Image::$ImageTypes[$type]['width']);
|
|
|
|
}
|
|
|
|
|
2013-07-28 20:50:02 +02:00
|
|
|
public function getAvatarFile($type = Image::NORMAL) {
|
2013-07-27 02:15:07 +02:00
|
|
|
if ($this->uses_gravatar)
|
2013-07-28 20:50:02 +02:00
|
|
|
throw new Exception('Cannot get avatar file if this user is configured to use Gravatar!');
|
2013-07-27 02:15:07 +02:00
|
|
|
|
2013-07-28 20:50:02 +02:00
|
|
|
$imageType = Image::$ImageTypes[$type];
|
|
|
|
return URL::to('t' . $this->id . '/cover_' . $imageType['name'] . '.png?' . $this->cover_id);
|
2013-07-27 02:15:07 +02:00
|
|
|
}
|
2015-04-24 11:23:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the token value for the "remember me" session.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRememberToken() {
|
2015-04-30 08:50:15 +02:00
|
|
|
return $this->remember_token;
|
2015-04-24 11:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the token value for the "remember me" session.
|
|
|
|
*
|
|
|
|
* @param string $value
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setRememberToken($value) {
|
2015-04-30 08:50:15 +02:00
|
|
|
$this->remember_token = $value;
|
2015-04-24 11:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the column name for the "remember me" token.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRememberTokenName() {
|
2015-04-30 08:50:15 +02:00
|
|
|
return "remember_token";
|
2015-04-24 11:23:45 +02:00
|
|
|
}
|
2013-07-25 23:33:04 +02:00
|
|
|
}
|