Преглед изворни кода

Count only finished projects when logged in as customer

Alan Lam пре 7 година
родитељ
комит
edb4c38dfc
3 измењених фајлова са 13 додато и 3 уклоњено
  1. 1 1
      controllers/account.php
  2. 4 2
      controllers/reports.php
  3. 8 0
      engine/customer.php

+ 1 - 1
controllers/account.php

@@ -30,7 +30,7 @@ if($user->isCustomer()) {
 		$dt = new DateTime($start);
 		$year_cycle_start_text = $dt->format("jS M");
 
-		$projects = $customer->getProjects();
+		$projects = $customer->getFinishedProjects();
 		$project_ids = array_column($projects, "id");
 
 		$tests = Test::query([

+ 4 - 2
controllers/reports.php

@@ -51,7 +51,7 @@ $all_projects = Project::query([
 if(Core::$user->isCustomer()) {
 	// Filter to only projects that have past the deadline
 	$all_projects = array_filter($all_projects, function(Project $project) {
-		return $project->isPastDeadline();
+		return $project->isFinished();
 	});
 }
 
@@ -60,6 +60,8 @@ foreach($all_projects as $p) {
 	$project_table_data[] = $p->getDataTableRow();
 }
 
+$all_project_ids = array_column($all_projects, "id");
+
 $data = [];
 $region_data = [];
 $area_manager_data = [];
@@ -83,7 +85,7 @@ if($submit) {
 			"id" => (new Constraint("NOT_IN"))->setValues(...$exclude_project_ids)
 		]);
 
-		$project_ids = array_column($projects, "id");
+		$project_ids = array_intersect($all_project_ids, array_column($projects, "id"));
 
 		// Enforce unique template ID in selection
 		$template_ids = array_unique(array_column($projects, "template_id"));

+ 8 - 0
engine/customer.php

@@ -88,6 +88,14 @@ class Customer extends Model {
 		return Project::query(["customer_id" => $this->id], ["sort" => "dts_deadline", "order" => "desc"]);
 	}
 
+	public function getFinishedProjects() {
+		$projects = array_filter($this->getProjects(), function(Project $p) {
+			return $p->isFinished();
+		});
+
+		return array_values($projects);
+	}
+
 	/**
 	 * @return Template[]
 	 * @throws Exception