|
@@ -4,11 +4,21 @@ class Template extends Model {
|
|
|
|
|
|
|
|
protected static $table = "template";
|
|
protected static $table = "template";
|
|
|
protected static $id_field = "id";
|
|
protected static $id_field = "id";
|
|
|
- protected static $fillable_fields = ["customer_id", "name", "json", "practice", "pass_stage"];
|
|
|
|
|
|
|
+ protected static $fillable_fields = ["customer_id", "name", "json", "json_file", "practice", "pass_stage"];
|
|
|
|
|
|
|
|
private $overrides = [];
|
|
private $overrides = [];
|
|
|
|
|
|
|
|
// Object methods
|
|
// Object methods
|
|
|
|
|
+ public function getJSON() {
|
|
|
|
|
+ $json_path = ROOT_DIR . "/json/" . $this->json_file;
|
|
|
|
|
+
|
|
|
|
|
+ if(!empty($this->json_file) && file_exists($json_path)) {
|
|
|
|
|
+ return file_get_contents($json_path);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $this->json;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function getCustomer() {
|
|
public function getCustomer() {
|
|
|
return Customer::get($this->customer_id);
|
|
return Customer::get($this->customer_id);
|
|
|
}
|
|
}
|
|
@@ -32,7 +42,7 @@ class Template extends Model {
|
|
|
public function getFields() {
|
|
public function getFields() {
|
|
|
$fields = [];
|
|
$fields = [];
|
|
|
|
|
|
|
|
- $json = json_decode($this->json);
|
|
|
|
|
|
|
+ $json = json_decode($this->getJSON());
|
|
|
$before_fields = $json->beforeTest;
|
|
$before_fields = $json->beforeTest;
|
|
|
$during_fields = $json->duringTest;
|
|
$during_fields = $json->duringTest;
|
|
|
$all_fields = array_merge($before_fields, $during_fields);
|
|
$all_fields = array_merge($before_fields, $during_fields);
|
|
@@ -46,14 +56,14 @@ class Template extends Model {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function getTesterInvoiceFields() {
|
|
public function getTesterInvoiceFields() {
|
|
|
- $json = json_decode($this->json);
|
|
|
|
|
|
|
+ $json = json_decode($this->getJSON());
|
|
|
if(!$json) throw new Exception("Failed to decode template JSON.");
|
|
if(!$json) throw new Exception("Failed to decode template JSON.");
|
|
|
|
|
|
|
|
return $json->testerInvoiceFields ?? [];
|
|
return $json->testerInvoiceFields ?? [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function getCustomerInvoiceFields() {
|
|
public function getCustomerInvoiceFields() {
|
|
|
- $json = json_decode($this->json);
|
|
|
|
|
|
|
+ $json = json_decode($this->getJSON());
|
|
|
if(!$json) throw new Exception("Failed to decode template JSON.");
|
|
if(!$json) throw new Exception("Failed to decode template JSON.");
|
|
|
|
|
|
|
|
return $json->customerInvoiceFields ?? [];
|
|
return $json->customerInvoiceFields ?? [];
|
|
@@ -79,7 +89,7 @@ class Template extends Model {
|
|
|
|
|
|
|
|
public function renderBeforeTestForm() {
|
|
public function renderBeforeTestForm() {
|
|
|
|
|
|
|
|
- $json = json_decode($this->json);
|
|
|
|
|
|
|
+ $json = json_decode($this->getJSON());
|
|
|
$fields = $json->beforeTest;
|
|
$fields = $json->beforeTest;
|
|
|
|
|
|
|
|
?>
|
|
?>
|
|
@@ -111,7 +121,7 @@ class Template extends Model {
|
|
|
|
|
|
|
|
public function renderDuringTestForm() {
|
|
public function renderDuringTestForm() {
|
|
|
|
|
|
|
|
- $json = json_decode($this->json);
|
|
|
|
|
|
|
+ $json = json_decode($this->getJSON());
|
|
|
$fields = $json->duringTest;
|
|
$fields = $json->duringTest;
|
|
|
|
|
|
|
|
?>
|
|
?>
|