| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- class Project extends Model {
- protected static $table = "project";
- protected static $id_field = "id";
- protected static $fillable_fields = ["customer_id", "template_id", "name", "test_count", "min_age", "max_age", "default_tester_fee", "dts_start", "dts_deadline", "dts_created", "dts_updated"];
- protected static $field_map = [
- ];
- // Object methods
- public function getCustomer() {
- return Customer::get($this->customer_id);
- }
- public function getTests() {
- $nvp = [];
- $nvp["project_id"] = $this->id;
- $nvp["status"] = (new Constraint("MORE_THAN"))->setValues(Test::STATUS_CANCELLED);
- return Test::query($nvp);
- }
- public function getLocations() {
- $links = ProjectLocation::query(["project_id" => $this->id]);
- return Location::query(["id" => array_column($links, "location_id")]);
- }
- public function getDisplayAgeRange() {
- if($this->min_age && $this->max_age) {
- return $this->min_age . " to " . $this->max_age;
- }
- else if($this->min_age) {
- return "At least " . $this->min_age;
- }
- else if($this->max_age) {
- return "Up to " . $this->max_age;
- }
- return "No age restriction";
- }
- public function getCompletedPercentage() {
- $test_count = $this->test_count;
- $tests = $this->getTests();
- $completed_tests = array_filter($tests, function($test) {
- return $test->status == Test::STATUS_COMPLETED;
- });
- $completed_test_count = count($completed_tests);
- return floor(($completed_test_count / $test_count) * 100);
- }
- public function getTemplate() {
- return Template::get($this->template_id);
- }
- }
- ?>
|