| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <?php
- class Test extends Model {
- protected static $table = "test";
- protected static $id_field = "id";
- 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_updated", "dts_assigned", "dts_verified"];
- protected static $field_map = [
- ];
- // 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;
- const STATUSES = [
- 0 => "Cancelled",
- 1 => "Unassigned",
- 2 => "Assigned",
- 3 => "Confirmed",
- 4 => "Started",
- 8 => "Pending Verification",
- 16 => "Completed",
- ];
- const STAGES = [
- 0 => "",
- 1 => "Challenge on entry",
- 2 => "Challenge while browsing",
- 3 => "Challenge during play",
- 4 => "Challenge on exit",
- 5 => "No challenge",
- ];
- const TEST_TIME_ANYTIME = 1;
- const TEST_TIME_DAY = 2;
- const TEST_TIME_NIGHT = 3;
- // Object methods
- public function sendAssignEmail($message) {
- $tester = $this->getTester();
- $location = $this->getLocation();
- $tester_message = "";
- if($message) {
- $tester_message = Email::getTextCellHtml($message);
- }
- $date_due = date("j M Y", strtotime($this->dts_due));
- $mail = new Email();
- $mail->loadHtmlTemplate("test_assign");
- $mail->setValues([
- "name" => $tester->first_name,
- "tester-message" => $tester_message,
- "test-url" => PROTOCOL . "://" . DOMAIN . "/account/tests/" . $this->id,
- "address" => $location->name . ", " . $location->getDisplayAddress(["address_1", "address_2", "city", "county", "postal_code"]),
- "date-due" => $date_due,
- "admin-first-name" => Core::$user->first_name,
- "admin-phone" => Core::$user->phone
- ]);
- $mail->setFrom(EMAIL_CONTACT, EMAIL_FROM_NAME);
- $mail->addAddress($tester->email, $tester->getDisplayName());
- $mail->setSubject("You have been allocated a test");
- $mail->send();
- }
- public function getChallengeStageText() {
- return Test::STAGES[$this->challenge_stage];
- }
- public function getStatusText() {
- return Test::STATUSES[$this->status];
- }
- public function getStatusClass() {
- switch($this->status) {
- case Test::STATUS_CANCELLED:
- return "secondary";
- case Test::STATUS_UNASSIGNED:
- return "danger";
- case Test::STATUS_ASSIGNED:
- case Test::STATUS_CONFIRMED:
- case Test::STATUS_STARTED:
- return "warning";
- case Test::STATUS_PENDING_VERIFICATION:
- return "primary";
- case Test::STATUS_COMPLETED:
- return "success";
- }
- }
- public function getProject() {
- return Project::get($this->project_id);
- }
- public function getLocation() {
- return Location::get($this->location_id);
- }
- public function getTester() {
- return User::get($this->tester_id);
- }
- public function getVerifier() {
- return User::get($this->verifier_id);
- }
- public function getValues($as_assoc_array = false) {
- $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);
- }
- else {
- $values = $rows;
- }
- return $values;
- }
- public function getDirectory() {
- $directory = ROOT_DIR . "/files/tests/" . $this->id;
- if(!file_exists($directory)) mkdir($directory, 0777, true);
- return $directory;
- }
- public function getDuration() {
- if(is_null($this->dts_end)) return false;
- $seconds = Util::getDurationFromDTS($this->dts_start, $this->dts_end);
- return $seconds;
- }
- public function getDisplayDuration() {
- $secs = $this->getDuration();
- $mins = floor($secs / 60);
- $secs = $secs % 60;
- return "$mins min. $secs sec.";
- }
- public function getPassClass() {
- if(is_null($this->pass)) return "secondary";
- return $this->pass ? "success" : "danger";
- }
- public function getPassIcon() {
- if(is_null($this->pass)) return "clock";
- return $this->pass ? "check-circle" : "times-circle";
- }
- public function getPassText() {
- if(is_null($this->pass)) return "Pending";
- return $this->pass ? "Pass" : "Fail";
- }
- public function assignTester($tester) {
- $this->tester_id = $tester->id;
- $this->dts_assigned = Util::getDateTime();
- $success = $this->commit();
- // TODO: Notify tester
- return $success;
- }
- }
- ?>
|