test.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. class Test extends Model {
  3. protected static $table = "test";
  4. protected static $id_field = "id";
  5. protected static $fillable_fields = ["project_id", "location_id", "tester_id", "status", "test_fee", "test_time", "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", "verifier_id", "verifier_notes", "pass", "dts_created", "dts_assigned", "dts_verified"];
  6. protected static $field_map = [
  7. ];
  8. // Constants
  9. const STATUS_CANCELLED = 0;
  10. const STATUS_UNASSIGNED = 1; // Location needs a tester
  11. const STATUS_ASSIGNED = 2; // Tester assigned
  12. const STATUS_CONFIRMED = 3; // Tester has said they can do it
  13. const STATUS_STARTED = 4;
  14. const STATUS_PENDING_VERIFICATION = 8;
  15. const STATUS_COMPLETED = 16;
  16. const STATUSES = [
  17. 0 => "Cancelled",
  18. 1 => "Unassigned",
  19. 2 => "Assigned",
  20. 3 => "Confirmed",
  21. 4 => "Started",
  22. 8 => "Pending Verification",
  23. 16 => "Completed",
  24. ];
  25. const TEST_TIME_ANYTIME = 1;
  26. const TEST_TIME_DAY = 2;
  27. const TEST_TIME_NIGHT = 3;
  28. // Object methods
  29. public function getStatusText() {
  30. return Test::STATUSES[$this->status];
  31. }
  32. public function getStatusClass() {
  33. switch($this->status) {
  34. case Test::STATUS_CANCELLED:
  35. return "secondary";
  36. case Test::STATUS_UNASSIGNED:
  37. return "danger";
  38. case Test::STATUS_ASSIGNED:
  39. case Test::STATUS_CONFIRMED:
  40. case Test::STATUS_STARTED:
  41. return "warning";
  42. case Test::STATUS_PENDING_VERIFICATION:
  43. return "primary";
  44. case Test::STATUS_COMPLETED:
  45. return "success";
  46. }
  47. }
  48. public function getProject() {
  49. return Project::get($this->project_id);
  50. }
  51. public function getLocation() {
  52. return Location::get($this->location_id);
  53. }
  54. public function getTester() {
  55. return User::get($this->tester_id);
  56. }
  57. public function getVerifier() {
  58. return User::get($this->verifier_id);
  59. }
  60. public function getValues() {
  61. return TestValue::query(["test_id" => $this->id]);
  62. }
  63. public function getDirectory() {
  64. $directory = ROOT_DIR . "/files/tests/" . $this->id;
  65. if(!file_exists($directory)) mkdir($directory, 0777, true);
  66. return $directory;
  67. }
  68. public function getDuration() {
  69. if(is_null($this->dts_end)) return false;
  70. $seconds = Util::getDurationFromDTS($this->dts_start, $this->dts_end);
  71. return $seconds;
  72. }
  73. public function getDisplayDuration() {
  74. $secs = $this->getDuration();
  75. $mins = floor($secs / 60);
  76. $secs = $secs % 60;
  77. return "$mins min. $secs sec.";
  78. }
  79. public function getPassClass() {
  80. if(is_null($this->pass)) return "secondary";
  81. return $this->pass ? "success" : "danger";
  82. }
  83. public function getPassText() {
  84. if(is_null($this->pass)) return "Pending";
  85. return $this->pass ? "Pass" : "Fail";
  86. }
  87. public function assignTester($tester) {
  88. $this->tester_id = $tester->id;
  89. $this->dts_assigned = Util::getDateTime();
  90. $success = $this->commit();
  91. // TODO: Notify tester
  92. return $success;
  93. }
  94. }
  95. ?>