2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
2015-06-16 21:35:35 +02:00
|
|
|
|
|
|
|
use Eloquent;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2017-01-30 20:40:43 +01:00
|
|
|
* Class UserAccount.
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
2015-06-16 21:35:35 +02:00
|
|
|
class UserAccount extends Eloquent
|
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2015-06-16 21:35:35 +02:00
|
|
|
public $timestamps = false;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param $userId
|
2017-01-30 20:40:43 +01:00
|
|
|
*
|
2016-07-03 18:11:58 +02: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;
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|