Files
monica/app/User.php
T
Régis Freyd 5b5b2da5f8 Add multi user support and subscriptions (#359)
This pull request adds support to multi users in one account. It also introduces the notion of subscriptions.

Accounts can now have multiple users.

Subscriptions are defined by a new env variable called REQUIRES_SUBSCRIPTION, and defaults to false. As promised, all the paid features on .com will be free if you download and host Monica on your own server.
2017-06-20 20:51:40 -04:00

119 lines
2.4 KiB
PHP

<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'timezone', 'locale', 'currency_id', 'fluid_layout'
];
/**
* Eager load account with every user.
*/
protected $with = ['account'];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* Get the account record associated with the user.
*
* @return BelongsTo
*/
public function account()
{
return $this->belongsTo('App\Account');
}
/**
* Assigns a default value just in case the sort order is empty
*
* @param string $value
* @return string
*/
public function getContactsSortOrderAttribute($value)
{
return ! empty($value) ? $value : 'firstnameAZ';
}
/**
* Indicates if the layout is fluid or not for the UI.
* @return string
*/
public function getFluidLayout()
{
if ($this->fluid_container == 'true') {
return 'container-fluid';
} else {
return 'container';
}
}
/**
* @return string
*/
public function getMetricSymbol()
{
if ($this->metric == 'fahrenheit') {
return 'F';
} else {
return 'C';
}
}
/**
* Get users's full name
*
* @return string
*/
public function getNameAttribute()
{
$completeName = $this->first_name;
if (!is_null($this->last_name)) {
$completeName = $completeName . ' ' . $this->last_name;
}
return $completeName;
}
/**
* Gets the currency for this user.
*
* @return BelongsTo
*/
public function currency()
{
return $this->belongsTo(Currency::class);
}
/**
* Set the contact view preference.
*
* @param string $preference
*/
public function updateContactViewPreference($preference)
{
$this->contacts_sort_order = $preference;
$this->save();
}
}