-
Thibault Debatty authoredThibault Debatty authored
Feedback.php 1.75 KiB
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* Represents a feedback provided by a user about an evidence : true detection
* or false alarm.
*/
class Feedback extends Model
{
/**
* The storage format of the model's date columns.
*
* @var string
*/
protected $dateFormat = 'U';
public function user()
{
return $this->belongsTo(\App\User::class);
}
public function timeForHumans() : string
{
return $this->created_at->toISOString();
}
public function badge() : string
{
if ($this->is_true_alert) {
return '<span class="badge badge-warning">True detection</span>';
} else {
return '<span class="badge badge-success">False alert</span>';
}
}
private $report = null;
public function report() : \Cylab\Mark\Evidence
{
if ($this->report != null) {
return $this->report;
}
try {
$this->report = Mark::get()->findEvidenceById($this->report_id);
} catch (\JsonRPC\Exception\ServerErrorException $ex) {
// may happen if the saved id is invalid (old data)
// should be replace by a static call Evidence::getNullReport()
$this->report = new \Cylab\Mark\Evidence([
"id" => "?",
"label" => "?",
"time" => 0,
"subject" => [],
"score" => 0,
"report" => "",
"references" => [],
"requests" => [],
"profile" => ["label" => ""]]);
}
return $this->report;
}
public static function findByReportId(string $id)
{
return self::where("report_id", $id)->first();
}
}