ldc-gen-game-web/app/Models/FaqQuestion.php

54 lines
1.1 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class FaqQuestion extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'question', 'answer', 'positive_vote',
'negative_vote', 'theme_id'
];
2022-03-15 16:27:41 +01:00
// * RELATIONSHIPS
/**
* Belongs To FaqTheme relationship
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
2021-08-18 17:08:02 +02:00
public function theme()
{
return $this->belongsTo(FaqTheme::class, 'theme_id');
}
2022-03-15 16:27:41 +01:00
/**
* Get utility attribute
*
* @return float
*/
public function getUtilityAttribute(): float
2021-08-18 17:08:02 +02:00
{
2022-03-15 16:27:41 +01:00
/** @var float */
$pourcent = 0;
2020-10-26 17:37:14 +01:00
2022-03-15 16:27:41 +01:00
if (
$this->positive_vote !== null &&
$this->negative_vote !== null &&
$this->positive_vote >= $this->negative_vote &&
$this->positive_vote > 0 && $this->negative_vote > 0
) {
$ratio = \floatval($this->negative_vote / $this->positive_vote);
$pourcent = \floatval(ceil((1 - $ratio) * 100));
}
return $pourcent;
}
}