1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/app/Models/UserAccount.php

73 lines
1.3 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Models;
2015-06-16 21:35:35 +02:00
use Eloquent;
/**
2017-01-30 20:40:43 +01:00
* Class UserAccount.
*/
2015-06-16 21:35:35 +02:00
class UserAccount extends Eloquent
{
/**
* @var bool
*/
2015-06-16 21:35:35 +02:00
public $timestamps = false;
/**
* @param $userId
2017-01-30 20:40:43 +01:00
*
* @return bool
*/
2015-06-16 21:35:35 +02:00
public function hasUserId($userId)
{
2017-01-30 20:40:43 +01:00
if (! $userId) {
2015-06-16 21:35:35 +02:00
return false;
}
2017-01-30 20:40:43 +01:00
for ($i = 1; $i <= 5; $i++) {
2015-06-16 21:35:35 +02:00
$field = "user_id{$i}";
if ($this->$field && $this->$field == $userId) {
return true;
}
}
2017-01-30 20:40:43 +01:00
2015-06-16 21:35:35 +02:00
return false;
}
/**
* @param $userId
*/
2015-06-16 21:35:35 +02:00
public function setUserId($userId)
{
if (self::hasUserId($userId)) {
return;
}
2017-01-30 20:40:43 +01:00
for ($i = 1; $i <= 5; $i++) {
2015-06-16 21:35:35 +02:00
$field = "user_id{$i}";
2017-01-30 20:40:43 +01:00
if (! $this->$field) {
2015-06-16 21:35:35 +02:00
$this->$field = $userId;
break;
}
}
}
/**
* @param $userId
*/
2015-06-16 21:35:35 +02:00
public function removeUserId($userId)
{
2017-01-30 20:40:43 +01:00
if (! $userId || ! self::hasUserId($userId)) {
2015-06-16 21:35:35 +02:00
return;
}
2017-01-30 20:40:43 +01:00
for ($i = 1; $i <= 5; $i++) {
2015-06-16 21:35:35 +02:00
$field = "user_id{$i}";
if ($this->$field && $this->$field == $userId) {
$this->$field = null;
}
}
}
}