firefly-iii/app/User.php

226 lines
7.3 KiB
PHP
Raw Normal View History

<?php
2016-02-05 05:08:25 -06:00
declare(strict_types = 1);
2015-02-05 21:39:52 -06:00
namespace FireflyIII;
2015-02-05 21:39:52 -06:00
2016-02-11 22:49:53 -06:00
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
2016-02-06 03:11:06 -06:00
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Foundation\Auth\User as Authenticatable;
2015-02-05 22:04:06 -06:00
/**
* Class User
*
* @package FireflyIII
2016-01-15 16:12:52 -06:00
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property string $email
* @property string $password
* @property string $remember_token
* @property string $reset
2016-04-25 11:43:09 -05:00
* @property bool $activated
* @property bool $isAdmin
* @property bool $has2FA
2016-01-15 16:12:52 -06:00
* @property boolean $blocked
* @property string $blocked_code
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Account[] $accounts
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Attachment[] $attachments
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Tag[] $tags
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Bill[] $bills
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Budget[] $budgets
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Category[] $categories
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Preference[] $preferences
2016-01-11 14:42:51 -06:00
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournal[] $transactionjournals
2016-01-15 16:12:52 -06:00
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Role[] $roles
2016-02-04 00:22:38 -06:00
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\RuleGroup[] $ruleGroups
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Rule[] $rules
2016-02-11 22:49:53 -06:00
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\ExportJob[] $exportjobs
2016-03-12 00:36:23 -06:00
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereId($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereEmail($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\User wherePassword($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereRememberToken($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereReset($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereBlocked($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\User whereBlockedCode($value)
* @mixin \Eloquent
*/
class User extends Authenticatable
{
2016-01-09 01:51:49 -06:00
2015-02-05 22:04:06 -06:00
/**
* The attributes that are mass assignable.
*
* @var array
*/
2015-07-26 08:51:07 -05:00
protected $fillable = ['email', 'password', 'blocked', 'blocked_code'];
2015-02-05 22:04:06 -06:00
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
2015-02-05 22:14:27 -06:00
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
2015-02-05 22:04:06 -06:00
2015-02-11 00:35:10 -06:00
/**
2016-02-06 03:11:06 -06:00
* @return HasMany
2015-02-11 00:35:10 -06:00
*/
2016-02-06 03:11:06 -06:00
public function accounts(): HasMany
2015-02-05 22:04:06 -06:00
{
2015-02-05 22:35:00 -06:00
return $this->hasMany('FireflyIII\Models\Account');
2015-02-05 22:04:06 -06:00
}
2015-02-05 22:01:24 -06:00
2016-02-11 22:49:53 -06:00
/**
* Alias to eloquent many-to-many relation's attach() method.
*
* Full credit goes to: https://github.com/Zizaco/entrust
*
* @param mixed $role
*/
public function attachRole($role)
{
if (is_object($role)) {
$role = $role->getKey();
}
if (is_array($role)) {
$role = $role['id'];
}
$this->roles()->attach($role);
}
2015-07-18 02:49:19 -05:00
/**
2016-02-06 03:11:06 -06:00
* @return HasMany
2015-07-18 02:49:19 -05:00
*/
2016-02-06 03:11:06 -06:00
public function attachments(): HasMany
2015-07-18 02:49:19 -05:00
{
return $this->hasMany('FireflyIII\Models\Attachment');
}
/**
2016-02-06 03:11:06 -06:00
* @return HasMany
*/
2016-02-06 03:11:06 -06:00
public function bills(): HasMany
{
2016-01-15 16:12:52 -06:00
return $this->hasMany('FireflyIII\Models\Bill');
}
2016-01-12 14:37:48 -06:00
/**
2016-02-06 03:11:06 -06:00
* @return HasMany
2016-01-12 14:37:48 -06:00
*/
2016-02-06 03:11:06 -06:00
public function budgets(): HasMany
2016-01-12 14:37:48 -06:00
{
2016-01-15 16:12:52 -06:00
return $this->hasMany('FireflyIII\Models\Budget');
2016-01-12 14:37:48 -06:00
}
/**
2016-02-06 03:11:06 -06:00
* @return HasMany
2016-01-12 14:37:48 -06:00
*/
2016-02-06 03:11:06 -06:00
public function categories(): HasMany
2016-01-12 14:37:48 -06:00
{
2016-01-15 16:12:52 -06:00
return $this->hasMany('FireflyIII\Models\Category');
2016-01-12 14:37:48 -06:00
}
2016-02-04 10:14:59 -06:00
/**
2016-02-06 03:11:06 -06:00
* @return HasMany
2016-02-04 10:14:59 -06:00
*/
2016-02-06 03:11:06 -06:00
public function exportjobs(): HasMany
2016-02-04 10:14:59 -06:00
{
return $this->hasMany('FireflyIII\Models\ExportJob');
}
2016-02-11 22:49:53 -06:00
/**
* Checks if the user has a role by its name.
*
* Full credit goes to: https://github.com/Zizaco/entrust
*
2016-02-17 15:02:32 -06:00
* @param string $name
2016-02-11 22:49:53 -06:00
*
* @return bool
*/
2016-02-17 15:02:32 -06:00
public function hasRole(string $name): bool
2016-02-11 22:49:53 -06:00
{
2016-02-17 15:02:32 -06:00
foreach ($this->roles as $role) {
if ($role->name == $name) {
return true;
2016-02-11 22:49:53 -06:00
}
}
return false;
}
2015-02-11 00:35:10 -06:00
/**
2016-02-06 03:11:06 -06:00
* @return HasManyThrough
2015-02-11 00:35:10 -06:00
*/
2016-02-06 03:11:06 -06:00
public function piggyBanks(): HasManyThrough
2015-02-05 22:14:27 -06:00
{
2016-01-15 16:12:52 -06:00
return $this->hasManyThrough('FireflyIII\Models\PiggyBank', 'FireflyIII\Models\Account');
2015-02-05 22:14:27 -06:00
}
2015-02-11 00:35:10 -06:00
/**
2016-02-06 03:11:06 -06:00
* @return HasMany
2015-02-11 00:35:10 -06:00
*/
2016-02-06 03:11:06 -06:00
public function preferences(): HasMany
2015-02-05 22:14:27 -06:00
{
2016-01-15 16:12:52 -06:00
return $this->hasMany('FireflyIII\Models\Preference');
2015-02-05 22:14:27 -06:00
}
2016-02-11 22:49:53 -06:00
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function roles(): BelongsToMany
{
return $this->belongsToMany('FireflyIII\Models\Role');
}
2015-02-11 00:35:10 -06:00
/**
2016-02-06 03:11:06 -06:00
* @return HasMany
2015-02-11 00:35:10 -06:00
*/
2016-02-06 03:11:06 -06:00
public function ruleGroups(): HasMany
2015-02-05 22:14:27 -06:00
{
2016-01-15 16:12:52 -06:00
return $this->hasMany('FireflyIII\Models\RuleGroup');
2015-02-05 22:14:27 -06:00
}
2015-02-11 00:35:10 -06:00
/**
2016-02-06 03:11:06 -06:00
* @return HasMany
2015-02-11 00:35:10 -06:00
*/
2016-02-06 03:11:06 -06:00
public function rules(): HasMany
2015-02-05 22:14:27 -06:00
{
2016-01-15 16:12:52 -06:00
return $this->hasMany('FireflyIII\Models\Rule');
2015-02-05 22:14:27 -06:00
}
2015-03-29 11:28:49 -05:00
/**
2016-02-06 03:11:06 -06:00
* @return HasMany
2015-03-29 11:28:49 -05:00
*/
2016-02-06 03:11:06 -06:00
public function tags(): HasMany
2015-03-29 11:28:49 -05:00
{
2016-01-15 16:12:52 -06:00
return $this->hasMany('FireflyIII\Models\Tag');
2015-03-29 11:28:49 -05:00
}
2015-02-11 00:35:10 -06:00
/**
2016-02-06 03:11:06 -06:00
* @return HasMany
2015-02-11 00:35:10 -06:00
*/
2016-02-06 03:11:06 -06:00
public function transactionjournals(): HasMany
2015-02-05 22:14:27 -06:00
{
2016-01-15 16:12:52 -06:00
return $this->hasMany('FireflyIII\Models\TransactionJournal');
2015-02-05 22:14:27 -06:00
}
2015-02-11 00:35:10 -06:00
/**
2016-02-06 03:11:06 -06:00
* @return HasManyThrough
2015-02-11 00:35:10 -06:00
*/
2016-02-06 03:11:06 -06:00
public function transactions(): HasManyThrough
2015-02-05 22:14:27 -06:00
{
2016-01-15 16:12:52 -06:00
return $this->hasManyThrough('FireflyIII\Models\Transaction', 'FireflyIII\Models\TransactionJournal');
2015-02-05 22:14:27 -06:00
}
2015-02-05 21:39:52 -06:00
}