json_file; if(!empty($this->json_file) && file_exists($json_path)) { return file_get_contents($json_path); } return $this->json; } public function getCustomer() { return Customer::get($this->customer_id); } public function getProcessingFilePath($file) { if(!$this->folder) throw new Exception("Template processing folder not set."); $folder_path = ROOT_DIR . "/template_processing/" . $this->folder; if(!file_exists($folder_path)) throw new Exception("Template processing folder does not exist."); $file_path = $folder_path . "/" . $file; if(!file_exists($file_path)) throw new Exception("Template processing file \"$file\" does not exist."); return $file_path; } public function getURL() { return "/account/templates/" . $this->id; } public function getFields() { $fields = []; $json = json_decode($this->getJSON()); $before_fields = $json->beforeTest; $during_fields = $json->duringTest; $all_fields = array_merge($before_fields, $during_fields); foreach($all_fields as $field) { if(empty($field->name)) continue; $fields[$field->name] = $field; } return $fields; } public function getTesterInvoiceFields() { $json = json_decode($this->getJSON()); if(!$json) throw new Exception("Failed to decode template JSON."); return $json->testerInvoiceFields ?? []; } public function getCustomerInvoiceFields() { $json = json_decode($this->getJSON()); if(!$json) throw new Exception("Failed to decode template JSON."); return $json->customerInvoiceFields ?? []; } public function setOverrides($overrides) { $this->overrides = $overrides; } public function applyOverridesToField($field) { foreach($this->overrides as $override) { if(empty($field->name)) continue; if($override->field == $field->name) { switch($override->element) { case "label": $field->label = $override->value; break; } } } return $field; } public function renderBeforeTestForm() { $json = json_decode($this->getJSON()); $fields = $json->beforeTest; ?>
getJSON()); $fields = $json->duringTest; ?>