diff --git a/classes/form/edittable_form.php b/classes/form/edittable_form.php new file mode 100644 index 0000000000000000000000000000000000000000..94648498477b9c7c5d899fc1a86456282d355ce8 --- /dev/null +++ b/classes/form/edittable_form.php @@ -0,0 +1,93 @@ +<?php + + +if (!defined('MOODLE_INTERNAL')) { + die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page +} + + + +require_once($CFG->libdir.'/formslib.php'); + +/** + * Default form for editing course section + * + * Course format plugins may specify different editing form to use + */ +class edittable_form extends moodleform { + + function definition() { + + $mform = $this->_form; + //$course = $this->_customdata['course']; + //$sectioninfo = $this->_customdata['cs']; + + + + /// Prepare course and the editor + + /*$mform->addElement('checkbox', 'display_groups', 'Afficher les groupes','Activer'); + + $mform->addHelpButton('display_groups', 'summary'); + + $mform->addElement('checkbox', 'display_custom', 'Activer la personnalisation', 'Activer'); + + $mform->addHelpButton('display_custom', 'summary'); + + $mform->addElement('checkbox', 'display_status', 'Activer le statut "En attente d\'évaluation de ma part"', 'Activer'); + + $mform->addHelpButton('display_status', 'summary'); + + $mform->addElement('checkbox', 'display_details', 'Afficher le détail des évaluation au clic', 'Activer'); + + $mform->addHelpButton('display_details', 'summary');*/ + $radioarray = array(); + $radioarray[] = $mform->createElement('checkbox', 'display_groups', 'Activer'); + $mform->addGroup($radioarray, 'groups', 'Afficher les groupes', array(' '), false); + $mform->addHelpButton('groups', 'modalite', 'format_iena'); + $radioarray = array(); + $radioarray[] = $mform->createElement('checkbox', 'display_custom', 'Activer'); + $mform->addGroup($radioarray, 'custom', 'Activer la personnalisation', array(' '), false); + $mform->addHelpButton('custom', 'modalite', 'format_iena'); + $radioarray = array(); + $radioarray[] = $mform->createElement('checkbox', 'display_status', 'Activer'); + $mform->addGroup($radioarray, 'status', 'Afficher les groupes', array(' '), false); + $mform->addHelpButton('status', 'modalite', 'format_iena'); + $radioarray = array(); + $radioarray[] = $mform->createElement('checkbox', 'display_details', 'Activer'); + $mform->addGroup($radioarray, 'details', 'Afficher les groupes', array(' '), false); + $mform->addHelpButton('details', 'modalite', 'format_iena'); + + + /*$mform->addElement('hidden', 'id'); + $mform->setType('id', PARAM_INT);*/ + + $this->add_action_buttons(); + //$mform->_registerCancelButton('cancel'); + } + + + + + + /** + * Load in existing data as form defaults + * + * @param stdClass|array $default_values object or array of default values + */ + function set_data($default_values) { + if (!is_object($default_values)) { + // we need object for file_prepare_standard_editor + $default_values = (object)$default_values; + } + $editoroptions = $this->_customdata['editoroptions']; + $default_values = file_prepare_standard_editor($default_values, 'summary', $editoroptions, + $editoroptions['context'], 'course', 'section', $default_values->id); + if (strval($default_values->name) === '') { + $default_values->name = false; + } + parent::set_data($default_values); + } + + +} diff --git a/classes/output/course_format_iena_table_option.php b/classes/output/course_format_iena_table_option.php new file mode 100644 index 0000000000000000000000000000000000000000..227ed14d45047e0b4165f2117e033d22921cdce7 --- /dev/null +++ b/classes/output/course_format_iena_table_option.php @@ -0,0 +1,217 @@ +<?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/>. +/** + * + * course_format_iena_sections + * + * @package format_iena + * @copyright 2018 Softia/Université lorraine + * @author vrignaud camille / Michaël Lebeau + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace format_iena\output; + +class course_format_iena_table_option { + /** @var boolean */ + + /** + * **/ + + public $optionname; + public $optionvalue; + public $courseid; + public $userid; + + + /** + * [__construct description] + * @param boolean $displaygroups [description] + * @param boolean $displaycustom [description] + * @param boolean $displaydetails [description] + * @param boolean $displaystatus [description] + * @param int $idcourse [description] + * @param int $iduser [description] + */ + public function __construct(string $option = null, int $value=0, int $courseid = 0, int $userid= 0){ + $this->optionname=$option; + $this->optionvalue=$value; + $this->courseid=$courseid; + $this->userid=$userid; + } + + /** + * + * @return array + * @throws dml_exception + */ + public function get_options_by_course_id($courseid) { + global $DB; + $requete=[]; + $requete = $DB->get_records('format_iena_options', ['courseid' => $courseid]); + return $requete; + } + + + + public function create_array_option(){ + global $DB; + $this->timecreated=time(); + + $arrayoptions=$DB->insert_record("format_iena_options", $this, true); + return $arrayoptions; + } + + public function get_array_options(){ + global $DB; + $arrayoptions = $DB->get_record('format_iena_options', ['id' => "1"]); + return $arrayoptions; + } + + public function toArray() { + $vars = []; + foreach ($this as $varname => $varvalue) { + $vars[$varname] = $varvalue; + } + return $vars; + } + + + + + + /** + * @return mixed + */ + public function getDisplaygroups() + { + return $this->displaygroups; + } + + /** + * @param mixed $displaygroups + * + * @return self + */ + public function setDisplaygroups($displaygroups) + { + $this->displaygroups = $displaygroups; + + return $this; + } + + /** + * @return mixed + */ + public function getDisplaycustom() + { + return $this->displaycustom; + } + + /** + * @param mixed $displaycustom + * + * @return self + */ + public function setDisplaycustom($displaycustom) + { + $this->displaycustom = $displaycustom; + + return $this; + } + + /** + * @return mixed + */ + public function getDisplaydetails() + { + return $this->displaydetails; + } + + /** + * @param mixed $displaydetails + * + * @return self + */ + public function setDisplaydetails($displaydetails) + { + $this->displaydetails = $displaydetails; + + return $this; + } + + /** + * @return mixed + */ + public function getDisplaystatus() + { + return $this->displaystatus; + } + + /** + * @param mixed $displaystatus + * + * @return self + */ + public function setDisplaystatus($displaystatus) + { + $this->displaystatus = $displaystatus; + + return $this; + } + + /** + * @return mixed + */ + public function getIdcourse() + { + return $this->idcourse; + } + + /** + * @param mixed $idcourse + * + * @return self + */ + public function setIdcourse($idcourse) + { + $this->idcourse = $idcourse; + + return $this; + } + + /** + * @return mixed + */ + public function getIduser() + { + return $this->iduser; + } + + /** + * @param mixed $iduser + * + * @return self + */ + public function setIduser($iduser) + { + $this->iduser = $iduser; + + return $this; + } + + +} diff --git a/classes/output/renderer.php b/classes/output/renderer.php index db0b4f6efffb10305f22df177a3a4f1f8dddcd99..6755a93b3df5eb679d021388a1406c6c83b0d9e4 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -107,6 +107,9 @@ class renderer extends section_renderer { echo $this->render_from_template('format_iena/send-message', $data); } + public function display_edit_page($data){ + echo $this->render_from_template('format_iena/suivi-edit', $data); + } } diff --git a/db/install.xml b/db/install.xml new file mode 100644 index 0000000000000000000000000000000000000000..03743422bc87bbbed9cb53fa4602689cb0814e0a --- /dev/null +++ b/db/install.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<XMLDB PATH="course/format/iena/db" VERSION="20240131" COMMENT="XMLDB file for Moodle course/format/iena" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd" +> + <TABLES> + <TABLE NAME="format_iena_options" COMMENT="Manage activity tracking table options"> + <FIELDS> + <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/> + <FIELD NAME="optionname" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false"/> + <FIELD NAME="optionvalue" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false"/> + <FIELD NAME="courseid" TYPE="int" LENGTH="8" NOTNULL="true" SEQUENCE="false"/> + <FIELD NAME="userid" TYPE="int" LENGTH="8" NOTNULL="true" SEQUENCE="false"/> + <FIELD NAME="timecreated" TYPE="int" LENGTH="16" NOTNULL="true" SEQUENCE="false"/> + <FIELD NAME="timemodified" TYPE="int" LENGTH="16" NOTNULL="false" SEQUENCE="false"/> + </FIELDS> + <KEYS> + <KEY NAME="primary" TYPE="primary" FIELDS="id"/> + </KEYS> + </TABLE> + </TABLES> +</XMLDB> diff --git a/db/upgrade.php b/db/upgrade.php index 4aceccdc28e07c7816651160f2a729b09117dd64..d55c89c64fa6c2d437e199ab9a88bf197563451d 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -27,7 +27,7 @@ function xmldb_format_iena_upgrade($oldversion) { global $CFG, $DB; $dbman = $DB->get_manager(); $result = true; - + error_log($oldversion); if ($oldversion < 2021220900) { // Support for old versions: we copy format options to the course_format_options table. try { @@ -93,5 +93,29 @@ function xmldb_format_iena_upgrade($oldversion) { // Format_iena savepoint reached. upgrade_plugin_savepoint(true, 2021070600, 'format', 'iena'); } + if ($oldversion < 2024012500) { + + // Define field id to be added to format_iena. + $table = new xmldb_table('format_iena_options'); + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); + $table->add_field('optionname', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, 'id'); + $table->add_field('optionvalue', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'optionname'); + $table->add_field('courseid', XMLDB_TYPE_INTEGER, '8', null, XMLDB_NOTNULL, null, null, 'optionvalue'); + $table->add_field('userid', XMLDB_TYPE_INTEGER, '8', null, XMLDB_NOTNULL, null, null, 'courseid'); + $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '16', null, XMLDB_NOTNULL, null, null, 'userid'); + $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '16', null, null, null, null, 'timecreated'); + + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + + // Conditionally launch add field id. + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + + // Iena savepoint reached. + upgrade_plugin_savepoint(true, 2024012500, 'format','iena'); + } + return $result; } diff --git a/styles.css b/styles.css index 9e889a53f317daa2e2e3e1607237327e14747ab2..f5b1cf0a562a8b1a713e720f31b452146927c0b0 100644 --- a/styles.css +++ b/styles.css @@ -231,6 +231,12 @@ ul.nav.navbar-nav.ml-auto { margin-left:10px; } +.right_info a:focus{ + outline: none!important; + background: none!important; + box-shadow: none!important; +} + .section_action_menu.ml-auto{ margin-left: 5px!important; } @@ -1146,6 +1152,8 @@ border-bottom: 1px solid #dee2e6; .right-info{ flex-basis: 15%; } + + .mobile-bouton-suivi{ display: block; min-width: 1rem; @@ -1178,3 +1186,10 @@ border-bottom: 1px solid #dee2e6; } } + + +/******************************************************** Paramètres du tableau de suivi ******************************************/ +#iena-suivi-edit .form-inline{ + padding-top: calc(0.375rem + 1px); +} + diff --git a/suivi_edit.php b/suivi_edit.php new file mode 100644 index 0000000000000000000000000000000000000000..6e762c59310143bdb2ec69cf6010d2454734c6d3 --- /dev/null +++ b/suivi_edit.php @@ -0,0 +1,111 @@ +<?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/>. +/** + * + * @package format_iena + * @copyright 2018 Softia/Université lorraine + * @author vrignaud camille / Thomas Fradet + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +use format_iena\output; + + +define('NO_OUTPUT_BUFFERING', true); + + + +require_once('../../../config.php'); +require_once($CFG->dirroot. '\course\format\iena\classes\form\edittable_form.php'); + + + +$PAGE->requires->css('/course/format/iena/styles.css'); + +//On va déjà chercher en BDD s'il y a des options + + + + + + + + + +function init_page($course) { + global $PAGE; + // Defines the id of the course with a get parameter. + // Getting DB information (*) of the course. + + $PAGE->set_title($course->fullname); + $PAGE->set_heading($course->fullname . " – " .get_string('table_progress', 'format_iena')); + $PAGE->set_pagelayout('incourse'); + + // Cache le menu dans le header. + $coursenode = $PAGE->navbar->add(get_string('table_progress', 'format_iena'), + null, navigation_node::TYPE_CONTAINER, null, 'suiviena'); + $coursenode->make_active(); + $coursenode->force_open(); + +} + +function create_options_form(){ + +} + + function set_data(){ + +} + +$courseid = required_param('course', PARAM_INT); +// Define the url of the view. +$url = new moodle_url('/course/format/iena/suivi_edit.php', array('courseid' => $courseid)); +$PAGE->set_url($url); + +$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); +require_login($course); + +$completion = new completion_info($course); +$context = context_course::instance($COURSE->id); + +if (!has_capability('course/iena:suivi', $context = context_course::instance($courseid), $USER->id)) { + $link = $CFG->wwwroot . '/course/view.php?id=' . $courseid; + header("Location: {$link}"); + exit; +} + + + + +// If a post is sent trought the page. +if (isset($_POST['action']) && !empty($_POST['action'])) { + // Si on change les filtres. + $data = []; + $data = set_data($data); + echo json_encode($data); +} else { + init_page($course, $PAGE); + echo $OUTPUT->header(); + $data = []; + $obj=new \format_iena\output\course_format_iena_table_option(); + $array=$obj->get_array_options(); + + $mform= new edittable_form(); + $data["form"]=$mform->render(); + $renderer = $PAGE->get_renderer('format_iena'); + $renderer->display_edit_page($data); + echo $OUTPUT->footer(); +} diff --git a/suivi_unit.php b/suivi_unit.php index befe60c2b874870f676c679e7c750c5e40c75800..5d70ec3dc7d2c946d0eb65207a1ef0b1800c92b4 100644 --- a/suivi_unit.php +++ b/suivi_unit.php @@ -29,6 +29,12 @@ require_once('entity/course_format_iena_sections.php'); require_once('entity/course_format_iena_groups.php'); $PAGE->requires->css('/course/format/iena/styles.css'); + + + + + + global $COURSE, $DB, $USER, $PAGE; function init_page($course) { @@ -45,6 +51,7 @@ function init_page($course) { null, navigation_node::TYPE_CONTAINER, null, 'suiviena'); $coursenode->make_active(); $coursenode->force_open(); + } function get_groups($context, $activegroupid, $progress, $groups) { @@ -222,6 +229,7 @@ function set_data($data, $modules, $progress, $groups, $activegroupid, $activese } $data['link_classicview'] = $CFG->wwwroot . "/report/progress/index.php?course=" . $COURSE->id; + $data['link_editview']=$CFG->wwwroot . "/course/format/iena/suivi_edit.php?course=" . $COURSE->id; // Pour le téléchargement du tableau ? if (!isset($data['data'])) { diff --git a/templates/suivi-edit.mustache b/templates/suivi-edit.mustache new file mode 100644 index 0000000000000000000000000000000000000000..16e3d9bb433fd268847569f3769947d398e355f8 --- /dev/null +++ b/templates/suivi-edit.mustache @@ -0,0 +1,4 @@ +<div id="iena-suivi-edit"> + <h2>Modifier les paramètres du suivi</h2> + {{{form}}} +</div> \ No newline at end of file diff --git a/templates/suivi.mustache b/templates/suivi.mustache index d7002c41daf1a0c3e238852b4723fa5c8d2e75d8..487e1d51357ce7470cdd993fc9f19d1fa5d21703 100644 --- a/templates/suivi.mustache +++ b/templates/suivi.mustache @@ -18,7 +18,10 @@ {{/link_bulkcompletion}} <div class="dropdown-item"> <a href="{{link_classicview}}" class="" role="menuitem"><i class="icon fa fa-pencil fa-fw " aria-hidden="true"></i>Vue classique</a> - </div> + </div> + <div class="dropdown-item"> + <a href="{{link_editview}}" class="" role="menuitem"><i class="icon fa fa-pencil fa-fw " aria-hidden="true"></i>Vue classique</a> + </div> </div> </div> </div> diff --git a/tests/my_test.php b/tests/my_test.php new file mode 100644 index 0000000000000000000000000000000000000000..e9f165623fbe821227855b1cb5aab9c64a35c469 --- /dev/null +++ b/tests/my_test.php @@ -0,0 +1,175 @@ +<?php + +namespace format_iena; + + + + +class my_test extends \advanced_testcase { + + public function test_get_array_options(){ + global $DB, $CFG; + $this->resetAfterTest(true); + $olddebug = $CFG->debug; + $CFG->debug = 0; + $generator = $this->getDataGenerator(); + $course1 = $generator->create_course(); + $course2 = $generator->create_course(); + $data=[ + "option1"=>[ + "option"=>"display_groups", + "value"=>"1", + "courseid"=>$course1->id, + "userid"=>"1", + ], + "option2"=>[ + "option"=>"display_custom", + "value"=>"1", + "courseid"=>$course1->id, + "userid"=>"1", + ], + "option3"=>[ + "option"=>"display_details", + "value"=>"1", + "courseid"=>$course1->id, + "userid"=>"1", + ], + "option4"=>[ + "option"=>"display_status", + "value"=>"1", + "courseid"=>$course2->id, + "userid"=>"1", + ] + ]; + // Create a set of options for the table. + + foreach($data as $x => $i){ + $obj=new \format_iena\output\course_format_iena_table_option($i["option"], $i["value"], $i["courseid"], $i["userid"]); + $arrayoptionsid=$obj->create_array_option(); + } + $arrayoptions=$obj->get_options_by_course_id($course1->id); + + $this->assertCount(3, $arrayoptions); + $arrayoptions2=$obj->get_options_by_course_id($course2->id); + + $this->assertCount(1, $arrayoptions2); + + $CFG->debug = $olddebug; + + + + } + + + public function test_create_option() { + global $DB, $CFG; + $this->resetAfterTest(true); + + /*$generator = $this->getDataGenerator(); + $cat1 = $generator->create_category(); + $cat2 = $generator->create_category(); + $sub1 = $generator->create_category(array('parent' => $cat1->id)); + $sub2 = $generator->create_category(array('parent' => $cat1->id)); + $course1 = $generator->create_course(array('category' => $cat1->id)); + $course2 = $generator->create_course(array('category' => $sub1->id)); + $course3 = $generator->create_course(array('category' => $sub1->id)); + $course4 = $generator->create_course(array('category' => $cat2->id)); + + $syscontext = \context_system::instance(); + + list($user, $roleid) = $this->get_user_objects($generator, $syscontext->id); + + course_capability_assignment::allow(array(self::CATEGORY_MANAGE, self::CATEGORY_VIEWHIDDEN), $roleid, $syscontext->id); + + // Check they are where we think they are. + $this->assertEquals(1, $cat1->get_courses_count()); + $this->assertEquals(1, $cat2->get_courses_count()); + $this->assertEquals(2, $sub1->get_courses_count()); + $this->assertEquals(0, $sub2->get_courses_count()); + + // Move the courses in sub category 1 to sub category 2. + $this->assertTrue( + \core_course\management\helper::move_courses_into_category($sub2->id, array($course2->id, $course3->id)) + ); + */ + + $olddebug = $CFG->debug; + $CFG->debug = 0; + + + $data=[ + "option"=>"display_groups", + "value"=>"1", + "courseid"=>"1", + "userid"=>"1", + ]; + // Create a set of options for the table. + $obj=new \format_iena\output\course_format_iena_table_option($data["option"], $data["value"], $data["courseid"], $data["userid"]); + + + $arrayoptionsid=$obj->create_array_option(); + // Check the preset data. + + $arrayoptions = $DB->get_record('format_iena_options', ['id' => $arrayoptionsid]); + + + $this->assertEquals($data["option"], $arrayoptions->optionname); + $this->assertEquals($data["value"], $arrayoptions->optionvalue); + $this->assertEquals($data["courseid"], $arrayoptions->courseid); + $this->assertEquals($data["userid"], $arrayoptions->userid); + + // Check the settings. + /* $settings = $DB->get_records('adminpresets_it', ['adminpresetid' => $presetid]); + $this->assertCount(4, $settings); + // These are the settings created in the generator. Check the results match them. + $expectedsettings = [ + 'enablebadges' => 0, + 'allowemojipicker' => 1, + 'mediawidth' => 900, + 'maxanswers' => 2, + ]; + foreach ($settings as $setting) { + $this->assertArrayHasKey($setting->name, $expectedsettings); + $this->assertEquals($expectedsettings[$setting->name], $setting->value); + }*/ + + $CFG->debug = $olddebug; + } + + /* public function test_get_options_by_id_course(){ + + global $DB, $CFG; + $this->resetAfterTest(true); + + + + + $CFG->debug = $olddebug; + + }*/ + + /*public function create_options_provider(): array { + return [ + 'Full preset' => [ + 'name' => 'Full', + 'comments' => null, + 'author' => null, + 'applypreset' => false, + 'iscore' => manager::FULL_PRESET, + 'iscoreresult' => manager::FULL_PRESET, + ], + 'Invalid iscore' => [ + 'name' => 'Invalid iscore value', + 'comments' => null, + 'author' => null, + 'applypreset' => false, + 'iscore' => -1, + 'iscoreresult' => manager::NONCORE_PRESET, + ], + ]; + }*/ + + + + +} \ No newline at end of file diff --git a/version.php b/version.php index 79762e5fefd327fd8e04ab20ff3e9925b1a91b13..2d359f447ffd04a70e32d1ba5699a998874ef047 100644 --- a/version.php +++ b/version.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2023000001; +$plugin->version = 2024012901; $plugin->requires = 2014111000; $plugin->component = 'format_iena'; $plugin->release = "1.0";