72 lines
1.6 KiB
PHP
72 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Modules\ManagementTools\Entities;
|
|
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class MtUserScore extends Model
|
|
{
|
|
protected $table = 'mt_user_scores';
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $casts = [
|
|
'score' => 'float',
|
|
];
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function task()
|
|
{
|
|
return $this->belongsTo(MtUserTask::class, 'task_id');
|
|
}
|
|
|
|
public function scoreCard()
|
|
{
|
|
return $this->belongsTo(MtScoreCard::class, 'score_card_id');
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function scopeForBusiness($query, $business_id)
|
|
{
|
|
return $query->where('business_id', $business_id);
|
|
}
|
|
|
|
public static function typeLabels(): array
|
|
{
|
|
return [
|
|
'1' => __('managementtools::lang.score_type_bonus'),
|
|
'2' => __('managementtools::lang.score_type_penalty'),
|
|
'3' => __('managementtools::lang.score_type_report'),
|
|
];
|
|
}
|
|
|
|
public function typeLabel(): string
|
|
{
|
|
if ($this->scoreCard) {
|
|
return $this->scoreCard->title;
|
|
}
|
|
|
|
return self::typeLabels()[$this->type] ?? $this->type;
|
|
}
|
|
|
|
public function displayPoints(): string
|
|
{
|
|
if ($this->scoreCard) {
|
|
return $this->scoreCard->pointsFormatted();
|
|
}
|
|
|
|
$points = (float) $this->score;
|
|
|
|
return $points > 0 ? '+'.number_format($points, 0) : number_format($points, 0);
|
|
}
|
|
}
|