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

31 lines
773 B
PHP
Raw Normal View History

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class FaqQuestions extends Model
{
2021-08-18 17:08:02 +02:00
protected $table = "faq_questions";
2021-08-18 17:08:02 +02:00
protected $fillable = ["question", "answer", "positive_vote", "negative_vote", "theme_id"];
2021-08-18 17:08:02 +02:00
public function theme()
{
return $this->belongsTo('App\Models\FaqThemes', 'theme_id');
}
2021-08-18 17:08:02 +02:00
public function getUtilityAttribute()
{
$pourcent = 0;
2020-10-26 17:37:14 +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) {
2021-08-18 17:08:02 +02:00
$ratio = $this->negative_vote / $this->positive_vote;
$pourcent = ceil((1 - $ratio) * 100);
}
return $pourcent;
}
}