ldc-gen-game-web/app/Models/FaqQuestion.php
Jérémy Munsch 1af96897f3
- Squash migration
- Normalize Model names and sql tables
- PHPCS clean up
- Change analytics form + field
2022-01-11 12:46:10 +01:00

35 lines
834 B
PHP

<?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'
];
public function theme()
{
return $this->belongsTo(FaqTheme::class, 'theme_id');
}
public function getUtilityAttribute()
{
$pourcent = 0;
if ($this->positive_vote !== null && $this->negative_vote !== null && $this->positive_vote >= $this->negative_vote && $this->positive_vote > 0 && $this->negative_vote > 0) {
$ratio = $this->negative_vote / $this->positive_vote;
$pourcent = ceil((1 - $ratio) * 100);
}
return $pourcent;
}
}