| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?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", "time_of_day", "tester_can_claim", "dts_start", "dts_deadline", "dts_created", "dts_updated", "dts_report"];
- 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() {
- $tests = $this->getTests();
- return Location::query(["id" => array_column($tests, "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);
- }
- public function getTimeOfDayText() {
- switch($this->time_of_day) {
- case "A": return "Anytime";
- case "D": return "Daytime";
- case "N": return "Nighttime";
- }
- }
- public function getTimeOfDayIcon() {
- switch($this->time_of_day) {
- case "A": return "adjust";
- case "D": return "sun";
- case "N": return "moon";
- }
- }
- }
- ?>
|