1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00
invoiceninja/app/Models/UserAccount.php
2017-01-30 21:40:43 +02:00

73 lines
1.3 KiB
PHP

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