Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output files and checklists #25

Open
wants to merge 5 commits into
base: v3.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions classes/event/vpl_outputlist_updated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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/>.

/**
* Class for logging of execution options update events
*
* @package mod_vpl
* @copyright 2016 onwards Frantisek Galcik
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Frantisek Galcik <[email protected]>
*/
namespace mod_vpl\event;

require_once(dirname( __FILE__ ) . '/../../locallib.php');
defined( 'MOODLE_INTERNAL' ) || die();
class vpl_outputlist_updated extends vpl_base {
protected function init() {
parent::init();
$this->data ['crud'] = 'u';
$this->legacyaction = 'set outputlist';
}
public function get_description() {
return $this->get_description_mod('view outputlist');
}
}
38 changes: 38 additions & 0 deletions classes/event/vpl_outputlist_viewed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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/>.

/**
* Class for logging of execution options update events
*
* @package mod_vpl
* @copyright 2016 onwards Frantisek Galcik
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Frantisek Galcik <[email protected]>
*/
namespace mod_vpl\event;

require_once(dirname( __FILE__ ) . '/../../locallib.php');
defined( 'MOODLE_INTERNAL' ) || die();
class vpl_outputlist_viewed extends vpl_base {
protected function init() {
parent::init();
$this->data ['crud'] = 'r';
$this->legacyaction = 'view outputlist';
}
public function get_description() {
return $this->get_description_mod('view outputlist');
}
}
3 changes: 2 additions & 1 deletion editor/VPLIDE.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,8 @@
result_container.show();
result_container.width(menu.width() / 3);
}
result.accordion('refresh');
// causes exception (not fully loaded?); refresh is invoked later during autoResizeTab
//result.accordion('refresh');
if (grade > '') {
result.accordion('option', 'active', 1);
} else {
Expand Down
10 changes: 9 additions & 1 deletion editor/VPLUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@
return $JQVPL('<div>' + t + '</div>').html();
};
VPL_Util.sanitizeText = function(s) {
return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
var map = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#039;'
};

