project.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. class Project extends Model {
  3. protected static $table = "project";
  4. protected static $id_field = "id";
  5. protected static $fillable_fields = ["customer_id", "template_id", "name", "test_count", "min_age", "max_age", "default_tester_fee", "time_of_day", "dts_start", "dts_deadline", "dts_created", "dts_updated", "dts_report"];
  6. protected static $field_map = [
  7. ];
  8. // Object methods
  9. public function getCustomer() {
  10. return Customer::get($this->customer_id);
  11. }
  12. public function getTests() {
  13. $nvp = [];
  14. $nvp["project_id"] = $this->id;
  15. $nvp["status"] = (new Constraint("MORE_THAN"))->setValues(Test::STATUS_CANCELLED);
  16. return Test::query($nvp);
  17. }
  18. public function getLocations() {
  19. $tests = $this->getTests();
  20. return Location::query(["id" => array_column($tests, "location_id")]);
  21. }
  22. public function getDisplayAgeRange() {
  23. if($this->min_age && $this->max_age) {
  24. return $this->min_age . " to " . $this->max_age;
  25. }
  26. else if($this->min_age) {
  27. return "At least " . $this->min_age;
  28. }
  29. else if($this->max_age) {
  30. return "Up to " . $this->max_age;
  31. }
  32. return "No age restriction";
  33. }
  34. public function getCompletedPercentage() {
  35. $test_count = $this->test_count;
  36. $tests = $this->getTests();
  37. $completed_tests = array_filter($tests, function($test) {
  38. return $test->status == Test::STATUS_COMPLETED;
  39. });
  40. $completed_test_count = count($completed_tests);
  41. return floor(($completed_test_count / $test_count) * 100);
  42. }
  43. public function getTemplate() {
  44. return Template::get($this->template_id);
  45. }
  46. public function getTimeOfDayText() {
  47. switch($this->time_of_day) {
  48. case "A": return "Anytime";
  49. case "D": return "Daytime";
  50. case "N": return "Nighttime";
  51. }
  52. }
  53. public function getTimeOfDayIcon() {
  54. switch($this->time_of_day) {
  55. case "A": return "adjust";
  56. case "D": return "sun";
  57. case "N": return "moon";
  58. }
  59. }
  60. }
  61. ?>