Commit 2c9cb038 authored by Myriam Delaruelle's avatar Myriam Delaruelle
Browse files

Optimisation - display button won't fetch completion from db anymore

parent 6ea159c1
......@@ -29,8 +29,8 @@ class course_format_iena_completion {
/**
* Get completion by sections
* @param type $section_names
* @param type $idSection
* @param array $section_names
* @param array $idSection
* @return type
*/
public static function get_completion_by_section($section_names, $idSection) {
......@@ -49,6 +49,7 @@ class course_format_iena_completion {
$modinfos_cms = $fast_modinfo->get_cms();
$modules = [];
//Il récupère les modules qui ne sont pas en cours de suppression, qui ont l'achèvement d'activité, et qui sont visibles pour l'user
foreach ($modinfos_cms as $cm) {
$module = $completion->get_data($cm, true, $USER->id, $fast_modinfo);
$module->url = "$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id";
......
......@@ -124,21 +124,6 @@
AND visibleoncoursepage = 1
AND completion != 0', array($id_section));
}
// if ($course->restrictedbreadcrum == 1) {
// // ne requête que les sections qui possèdent des activités suivies dans le suivi de progression pour la barre de progression
// $requete = $DB->get_records_sql('SELECT cm.id FROM {course_modules} as cm
// INNER JOIN {format_iena_settings} as iena on cm.id = iena.cmid
// WHERE cm.section = ?
// AND cm.visible = 1
// AND iena.hide = 1
// AND cm.deletioninprogress = 0
// AND cm.completion != 0', array($id_section));
// } else {
// $requete = $DB->get_records_sql('SELECT id FROM {course_modules} WHERE section = ? AND deletioninprogress = 0
// AND visible = 1
// AND completion != 0', array($id_section));
// }
$ressources = array();
$i = 0;
......
......@@ -131,16 +131,16 @@ class format_iena_renderer extends format_topics_renderer{
/**
* Add style attributes, classes (useless?), format section summary and add the hidden/restricted message
* @param type $section
* @param type $course
* @param type $onsectionpage
* @param StdClass $section
* @param StdClass $course
* @param bool $onsectionpage
* @param type|null $sectionreturn
* @param type|bool $iena
* @param type $groups
* @return type
*/
protected function get_section_header($section, $course, $onsectionpage, $sectionreturn = null, $iena = false, $groups=false){
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();
$o = '';
......@@ -218,13 +218,20 @@ class format_iena_renderer extends format_topics_renderer{
} else {
$section->date = "";
}
//Bouton de suivi dans chaque section : si pas d'activités suivies on n'affiche pas le bouton
if (has_capability('course/iena:suivi', $context = context_course::instance($COURSE->id), $USER->id)) {
$ressources_entity = new course_format_iena_section_ressources();
$modules = $ressources_entity->get_ressources_completion_on_by_id_section($section->id);
$nb_modules = count($modules);
if($nb_modules>0){
//$modules = $ressources_entity->get_ressources_completion_on_by_id_section($section->id);
$display_button=false;
foreach ($mods->get_cms() as $cm) {
if($cm->completion>0 && $cm->section==$section->id){
$display_button=true;
break;
}
}
//$nb_modules = count($modules);
if($display_button){
//si trop d'étudiants on va afficher le premier groupe dans le suivi
if($this->count_students($context)>299 && count($groups)>0){
$section->link_suivi = $CFG->wwwroot . "/course/format/iena/suivi_unit.php?courseid=" . $COURSE->id . "&sectionid=" . $section->id . "&groupid=".reset($groups)->id;
......@@ -238,8 +245,7 @@ class format_iena_renderer extends format_topics_renderer{
}
return $section;
}
......@@ -746,7 +752,7 @@ class format_iena_renderer extends format_topics_renderer{
continue;
}
if (!$thissection->available && !empty($thissection->availableinfo)) {
$thissection= $this->get_section_header($thissection, $course, false, 0, $groups);
$thissection= $this->get_section_header($thissection, $course, false,$modinfo, 0, $groups);
continue;
}
......@@ -756,7 +762,7 @@ class format_iena_renderer extends format_topics_renderer{
continue;
}
}
$thissection=$this->get_section_header($thissection, $course, false, 0, true, $groups);
$thissection=$this->get_section_header($thissection, $course, false, $modinfo,0, true, $groups);
if ($thissection->uservisible) {
$thissection->resources= $this->courserenderer->course_section_cm_list($course, $thissection, 0);
......@@ -778,6 +784,7 @@ class format_iena_renderer extends format_topics_renderer{
if($editing){
$sections['link_add_sections']=new moodle_url('/course/changenumsections.php', ['courseid' => $course->id, 'insertsection' => 0, 'increase' => false, 'sesskey' => sesskey(), 'sectionreturn' => 0]);
}
echo $this->get_view_iena_new($course, $nameSections, $idSections);
echo $this->render_from_template('format_iena/sections', $sections);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment