project.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. $links = ProjectLocation::query(["project_id" => $this->id]);
  20. return Location::query(["id" => array_column($links, "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. }
  47. ?>