X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/80865b30a5d6a82e86d21e272ae58977d4430a64..refs/pull/139/head:/app/User.php diff --git a/app/User.php b/app/User.php index e1b7c143b..74aec7e3a 100644 --- a/app/User.php +++ b/app/User.php @@ -1,9 +1,6 @@ -belongsToMany('BookStack\Role'); + return $this->belongsToMany(Role::class); } /** @@ -116,7 +113,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon */ public function socialAccounts() { - return $this->hasMany('BookStack\SocialAccount'); + return $this->hasMany(SocialAccount::class); } /** @@ -151,7 +148,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon */ public function avatar() { - return $this->belongsTo('BookStack\Image', 'image_id'); + return $this->belongsTo(Image::class, 'image_id'); } /** @@ -162,4 +159,19 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon { return '/settings/users/' . $this->id; } + + /** + * Get a shortened version of the user's name. + * @param int $chars + * @return string + */ + public function getShortName($chars = 8) + { + if (strlen($this->name) <= $chars) return $this->name; + + $splitName = explode(' ', $this->name); + if (strlen($splitName[0]) <= $chars) return $splitName[0]; + + return ''; + } }