diff --git a/amd/build/submissionform.min.js b/amd/build/submissionform.min.js new file mode 100644 index 0000000000000000000000000000000000000000..6dbfeb52d52ab02230b3d5689ae72aa51a7e71b9 --- /dev/null +++ b/amd/build/submissionform.min.js @@ -0,0 +1 @@ +define(["jquery"],function(a){function b(b){"archive"==b?(a("#id_headersubmitarchive").show().removeClass("collapsed"),a("#id_headersubmitfiles").hide()):(a("#id_headersubmitarchive").hide(),a("#id_headersubmitfiles").show().removeClass("collapsed"))}return{setup:function(){var c=a('select[name="submitmethod"]');c.change(function(){b(c.val())}),b(c.val())}}}); \ No newline at end of file diff --git a/amd/src/submissionform.js b/amd/src/submissionform.js new file mode 100644 index 0000000000000000000000000000000000000000..87314689eb8eeff494983846af0d4d1d00cd1b15 --- /dev/null +++ b/amd/src/submissionform.js @@ -0,0 +1,21 @@ +define(['jquery'], function($) { + function updateHeaders(submitType) { + if (submitType == 'archive') { + $('#id_headersubmitarchive').show().removeClass('collapsed'); + $('#id_headersubmitfiles').hide(); + } else { + $('#id_headersubmitarchive').hide(); + $('#id_headersubmitfiles').show().removeClass('collapsed'); + } + } + + return { + setup: function() { + var $select = $('select[name="submitmethod"]'); + $select.change(function() { + updateHeaders($select.val()); + }); + updateHeaders($select.val()); + } + }; +}); \ No newline at end of file diff --git a/classes/event/variation_added.php b/classes/event/variation_added.php index 165b496de043b059949588124d998af0bff692e8..886d219ed43630b04a4731097a15cd9652c85c1b 100644 --- a/classes/event/variation_added.php +++ b/classes/event/variation_added.php @@ -30,5 +30,9 @@ class variation_added extends variation_base { protected function init() { parent::init(); $this->data ['crud'] = 'c'; + $this->legacyaction = 'added variation'; + } + public function get_description() { + return $this->get_description_mod( 'added' ); } } diff --git a/classes/event/variation_assigned.php b/classes/event/variation_assigned.php new file mode 100644 index 0000000000000000000000000000000000000000..0b1e2f06193bbe56e081a8bf75f1cf232d78376b --- /dev/null +++ b/classes/event/variation_assigned.php @@ -0,0 +1,49 @@ +. + +/** + * Class for logging of assigned variation events + * + * @package mod_vpl + * @copyright 2020 onwards Juan Carlos Rodríguez-del-Pino + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author Juan Carlos Rodríguez-del-Pino + */ +namespace mod_vpl\event; + +defined( 'MOODLE_INTERNAL' ) || die(); +require_once(dirname( __FILE__ ) . '/../../locallib.php'); +class variation_assigned extends variation_base { + protected function init() { + parent::init(); + $this->legacyaction = 'assigned variation'; + $this->data ['crud'] = 'c'; + } + public function get_description() { + return $this->get_description_mod( 'assigned' ); + } + public static function log($vpl, $varid = null, $userid = null) { + $vplinstance = $vpl->get_instance(); + $info = array ( + 'objectid' => $varid, + 'contextid' => $vpl->get_context()->id, + 'relateduserid' => $userid, + 'courseid' => $vplinstance->course, + 'other' => array('vplid' => $vplinstance->id), + ); + parent::log( $info ); + } +} \ No newline at end of file diff --git a/classes/event/variation_base.php b/classes/event/variation_base.php index 0cebf417da939269a576c9287324c8c5287ae041..ab57d6a367f60333a8f8f5b1773dde49d8221522 100644 --- a/classes/event/variation_base.php +++ b/classes/event/variation_base.php @@ -26,20 +26,42 @@ namespace mod_vpl\event; defined( 'MOODLE_INTERNAL' ) || die(); require_once(dirname( __FILE__ ) . '/../../locallib.php'); -class variation_base extends vpl_base { +class variation_base extends base { + public static function get_objectid_mapping() { + return array('db' => VPL_VARIATIONS, 'restore' => VPL_VARIATIONS); + } + public static function get_other_mapping() { + // Nothing to map. + return false; + } protected function init() { - parent::init(); + $this->data ['crud'] = 'u'; + $this->data ['edulevel'] = self::LEVEL_TEACHING; $this->data ['objecttable'] = VPL_VARIATIONS; - $this->legacyaction = 'variations form'; - } - public function get_description() { - return $this->get_description_mod( 'variation' ); } - public static function log($info) { - if (is_array( $info )) { - parent::log( $info ); + public static function log($vpl, $varid = null) { + if (is_array($vpl)) { + $info = $vpl; } else { - throw new \coding_exception( 'Parameter must be an array' ); + $vplinstance = $vpl->get_instance(); + $info = array ( + 'objectid' => $varid, + 'contextid' => $vpl->get_context()->id, + 'courseid' => $vplinstance->course, + 'other' => array('vplid' => $vplinstance->id), + ); + } + parent::log( $info ); + } + public function get_url() { + return $this->get_url_base( 'view.php' ); + } + public function get_description_mod($mod) { + $desc = 'The user with id ' . $this->userid . ' ' . $mod; + $desc .= ' variation with id ' . $this->objectid . ' of VPL activity with id ' . $this->other['vplid']; + if ($this->relateduserid) { + $desc .= ' for user with id ' . $this->relateduserid; } + return $desc; } } diff --git a/classes/event/variation_deleted.php b/classes/event/variation_deleted.php index 93627fbcc3e37c35173e05761d59ff46de17784e..de5b299f869fe21c4249e5d7265bb4495a4f41e6 100644 --- a/classes/event/variation_deleted.php +++ b/classes/event/variation_deleted.php @@ -28,5 +28,9 @@ class variation_deleted extends variation_base { protected function init() { parent::init(); $this->data['crud'] = 'd'; + $this->legacyaction = 'deleted variation'; + } + public function get_description() { + return $this->get_description_mod( 'deleted' ); } } diff --git a/classes/event/variation_updated.php b/classes/event/variation_updated.php index b8a2d1f3041dff9b7812468a43aa37e931c8cd8f..a6c18f30f4ae2ddcc64cb15f58c4000d17d427e6 100644 --- a/classes/event/variation_updated.php +++ b/classes/event/variation_updated.php @@ -30,5 +30,9 @@ class variation_updated extends variation_base { protected function init() { parent::init(); $this->data ['crud'] = 'u'; + $this->legacyaction = 'updated variation'; + } + public function get_description() { + return $this->get_description_mod( 'updated' ); } } diff --git a/classes/event/vpl_base.php b/classes/event/vpl_base.php index ef9df045c9239ba7fc3f7bd40ea485becfb04249..6a2926f52addabf0d5332eef4225439f7bfdbbb9 100644 --- a/classes/event/vpl_base.php +++ b/classes/event/vpl_base.php @@ -45,7 +45,7 @@ class vpl_base extends base { } else { $einfo = array ( 'objectid' => $vpl->get_instance()->id, - 'context' => $vpl->get_context() + 'contextid' => $vpl->get_context()->id ); parent::log( $einfo ); } diff --git a/editor/editor_utility.php b/editor/editor_utility.php index 39a5a4d48cab5c18150c2f12fe718685b8acc4df..70a5099091a7f7734a7c072b7cd70cbc28a248c2 100644 --- a/editor/editor_utility.php +++ b/editor/editor_utility.php @@ -57,172 +57,23 @@ class vpl_editor_util { $PAGE->requires->js_init_call('M.util.init_colour_picker', array('interfacetheme-colorpicker-secondary')); echo ''; } + public static function print_editor() { global $OUTPUT; - echo $OUTPUT->box_start(); -?> -
-
-
- -
-
-
    -
    -
    -
    -
    -
    -
    - - - - - - - - - -
    - -
    - -
    -
    
    -    
    - - - -
    -box_end(); + $context = new stdClass(); + $context->currenttheme = get_user_preferences('vpl_interfacetheme', 'modernblue'); + $context->currentprimarycolor = get_user_preferences('vpl_custom_interface_theme_color_primary', '#000000'); + $context->currentsecondarycolor = get_user_preferences('vpl_custom_interface_theme_color_secondary', '#FFFFFF'); + $context->installedthemes = array(); + foreach (self::get_installed_themes() as $id => $name) { + $theme = new stdClass(); + $theme->id = $id; + $theme->name = $name; + $context->installedthemes[] = $theme; + } + echo $OUTPUT->box($OUTPUT->render_from_template('mod_vpl/editor', $context)); } - public static function strings_for_js() { global $PAGE; $PAGE->requires->strings_for_js( diff --git a/filegroup.class.php b/filegroup.class.php index 1e5cc7c03284128092735992be12c9ffddaa7606..12edff46d8f463cf0da8cdb21a940c479d2a9d04 100644 --- a/filegroup.class.php +++ b/filegroup.class.php @@ -440,7 +440,7 @@ class file_group_process { * return the directory file * @return string */ - public function get_dir() { + public function get_dir() { return $this->dir; } } diff --git a/forms/grade_form.php b/forms/grade_form.php index befee37581492618b1a56f9143c9b27a7ea97421..6c32fad99b7ee360c172efdd67dd56c3655a60bf 100644 --- a/forms/grade_form.php +++ b/forms/grade_form.php @@ -40,7 +40,7 @@ class mod_vpl_grade_form extends moodleform { $options = array (); $options [- 1] = get_string( 'nograde' ); if ($scaleid > 0) { - for ($i = 0; $i <= $scaleid; $i ++) { + for ($i = 0; $i <= $scaleid; $i ++) { $options [$i] = $i . ' / ' . $scaleid; } } else if ($scaleid < 0) { @@ -53,7 +53,7 @@ class mod_vpl_grade_form extends moodleform { } return $options; } - public function __construct($page, & $vpl,& $submission) { + public function __construct($page, & $vpl, & $submission) { $this->vpl = & $vpl; $this->submission = & $submission; parent::__construct( $page ); @@ -93,12 +93,12 @@ class mod_vpl_grade_form extends moodleform { } $gridscore = $gradinginstance->get_controller()->get_min_max_score()['maxscore']; - $mform->addElement('header','hAdvancedGrading', get_string( 'gradingmanagement','grading') ); + $mform->addElement('header', 'hAdvancedGrading', get_string( 'gradingmanagement', 'grading') ); $mform->addElement('grading', 'advancedgrading', '', array('gradinginstance' => $gradinginstance)); - $mform->addElement('hidden','advancedgradinginstanceid', $gradinginstance->get_id()); + $mform->addElement('hidden', 'advancedgradinginstanceid', $gradinginstance->get_id()); $mform->setType('advancedgradinginstanceid', PARAM_INT); // Numeric grade. if ($grade > 0) { @@ -106,14 +106,14 @@ class mod_vpl_grade_form extends moodleform { $jscript = 'VPL.mergeGrade(' . $grade . ','.$graderaw.','.$gridscore.')'; //~ $html = ' ' . s( get_string( 'merge', VPL ) ) . ''; //~ $mform->addElement('html', $html ); - $mform->addElement('button','btnmerge', get_string( 'merge', VPL ),'onclick="' . $jscript . '"' ); + $mform->addElement('button', 'btnmerge', get_string( 'merge', VPL ), 'onclick="' . $jscript . '"' ); //$mform->registerNoSubmitButton('btnmerge'); } } - $mform->addElement('header','hGrade', get_string( 'grade') ); + $mform->addElement('header', 'hGrade', get_string( 'grade') ); //$mform->addElement('html','
    '); - $buttonarray=array(); + $buttonarray = array(); if ($grade != 0) { if ($grade > 0) { $buttonarray[] =& $mform->createElement('text', 'grade', '', 'size="6"' ); @@ -123,7 +123,7 @@ class mod_vpl_grade_form extends moodleform { } } $buttonarray[] =& $mform->createElement('submit', 'save', get_string( 'grade' ) ); - if ($inpopup) { + if ($inpopup) { $buttonarray[] =& $mform->createElement('submit', 'savenext', get_string( 'gradeandnext', VPL ) ); } $buttonarray[] =& $mform->createElement('submit', 'removegrade', get_string( 'removegrade', VPL ) ); @@ -147,7 +147,7 @@ class mod_vpl_grade_form extends moodleform { } $mform->addGroup($buttonarray, 'buttonar', get_string('grades'), array(' '), false); //$mform->addElement('html', '
    ' ); - $textarray=array(); + $textarray = array(); if ($grade != 0) { //$mform->addElement('html','
    '.s( get_string( 'comments', VPL )).'
    ' ); //$textarray[] =& $mform->createElement('textarea', 'comments', get_string( 'comments', VPL ), 'rows="18" cols="70"' ); diff --git a/forms/gradesubmission.php b/forms/gradesubmission.php index 11076de0175a7933a1c6ca194236dccd25ac9054..35855b9ce7138a2bcee635b9375711912558a9cb 100644 --- a/forms/gradesubmission.php +++ b/forms/gradesubmission.php @@ -96,7 +96,7 @@ if ($subinstance->dategraded == 0 || $subinstance->grader == $USER->id || $subin } else { $href = 'gradesubmission.php'; } - $gradeform = new mod_vpl_grade_form( $href, $vpl,$submission ); + $gradeform = new mod_vpl_grade_form( $href, $vpl, $submission ); if ($gradeform->is_cancelled()) { // Grading canceled. vpl_inmediate_redirect( $link ); } else if ($fromform = $gradeform->get_data()) { // Grade (new or update). @@ -127,15 +127,14 @@ if ($subinstance->dategraded == 0 || $subinstance->grader == $USER->id || $subin vpl_redirect( $link, get_string( 'badinput' ), 'error' ); } - if ($submission->is_graded()) { + if ($submission->is_graded()) { $action = 'update grade'; } else { $action = 'grade'; } $gradinginstance = $submission->get_grading_instance(); if ($gradinginstance) { - $advancedgrading = $gradinginstance->submit_and_get_grade($fromform->advancedgrading, - $submissionid); + $advancedgrading = $gradinginstance->submit_and_get_grade($fromform->advancedgrading, $submissionid); } if (! $submission->set_grade( $fromform )) { vpl_redirect( $link, get_string( 'gradenotsaved', VPL ), 'error' ); diff --git a/forms/submission.php b/forms/submission.php index 984f8b5027b7244085da6848267c2ea43c4dcba3..e7b822a59320e211fc8859373ed320a6820d838f 100644 --- a/forms/submission.php +++ b/forms/submission.php @@ -56,7 +56,7 @@ if ($userid == $USER->id) { // Make own submission. $instance = $vpl->get_instance(); $vpl->print_header( get_string( 'submission', VPL ) ); $vpl->print_view_tabs( basename( __FILE__ ) ); -$mform = new mod_vpl_submission_form( 'submission.php', $vpl ); +$mform = new mod_vpl_submission_form( 'submission.php', $vpl, $userid ); if ($mform->is_cancelled()) { vpl_inmediate_redirect( vpl_mod_href( 'view.php', 'id', $id ) ); die(); @@ -72,23 +72,82 @@ if ($fromform = $mform->get_data()) { $rfn = $vpl->get_fgm('required'); $reqfiles = $rfn->getFileList(); $files = array (); - for ($i = 0; $i < $instance->maxfiles; $i ++) { - $attribute = 'file' . $i; - $name = $mform->get_new_filename( $attribute ); - $data = $mform->get_file_content( $attribute ); - if ($data !== false && $name !== false) { + $prevsub = $vpl->last_user_submission( $userid ); + $firstsub = ($prevsub === false); + $prevsubfiles = (new mod_vpl_submission( $vpl, $prevsub ))->get_submitted_fgm()->getAllFiles(); + if ($fromform->submitmethod == 'archive') { + if (!$firstsub && $fromform->archiveaction == 'replace') { + // Use files of previous submission. + foreach ($prevsubfiles as $subfilename => $subfilecontent) { + $files[$subfilename] = $subfilecontent; + } + } + // Open archive. + $zipname = $mform->save_temp_file( 'archive' ); + $zip = new ZipArchive(); + $zip->open($zipname); + $subreqfiles = array(); + $subotherfiles = array(); + // Read archive and split between required / additional files. + for ($i = 0; $i < $zip->numFiles; $i++) { + $filename = $zip->statIndex($i)['name']; + if (substr($filename, -1) == '/') { // Directory. + continue; + } + $filecontent = file_get_contents('zip://' . $zipname . '#' . $filename); // Autodetect text file encode if not binary. - if (! vpl_is_binary( $name )) { - $encode = mb_detect_encoding( $data, 'UNICODE, UTF-16, UTF-8, ISO-8859-1', true ); - if ($encode > '') { // If code detected. - $data = iconv( $encode, 'UTF-8', $data ); + if (! vpl_is_binary( $filename )) { + $encoding = mb_detect_encoding( $filecontent, 'UNICODE, UTF-16, UTF-8, ISO-8859-1', true ); + if ($encoding > '') { // If code detected. + $filecontent = iconv( $encoding, 'UTF-8', $filecontent ); } - $files [$name] = $data; } else { - if (in_array($name . '.b64', $reqfiles)) { - $files [$name . '.b64'] = base64_encode($data); - } else { - $files [$name] = $data; + if (in_array($filename . '.b64', $reqfiles)) { + $filename = $filename . '.b64'; + $filecontent = base64_encode($filecontent); + } + } + if (in_array($filename, $reqfiles)) { + $subreqfiles[$filename] = $filecontent; + } else { + $subotherfiles[$filename] = $filecontent; + } + } + foreach ($reqfiles as $reqfile) { + if (isset($subreqfiles[$reqfile])) { + $files[$reqfile] = $subreqfiles[$reqfile]; + } + } + foreach ($subotherfiles as $filename => $filecontent) { + $files[$filename] = $filecontent; + } + // Close archive. + $zip->close(); + unlink($zipname); + } else { + for ($i = 0; $i < $instance->maxfiles; $i ++) { + $field = 'file' . $i; + if (!$firstsub && isset($fromform->{$field . 'action'}) && $fromform->{$field . 'action'} == 'keep') { + $filename = $fromform->{$field . 'name'}; + $files[$filename] = $prevsubfiles[$filename]; + } else { + $name = $mform->get_new_filename( $field ); + $data = $mform->get_file_content( $field ); + if ($data !== false && $name !== false) { + // Autodetect text file encode if not binary. + if (! vpl_is_binary( $name )) { + $encode = mb_detect_encoding( $data, 'UNICODE, UTF-16, UTF-8, ISO-8859-1', true ); + if ($encode > '') { // If code detected. + $data = iconv( $encode, 'UTF-8', $data ); + } + $files [$name] = $data; + } else { + if (in_array($name . '.b64', $reqfiles)) { + $files [$name . '.b64'] = base64_encode($data); + } else { + $files [$name] = $data; + } + } } } } diff --git a/forms/submission_form.php b/forms/submission_form.php index 6096ec5e2911568d0a35390f1bdf7e5e5c1590b4..b148047db3d40c20d0804baef9c3b459363e4b57 100644 --- a/forms/submission_form.php +++ b/forms/submission_form.php @@ -28,20 +28,22 @@ defined( 'MOODLE_INTERNAL' ) || die(); global $CFG; require_once($CFG->libdir.'/formslib.php'); require_once(dirname(__FILE__).'/../locallib.php'); +require_once(dirname(__FILE__).'/edit.class.php'); class mod_vpl_submission_form extends moodleform { protected $vpl; + protected $userid; protected function getinternalform() { return $this->_form; } - public function __construct($page, $vpl) { + public function __construct($page, $vpl, $userid) { $this->vpl = $vpl; + $this->userid = $userid; parent::__construct( $page ); } protected function definition() { global $CFG; $mform = & $this->_form; - $mform->addElement( 'header', 'headersubmission', get_string( 'submission', VPL ) ); // Identification info. $mform->addElement( 'hidden', 'id' ); $mform->setType( 'id', PARAM_INT ); @@ -54,18 +56,87 @@ class mod_vpl_submission_form extends moodleform { ) ); $mform->setType( 'comments', PARAM_TEXT ); + $firstsub = ($this->vpl->last_user_submission( $this->userid ) === false); + + $mform->addElement( 'select', 'submitmethod', get_string( 'submitmethod', VPL ), + array('archive' => get_string( 'archive', VPL ), 'files' => get_string( 'files' )) ); + + $mform->addElement( 'header', 'headersubmitarchive', get_string( 'submitarchive', VPL ) ); + + if (!$firstsub) { + $mform->addElement( 'radio', 'archiveaction', get_string( 'submitarchive', VPL ), + get_string( 'archivereplacedelete', VPL ), 'replacedelete'); + $mform->addElement( 'radio', 'archiveaction', '', + get_string( 'archivereplace', VPL ), 'replace' ); + $mform->disabledIf( 'archiveaction', 'submitmethod', 'neq', 'archive' ); + } + $mform->addElement( 'filepicker', 'archive', null, null, array('accepted_types' => '.zip') ); + $mform->disabledIf( 'archive', 'submitmethod', 'neq', 'archive' ); + + $mform->addElement( 'header', 'headersubmitfiles', get_string( 'submitfiles', VPL ) ); + // Files upload. $instance = $this->vpl->get_instance(); - $files = $this->vpl->get_files('required'); - $nfiles = count( $files ); - for ($i = 0; $i < $instance->maxfiles; $i ++) { + $reqfiles = $this->vpl->get_files('required'); + $i = 0; + foreach ($reqfiles as $reqfile) { $field = 'file' . $i; - if ($i < $nfiles) { - $mform->addElement( 'filepicker', $field, $files [$i] ); - } else { - $mform->addElement( 'filepicker', $field, get_string( 'anyfile', VPL ) ); + if (!$firstsub) { + $mform->addElement( 'radio', $field . 'action', $reqfile, + get_string( 'keepcurrentfile', VPL ), 'keep'); + $mform->addElement( 'radio', $field . 'action', '', + get_string( 'replacefile', VPL ), 'replace' ); + $mform->disabledIf( $field . 'action', 'submitmethod', 'neq', 'files' ); + $mform->addElement( 'hidden', $field . 'name', $reqfile ); + $mform->setType( $field . 'name', PARAM_RAW ); } + $mform->addElement( 'filepicker', $field ); + $mform->disabledIf( $field, 'submitmethod', 'neq', 'files' ); + if (!$firstsub) { + $mform->disabledIf( $field, $field . 'action', 'neq', 'replace' ); + } + $i++; + } + $submission = $this->vpl->last_user_submission( $this->userid ); + if ($submission !== false) { + $subfiles = (new mod_vpl_submission( $this->vpl, $submission ))->get_submitted_fgm()->getFileList(); + foreach ($subfiles as $subfile) { + if (!in_array($subfile, $reqfiles)) { + $field = 'file' . $i; + if (!$firstsub) { + $mform->addElement( 'radio', $field . 'action', $subfile, get_string( 'keepcurrentfile', VPL ), 'keep'); + $mform->addElement( 'radio', $field . 'action', '', get_string( 'deletefile', VPL ), 'delete' ); + $mform->addElement( 'radio', $field . 'action', '', get_string( 'replacefile', VPL ), 'replace' ); + $mform->disabledIf( $field . 'action', 'submitmethod', 'neq', 'files' ); + $mform->addElement( 'hidden', $field . 'name', $subfile ); + $mform->setType( $field . 'name', PARAM_RAW ); + } + $mform->addElement( 'filepicker', $field ); + $mform->disabledIf( $field, 'submitmethod', 'neq', 'files' ); + if (!$firstsub) { + $mform->disabledIf( $field, $field . 'action', 'neq', 'replace' ); + } + $i++; + } + } + } + + while ($i < $instance->maxfiles) { + $field = 'file' . $i; + $mform->addElement( 'filepicker', $field, get_string( 'anyfile', VPL ) ); + $mform->disabledIf( $field, 'submitmethod', 'neq', 'files' ); + $i++; } $this->add_action_buttons( true, get_string( 'submit' ) ); + + global $PAGE; + $PAGE->requires->js_call_amd('mod_vpl/submissionform', 'setup'); + } + public function set_data($data) { + for ($i = 0; $i < $this->vpl->get_instance()->maxfiles; $i++) { + $data->{'file'.$i.'action'} = 'keep'; + $data->{'archiveaction'} = 'replacedelete'; + } + parent::set_data($data); } } diff --git a/forms/variations.php b/forms/variations.php index 58d669e4b4e69f8341b237f0dbf8d0d1cbd91dcc..10135993bc7d17c6750addad850ef2a2e31360ce 100644 --- a/forms/variations.php +++ b/forms/variations.php @@ -51,14 +51,14 @@ class mod_vpl_variation_form extends moodleform { protected $varid; protected $number; // Parm $varid = -1 new variation. - public function __construct($page, $number, $varid = -1) { + public function __construct($page, $number = 0, $varid = 0) { $this->number = $number; $this->varid = $varid; parent::__construct( $page ); } protected function definition() { $mform = & $this->_form; - if ($this->number >= 0) { + if ($this->number > 0) { $title = get_string( 'variation', VPL, "{$this->number}" ); } else { $title = get_string( 'add' ); @@ -68,21 +68,21 @@ class mod_vpl_variation_form extends moodleform { $mform->setType( 'id', PARAM_INT ); $mform->addElement( 'hidden', 'varid', $this->varid ); $mform->setType( 'varid', PARAM_INT ); + $mform->addElement( 'text', 'identification', get_string( 'varidentification', VPL ), array ( 'size' => '20' ) ); $mform->setDefault( 'identification', '' ); - $mform->setType( 'identification', PARAM_RAW ); - $mform->addElement( 'textarea', 'description', get_string( 'description', VPL ), array ( - 'cols' => 45, - 'rows' => 5 - ) ); - $mform->setType( 'description', PARAM_CLEANHTML ); - $mform->setDefault( 'description', '' ); + $mform->setType( 'identification', PARAM_ALPHANUM ); + $fieldname = 'description' . $this->varid; // Allows multile editors in page. + $mform->addElement('editor', $fieldname, get_string('description', VPL)); + $mform->setType($fieldname, PARAM_RAW); + $mform->setDefault( $fieldname, '' ); + $buttongroup = array (); $buttongroup [] = $mform->createElement( 'submit', 'save', get_string( 'save', VPL ) ); $buttongroup [] = $mform->createElement( 'submit', 'cancel', get_string( 'cancel' ) ); - if ($this->number >= 0) { + if ($this->number > 0) { $menssage = addslashes( get_string( 'delete' ) ); $onclick = 'onclick="return confirm(\'' . $menssage . '\')"'; $buttongroup [] = $mform->createElement( 'submit', 'delete', get_string( 'delete' ), $onclick ); @@ -95,20 +95,15 @@ require_login(); $id = required_param( 'id', PARAM_INT ); $vpl = new mod_vpl( $id ); -$vpl->prepare_page( 'forms/variations.php', array ( 'id' => $id ) ); -vpl_include_jsfile( 'hideshow.js' ); $vplid = $vpl->get_instance()->id; +$vpl->prepare_page( 'forms/variations.php', array ( 'id' => $id ) ); $vpl->require_capability( VPL_MANAGE_CAPABILITY ); -global $PAGE; -$PAGE->force_settings_menu(); $href = vpl_mod_href( 'forms/variations.php', 'id', $id ); -$vpl->print_header( get_string( 'variations', VPL ) ); -$vpl->print_heading_with_help( 'variations' ); // Generate default form and check for action. -if (optional_param( 'varid', - 13, PARAM_INT ) == - 13) { // No variation saved. +if (optional_param( 'varid', null, PARAM_INT ) === null) { // No variation saved. $oform = new mod_vpl_variation_option_form( $href, $vpl ); - if ($oform->is_cancelled()) { - vpl_inmediate_redirect( $href ); // Reload page. + if (isset($_POST['cancel'])) { + redirect( $href, get_string('cancelled') ); } else if ($fromform = $oform->get_data()) { vpl_truncate_string( $fromform->variationtitle, 255 ); $instance = $vpl->get_instance(); @@ -116,41 +111,43 @@ if (optional_param( 'varid', - 13, PARAM_INT ) == - 13) { // No variation saved. $instance->variationtitle = $fromform->variationtitle; $vpl->update(); \mod_vpl\event\vpl_variation_updated::log( $vpl ); - vpl_inmediate_redirect( $href ); + redirect( $href, get_string('updated', '', $instance->variationtitle) ); } $vplinstmod = clone $vpl->get_instance(); $vplinstmod->id = $id; $oform->set_data( $vplinstmod ); } -$mform = new mod_vpl_variation_form( $href, 0 ); -if ($mform->is_cancelled()) { - vpl_inmediate_redirect( $href ); // Reload page. +$varid = optional_param( 'varid', 0, PARAM_INT ); +$mform = new mod_vpl_variation_form( $href, 0, $varid ); +if ( isset($_POST['cancel']) ) { + redirect( $href, get_string('cancelled') ); // Reload page. } else if ($fromform = $mform->get_data()) { - if (isset( $fromform->delete )) { // Delete variation and its assignned variations to users. + if ( isset($_POST['delete']) ) { // Deletes variation and its assignned variations. if ($DB->delete_records( VPL_VARIATIONS, array ( 'id' => $fromform->varid, 'vpl' => $vplid ) )) { - \mod_vpl\event\variation_deleted::log( array ( - 'objectid' => $fromform->varid, - 'context' => $vpl->get_context() - ) ); + \mod_vpl\event\variation_deleted::log( $vpl, $fromform->varid ); $DB->delete_records( VPL_ASSIGNED_VARIATIONS, array ( - 'id' => $fromform->varid + 'variation' => $fromform->varid ) ); + } else { + print_error( VPL_VARIATIONS . ' record not deleted' . $fromform->varid . ' ' . $vplid, VPL, $href ); } + redirect( $href, get_string('deleted') ); } else { - if ($fromform->varid == - 1) { // New record. + if ($fromform->varid <= 0) { // New record. $fromform->vpl = $vplid; unset( $fromform->id ); + $fromform->description = $fromform->description0['text']; vpl_truncate_variations( $fromform ); if ($vid = $DB->insert_record( VPL_VARIATIONS, $fromform )) { - \mod_vpl\event\variation_added::log( array ( - 'objectid' => $vid, - 'context' => $vpl->get_context() - ) ); + \mod_vpl\event\variation_added::log( $vpl, $vid ); + } else { + print_error( VPL_VARIATIONS . ' record not inserted' . $fromform->varid . ' ' . $vplid, VPL, $href ); } + redirect( $href, get_string('saved', VPL) ); } else { // Update record. if ($DB->get_record( VPL_VARIATIONS, array ( 'id' => $fromform->varid, @@ -158,21 +155,24 @@ if ($mform->is_cancelled()) { ) )) { // Check consistence. $fromform->vpl = $vplid; $fromform->id = $fromform->varid; + $fieldname = 'description' . $fromform->varid; + $fromform->description = $fromform->{$fieldname}['text']; vpl_truncate_variations( $fromform ); $DB->update_record( VPL_VARIATIONS, $fromform ); - \mod_vpl\event\variation_updated::log( array ( - 'objectid' => $fromform->varid, - 'context' => $vpl->get_context() - ) ); + \mod_vpl\event\variation_updated::log( $vpl, $fromform->varid ); + redirect( $href, get_string('updated', '', $fromform->identification) ); } else { - $vpl->print_header( get_string( 'variations', VPL ) ); - $vpl->print_heading_with_help( 'variations' ); - print_error( VPL_VARIATIONS . ' record inconsistence', VPL, $href ); + print_error( VPL_VARIATIONS . ' record inconsistence ' . $id . ' ' . $vplid, VPL, $href ); } } } - vpl_inmediate_redirect( $href ); } + +global $PAGE; +$PAGE->force_settings_menu(); +$vpl->print_header( get_string( 'variations', VPL ) ); +$vpl->print_heading_with_help( 'variations' ); + // Display page. if (isset( $oform )) { $oform->display(); @@ -189,10 +189,12 @@ foreach ($list as $variation) { $aform = new mod_vpl_variation_form( $href, $number, $variation->id ); $variation->varid = $variation->id; $variation->id = $id; + $fieldname = 'description' . $variation->varid; + $variation->$fieldname = array('text' => $variation->description); $aform->set_data( $variation ); $aform->display(); $number ++; } -$lastform = new mod_vpl_variation_form( $href, - 1 ); +$lastform = new mod_vpl_variation_form( $href ); $lastform->display(); $vpl->print_footer(); diff --git a/jscript/grade.js b/jscript/grade.js index 6a6a989f4488529786ae6191fb83d23b269bc1ec..1ddf9bb6a4b05f0fff536202a001905231dfad4b 100644 --- a/jscript/grade.js +++ b/jscript/grade.js @@ -12,7 +12,7 @@ // // You should have received a copy of the GNU General Public License // along with VPL for Moodle. If not, see . - + /** * JavaScript functions to help grade form * @package mod_vpl @@ -20,9 +20,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @author Juan Carlos Rodríguez-del-Pino */ - + /* globals VPL: true */ - + (function() { if (typeof VPL != 'object') { VPL = {}; @@ -38,7 +38,7 @@ }; // Resize comments view div to greatest visible size. VPL.resizeSView = function() { - var grade_view = window.document.getElementById('vpl_grade_view'); + var grade_view = window.document.getElementById('vpl_grade_view'); var comments_view = window.document.getElementById('vpl_grade_comments'); var textarea = window.document.getElementsByTagName('textarea')[0]; var form_view = window.document.getElementById('vpl_grade_form'); @@ -61,9 +61,9 @@ submission_view.style.height = newHeight + 'px'; } }; - + /* Set the resize controler */ - + VPL.resizeSView(); setInterval(VPL.resizeSView, 1000); /** @@ -78,7 +78,7 @@ var match; while ((match = regDiscount.exec(text)) !== null) { var rest = parseFloat(match[1]); - if (rest < 0) { + if (rest < 0) { grade += rest; } } @@ -90,8 +90,8 @@ grade = Math.round(100 * grade) / 100; form1.grade.value = grade; }; - -/** + + /** * Merge numeric grade from the proposed grade and advancedgrading * end of lines. valid grade format: "- text (-grade)" */ @@ -118,7 +118,7 @@ }else{ text = text.replace(/#Grid grade.*/,gridcomment); } - + fieldcomments.value = text; /* Max two decimal points */ grade = Math.round(100 * grade) / 100; diff --git a/lang/en/vpl.php b/lang/en/vpl.php index 19b8ab3b6b47ee9a9d87a16f30481c551084b2f1..848174cc552706afaa131e4e37bb081dd241da43 100644 --- a/lang/en/vpl.php +++ b/lang/en/vpl.php @@ -28,6 +28,9 @@ $string ['allfiles'] = 'All files'; $string ['allowshowprevious'] = 'Allow student show previous submissions'; $string ['allsubmissions'] = 'All submissions'; $string ['anyfile'] = 'Any file'; +$string ['archive'] = 'Archive'; +$string ['archivereplace'] = 'Replace only files present in archive'; +$string ['archivereplacedelete'] = 'Replace all files and delete files not present in archive'; $string ['attemptnumber'] = 'Attempt number {$a}'; $string ['autodetect'] = 'Autodetect'; $string ['automaticevaluation'] = 'Automatic evaluation'; @@ -80,6 +83,7 @@ $string ['delete'] = 'Delete'; $string ['delete_file_fq'] = "delete '{\$a}' file?"; $string ['delete_file_q'] = 'Delete file?'; $string ['deleteallsubmissions'] = 'Delete all submissions'; +$string ['deletefile'] = 'Delete file'; $string ['description'] = 'Description'; $string ['diff'] = 'diff'; $string ['discard_submission_period'] = 'Discard submission period'; @@ -159,6 +163,7 @@ $string ['jail_servers'] = 'Execution servers list'; $string ['jail_servers_config'] = 'Execution servers config'; $string ['jail_servers_description'] = 'Write a line for each server'; $string ['joinedfiles'] = 'Joined selected files'; +$string ['keepcurrentfile'] = 'Keep current file'; $string ['keepfiles'] = 'Files to keep when running'; $string ['keyboard'] = 'Keyboard'; $string ['lasterror'] = 'Last error info'; @@ -252,6 +257,7 @@ $string ['removegrade'] = 'Remove grade'; $string ['rename'] = 'Rename'; $string ['rename_file'] = 'Rename file'; $string ['replace_find'] = 'Replace/Find'; +$string ['replacefile'] = 'Replace'; $string ['replacenewer'] = "A newer version was already saved.\nDo you want to replace the newer version with this one?"; $string ['requestedfiles'] = 'Requested files'; $string ['requirednet'] = 'Allowed submission from net'; @@ -301,6 +307,9 @@ $string ['submissionscharts'] = 'Submissions charts'; $string ['submissionselection'] = 'Submission selection'; $string ['submissionslist'] = 'Submissions list'; $string ['submissionview'] = 'Submission view'; +$string ['submitarchive'] = 'Submit archive'; +$string ['submitfiles'] = 'Submit files'; +$string ['submitmethod'] = 'Submit method'; $string ['submittedby'] = 'Submitted by {$a}'; $string ['submittedon'] = 'Submitted on'; $string ['submittedonp'] = 'Submitted on {$a}'; diff --git a/lib.php b/lib.php index 1fc60debafae0fd825ba7dacf58fb358f31a725d..feaf46269fe7eb60c83f354e329f3b8e24b627c9 100644 --- a/lib.php +++ b/lib.php @@ -599,15 +599,12 @@ function vpl_extend_settings_navigation(settings_navigation $settings, navigatio )), $fkn); // Advanced settings. - $urlexecutionfiles = new moodle_url( '/mod/vpl/forms/files.php', array ( - 'id' => $cmid, - 'type' => 'execution' - )); - $advanced = vpl_navi_node_create($vplnode, 'advancedsettings', - $urlexecutionfiles, $fkn, - navigation_node::TYPE_CONTAINER, 'moodle'); + $advanced = vpl_navi_node_create($vplnode, 'advancedsettings', null, $fkn, navigation_node::TYPE_CONTAINER, 'moodle'); vpl_navi_node_create($advanced, 'executionfiles', - $urlexecutionfiles); + new moodle_url( '/mod/vpl/forms/files.php', array ( + 'id' => $cmid, + 'type' => 'execution' + ))); vpl_navi_node_create($advanced, 'maxresourcelimits', new moodle_url( '/mod/vpl/forms/executionlimits.php', $parms )); vpl_navi_node_create($advanced, 'keepfiles', diff --git a/locallib.php b/locallib.php index 6b7f6f84af6a465adab180b71de95845f5efa72e..f1de56ff0500d10b034ddba0be258fbb9af58e69 100644 --- a/locallib.php +++ b/locallib.php @@ -973,4 +973,16 @@ function vpl_get_name_fields_display() { } $strname = trim(fullname($nameformat)); return substr($strname, 0, strlen($strname) - 2); +} + +/** + * Return action_menu_link for menu in list + * @param string $str + * @param moodle_url $link + * @param string $comp value for get_string + * @return action_menu_link_secondary + */ +function vpl_get_menu_action_link($str, $link, $comp = 'mod_vpl') { + $stri18n = get_string($str, $comp); + return new action_menu_link_secondary($link, new pix_icon($str, '', 'mod_vpl'), $stri18n); } \ No newline at end of file diff --git a/similarity/diff.class.php b/similarity/diff.class.php index e4d69b92c5cdc7b2bca65a6c78e51bf4bf7ad282..ae52f7070ac5bc9a36adfdb462d57cfa92683cf4 100644 --- a/similarity/diff.class.php +++ b/similarity/diff.class.php @@ -65,10 +65,10 @@ class vpl_diff { // Due to PHP arrays architecture, the calculatediff function consumes a lot of memory. // To reduce that memory consumption, we put information on the "prev" on the 29th and 30th bits of integers. - static private $PREVX = 2**29; - static private $PREVY = 2**30; - static private function trueValue($value) { - return $value & ~(self::$PREVX + self::$PREVY); + static private $prevx = 2 ** 29; + static private $prevy = 2 ** 30; + static private function truevalue($value) { + return $value & ~(self::$prevx + self::$prevy); } /** @@ -87,11 +87,11 @@ class vpl_diff { $matrix[$i][$j] = 0; } // Set prev for first column. - $matrix[$i][0] = self::$PREVY; + $matrix[$i][0] = self::$prevy; } // Set prev for first row. for ($j = 0; $j <= $nl2; $j ++) { - $matrix[0][$j] = self::$PREVX; + $matrix[0][$j] = self::$prevx; } } @@ -137,20 +137,20 @@ class vpl_diff { for ($i = 1; $i <= $nl1; $i ++) { $line = $lines1 [$i - 1]; for ($j = 1; $j <= $nl2; $j ++) { - if (self::trueValue($matrix[$i][$j - 1]) > self::trueValue($matrix[$i - 1][$j])) { - $max = self::trueValue($matrix[$i][$j - 1]); - $best = self::$PREVY; + if (self::truevalue($matrix[$i][$j - 1]) > self::truevalue($matrix[$i - 1][$j])) { + $max = self::truevalue($matrix[$i][$j - 1]); + $best = self::$prevy; } else { - $max = self::trueValue($matrix[$i - 1][$j]); - $best = self::$PREVX; + $max = self::truevalue($matrix[$i - 1][$j]); + $best = self::$prevx; } if ($detaileddiff) { $prize = self::diffline( $line, $lines2 [$j - 1] ); } else { $prize = $line === $lines2 [$j - 1] ? 1 : 0; } - if (self::trueValue($matrix[$i - 1][$j - 1]) + $prize >= $max) { - $max = self::trueValue($matrix[$i - 1][$j - 1]) + $prize; + if (self::truevalue($matrix[$i - 1][$j - 1]) + $prize >= $max) { + $max = self::truevalue($matrix[$i - 1][$j - 1]) + $prize; $best = 0; } $matrix [$i] [$j] = $max + $best; @@ -167,9 +167,9 @@ class vpl_diff { $pair->i = $pi; $pair->j = $pj; $pairs [] = $pair; - if (($matrix[$pi][$pj] & self::$PREVY) > 0) { + if (($matrix[$pi][$pj] & self::$prevy) > 0) { $pj --; - } else if (($matrix[$pi][$pj] & self::$PREVX) > 0) { + } else if (($matrix[$pi][$pj] & self::$prevx) > 0) { $pi --; } else { $pi --; diff --git a/similarity/similarity_factory.class.php b/similarity/similarity_factory.class.php index 4dc050c7db6b4e4ba4d00988b01a0524e5489f0d..225dec0d4913b4f6644b13a677fa2e8a56c05086 100644 --- a/similarity/similarity_factory.class.php +++ b/similarity/similarity_factory.class.php @@ -34,7 +34,7 @@ class vpl_filetype { 'js' => 'c', // JavaScript as C. 'cc' => 'cpp', 'C' => 'cpp', - 'mod' => 'c', //Opl as C + 'mod' => 'c', // Opl as C. 'cpp' => 'cpp', 'cs' => 'cpp', // C# as C++. 'ads' => 'ada', diff --git a/templates/editor.mustache b/templates/editor.mustache new file mode 100644 index 0000000000000000000000000000000000000000..3edc4839976a19c6cb833842a546abdf16857f78 --- /dev/null +++ b/templates/editor.mustache @@ -0,0 +1,208 @@ +{{! + 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 . +}} +{{! + @template mod_vpl/editor + + Classes required for JS: + * none + + Data attributes required for JS: + * none + + Context variables required for this template: + * currenttheme Current interface theme. + * installedthemes Array of all installed editor themes. + * id Editor theme actual name. + * name Editor theme displayable name. + * currentprimarycolor Current primary color for custom interface theme. + * currentsecondarycolor Current secondary color for custom interface theme. + + Example context (json): + { + "currenttheme": "custom", + "installedthemes": [ + { + "id": "ambiance", + "name": "Ambiance" + }, + { + "id": "chrome", + "name": "Chrome" + } + ] + "currentprimarycolor": "#000000", + "currentsecondarycolor": "#FFFFFF" + } +}} +
    +
    +
    + +
    +
    +
      +
      +
      +
      +
      +
      +
      + + + + + + + + + +
      + +
      + +
      +
      
      +    
      + + + +
      \ No newline at end of file diff --git a/views/previoussubmissionslist.php b/views/previoussubmissionslist.php index 34678f1553b348c0145c598e4b0fb9bfb2b46fa0..ecc1ff787cf6776ec00a3906a9fcd4b1da03d687 100644 --- a/views/previoussubmissionslist.php +++ b/views/previoussubmissionslist.php @@ -37,13 +37,9 @@ function vpl_actions_menu($id, $userid, $subid) { $menu = new action_menu(); $linkparms = array('id' => $id, 'userid' => $userid, 'submissionid' => $subid); $link = new moodle_url('/mod/vpl/forms/submissionview.php', $linkparms); - $stri18n = get_string('submissionview', 'mod_vpl'); - $action = new action_menu_link_secondary($link, new pix_icon('submissionview', '', 'mod_vpl'), $stri18n); - $menu->add($action); - $stri18n = get_string('copy', 'mod_vpl'); + $menu->add( vpl_get_menu_action_link('submissionview', $link) ); $link = new moodle_url('/mod/vpl/forms/edit.php', array_merge($linkparms, array('privatecopy' => 1))); - $action = new action_menu_link_secondary($link, new pix_icon('copy', '', 'mod_vpl'), $stri18n); - $menu->add($action); + $menu->add( vpl_get_menu_action_link('copy', $link) ); return $menu; } diff --git a/views/submissionslist.php b/views/submissionslist.php index fe9cc1000274d1d5de804742ebbc40bea8d4a87d..facabeec1e30de19961b72708ee5006f4e6a1aae 100644 --- a/views/submissionslist.php +++ b/views/submissionslist.php @@ -50,37 +50,25 @@ function vpl_get_listmenu($id, $showgrades, $group) { $menu = new action_menu(); $url = new moodle_url( '/mod/vpl/views/activityworkinggraph.php', array ( 'id' => $id) ); - $menu->add(vpl_get_action_link('submissionscharts', $url)); + $menu->add(vpl_get_menu_action_link('submissionscharts', $url)); if ($showgrades) { $url = get_this_page_url($id, 0, $group); - $menu->add(vpl_get_action_link('submissionslist', $url)); + $menu->add(vpl_get_menu_action_link('submissionslist', $url)); } else { $url = get_this_page_url($id, 1, $group); - $menu->add(vpl_get_action_link('gradercomments', $url)); + $menu->add(vpl_get_menu_action_link('gradercomments', $url)); } $url = new moodle_url( '/mod/vpl/views/downloadallsubmissions.php', array ( 'id' => $id) ); - $menu->add(vpl_get_action_link('downloadsubmissions', $url)); + $menu->add(vpl_get_menu_action_link('downloadsubmissions', $url)); $url = new moodle_url( '/mod/vpl/views/downloadallsubmissions.php', array ( 'id' => $id, 'all' => 1) ); - $menu->add(vpl_get_action_link('downloadallsubmissions', $url)); + $menu->add(vpl_get_menu_action_link('downloadallsubmissions', $url)); return $menu; } -/** - * Return action_menu_link for menu in list - * @param string $str - * @param moodle_url $link - * @param string $comp value for get_string - * @return action_menu_link_secondary - */ -function vpl_get_action_link($str, $link, $comp = 'mod_vpl') { - $stri18n = get_string($str, $comp); - return new action_menu_link_secondary($link, new pix_icon($str, '', 'mod_vpl'), $stri18n); -} - require_login(); $id = required_param( 'id', PARAM_INT ); @@ -249,7 +237,7 @@ foreach ($list as $uginfo) { $gradecomments = ''; $linkparms = array('id' => $id, 'userid' => $user->id); $viewlink = new moodle_url('/mod/vpl/forms/submissionview.php', $linkparms); - $actions->add(vpl_get_action_link('submissionview', $viewlink)); + $actions->add(vpl_get_menu_action_link('submissionview', $viewlink)); if ($submission == null) { $subtime = $OUTPUT->action_link( $viewlink, get_string( 'nosubmission', VPL ) ); $prev = ''; @@ -270,7 +258,7 @@ foreach ($list as $uginfo) { array( 'title' => get_string('previoussubmissionslist', VPL) ) ); - $actions->add(vpl_get_action_link('previoussubmissionslist', $prevlink)); + $actions->add(vpl_get_menu_action_link('previoussubmissionslist', $prevlink)); } else { $prev = ''; } @@ -336,7 +324,7 @@ foreach ($list as $uginfo) { } $link = new moodle_url('/mod/vpl/forms/gradesubmission.php', $linkparms); - $actions->add(vpl_get_action_link('grade', $link, 'moodle')); + $actions->add(vpl_get_menu_action_link('grade', $link, 'moodle')); // Add div id to submission info. $grader = '
      ' . $grader . '
      '; $gradedon = '
      '. @@ -350,7 +338,7 @@ foreach ($list as $uginfo) { array( 'title' => get_string('copy', VPL) ) ); - $actions->add(vpl_get_action_link('copy', $copylink)); + $actions->add(vpl_get_menu_action_link('copy', $copylink)); $submissiondata = array ( $usernumberlink, diff --git a/vpl.class.php b/vpl.class.php index fcd83948314969d5ebc4578c4b7262dd77067170..7a7361ddd59b6999209f133d740971fa4906f8bc 100644 --- a/vpl.class.php +++ b/vpl.class.php @@ -321,7 +321,7 @@ class mod_vpl { $ret .= ' (' . $grouping->name . ')'; } } - return $ret; + return format_string($ret); } /** @@ -1603,9 +1603,8 @@ class mod_vpl { * Show vpl name */ public function print_name() { - echo '

      '; - p( $this->get_printable_name() ); - echo '

      '; + global $OUTPUT; + echo $OUTPUT->heading($this->get_printable_name()); } public function str_restriction($str, $value = null, $raw = false) { @@ -1896,15 +1895,19 @@ class mod_vpl { if (! $DB->insert_record( VPL_ASSIGNED_VARIATIONS, $assign )) { print_error( 'vpl variation not assigned' ); } + \mod_vpl\event\variation_assigned::log( $this, $variation->id, $userid); } else { - if ($varassigned === false || $varassigned->vpl != $this->instance->id) { // Test consistency. - // TODO repair inconsistence? - print_error( 'vpl assigned variation inconsistency' ); - } $variation = $DB->get_record( VPL_VARIATIONS, array ( 'id' => $varassigned->variation ) ); + if ($variation == false || $variation->vpl != $varassigned->vpl) { // Checks consistency. + $DB->delete_records( VPL_ASSIGNED_VARIATIONS, + array ( + 'id' => $varassigned->id + ) ); + print_error( 'vpl assigned variation inconsistency. Fixed removing the current assigment.' ); + } } return $variation; } diff --git a/vpl_submission.class.php b/vpl_submission.class.php index 4d02f8daff0f60bcfa89067728ff1087ada4a788..c44b45f2858963827a1661dfd1bb8fe904cb4091 100644 --- a/vpl_submission.class.php +++ b/vpl_submission.class.php @@ -722,7 +722,8 @@ class mod_vpl_submission { $cangrade = has_capability(VPL_GRADE_CAPABILITY, $this->vpl->get_context()); // Only show the grade if it is not hidden in gradebook. $userid = ($cangrade || has_capability( VPL_MANAGE_CAPABILITY, $this->vpl->get_context() )) ? null : $USER->id; - $gradeinfo = grade_get_grades( $this->vpl->get_course()->id, 'mod', 'vpl', $this->vpl->get_instance()->id, $userid ); + $gradeinfo = grade_get_grades( $this->vpl->get_course()->id, 'mod', 'vpl', + $this->vpl->get_instance()->id, $userid ); $ret .= $gradinginstance->get_controller()->render_grade($PAGE, $this->instance->id, $gradeinfo, @@ -743,7 +744,7 @@ class mod_vpl_submission { } } if ($return) { - return $ret; + return $ret; } else { if ($ret) { echo $OUTPUT->box( $ret ); @@ -915,7 +916,7 @@ class mod_vpl_submission { * @return string text with links */ public function add_filelink($text) { - // Format filename:linenumber. + // Format filename:linenumber. $ret = ''; $list = $this->get_submitted_fgm()->getFileList(); usort( $list, 'vpl_compare_filenamebylengh' ); @@ -956,7 +957,7 @@ class mod_vpl_submission { $html .= '
      '; $html .= $comment; } else { - $div = new vpl_hide_show_div( false ); + $div = new vpl_hide_show_div( false ); $html .= $div->generate( true ); $html .= ''; $html .= s( $title ); @@ -997,7 +998,7 @@ class mod_vpl_submission { } // Is title line. if (strlen( $line ) > 1 && $line [0] == '-') { // Title. - $html .= $this->get_last_comment( $title, $comment, $dropdown ); + $html .= $this->get_last_comment( $title, $comment, $dropdown ); $line = trim( substr( $line, 1 ) ); if ($line [strlen( $line ) - 1] == ')') { // Has grade? $posopen = strrpos( $line, '(' ); @@ -1038,10 +1039,9 @@ class mod_vpl_submission { $comment .= ''; } $comment .= '
      '; - } else if (strlen( $line ) > 1 && $line [0] == '#') { // Teacher comment - $html .= $this->get_last_comment( $title, $comment, $dropdown ); - - }else{ // Regular text. + } else if (strlen( $line ) > 1 && $line [0] == '#') { // Teacher comment. + $html .= $this->get_last_comment( $title, $comment, $dropdown ); + } else { // Regular text. $comment .= $this->add_filelink( s( $line ) ) . '
      '; } } @@ -1074,7 +1074,7 @@ class mod_vpl_submission { * @return array of mensajes */ public function filter_feedback(&$list) { - $text = $this->get_grade_comments(); + $text = $this->get_grade_comments(); $nl = vpl_detect_newline( $text ); $lines = explode( $nl, $text ); foreach ($lines as $line) { @@ -1159,7 +1159,7 @@ class mod_vpl_submission { $ret ['executed'] = 1; $ret ['execution'] = file_get_contents( $execfn ); } else { - $ret ['executed'] = 0; + $ret ['executed'] = 0; } $ret ['nevaluations'] = $this->instance->nevaluations; $vplinstance = $this->vpl->get_instance(); @@ -1277,7 +1277,7 @@ class mod_vpl_submission { if (strlen( $compilation )) { $params .= vpl_param_tag( 'compilation', $compilation ); } - if (strlen( $execution )) { + if (strlen( $execution )) { $params .= vpl_param_tag( 'evaluation', $execution ); } if (strlen( $grade )) {