has("trackingcodes", ["code" => $code])) { $this->exists = true; $info = $database->get("trackingcodes", ["containerid", "code", "codetype"], ["code" => $code]); $this->code = $info["code"]; $this->containerid = $info["containerid"]; $this->type = $info["codetype"]; } else { $this->exists = false; } } public function getCarrier(): string { return TrackingCode::typeToCarrier($this->type); } public function save() { global $database; if (!$database->has("containers", ["containerid" => $this->containerid])) { throw new Exception("No container with ID $this->containerid exists."); return false; } if ($database->has("trackingcodes", ["code" => $code])) { $database->update("trackingcodes", [ "codetype" => $this->type, "containerid" => $this->containerid ], ["code" => $this->code]); } else { $database->insert("trackingcodes", [ "code" => $this->code, "containerid" => $this->containerid, "codetype" => $this->type ]); $this->exists = true; } } public static function typeToCarrier($type) { switch (strtolower($type)) { case "usps": return "USPS"; case "ups": return "UPS"; case "fedex": return "FedEx"; default: return ""; } } }