55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Entities\Mangboard;
|
|
|
|
use CodeIgniter\Entity\Entity;
|
|
|
|
class UserEntity extends Entity
|
|
{
|
|
protected $datamap = [];
|
|
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
|
protected $casts = [];
|
|
|
|
public function __toString()
|
|
{
|
|
return "{$this->getName()}";
|
|
}
|
|
public function getName()
|
|
{
|
|
return $this->attributes['user_name'];
|
|
}
|
|
public function getPoint()
|
|
{
|
|
return $this->attributes['user_point'];
|
|
}
|
|
public function setPoint(int $point, string $sign = "plus")
|
|
{
|
|
switch (strtolower($sign)) {
|
|
case 'minus':
|
|
if ($this->attributes['user_point'] < $point) {
|
|
throw new \Exception("기존포인트:{$this->attributes['user_point']}가 감소 포인트:-{$point} 작습니다.\n");
|
|
}
|
|
$this->attributes['user_point'] -= $point;
|
|
break;
|
|
case 'plus':
|
|
$this->attributes['user_point'] += $point;
|
|
break;
|
|
default:
|
|
throw new \Exception("{$sign}에 해당하는 작업은 수행할수 없습니다.\n");
|
|
// break;
|
|
}
|
|
}
|
|
|
|
public function getLevel()
|
|
{
|
|
return $this->attributes['user_level'];
|
|
}
|
|
public function setLevel(int $level_unit)
|
|
{
|
|
$level = intval($this->getPoint() / $level_unit * $level_unit / $level_unit);
|
|
if ($this->attributes['user_level'] != $level) {
|
|
$this->attributes['user_level'] = $level;
|
|
}
|
|
}
|
|
}
|