return s.replace(/[&<>"']/g, function(m) { return map[m]; });
};

VPL_Util.setProtocol = function(coninfo) {
Expand Down
63 changes: 63 additions & 0 deletions filegroup.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,40 @@ public function getfiledata($mix) {
return '';
}

/**
* Get file size by number or name
*
* @param int/string $mix
* @return int
*/
function get_file_size($mix) {
if (is_int( $mix )) {
$num = $mix;
$filelist = $this->getFileList();
if ($num >=0 && $num < count($filelist)) {
$filename = $this->dir.self::encodeFileName( $filelist[$num] );
if (file_exists( $filename )) {
return filesize( $filename );
} else {
return -1;
}
}
} else if (is_string( $mix )) {
$filelist = $this->getFileList();
if (array_search( $mix, $filelist ) !== false) {
$fullfilename = $this->dir.self::encodeFileName( $mix );
if (file_exists( $fullfilename )) {
return filesize( $fullfilename );
} else {
return -1;
}
}
}

debugging( "File not found $mix" , DEBUG_DEVELOPER );
return '';
}

/**
* Return is there is some file with data
*
Expand Down Expand Up @@ -409,5 +443,34 @@ public function download_files($name, $watermark = false) {
die();
}
}

/**
* Download a file
* @param $filename filename
* @return boolean true, if the file has been sent, false otherwise.
*/
function download_file($filename) {
$filelist = $this->getFileList();

if (array_search( $filename, $filelist ) !== false) {
$fullfilename = $this->dir.self::encodeFileName( $filename );
if (!file_exists( $fullfilename )) {
return false;
}
} else {
return false;
}

@header( 'Content-Description: File Transfer' );
@header( 'Content-Type: application/octet-stream' );
@header( 'Content-Disposition: attachment; filename="'.basename($filename).'"' );
@header( 'Expires: 0' );
@header( 'Cache-Control: must-revalidate' );
@header( 'Pragma: public' );
@header( 'Content-Length: ' . filesize($fullfilename) );
readfile( $fullfilename );
return true;
}

}

2 changes: 1 addition & 1 deletion forms/evaluation.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@
} else {
$nexturl = "../forms/submissionview.php?id={$id}&userid={$userid}";
}
vpl_editor_util::generateEvaluateScript( $ajaxurl, $nexturl );
vpl_editor_util::generate_evaluate_script( $ajaxurl, $nexturl );
$vpl->print_footer();
8 changes: 5 additions & 3 deletions forms/gradesubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,15 @@ function vpl_grade_header($vpl, $inpopup) {
} else {
$res = $submission->getCE();
if ($res ['executed']) {
$graderaw = $submission->proposedGrade($res['execution']);
if ( $graderaw > '' ) {
$parsed_execution = $submission->parse_execution($res['execution']);
$graderaw = $parsed_execution->grade;

if( $graderaw > '' ) {
$data->grade = format_float($graderaw, 5, true, true);
} else {
$data->grade = '';
}
$data->comments = $submission->proposedComment( $res ['execution'] );
$data->comments = $parsed_execution->comments;
}
}
if (! empty( $CFG->enableoutcomes )) {
Expand Down
150 changes: 150 additions & 0 deletions forms/outputfiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?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/>.

/**
* @version $Id: outputfiles.php,v 1.0 2016-09-07 20:19:00 fero Exp $
* @package mod_vpl
* @copyright 2016 Frantisek Galcik
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Frantisek Galcik <[email protected]>
*/

require_once dirname(__FILE__) . '/../../../config.php';
require_once dirname(__FILE__) . '/../locallib.php';
require_once dirname(__FILE__) . '/../vpl.class.php';
require_once $CFG->libdir . '/formslib.php';

class mod_vpl_outputfiles_form extends moodleform {
public $clear_selection = false;
public $clear_newfile = false;

protected $filenames;

function __construct($page, $filenames) {
$this->filenames = $filenames;
parent::__construct($page);
}

protected function definition() {
$mform = &$this->_form;
$mform->addElement('hidden', 'id', required_param('id', PARAM_INT));
$mform->setType('id', PARAM_INT);
$mform->addElement('header', 'header_outputfiles', get_string('outputfiles', VPL));

$mform->addElement('text', 'newfile', get_string('newoutputfile', VPL));
$mform->setType('newfile', PARAM_NOTAGS);
$mform->addHelpButton('newfile', 'newoutputfile', VPL);
$mform->addElement('submit', 'addoutputfile', get_string('addoutputfile', VPL));

if (count($this->filenames) > 0) {
$num = 0;
foreach ($this->filenames as $filename) {
$mform->addElement('checkbox', 'outputfile' . $num, s($filename));
$mform->setDefault('outputfile' . $num, false);
$num++;
}
$mform->addElement('submit', 'removeoutputfiles', get_string('removeoutputfiles', VPL));
}
}

public function validation($data, $files) {
$errors = array();
if (!empty($data['addoutputfile'])) {
$filename = trim($data['newfile']);
if (($filename == '') || !vpl_is_valid_path_name($filename)) {
$errors['newfile'] = get_string('invalidfilename', VPL);
}

if (in_array($filename, $this->filenames)) {
$errors['newfile'] = get_string('duplicatedfilename', VPL);
}
}

return $errors;
}

function definition_after_data() {
parent::definition_after_data();
$mform = &$this->_form;

if ((count($this->filenames) > 0) && ($this->clear_selection)) {
$num = 0;
foreach ($this->filenames as $filename) {
$mform->getElement('outputfile' . $num)->setValue(false);
$num++;
}
}

if ($this->clear_newfile) {
$mform->getElement('newfile')->setValue('');
}
}
}

require_login();

$id = required_param('id', PARAM_INT);
$vpl = new mod_vpl($id);
$vpl->prepare_page('forms/outputfiles.php', array(
'id' => $id
));
vpl_include_jsfile('hideshow.js');
$vpl->require_capability(VPL_MANAGE_CAPABILITY);

//Display page
$vpl->print_header(get_string('outputfiles', VPL));
$vpl->print_heading_with_help('outputfiles');

$filenames = $vpl->get_output_files();
$mform = new mod_vpl_outputfiles_form('outputfiles.php', $filenames);
if ($fromform = $mform->get_data()) {
$list_changed = false;
$clear_newfile = false;
$clear_selection = false;
if (!empty($fromform->removeoutputfiles)) {
$nlist = count($filenames);
$new_filenames = array();
for ($i = 0; $i < $nlist; $i++) {
$name = 'outputfile' . $i;
if (empty($fromform->$name)) {
$new_filenames[] = $filenames[$i];
}
}
$filenames = $new_filenames;
$list_changed = true;
$clear_selection = true;
}

if (!empty($fromform->addoutputfile)) {
array_unshift($filenames, trim($fromform->newfile));
$list_changed = true;
$clear_newfile = true;
$clear_selection = true;
}

if ($list_changed) {
$vpl->set_output_files($filenames);
\mod_vpl\event\vpl_outputlist_updated::log($vpl);
vpl_notice(get_string('outputlistupdated', VPL));
$mform = new mod_vpl_outputfiles_form('outputfiles.php', $filenames);
$mform->clear_newfile = $clear_newfile;
$mform->clear_selection = $clear_selection;
}
}

\mod_vpl\event\vpl_outputlist_viewed::log($vpl);
$mform->display();
$vpl->print_footer();
2 changes: 1 addition & 1 deletion forms/requiredfiles.json.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'action' => $action
) ) );
echo $OUTPUT->header(); // Send headers.
$data = json_decode( file_get_contents( 'php://input' ) );
$actiondata = json_decode( file_get_contents( 'php://input' ) );
switch ($action) {
case 'save' :
$postfiles = mod_vpl_edit::filesfromide($actiondata->files);
Expand Down
Loading