|
|
@@ -30,8 +30,10 @@ class Project extends Model {
|
|
|
protected static $id_field = "id";
|
|
|
protected static $fillable_fields = ["customer_id", "template_id", "name", "test_count", "min_age", "max_age", "default_customer_fee", "default_tester_fee", "time_of_day", "tester_can_claim", "template_overrides_json", "dts_start", "dts_deadline", "dts_created", "dts_updated", "dts_report", "dts_finished", "user_id_finished"];
|
|
|
|
|
|
- protected static $field_map = [
|
|
|
- ];
|
|
|
+ /**
|
|
|
+ * @var Test[] $tests
|
|
|
+ */
|
|
|
+ protected $tests = null;
|
|
|
|
|
|
// Object methods
|
|
|
/**
|
|
|
@@ -46,11 +48,50 @@ class Project extends Model {
|
|
|
*/
|
|
|
public function getTests() {
|
|
|
|
|
|
+ if(!is_null($this->tests)) return $this->tests;
|
|
|
+
|
|
|
$nvp = [];
|
|
|
$nvp["project_id"] = $this->id;
|
|
|
$nvp["status"] = (new Constraint("MORE_THAN"))->setValues(Test::STATUS_CANCELLED);
|
|
|
|
|
|
- return Test::query($nvp);
|
|
|
+ $this->tests = Test::query($nvp);
|
|
|
+
|
|
|
+ return $this->tests;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getTestCount() {
|
|
|
+ if(is_null($this->tests)) $this->getTests();
|
|
|
+ return count($this->tests);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getPassCount() {
|
|
|
+ $count = 0;
|
|
|
+ $tests = $this->getTests();
|
|
|
+ foreach($tests as $test) {
|
|
|
+ if(!$test->isPass()) continue;
|
|
|
+ ++$count;
|
|
|
+ }
|
|
|
+ return $count;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getFailCount() {
|
|
|
+ $count = 0;
|
|
|
+ $tests = $this->getTests();
|
|
|
+ foreach($tests as $test) {
|
|
|
+ if(!$test->isFail()) continue;
|
|
|
+ ++$count;
|
|
|
+ }
|
|
|
+ return $count;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getPendingCount() {
|
|
|
+ $count = 0;
|
|
|
+ $tests = $this->getTests();
|
|
|
+ foreach($tests as $test) {
|
|
|
+ if(!$test->isPending()) continue;
|
|
|
+ ++$count;
|
|
|
+ }
|
|
|
+ return $count;
|
|
|
}
|
|
|
|
|
|
public function getLocations() {
|
|
|
@@ -148,6 +189,10 @@ class Project extends Model {
|
|
|
return time() > $deadline_unix;
|
|
|
}
|
|
|
|
|
|
+ public function isFinished() {
|
|
|
+ return $this->dts_finished === null;
|
|
|
+ }
|
|
|
+
|
|
|
public function markFinished() {
|
|
|
|
|
|
if(!Core::$user) throw new Exception("Trying to mark project as finished while not logged in.");
|
|
|
@@ -191,4 +236,11 @@ class Project extends Model {
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ public function getTestResultsUrl(): string {
|
|
|
+ $customer = $this->getCustomer();
|
|
|
+ $customer_slug = Util::slugWithId($customer->name, $customer->id);
|
|
|
+ $project_slug = Util::slugWithId($this->name, $this->id);
|
|
|
+ return "/account/test-results/{$customer_slug}/{$project_slug}";
|
|
|
+ }
|
|
|
+
|
|
|
}
|