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

69 lines
1.2 KiB
PHP
Raw Normal View History

2015-06-16 21:35:35 +02:00
<?php namespace App\Models;
use Eloquent;
/**
* 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
* @return bool
*/
2015-06-16 21:35:35 +02:00
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
*/
2015-06-16 21:35:35 +02:00
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
*/
2015-06-16 21:35:35 +02:00
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;
}
}
}
}