2020-10-26 13:47:52 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
2022-01-11 12:39:28 +01:00
|
|
|
class FaqQuestion extends Model
|
2020-10-26 13:47:52 +01:00
|
|
|
{
|
2022-01-11 12:39:28 +01:00
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'question', 'answer', 'positive_vote',
|
|
|
|
|
'negative_vote', 'theme_id'
|
|
|
|
|
];
|
2020-10-26 13:47:52 +01:00
|
|
|
|
2022-08-11 10:26:29 +02:00
|
|
|
/**
|
|
|
|
|
* Theme relation
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
2021-08-18 17:08:02 +02:00
|
|
|
public function theme()
|
|
|
|
|
{
|
2022-01-11 12:39:28 +01:00
|
|
|
return $this->belongsTo(FaqTheme::class, 'theme_id');
|
2020-10-26 13:47:52 +01:00
|
|
|
}
|
2020-10-26 16:01:14 +01:00
|
|
|
|
2022-08-11 10:26:29 +02:00
|
|
|
/**
|
|
|
|
|
* get Utility
|
|
|
|
|
* @return float|integer
|
|
|
|
|
*/
|
2021-08-18 17:08:02 +02:00
|
|
|
public function getUtilityAttribute()
|
|
|
|
|
{
|
2020-10-26 16:01:14 +01:00
|
|
|
$pourcent = 0;
|
2020-10-26 17:37:14 +01:00
|
|
|
|
2022-08-11 10:26:29 +02: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;
|
2020-10-26 16:01:14 +01:00
|
|
|
$pourcent = ceil((1 - $ratio) * 100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $pourcent;
|
|
|
|
|
}
|
2020-10-26 13:47:52 +01:00
|
|
|
}
|