<?php
namespace Empire\Core;
use Empire\Legacy\db;
use App\Service\WarrantImageService;
class Warrant extends AbstractEntity implements Named {
const PRIMARY_FIELD = "BOUN_ID";
const TABLE = "BOUNTY";
const RESULT_DEAD = 1;
const RESULT_ALIVE = 2;
const RESULT_DEAD_OR_ALIVE = 3;
const RESULTS = [
self::RESULT_DEAD => "Dead",
self::RESULT_ALIVE => "Alive",
self::RESULT_DEAD_OR_ALIVE => "Dead or Alive",
];
const STATUS_ACTIVE = 1;
const STATUS_CAPTURED = 2;
const STATUS_KILLED = 3;
const STATI = [
self::STATUS_ACTIVE => "Active",
self::STATUS_CAPTURED => "Captured",
self::STATUS_KILLED => "Killed",
];
private $BOUN_ID, $BOUN_NAME, $BOUN_AMOUNT, $BOUN_DESC, $BOUN_AVATAR, $BOUN_CRIMES, $BOST_ID, $BORE_ID;
public $name, $amount, $desc, $avatar, $crimes, $status, $result;
public function initialize() {
$this->id = $this->BOUN_ID;
$this->name = $this->BOUN_NAME;
$this->amount = $this->BOUN_AMOUNT;
$this->desc = html_entity_decode($this->BOUN_DESC);
$this->avatar = WarrantImageService::getWarrantUrl($this->name, false);
$this->crimes = html_entity_decode($this->BOUN_CRIMES);
$this->status = self::STATI[$this->BOST_ID];
$this->result = self::RESULTS[$this->BORE_ID];
}
public function getPrimaryField() {
return self::PRIMARY_FIELD;
}
public function getTable() {
return self::TABLE;
}
public function getName() {
return $this->name;
}
/**
* @return Warrant[]
* @throws \Exception
*/
public static function loadAll() {
$stmt = db::prepare("SELECT * FROM BOUNTY ORDER BY BOUN_NAME ASC");
return db::fetchArrayOfObjects($stmt, Warrant::class);
}
}