From 1f3aa0412fef7e63d31d0e94eaef4661cd98e8a1 Mon Sep 17 00:00:00 2001
From: Myriam Delaruelle
 <Myriam Delaruelle@bdn-un-mdelarue.ad.univ-lorraine.fr>
Date: Mon, 8 Nov 2021 10:27:28 +0100
Subject: [PATCH] Fix css student progress, section progress and added two
 filtering options for the array

---
 entity/course_format_iena_completion.php |  6 ++++--
 format.php                               |  1 +
 renderer.php                             | 11 ++++++++++-
 styles.css                               |  9 ++++++++-
 templates/section.mustache               |  3 +++
 5 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/entity/course_format_iena_completion.php b/entity/course_format_iena_completion.php
index 25f5944..9df7969 100644
--- a/entity/course_format_iena_completion.php
+++ b/entity/course_format_iena_completion.php
@@ -34,7 +34,7 @@ class course_format_iena_completion {
 	 * @return type
 	 */
 	public static function get_completion_by_section($section_names, $idSection) {
-
+	
 		global $COURSE, $USER, $DB, $CFG;
 
 		$completion = new \completion_info($COURSE);
@@ -94,7 +94,9 @@ class course_format_iena_completion {
 			$total_modules += count($inner_modules);
 			array_push($sections, $section);
 		}
-
+		if($total_modules==0){
+			return false;
+		}
 		$progress = new StdClass();
 		$progress->total = number_format( 100 * $total_completed / $total_modules, 0);
 		$progress->sections = $sections;
diff --git a/format.php b/format.php
index 3b82b05..1f0c833 100644
--- a/format.php
+++ b/format.php
@@ -31,6 +31,7 @@
 	require_once($CFG->libdir . '/completionlib.php');
 	require_once('entity/course_format_iena_section_ressources.php');
 	require_once('entity/course_format_iena_sections.php');
+	require_once('entity/course_format_iena_completion.php');
 	require_once('entity/course_format_iena_cron_action.php');
 	require_once('entity/course_format_iena_groups.php');
 	require_once('entity/course_format_iena_attendance.php');
diff --git a/renderer.php b/renderer.php
index 6e3b78c..c33830e 100644
--- a/renderer.php
+++ b/renderer.php
@@ -142,7 +142,7 @@ class format_iena_renderer extends format_topics_renderer{
 	protected function get_section_header($section, $course, $onsectionpage, $mods, $sectionreturn = null, $iena = false, $groups=false){
 		
 		global $PAGE, $CFG, $COURSE, $USER;
-		$section_entity = new course_format_iena_sections();
+		$completion_entity = new course_format_iena_completion();
 		$o = '';
 		$currenttext = '';
 		$sectionstyle = '';
@@ -243,6 +243,15 @@ class format_iena_renderer extends format_topics_renderer{
 			}
 			
 			
+		}
+		else{
+			//On va chercher la progression pour la section
+			$section_progress=$completion_entity->get_completion_by_section([$section->name], [$section->id]);
+			if($section_progress){
+				$section->section_progress=$section_progress->total;	
+			}
+			
+			
 		}
 		
 	
diff --git a/styles.css b/styles.css
index 00722a3..e234da9 100644
--- a/styles.css
+++ b/styles.css
@@ -224,6 +224,12 @@ ul.nav.navbar-nav.ml-auto {
     font-weight: 400;
 }
 
+.label_item.sect-date.prog{
+	background-color:#40aca3;
+	font-weight: bold;
+	color: white;
+}
+
 .iena-description {
 	background: #EEE;
 	color: #323232;
@@ -695,6 +701,7 @@ th.th-rotate > div > span {
 
 .section-progress span.icon-progress::after, .iena-progress-legend span.icon-progress::after{
 	font-size: small;
+	line-height: 1rem!important;
 }
 
 
@@ -826,7 +833,7 @@ tbody th{
 }
 
 #caption-iena .icon-progress::after{
-	line-height: 24px;
+	
 }
 
 .iena-icon-distance, .iena-icon-presence{
diff --git a/templates/section.mustache b/templates/section.mustache
index c8109e8..bd3717d 100644
--- a/templates/section.mustache
+++ b/templates/section.mustache
@@ -35,6 +35,9 @@
 
 					</a>
 				{{/link_suivi}}
+				{{#section_progress}}
+					<div class="label_item sect-date prog" >{{section_progress}}%</div>
+				{{/section_progress}}
 				
 
 			</div>
-- 
GitLab