From 4acc9eb9a171bc956f7f610560e49d08ccc8f070 Mon Sep 17 00:00:00 2001 From: Astor Bizard <astor.bizard@grenoble-inp.fr> Date: Tue, 25 Feb 2020 17:05:22 +0100 Subject: [PATCH] Code factoring for teacher files --- editor/editor_utility.php | 28 ++++---------- forms/edit.php | 6 +-- forms/files.json.php | 10 +---- forms/files.php | 79 +++++++++++++++------------------------ lang/en/vpl.php | 15 ++++---- views/downloadfiles.php | 46 +++++++++++++++++++++++ 6 files changed, 97 insertions(+), 87 deletions(-) create mode 100644 views/downloadfiles.php diff --git a/editor/editor_utility.php b/editor/editor_utility.php index dfd41d4f..cbf993de 100644 --- a/editor/editor_utility.php +++ b/editor/editor_utility.php @@ -38,10 +38,8 @@ class vpl_editor_util { $PAGE->requires->css( new moodle_url( '/mod/vpl/editor/VPLIDE.css' ) ); } public static function generate_requires($options) { - global $PAGE; - global $CFG; + global $PAGE, $CFG; $plugincfg = get_config('mod_vpl'); - $tagid = 'vplide'; $options ['i18n'] = self::i18n(); if ( isset($plugincfg->editor_theme) ) { $options ['theme'] = $plugincfg->editor_theme; @@ -56,13 +54,13 @@ class vpl_editor_util { $PAGE->requires->js( new moodle_url( '/mod/vpl/editor/zip/unzip.js' ) ); $PAGE->requires->js( new moodle_url( '/mod/vpl/editor/xterm/term.js' ) ); $PAGE->requires->js( new moodle_url( '/mod/vpl/editor/noVNC/include/util.js' ) ); - $PAGE->requires->js_call_amd('mod_vpl/vplide', 'init', array($tagid, $options)); + $PAGE->requires->js_call_amd('mod_vpl/vplide', 'init', array('vplide', $options)); } - public static function print_tag() { - global $CFG; - $tagid = 'vplide'; + public static function print_editor() { + global $OUTPUT; + echo $OUTPUT->box_start(); ?> -<div id="<?php echo $tagid;?>" class="vpl_ide vpl_ide_root"> +<div id="vplide" class="vpl_ide vpl_ide_root"> <div id="vpl_menu" class="vpl_ide_menu"></div> <div id="vpl_tr" class="vpl_ide_tr"> <div id="vpl_filelist" style="display: none;"> @@ -228,6 +226,7 @@ class vpl_editor_util { </div> </div> <?php + echo $OUTPUT->box_end(); } /** * get list of i18n translations for the editor @@ -249,7 +248,7 @@ class vpl_editor_util { 'connection_fail', 'console', 'copy', - 'correctedfiles', + 'correctedfiles', 'create_new_file', 'cut', 'description', @@ -357,15 +356,4 @@ class vpl_editor_util { $options ['nexturl'] = $nexturl; $PAGE->requires->js_call_amd('mod_vpl/evaluationmonitor', 'init', array($options) ); } - public static function generate_batch_evaluate_sript($ajaxurls) { - $options = Array (); - $options ['i18n'] = self::i18n(); - $options ['ajaxurls'] = $ajaxurls; - $joptions = json_encode( $options ); -?> -<script> - VPL_Batch_Evaluation(<?php echo $joptions;?>); -</script> -<?php - } } diff --git a/forms/edit.php b/forms/edit.php index ac239a98..f0d9a71e 100644 --- a/forms/edit.php +++ b/forms/edit.php @@ -33,7 +33,7 @@ $id = required_param('id', PARAM_INT); $userid = optional_param('userid', false, PARAM_INT); $copy = optional_param('privatecopy', false, PARAM_INT); $subid = optional_param( 'submissionid', false, PARAM_INT ); -global $USER, $DB, $OUTPUT; +global $USER, $DB; $vpl = new mod_vpl($id); $pageparms = array('id' => $id); if ($userid && ! $copy) { @@ -130,7 +130,5 @@ if ($copy && $grader) { vpl_editor_util::generate_requires($options); $vpl->print_header( get_string( 'edit', VPL ) ); $vpl->print_view_tabs( basename( __FILE__ ) ); -echo $OUTPUT->box_start(); -vpl_editor_util::print_tag(); -echo $OUTPUT->box_end(); +vpl_editor_util::print_editor(); $vpl->print_footer(); diff --git a/forms/files.json.php b/forms/files.json.php index e81d24f2..a944e196 100644 --- a/forms/files.json.php +++ b/forms/files.json.php @@ -47,15 +47,9 @@ try { // TODO use or not sesskey "require_sesskey();". require_login( $vpl->get_course(), false ); $vpl->require_capability( VPL_MANAGE_CAPABILITY ); - $PAGE->set_url( new moodle_url( '/mod/vpl/forms/files.json.php', array ( - 'id' => $id, - 'type' => $type, - 'action' => $action - ) ) ); - echo $OUTPUT->header(); // Send headers. $actiondata = json_decode( file_get_contents( 'php://input' ) ); - if ($type=='testcases'){ - $action .='cases'; + if ($type == 'testcases') { + $action .= 'cases'; } switch ($action) { case 'save' : diff --git a/forms/files.php b/forms/files.php index 501a09b0..d65879bf 100644 --- a/forms/files.php +++ b/forms/files.php @@ -15,10 +15,10 @@ // along with VPL for Moodle. If not, see <http://www.gnu.org/licenses/>. /** - * Edit file + * Edit teacher files * * @package mod_vpl - * @copyright 2012 Juan Carlos RodrÃguez-del-Pino + * @copyright 2012 Juan Carlos RodrÃguez-del-Pino, 2020 Astor Bizard * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @author Juan Carlos RodrÃguez-del-Pino <jcrodriguez@dis.ulpgc.es> */ @@ -26,69 +26,52 @@ require_once(dirname(__FILE__). '/../../../config.php'); require_once(dirname(__FILE__). '/../locallib.php'); require_once(dirname(__FILE__). '/../vpl.class.php'); -//require_once(dirname( __FILE__ ). '/edit.class.php'); require_once(dirname(__FILE__). '/../editor/editor_utility.php'); - - require_login(); $id = required_param( 'id', PARAM_INT ); $type = required_param( 'type', PARAM_ALPHANUMEXT ); - + $vpl = new mod_vpl( $id ); -$instance = $vpl->get_instance(); -$vpl->prepare_page( 'forms/files.php', array ( 'id' => $id ,'type' =>$type ) ); +$vpl->prepare_page( 'forms/files.php', array ( 'id' => $id, 'type' => $type ) ); $vpl->require_capability( VPL_MANAGE_CAPABILITY ); - -$options = Array (); +$options = array(); $options ['restrictededitor'] = false; $options ['save'] = true; -$options ['run'] = ($type=='execution'); -$options ['debug'] = ($type=='execution'); -$options ['evaluate'] = ($type=='execution'); +$options ['run'] = ($type == 'execution'); +$options ['debug'] = ($type == 'execution'); +$options ['evaluate'] = ($type == 'execution'); $options ['ajaxurl'] = "files.json.php?id={$id}&type={$type}&action="; $options ['download'] = "../views/downloadfiles.php?id={$id}&type={$type}"; -$options ['resetfiles'] = ($type=='corrected'); +$options ['resetfiles'] = ($type == 'corrected'); $options ['correctedfiles'] = false; -$options ['minfiles'] = 0; -$options ['maxfiles'] = ($type=='execution')?1000:$instance->maxfiles; $options ['saved'] = true; -vpl_editor_util::generate_requires($options); +switch ($type) { + case 'required': + $options ['minfiles'] = 0; + $options ['maxfiles'] = $vpl->get_instance()->maxfiles; + break; + case 'execution': + $options ['minfiles'] = $vpl->get_fgm('execution')->get_numstaticfiles(); + $options ['maxfiles'] = 1000; + break; + case 'corrected': + $options ['minfiles'] = count($vpl->get_fgm('required')->getfilelist()); + $options ['maxfiles'] = $vpl->get_instance()->maxfiles; + break; + case 'testcases': + $options ['minfiles'] = 1; + $options ['maxfiles'] = 1; + break; + default: + throw new moodle_exception('unknownfiletype', VPL, vpl_mod_href('view.php', 'id', $id), $type); +} +vpl_editor_util::generate_requires($options); $vpl->print_header( get_string( $type.'files', VPL ) ); $vpl->print_heading_with_help( $type.'files' ); - -// Get files. -if ($type=='testcases'){ - $options ['minfiles'] = 1; - $options ['maxfiles'] = 1; - $fgm = $vpl->get_fgm('execution'); - $filename='vpl_evaluate.cases'; -}else{ - $fgm = $vpl->get_fgm($type); -} -if ($type=='execution'){ - $options ['minfiles'] = $vpl->get_fgm('execution')->get_numstaticfiles(); -} - -$files = Array(); -if (isset($filename)){ - $files[$filename]=$fgm->getFileData($filename); -}else{ - $filelist =$fgm->getFileList(); - $nf = count($filelist); - for( $i = 0; $i < $nf; $i++){ - $filename=$filelist[$i]; - $filedata=$fgm->getFileData($filelist[$i]); - $files[$filename]=$filedata; - } -} -session_write_close(); - -echo $OUTPUT->box_start(); -vpl_editor_util::print_tag( $options,$files ); -echo $OUTPUT->box_end(); +vpl_editor_util::print_editor(); $vpl->print_footer_simple(); diff --git a/lang/en/vpl.php b/lang/en/vpl.php index 3cdb0ebd..1cb1e084 100644 --- a/lang/en/vpl.php +++ b/lang/en/vpl.php @@ -24,7 +24,7 @@ $string ['acceptcertificatesnote'] = "<p>You are using an encrypted connection.< $string ['addfile'] = 'Add file'; $string ['advanced'] = 'Advanced'; $string ['allfiles'] = 'All files'; -$string ['allowshowprevious'] = 'Allow student show previous submissions'; +$string ['allowshowprevious'] = 'Allow student show previous submissions'; $string ['allsubmissions'] = 'All submissions'; $string ['anyfile'] = 'Any file'; $string ['attemptnumber'] = 'Attempt number {$a}'; @@ -50,7 +50,7 @@ $string ['connection_closed'] = 'connection closed'; $string ['connection_fail'] = 'connection fail'; $string ['console'] = 'Console'; $string ['copy'] = 'Copy'; -$string ['correctedfiles'] = 'Corrected files'; +$string ['correctedfiles'] = 'Corrected files'; $string ['create_new_file'] = 'Create a new file'; $string ['currentstatus'] = 'Current status'; $string ['cut'] = 'Cut'; @@ -263,7 +263,7 @@ $string ['sureresetfiles'] = 'Do you want to lost all your work and reset the fi $string ['surecorrectedfiles'] = 'Do you want to lost all your work and reset the files to its corrected files?'; $string ['test'] = 'Test activity'; $string ['testcases'] = 'Test cases'; -$string ['testcasesfiles'] = 'Test cases file'; +$string ['testcasesfiles'] = 'Test cases file'; $string ['timelimited'] = 'Time limited'; $string ['timeleft'] = 'Time left'; $string ['timeout'] = 'Timeout'; @@ -271,6 +271,7 @@ $string ['timeunlimited'] = 'Time unlimited'; $string ['totalnumberoferrors'] = "Errors"; $string ['undo'] = 'Undo'; $string ['unexpected_file_name'] = "Incorrect file name: expected '{\$a->expected}' and found '{\$a->found}'"; +$string ['unknownfiletype'] = "Unknown files type: {\$a}."; $string ['unzipping'] = 'Unzipping ...'; $string ['uploadfile'] = 'Upload file'; $string ['usableasbase'] = 'Usable as base'; @@ -325,9 +326,9 @@ $string ['step'] = 'Step'; $string ['check_jail_servers_help'] = "<p>This page check and show the status of execution servers used for this activity.</p>"; -$string ['correctedfiles_help'] = '<p>Here you set names and its content up for the corrected files to the max number of files that was set in the basic description of the activity.</p> -<p>If you don\'t set names for whole number of files, the unnamed files are optional and can have any name.</p> -<p>You also can add contents to the corrected files, so these contents will be available for teacher.</p>'; +$string ['correctedfiles_help'] = '<p>Here you set names and its content up for the corrected files to the max number of files that was set in the basic description of the activity.</p> +<p>If you don\'t set names for whole number of files, the unnamed files are optional and can have any name.</p> +<p>You also can add contents to the corrected files, so these contents will be available for teacher.</p>'; $string ['executionfiles_help'] = '<h2>Introduction</h2> <p>Here you set the files that are needed to prepare the execution, debug or assessment of a submission. This includes scripting files, @@ -441,7 +442,7 @@ $string ['modulename_help'] = '<p>VPL is a activity module for Moodle that manag </ul> <p><a href="http://vpl.dis.ulpgc.es">Virtual Programming lab Home Page</a></p>'; $string ['modulename_link'] = 'mod/vpl/view'; -$string ['requiredfiles_help'] = '<p>Here you set names and its initial content up for the requested files to the max number of files that was set in the basic description of the activity.</p> +$string ['requiredfiles_help'] = '<p>Here you set names and its initial content up for the requested files to the max number of files that was set in the basic description of the activity.</p> <p>If you don\'t set names for whole number of files, the unnamed files are optional and can have any name.</p> <p>You also can add contents to the requested files, so these contents will be available the first time that they will be opened with the editor, if no previous submission exists.</p>'; $string ['resourcelimits_help'] = '<p>You can set limits for the execution time, the memory used, the execution files sizes and the number of processes to be executed simultaneously.</p> diff --git a/views/downloadfiles.php b/views/downloadfiles.php new file mode 100644 index 00000000..cf438a61 --- /dev/null +++ b/views/downloadfiles.php @@ -0,0 +1,46 @@ +<?php +// This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/ +// +// VPL for 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. +// +// VPL for 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 VPL for Moodle. If not, see <http://www.gnu.org/licenses/>. + +/** + * Download VPL files + * + * @package mod_vpl + * @copyright 2012 Juan Carlos RodrÃguez-del-Pino, 2020 Astor Bizard + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author Juan Carlos RodrÃguez-del-Pino <jcrodriguez@dis.ulpgc.es> + */ + +require_once(dirname(__FILE__).'/../../../config.php'); +require_once(dirname(__FILE__).'/../locallib.php'); +require_once(dirname(__FILE__).'/../vpl.class.php'); +require_once(dirname(__FILE__).'/../filegroup.class.php'); + +require_login(); +$id = required_param( 'id', PARAM_INT ); +$type = required_param( 'type', PARAM_ALPHANUMEXT ); +if ($type != 'required' && $type != 'execution' && $type != 'corrected' && $type != 'testcases') { + throw new moodle_exception('unknownfiletype', VPL, vpl_mod_href('view.php', 'id', $id), $type); +} +$vpl = new mod_vpl( $id ); +if (!$vpl->has_capability( VPL_MANAGE_CAPABILITY )) { + $vpl->restrictions_check(); + if ($type != 'required' || !$vpl->is_visible()) { + throw new moodle_exception('nopermissions', '', '', get_string('download') . ' ' . get_string($type . 'files', VPL)); + } +} +$filegroup = $vpl->get_fgm($type); +$filegroup->download_files( $vpl->get_printable_name() . '(' . get_string($type.'files', VPL) . ')' ); +die(); \ No newline at end of file -- GitLab