From 40a84c1da706812323839a488004d0b2cd21162d Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Fri, 15 Apr 2022 20:55:14 +0200
Subject: [PATCH] year

---
 .../extranet/academic_years_controller.rb            |  2 ++
 app/models/education/academic_year.rb                |  4 ++--
 app/views/extranet/academic_years/show.html.erb      | 12 ++++++------
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/app/controllers/extranet/academic_years_controller.rb b/app/controllers/extranet/academic_years_controller.rb
index bdae2dcb1..ae8af0b8c 100644
--- a/app/controllers/extranet/academic_years_controller.rb
+++ b/app/controllers/extranet/academic_years_controller.rb
@@ -9,6 +9,8 @@ class Extranet::AcademicYearsController < Extranet::ApplicationController
   end
 
   def show
+    @cohorts = @academic_year.cohorts_in_context(current_context.about)
+    @alumni = @academic_year.alumni_in_context(current_context.about)
     breadcrumb
   end
 
diff --git a/app/models/education/academic_year.rb b/app/models/education/academic_year.rb
index 2921bc3be..42878678e 100644
--- a/app/models/education/academic_year.rb
+++ b/app/models/education/academic_year.rb
@@ -29,12 +29,12 @@ class Education::AcademicYear < ApplicationRecord
 
   def cohorts_in_context(context)
     return cohorts if context.nil? || !context.respond_to?(:cohorts)
-    cohorts & context.cohorts
+    cohorts.where(id: context.cohorts.pluck(:id))
   end
 
   def alumni_in_context(context)
     return alumni if context.nil? || !context.respond_to?(:alumni)
-    people & context.alumni
+    people.where(id: context.alumni.pluck(:id))
   end
 
   def to_s
diff --git a/app/views/extranet/academic_years/show.html.erb b/app/views/extranet/academic_years/show.html.erb
index b4db00980..ffc0c7668 100644
--- a/app/views/extranet/academic_years/show.html.erb
+++ b/app/views/extranet/academic_years/show.html.erb
@@ -5,13 +5,13 @@
 </header>
 
 <h2 class="mb-4">
-  <%= @academic_year.cohorts.count %>
-  <%= Education::Cohort.model_name.human(count: @academic_year.cohorts.count).downcase %>
+  <%= @cohorts.count %>
+  <%= Education::Cohort.model_name.human(count: @cohorts.count).downcase %>
 </h2>
-<%= render 'extranet/cohorts/list', cohorts: @academic_year.cohorts %>
+<%= render 'extranet/cohorts/list', cohorts: @cohorts %>
 
 <h2 class="mt-5 mb-4">
-  <%= @academic_year.people.count %>
-  <%= University::Person::Alumnus.model_name.human(count: @academic_year.people.count).downcase %>
+  <%= @alumni.count %>
+  <%= University::Person::Alumnus.model_name.human(count: @alumni.count).downcase %>
 </h2>
-<%= render 'extranet/persons/list', people: @academic_year.people %>
+<%= render 'extranet/persons/list', people: @alumni %>
-- 
GitLab