|
|
@@ -47,23 +47,23 @@ class Test extends Model {
|
|
|
protected static $id_field = "id";
|
|
|
protected static $fillable_fields = ["project_id", "location_id", "tester_id", "status", "status_tester_invoice", "customer_fee", "test_fee", "test_time", "test_travel_cost", "test_travel_cost_description", "shop_left", "shop_right", "attire", "challenge_stage", "challenge_description", "challenger_name", "challenger_description", "challenger_gender", "challenger_eye_contact", "additional_notes", "dts_due", "dts_start", "dts_end", "dts_tester_invoice_generated", "dts_tester_invoice_paid", "verifier_id", "verifier_notes", "pass", "retest", "void", "dts_created", "dts_updated", "dts_assigned", "dts_verified"];
|
|
|
|
|
|
- const TEST_FIELDS = ["shop_left", "shop_right", "attire", "challenge_stage", "challenge_description", "challenger_name", "challenger_description", "challenger_gender", "challenger_eye_contact", "additional_notes"];
|
|
|
+ public const TEST_FIELDS = ["shop_left", "shop_right", "attire", "challenge_stage", "challenge_description", "challenger_name", "challenger_description", "challenger_gender", "challenger_eye_contact", "additional_notes"];
|
|
|
|
|
|
// Constants
|
|
|
|
|
|
- const STATUS_CANCELLED = 0;
|
|
|
- const STATUS_UNASSIGNED = 1; // Location needs a tester
|
|
|
- const STATUS_ASSIGNED = 2; // Tester assigned
|
|
|
- const STATUS_CONFIRMED = 3; // Tester has said they can do it
|
|
|
- const STATUS_STARTED = 4;
|
|
|
- const STATUS_PENDING_VERIFICATION = 8;
|
|
|
- const STATUS_COMPLETED = 16;
|
|
|
+ public const STATUS_CANCELLED = 0;
|
|
|
+ public const STATUS_UNASSIGNED = 1; // Location needs a tester
|
|
|
+ public const STATUS_ASSIGNED = 2; // Tester assigned
|
|
|
+ public const STATUS_CONFIRMED = 3; // Tester has said they can do it
|
|
|
+ public const STATUS_STARTED = 4;
|
|
|
+ public const STATUS_PENDING_VERIFICATION = 8;
|
|
|
+ public const STATUS_COMPLETED = 16;
|
|
|
|
|
|
- const STATUS_TESTER_INVOICE_NONE = 0;
|
|
|
- const STATUS_TESTER_INVOICE_PENDING = 100;
|
|
|
- const STATUS_TESTER_INVOICE_PAID = 200;
|
|
|
+ public const STATUS_TESTER_INVOICE_NONE = 0;
|
|
|
+ public const STATUS_TESTER_INVOICE_PENDING = 100;
|
|
|
+ public const STATUS_TESTER_INVOICE_PAID = 200;
|
|
|
|
|
|
- const STATUSES = [
|
|
|
+ public const STATUSES = [
|
|
|
0 => "Cancelled",
|
|
|
1 => "Unassigned",
|
|
|
2 => "Assigned",
|
|
|
@@ -73,13 +73,13 @@ class Test extends Model {
|
|
|
16 => "Completed",
|
|
|
];
|
|
|
|
|
|
- const STATUSES_TESTER_INVOICE = [
|
|
|
+ public const STATUSES_TESTER_INVOICE = [
|
|
|
Test::STATUS_TESTER_INVOICE_NONE,
|
|
|
Test::STATUS_TESTER_INVOICE_PENDING,
|
|
|
Test::STATUS_TESTER_INVOICE_PAID
|
|
|
];
|
|
|
|
|
|
- const STAGES = [
|
|
|
+ public const STAGES = [
|
|
|
0 => "",
|
|
|
1 => "Challenge on entry",
|
|
|
2 => "Challenge while browsing",
|
|
|
@@ -88,10 +88,6 @@ class Test extends Model {
|
|
|
5 => "No challenge",
|
|
|
];
|
|
|
|
|
|
- const TEST_TIME_ANYTIME = 1;
|
|
|
- const TEST_TIME_DAY = 2;
|
|
|
- const TEST_TIME_NIGHT = 3;
|
|
|
-
|
|
|
// Static methods
|
|
|
|
|
|
/**
|
|
|
@@ -100,11 +96,11 @@ class Test extends Model {
|
|
|
*/
|
|
|
public static function getStatusTesterInvoiceText(int $status): string {
|
|
|
switch($status) {
|
|
|
- case Test::STATUS_TESTER_INVOICE_NONE:
|
|
|
+ case self::STATUS_TESTER_INVOICE_NONE:
|
|
|
return __("No Invoice Generated");
|
|
|
- case Test::STATUS_TESTER_INVOICE_PENDING:
|
|
|
+ case self::STATUS_TESTER_INVOICE_PENDING:
|
|
|
return __("Pending Payment");
|
|
|
- case Test::STATUS_TESTER_INVOICE_PAID:
|
|
|
+ case self::STATUS_TESTER_INVOICE_PAID:
|
|
|
return __("Paid");
|
|
|
}
|
|
|
return __("Unknown");
|
|
|
@@ -116,11 +112,11 @@ class Test extends Model {
|
|
|
*/
|
|
|
public static function getStatusTesterInvoiceClass(int $status): string {
|
|
|
switch($status) {
|
|
|
- case Test::STATUS_TESTER_INVOICE_NONE:
|
|
|
+ case self::STATUS_TESTER_INVOICE_NONE:
|
|
|
return "secondary";
|
|
|
- case Test::STATUS_TESTER_INVOICE_PENDING:
|
|
|
+ case self::STATUS_TESTER_INVOICE_PENDING:
|
|
|
return "warning";
|
|
|
- case Test::STATUS_TESTER_INVOICE_PAID:
|
|
|
+ case self::STATUS_TESTER_INVOICE_PAID:
|
|
|
return "success";
|
|
|
}
|
|
|
return "";
|
|
|
@@ -145,7 +141,8 @@ class Test extends Model {
|
|
|
// Output
|
|
|
HTTP::setDownloadHeaders("export.csv");
|
|
|
|
|
|
- $handle = fopen("php://output", "w");
|
|
|
+ $handle = fopen("php://output", "wb");
|
|
|
+ /** @noinspection PhpIncludeInspection */
|
|
|
require $processing_file_path;
|
|
|
fclose($handle);
|
|
|
}
|
|
|
@@ -406,7 +403,7 @@ class Test extends Model {
|
|
|
public function decline(): bool {
|
|
|
$this->sendDeclineEmail();
|
|
|
|
|
|
- $this->status = Test::STATUS_UNASSIGNED;
|
|
|
+ $this->status = self::STATUS_UNASSIGNED;
|
|
|
$this->tester_id = null;
|
|
|
$this->dts_due = null;
|
|
|
$this->dts_assigned = null;
|
|
|
@@ -419,14 +416,14 @@ class Test extends Model {
|
|
|
*/
|
|
|
public function getChallengeStageText(): string {
|
|
|
if(is_null($this->challenge_stage)) return "";
|
|
|
- return Test::STAGES[$this->challenge_stage];
|
|
|
+ return self::STAGES[$this->challenge_stage];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @return string
|
|
|
*/
|
|
|
public function getStatusText(): string {
|
|
|
- return Test::STATUSES[$this->status];
|
|
|
+ return self::STATUSES[$this->status];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -434,17 +431,17 @@ class Test extends Model {
|
|
|
*/
|
|
|
public function getStatusClass(): string {
|
|
|
switch($this->status) {
|
|
|
- case Test::STATUS_CANCELLED:
|
|
|
+ case self::STATUS_CANCELLED:
|
|
|
return "secondary";
|
|
|
- case Test::STATUS_UNASSIGNED:
|
|
|
+ case self::STATUS_UNASSIGNED:
|
|
|
return "danger";
|
|
|
- case Test::STATUS_ASSIGNED:
|
|
|
- case Test::STATUS_CONFIRMED:
|
|
|
- case Test::STATUS_STARTED:
|
|
|
+ case self::STATUS_ASSIGNED:
|
|
|
+ case self::STATUS_CONFIRMED:
|
|
|
+ case self::STATUS_STARTED:
|
|
|
return "warning";
|
|
|
- case Test::STATUS_PENDING_VERIFICATION:
|
|
|
+ case self::STATUS_PENDING_VERIFICATION:
|
|
|
return "primary";
|
|
|
- case Test::STATUS_COMPLETED:
|
|
|
+ case self::STATUS_COMPLETED:
|
|
|
return "success";
|
|
|
}
|
|
|
return "";
|
|
|
@@ -491,9 +488,10 @@ class Test extends Model {
|
|
|
$rows = TestValue::query(["test_id" => $this->id]);
|
|
|
|
|
|
if($as_assoc_array) {
|
|
|
- $k = array_column($rows, "name");
|
|
|
- $v = array_column($rows, "value");
|
|
|
- $values = array_combine($k, $v);
|
|
|
+ $values = [];
|
|
|
+ foreach($rows as $row) {
|
|
|
+ $values[$row->name] = $row->value;
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
$values = $rows;
|
|
|
@@ -515,9 +513,8 @@ class Test extends Model {
|
|
|
* @return bool|float|int
|
|
|
*/
|
|
|
public function getDuration() {
|
|
|
- if(is_null($this->dts_end)) return false;
|
|
|
- $seconds = Util::getDurationFromDTS($this->dts_start, $this->dts_end);
|
|
|
- return $seconds;
|
|
|
+ if($this->dts_end === null) return false;
|
|
|
+ return Util::getDurationFromDTS($this->dts_start, $this->dts_end);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -526,7 +523,7 @@ class Test extends Model {
|
|
|
public function getDisplayDuration(): string {
|
|
|
$secs = $this->getDuration();
|
|
|
$mins = floor($secs / 60);
|
|
|
- $secs = $secs % 60;
|
|
|
+ $secs %= 60;
|
|
|
|
|
|
return "$mins min. $secs sec.";
|
|
|
}
|
|
|
@@ -535,7 +532,8 @@ class Test extends Model {
|
|
|
* @return string Bootstrap class name
|
|
|
*/
|
|
|
public function getPassClass(): string {
|
|
|
- if(is_null($this->pass)) return "secondary";
|
|
|
+ if($this->isVoid()) return "muted";
|
|
|
+ if($this->pass === null) return "secondary";
|
|
|
return $this->pass ? "success" : "danger";
|
|
|
}
|
|
|
|
|
|
@@ -543,7 +541,8 @@ class Test extends Model {
|
|
|
* @return string FA icon name without prefix
|
|
|
*/
|
|
|
public function getPassIcon(): string {
|
|
|
- if(is_null($this->pass)) return "clock";
|
|
|
+ if($this->isVoid()) return "minus-circle";
|
|
|
+ if($this->pass === null) return "clock";
|
|
|
return $this->pass ? "check-circle" : "times-circle";
|
|
|
}
|
|
|
|
|
|
@@ -551,15 +550,18 @@ class Test extends Model {
|
|
|
* @return string Pending, Pass or Fail
|
|
|
*/
|
|
|
public function getPassText(): string {
|
|
|
- if(is_null($this->pass)) return __("Pending");
|
|
|
+ if($this->isVoid()) return __("Void");
|
|
|
+ if($this->pass === null) return __("Pending");
|
|
|
return $this->pass ? __("Pass") : __("Fail");
|
|
|
}
|
|
|
|
|
|
+ /** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
public function getMPDF(): Mpdf {
|
|
|
- /** @var Mpdf $mpdf */
|
|
|
$id = $this->id;
|
|
|
$output = false;
|
|
|
require ROOT_DIR . "/controllers/test_pdf.php";
|
|
|
+
|
|
|
+ /** @var Mpdf $mpdf */
|
|
|
return $mpdf;
|
|
|
}
|
|
|
|
|
|
@@ -571,12 +573,9 @@ class Test extends Model {
|
|
|
public function assignTester(User $tester): bool {
|
|
|
$this->tester_id = $tester->id;
|
|
|
$this->dts_assigned = Util::getDateTime();
|
|
|
- $success = $this->commit();
|
|
|
-
|
|
|
// TODO: Notify tester
|
|
|
|
|
|
- return $success;
|
|
|
-
|
|
|
+ return $this->commit();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -588,10 +587,10 @@ class Test extends Model {
|
|
|
$nvp = [
|
|
|
"dts_start" => (new Constraint("LESS_THAN"))->setValues($this->dts_start),
|
|
|
"location_id" => $this->location_id,
|
|
|
- "status" => Test::STATUS_COMPLETED,
|
|
|
+ "status" => self::STATUS_COMPLETED,
|
|
|
];
|
|
|
|
|
|
- $tests = Test::query($nvp, [
|
|
|
+ $tests = self::query($nvp, [
|
|
|
"sort" => "dts_start",
|
|
|
"order" => "desc",
|
|
|
]);
|
|
|
@@ -605,7 +604,7 @@ class Test extends Model {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public function unassignTester(): bool {
|
|
|
- $this->status = Test::STATUS_UNASSIGNED;
|
|
|
+ $this->status = self::STATUS_UNASSIGNED;
|
|
|
$this->tester_id = null;
|
|
|
$this->dts_due = null;
|
|
|
$this->dts_assigned = null;
|
|
|
@@ -649,7 +648,7 @@ class Test extends Model {
|
|
|
return $this->getStatus() === self::STATUS_PENDING_VERIFICATION;
|
|
|
}
|
|
|
|
|
|
- public function getPDFPath() {
|
|
|
+ public function getPDFPath(): string {
|
|
|
$directory = $this->getDirectory();
|
|
|
return sprintf("%s/pdf.pdf", $directory);
|
|
|
}
|
|
|
@@ -693,8 +692,8 @@ class Test extends Model {
|
|
|
*/
|
|
|
public function markTesterInvoicePaid(): bool {
|
|
|
|
|
|
- if($this->status_tester_invoice == Test::STATUS_TESTER_INVOICE_PENDING) {
|
|
|
- $this->status_tester_invoice = Test::STATUS_TESTER_INVOICE_PAID;
|
|
|
+ if($this->getTesterInvoiceStatus() === self::STATUS_TESTER_INVOICE_PENDING) {
|
|
|
+ $this->status_tester_invoice = self::STATUS_TESTER_INVOICE_PAID;
|
|
|
$this->dts_tester_invoice_paid = Util::getDateTime();
|
|
|
return $this->commit();
|
|
|
}
|
|
|
@@ -707,8 +706,8 @@ class Test extends Model {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public function rejectTesterInvoice(): bool {
|
|
|
- if($this->status_tester_invoice == Test::STATUS_TESTER_INVOICE_PENDING) {
|
|
|
- $this->status_tester_invoice = Test::STATUS_TESTER_INVOICE_NONE;
|
|
|
+ if($this->getTesterInvoiceStatus() === self::STATUS_TESTER_INVOICE_PENDING) {
|
|
|
+ $this->status_tester_invoice = self::STATUS_TESTER_INVOICE_NONE;
|
|
|
$this->dts_tester_invoice_generated = null;
|
|
|
|
|
|
if($this->hasTesterInvoicePDF()) {
|