-
Myriam Delaruelle authoredMyriam Delaruelle authored
renderer.php 25.97 KiB
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* format_iena
*
* @package format_iena
* @category format
* @copyright 2018 Softia/Université lorraine
* @author vrignaud camille/Thomas Fradet
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/course/format/topics/renderer.php');
require_once($CFG->dirroot . '/course/format/iena/view/view_course_header.php');
/**
* format_iena_renderer
*
* @package format_iena
* @category format
* @copyright 2018 Softia/Université lorraine
* @author vrignaud camille
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class format_iena_renderer extends format_topics_renderer{
/**
* start_section_list
*
* @return string
*/
//bientôt useless
protected function start_section_list()
{
return html_writer::start_tag('ul', ['class' => 'iena-editing']);
}
/**
* section_header
*
* @param stdclass $section
* @param stdclass $course
* @param bool $onsectionpage
* @param int $sectionreturn
* @return string
*/
//Bientôt useless
protected function section_header($section, $course, $onsectionpage, $sectionreturn = null, $iena = false){
global $PAGE, $CFG;
$o = '';
$currenttext = '';
$sectionstyle = '';
if ($section->section != 0) {
if (!$section->visible) {
$sectionstyle = ' hidden';
} elseif (course_get_format($course)->is_section_current($section)) {
$sectionstyle = ' current';
}
}
if ($PAGE->user_is_editing()) {
$o .= html_writer::start_tag('li', ['id' => 'section-' . $section->section,
'class' => 'section main clearfix' . $sectionstyle,
'role' => 'region', 'aria-label' => get_section_name($course, $section)]);
}
$o .= html_writer::tag('span', $this->section_title($section, $course), ['class' => 'hidden sectionname']);
//This is were the editing menu is generated
if ($PAGE->user_is_editing()) {
$leftcontent = $this->section_left_content($section, $course, $onsectionpage);
$o .= html_writer::tag('div', $leftcontent, ['class' => 'left side']);
$rightcontent = $this->section_right_content($section, $course, $onsectionpage);
$o .= html_writer::tag('div', $rightcontent, ['class' => 'right side']);
}
$hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));
$hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));
$classes = ' accesshide';
if ($hasnamenotsecpg || $hasnamesecpg) {
$classes = '';
}
$sectionname = html_writer::tag('span', $this->section_title($section, $course));
if ($PAGE->user_is_editing()) {
$o .= $this->output->heading($sectionname, 3, 'sectionname' . $classes);
}
// if ($course->showdefaultsectionname) {
// $o .= $this->output->heading($sectionname, 3, 'sectionname' . $classes);
// }
// if (!$iena) { $o .= $sectionname; }
$context = context_course::instance($course->id);
/* résumé de section */
if ( $section->summary != "" ) {
$o .= html_writer::start_tag('div', ['class' => 'iena-description']);
$o .= html_writer::start_tag('div', ['class' => 'small']);
$o .= html_writer::start_tag('div', ['class' => 'iena-summary']);
$o .= $this->format_summary_text($section);
$o .= html_writer::end_tag('div');
$o .= html_writer::end_tag('div');
$o .= html_writer::end_tag('div');
$o .= html_writer::tag('a', 'Voir la description complète', ['href' => '#', 'class' => 'voir-plus']);
}
$o .= $this->section_availability_message($section, has_capability('moodle/course:viewhiddensections', $context));
return $o;
}
/**
* Add style attributes, classes (useless?), format section summary and add the hidden/restricted message
* @param type $section
* @param type $course
* @param type $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){
global $PAGE, $CFG, $COURSE, $USER;
$section_entity = new course_format_iena_sections();
$o = '';
$currenttext = '';
$sectionstyle = '';
if ($section->section != 0) {
if (!$section->visible) {
$section->sectionstyle = ' hidden';
} elseif (course_get_format($course)->is_section_current($section)) {
$section->sectionstyle = ' current';
}
}
$section->edit=$this->section_title_without_link($section, $course);
$hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));
$hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));
$section->classes = ' accesshide';
if ($hasnamenotsecpg || $hasnamesecpg) {
$section->classes = '';
}
$section->sectionname = get_section_name($course, $section);
$context = context_course::instance($course->id);
if($section->summary != ""){
$section->summary=$this->format_summary_text($section);
}
$section->messageavailability= $this->section_availability_message($section, has_capability('moodle/course:viewhiddensections', $context));
/* Paramètres */
$presence = "";
$format = course_get_format($course);
$param_section = (object)$format->get_format_options($section);
if ($param_section !== false) {
if (isset($param_section->presence)) {
if ($param_section->presence == 1) {
$section->presence = "En présence";
$string_date_presence="Le ";
} else if ($param_section->presence == 2) {
$section->presence = "À distance";
$string_date_presence="Pour le ";
}
}
if (isset($param_section->daterendu) && $param_section->daterendu != 0) {
$section->date=date("j/m H:i", $param_section->daterendu);
$section->date_jour = date("j/m", $param_section->daterendu);
$section->date_heure = date("H:i", $param_section->daterendu);
/*$section->dateUp = new DateTime("@$param_section->daterendu");
$section->date = $section->dateUp->format("j/m H:i");
$section->date_jour = $section->dateUp->format("j/m");
$section->date_heure = $section->dateUp->format("H:i");
$section->dateUp = $section->dateUp->getTimestamp();*/
if($string_date_presence){
$section->string_date=$string_date_presence.$section->date_jour." à ".$section->date_heure;
}
else{
$section->string_date="Le ".$section->date_jour." à ".$section->date_heure;
}
} else {
$section->date = "";
}
} 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){
//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 . "§ionid=" . $section->id . "&groupid=".reset($groups)->id;
}
else{
$section->link_suivi = $CFG->wwwroot . "/course/format/iena/suivi_unit.php?courseid=" . $COURSE->id . "§ionid=" . $section->id . "&groupid=0";
}
}
}
return $section;
}
//useless
/*public function get_completion_by_section($idSection){
global $COURSE, $USER;
$ressources_entity = new course_format_iena_section_ressources();
$section_entity = new course_format_iena_sections();
$modules = $ressources_entity->get_ressources_completion_on_by_id_section($idSection);
$nb_modules = count($modules);
if ($nb_modules == 0) {
return array($nb_modules, 999);
}
$valueI = 100 / $nb_modules;
$valueTotal = 0;
foreach ($modules as $module) {
$complet = $ressources_entity->get_completions_by_module($USER->id, $COURSE->id, $module->id);
if ($complet->completionstate != 0) {
$valueTotal += $valueI;
}
}
return array($modules, $valueTotal);
}*/
//Bientôt useless
public function get_view_iena($course, $htmlsection, $nameSection, $introSection, $idSection){
global $CFG, $COURSE, $USER;
$section_entity = new course_format_iena_sections();
// nouvelle génération du header
$view = "";
require_once($CFG->dirroot . '/course/format/iena/entity/course_format_iena_completion.php');
// return false if completion disabled (site or course)
$cpl = course_format_iena_completion::get_completion_by_section($nameSection, $idSection);
/* Passer le calcul de complétion de la classe course_format_iena_completion à part à la vue qui fait le header permet de ne pas récupérer deux fois les mêmes informations. */
$header = new view_course_header($nameSection, $idSection, $course, $cpl);
$view .= $header->get_content();
$i = 0;
$link = $CFG->wwwroot . "/course/format/iena/suivi_unit.php?courseid=" . $COURSE->id;
$view .= "<!-- <script defer src=\"https://use.fontawesome.com/releases/v5.0.8/js/all.js\"></script> -->
<style>
/*
style for clean page
*/
/* [BOOST] : course header */
#page-header .card {
border: none;
}
#page-header .card-body {
padding-left: 0;
}
/* [BOOST] : left nav */
#nav-drawer,
[data-region='drawer'] {
background-color: #fff;
}
#nav-drawer .list-group-item {
border: 1px solid #ffffff;
}
#nav-drawer .list-group-item:hover {
background-color: #e7e9ea;
}
#nav-drawer .list-group-item.active:hover {
color: #000000;
}
/* [BOOST] : blocks */
#block-region-side-pre section.block {
border: none;
}
#block-region-side-pre section.block .card-body {
padding-top: 0;
}
/* [BOOST] : margin for ul, because ul is used to list sections */
ul, ul ul {
padding-left: 2.5rem;
margin-bottom: 0.5rem !important;
}
/* style for ? */
#completionprogressid {
display: none;
}
#region-main > .card {
border: none;
overflow-x: visible !important;
overflow-y: visible;
}
#region-main > .card > .card-body {
border: none;
padding: 0;
}
.centered {
display:flex;justify-content:center;align-items:center;
}
.contenu {
min-width: 15rem;
}
ul.bulle {
list-style: none;
padding:5%;
}
.bulle {
list-style: none;
}
.bulle > li {
list-style: none;
font-weight: normal;
font-size: 0.8rem;
line-height: 1rem;
padding-top: 5%;
}
</style>";
foreach ($htmlsection as $section) {
$presence = "";
if (!$section) {
continue;
}
$param_section = $section_entity->get_section_settings_by_id_section($idSection[$i]);
// dates, modality and notification section parameters : false if not set.
if ($param_section !== false) {
if ($param_section->presence && $i != 0) {
if ($param_section->presence == 1) {
$presence = "En présence";
} else if ($param_section->presence == 2) {
$presence = "A distance";
}
}
if ($param_section->date_rendu) {
$dateUp = date_create($param_section->date_rendu);
$date = $dateUp->format("j/m H:i");
$date_jour = $dateUp->format("j/m");
$date_heure = $dateUp->format("H:i");
$dateUp = $dateUp->getTimestamp();
} else {
$date = "";
}
} else {
$date = "";
}
$titre = $nameSection[$i];
$sectionIntro = $introSection[$i];
//If section is hidden continue
if ($titre == null && !(has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id))) {
$i++;
continue;
}
$view .= "<section class=\"section iena-section\" id=\"section-$i\">
<div class=\"card card_block\">
<div class=\"heading-iena set_height\">";
if ( $cpl != false && count($cpl->sections[$i]->modules) > 0 && !has_capability('course/iena:suivi', $context = context_course::instance($COURSE->id), $USER->id)) {
$view .= "<div class='iena-percent set_height'>" . $cpl->sections[$i]->completion . "%</div>";
}
if (has_capability('course/iena:suivi', $context = context_course::instance($COURSE->id), $USER->id) && $i != 0) {
$course_groups = groups_get_all_groups($COURSE->id);
$group_indicateur = 0;
$view .= "<a href='$link§ionid=".$idSection[$i]."style='color : white'>";
$view .="<div onclick='change_grouplink(this)' style='display:block' class='nb_pers set_height id_groupe0'>";
$view .= "Suivi étudiants";
$view .= "</div>";
$view .="</a>";
}
$view .= "<div class=\"titre_section set_height\">
<p>$titre</p>
</div>
<div class=\"right_info\">
";
// if ($presence) {
// $view .= "
// <div class=\"label_item\">
// $presence
// </div>";
// }
if ($date) {
$link_date = $CFG->wwwroot . "/calendar/view.php?view=month&time=" . $dateUp . "&course=" . $COURSE->id;
if ($presence && $presence == "A distance") {
$view .= "
<div class=\"label_item sect-date\">
À distance
</div>
<div class=\"label_item sect-date\">
Pour le $date_jour à $date_heure
</div>";
} else if ($presence && $presence == "En présence") {
$view .= "
<div class=\"label_item sect-date\">
En présence
</div>
<div class=\"label_item sect-date\">
Le $date_jour à $date_heure
</div>";
} else {
$view .= "
<div class=\"label_item sect-date\">
Le $date_jour à $date_heure
</div>";
}
} else {
if ($presence && $presence == "A distance") {
$view .= "
<div class=\"label_item sect-date\">
À distance
</div>";
} else if ($presence && $presence == "En présence") {
$view .= "
<div class=\"label_item sect-date\">
En présence
</div>";
}
}
$cpt = "";
if ($cpt != "") {
$view .= "
<div class=\"titre_section set_height\">
";
$view .= $cpt;
$view .= "</div>
";
}
$link_param = $CFG->wwwroot . "/course/format/iena/param_section.php?courseid=" . $COURSE->id . "§ionid=" . $idSection[$i];
if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id) && $i != 0) {
$view .= "<div class=\"titre_section set_height\">
<a href='$link_param' style=\"color : white\">
<i class=\"fa fa-cog \" aria-hidden=\"true\" ></i>
</a>
</div>";
}
$view .= "</div>
</div>
";
$view .= "<div class=\"wrapper section\">";
$view .= $sectionIntro;
$view .= "<div class=\"wrapper\">
$section
</div >
</div>
</section>";
$i++;
}
return $view;
}
/**
* Render le template du header avec les infos nécessaires : le progrès
* @param StdObject $course
* @param array<string> $nameSections
* @param array<int> $idSections
* @return type
*/
public function get_view_iena_new($course,$nameSections, $idSections){
global $CFG, $COURSE, $USER;
$section_entity = new course_format_iena_sections();
require_once($CFG->dirroot . '/course/format/iena/entity/course_format_iena_completion.php');
// return false if completion disabled (site or course)
$cpl = course_format_iena_completion::get_completion_by_section($nameSections, $idSections);
/* Passer le calcul de complétion de la classe course_format_iena_completion à part à la vue qui fait le header permet de ne pas récupérer deux fois les mêmes informations. */
$header = new view_course_header($nameSections, $idSections, $course, $cpl);
$course_infos= $header->create_view($cpl);
//$course_infos=$header->get_data($cpl);
echo $this->render_from_template('format_iena/course-header', $course_infos);
}
public function count_students($context){
$count = count_enrolled_users($context);
return $count;
}
//Seulement en mode édition -
//bientôt useless
public function print_iena_section_pages($course){
global $PAGE, $USER;
$context = context_course::instance($course->id);
$course = course_get_format($course)->get_course();
$completion = new \completion_info($course);
$modinfo = get_fast_modinfo($course);
// $course = course_get_format($course)->get_course();
// $completioninfo = new completion_info($course);
if (isset($_COOKIE['sectionvisible_' . $course->id])) {
$sectionvisible = $_COOKIE['sectionvisible_' . $course->id];
} elseif ($course->marker > 0) {
$sectionvisible = $course->marker;
} else {
$sectionvisible = 1;
}
$htmlsection = false;
$nameSection = [];
$idSection = false;
$introSection = false;
//On récupère toutes les infos des sections
foreach ($modinfo->get_section_info_all() as $section => $thissection) {
//Nom de la section
$htmlsection[$section] = '';
$numsections = course_get_format($course)->get_last_section_number();
// if ($section > $numsections) {
// // if ($section > $course->numsections) {
// // continue;
// }
/* if is not editing verify the rules to display the sections */
if (!$PAGE->user_is_editing() && (!has_capability('moodle/course:viewhiddensections', $context = context_course::instance($course->id), $USER->id))) {
//si la section est cachée
if (isset($course->hiddensections) && !(int)$thissection->visible) {
continue;
}
//si la section n'est pas disponible
if (!$thissection->available && !empty($thissection->availableinfo)) {
$htmlsection[$section] .= $this->section_header($thissection, $course, false, 0);
continue;
}
if (!$thissection->uservisible || !$thissection->visible) {
$htmlsection[$section] .= $this->section_hidden($section, $course->id);
continue;
}
}
//Affiche le nom de la section en mode propre sans lien
$idSection[$section] = $thissection->id;
// $nameSection[$section] .= $this->section_title_without_link($thissection, $course);
$nameSection[$section] = $this->section_title_without_link($thissection, $course);
if ($PAGE->user_is_editing()) {
$htmlsection[$section] .= $this->section_header($thissection, $course, false, 0);
}
$introSection[$section] = $this->section_header($thissection, $course, false, 0, true);
if ($thissection->uservisible) {
/* Ne pas enlever sinon le activity chooser ne fonctionne pas en JS */
$htmlsection[$section] .= "<div class='content'>";
// Renvoie le lien du cours avec icone
$htmlsection[$section] .= $this->courserenderer->course_section_cm_list($course, $thissection, 0);
$htmlsection[$section] .= $this->courserenderer->course_section_add_cm_control($course, $section, 0);
$htmlsection[$section] .= "</div>";
}
/* pas de footer car on ne commence par la structure par une div non fermée et que ce footer ferme par une div */
// $htmlsection[$section] .= $this->section_footer();
} //ENDFOREACH
// echo $completioninfo->display_help_icon();
echo $this->output->heading($this->page_title(), 2, 'accesshide');
echo $this->course_activity_clipboard($course, 0);
echo $this->start_section_list();
//A ce stade on à toutes les activité déja prête en HTML par contre il manque le nom des sections
// Il se trouve dans : $thissection->name
if ($PAGE->user_is_editing()) {
// echo $completioninfo->display_help_icon();
echo $this->output->heading($this->page_title(), 2, 'accesshide');
echo $this->course_activity_clipboard($course, 0);
echo $this->start_section_list();
}
//here all activities are displayed
//If we are in etition mode then we display the "BASE" page Otherwise our model
if (!$PAGE->user_is_editing()) {
echo $this->get_view_iena($course, $htmlsection, $nameSection, $introSection, $idSection);
} else {
foreach ($htmlsection as $current) {
echo $current;
}
}
//At this stage nothing is yet displayed except the icon: Your progress
// if ($course->sectionposition == 1 and isset($htmlsection0)) {
// if ($PAGE->user_is_editing())
// echo html_writer::tag('span', $htmlsection0, ['class' => 'below']);
// }
//Add the + and - at the end of the page to see which part of the code to really keep
if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
foreach ($modinfo->get_section_info_all() as $section => $thissection) {
if ($section <= $numsections or empty($modinfo->sections[$section])) {
continue;
}
echo $this->stealth_section_header($section);
echo $this->courserenderer->course_section_cm_list($course, $thissection, 0);
echo $this->stealth_section_footer();
}
echo $this->end_section_list();
echo html_writer::start_tag('div', ['id' => 'changenumsections', 'class' => 'mdl-right']);
$straddsection = get_string('addsections');
$url = $url = new moodle_url('/course/changenumsections.php', ['courseid' => $course->id, 'insertsection' => 0, 'increase' => false, 'sesskey' => sesskey(), 'sectionreturn' => 0]);
$icon = $this->output->pix_icon('t/switch_plus', $straddsection);
echo html_writer::link($url, $icon . $straddsection, ['class' => 'increase-sections']);
echo html_writer::end_tag('div');
} else {
echo $this->end_section_list();
}
echo html_writer::tag('style', '.course-content ul.iena #section-' . $sectionvisible . ' { display: block; }');
//if (!$PAGE->user_is_editing()) {
//$PAGE->requires->js_init_call('M.format_iena.init', [$course->numsections]);
//}
}
/**
* Fetch the course sections with infos
* @param StdObject $course
* @param bool $onsectionpage
* @return templates
*/
public function get_iena_sections($course, $editing, $onsectionpage=false){
global $PAGE, $USER;
$context = context_course::instance($course->id);
$completion = new \completion_info($course);
$groups=groups_get_all_groups($course->id);
$modinfo = get_fast_modinfo($course);
if (isset($_COOKIE['sectionvisible_' . $course->id])) {
$sectionvisible = $_COOKIE['sectionvisible_' . $course->id];
} elseif ($course->marker > 0) {
$sectionvisible = $course->marker;
} else {
$sectionvisible = 1;
}
$htmlsection = false;
$nameSections = [];
$idSections = [];
$introSection = false;
$sections=['sections'=>[]];
foreach($modinfo->get_section_info_all() as $section => $thissection){
if (!$PAGE->user_is_editing() && (!has_capability('moodle/course:viewhiddensections', $context = context_course::instance($course->id), $USER->id))) {
if (isset($course->hiddensections) && !(int)$thissection->visible) {
continue;
}
if (!$thissection->available && !empty($thissection->availableinfo)) {
$thissection= $this->get_section_header($thissection, $course, false, 0, $groups);
continue;
}
if (!$thissection->uservisible || !$thissection->visible) {
$htmlsection = $this->section_hidden($section, $course->id);
continue;
}
}
$thissection=$this->get_section_header($thissection, $course, false, 0, true, $groups);
if ($thissection->uservisible) {
$thissection->resources= $this->courserenderer->course_section_cm_list($course, $thissection, 0);
if ($editing) {
$thissection->addresources = $this->courserenderer->course_section_add_cm_control($course, $thissection->section, 0);
$thissection->leftcontent = $this->section_left_content($thissection, $course, $onsectionpage);
$thissection->rightcontent = $this->section_right_content($thissection, $course, $onsectionpage);
}
}
array_push($sections['sections'], $thissection);
array_push($nameSections, $thissection->name);
array_push($idSections, $thissection->id);
}
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);
}
//If edit mode, we use the old code that generates HTML, else we use the templates - bientôt useless
public function switch_mode($course){
global $PAGE, $CFG;
$context = context_course::instance($course->id);
$course = course_get_format($course)->get_course();
if($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)){
//$this->print_iena_section_pages($course);
$this->get_iena_sections($course, true);
}
else{
$this->get_iena_sections($course, false);
}
}
public function display_completion($data){
echo $this->render_from_template('format_iena/suivi', $data);
}
public function display_table_completion($data){
echo $this->render_from_template('format_iena/suivi-table', $data);
}
public function display_message($data){
echo $this->render_from_template('format_iena/send-message', $data);
}
}