Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c82353d
Updating CI.
mchurchward Aug 21, 2024
1f43c39
Circumvent number on string error, resolves #538. (#563)
lucaboesch Aug 21, 2024
afe3b05
delete all includes incomplete responses (#562)
Syxton Aug 21, 2024
6253d1a
Change default of 'resp_view' select setting to never (#550)
FelixDiLenarda Aug 21, 2024
a906ac0
Prepare for Moodle 4.3.
lucaboesch Oct 15, 2023
0861ca8
Fixing Moodle Code Checker issues.
lucaboesch Jan 19, 2024
6aa0ea8
Add file question type
laurentdavid Feb 15, 2023
763ab68
Fix preview submission (no sesskey)
laurentdavid May 10, 2023
19335bf
Fix PHPdoc issue with pluginfile
laurentdavid May 15, 2023
a067434
Further fixes:
laurentdavid May 10, 2023
71712af
Tackle creation of dynamic properties.
lucaboesch Oct 15, 2023
c6bbfe2
Update version to 2023101500.
lucaboesch Oct 15, 2023
604bf5c
Fix upload when several file upload questions are used.
srobotta Jan 17, 2024
c4f93c5
Fix handling of file uploads
srobotta Jan 18, 2024
485bc50
Change refence of file.itemid to questionnaire_response_file.id
srobotta Jan 18, 2024
1df20f1
update existing files.itemid to questionnaire_response_file.id
srobotta Jan 18, 2024
ba60a47
Adding savepoint.
lucaboesch Jan 18, 2024
5fe7dce
Improvements to satisfy code checker.
lucaboesch Jan 18, 2024
de7e244
Make the file upload work with required setting, fix delete of records
srobotta Mar 22, 2024
3e23090
Add file question type
laurentdavid Feb 15, 2023
7ac2fe4
Add file question type
laurentdavid Feb 15, 2023
8d31fd5
File question type Behat tests.
lucaboesch Jan 20, 2024
61e3a2c
Fix behat test with two file uploads
srobotta Mar 25, 2024
9a4fa39
Fix codechecker issues
srobotta Mar 25, 2024
cf57ff1
Make sid public, because its already used via #[\AllowDynamicProperties]
srobotta Apr 5, 2024
498f149
Fix issues that got lost with the last rebase
srobotta Apr 5, 2024
998cdc1
Remove unused include that fails anyway
srobotta Aug 26, 2024
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
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [push, pull_request]

jobs:
test:
runs-on: 'ubuntu-latest'
runs-on: ubuntu-22.04

services:
postgres:
Expand All @@ -14,14 +14,14 @@ jobs:
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3

mariadb:
image: mariadb:10.6
image: mariadb:10
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"

ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3
Expand All @@ -45,7 +45,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: plugin

Expand All @@ -60,12 +60,12 @@ jobs:

- name: Deploy moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
# Add dirs to $PATH
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
# PHPUnit depends on en_AU.UTF-8 locale
sudo locale-gen en_AU.UTF-8
# Install nvm.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

- name: Install Moodle
# Need explicit IP to stop mysql client fail on attempt to use unix socket.
Expand All @@ -92,7 +92,7 @@ jobs:

- name: Moodle Code Checker
if: ${{ always() }}
run: moodle-plugin-ci codechecker || true
run: moodle-plugin-ci codechecker

- name: Moodle PHPDoc Checker
if: ${{ always() }}
Expand Down
4 changes: 4 additions & 0 deletions classes/feedback_section_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot.'/mod/questionnaire/lib.php');

#[\AllowDynamicProperties]
/**
* Print the form to add or edit a questionnaire-instance
*
Expand All @@ -38,6 +39,9 @@ class feedback_section_form extends \moodleform {
*/
public $context;

/** @var int $sid The section id. */
public $sid;

/**
* Form definition.
*/
Expand Down
2 changes: 1 addition & 1 deletion classes/file_storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace mod_questionnaire;

/**
* Defines the file stoeage class for questionnaire.
* Defines the file storage class for questionnaire.
* @package mod_questionnaire
* @copyright 2020 onwards Mike Churchward ([email protected])
* @author Mike Churchward
Expand Down
1 change: 1 addition & 0 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ public function print_preview_formend($url, $submitstr, $resetstr) {
$output .= \html_writer::start_tag('div');
$output .= \html_writer::empty_tag('input', ['type' => 'submit', 'name' => 'submit', 'value' => $submitstr,
'class' => 'btn btn-primary']);
$output .= \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()]);
$output .= ' ';
$output .= \html_writer::tag('a', $resetstr, ['href' => $url, 'class' => 'btn btn-secondary mr-1']);
$output .= \html_writer::end_tag('div') . "\n";
Expand Down
237 changes: 237 additions & 0 deletions classes/question/file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
<?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/>.
namespace mod_questionnaire\question;
use core_media_manager;
use form_filemanager;
use mod_questionnaire\responsetype\response\response;
use moodle_url;
use MoodleQuickForm;

/**
* This file contains the parent class for text question types.
*
* @author Laurent David
* @author Martin Cornu-Mansuy
* @copyright 2023 onward CALL Learning <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package mod_questionnaire
*/
class file extends question {

/**
* Get name.
*
* @return string
*/
public function helpname() {
return 'file';
}

/**
* Override and return a form template if provided. Output of question_survey_display is iterpreted based on this.
*
* @return boolean | string
*/
public function question_template() {
return false;
}

/**
* Override and return a response template if provided. Output of response_survey_display is iterpreted based on this.
*
* @return boolean | string
*/
public function response_template() {
return false;
}

/**
* Get response class.
*
* @return object|string
*/
protected function responseclass() {
return '\\mod_questionnaire\\responsetype\\file';
}

/**
* Survey display output.
*
* @param response $response
* @param object $descendantsdata
* @param bool $blankquestionnaire
* @return string
*/
protected function question_survey_display($response, $descendantsdata, $blankquestionnaire = false) {
global $CFG, $PAGE;
require_once($CFG->libdir . '/filelib.php');

$elname = 'q' . $this->id;
// Make sure there is a response, fetch the draft id from the original request.
if (isset($response->answers[$this->id]) && !empty($response->answers[$this->id]) && isset($_REQUEST[$elname . 'draft'])) {
$draftitemid = (int)$_REQUEST[$elname . 'draft'];
} else {
$draftitemid = file_get_submitted_draft_itemid($elname);
}
if ($draftitemid > 0) {
file_prepare_draft_area($draftitemid, $this->context->id,
'mod_questionnaire', 'file', $this->id, self::get_file_manager_option());
} else {
$draftitemid = file_get_unused_draft_itemid();
}
// Filemanager form element implementation is far from optimal, we need to rework this if we ever fix it...
require_once("$CFG->dirroot/lib/form/filemanager.php");

$options = array_merge(self::get_file_manager_option(), [
'client_id' => uniqid(),
'itemid' => $draftitemid,
'target' => $this->id,
'name' => $elname,
]);
$fm = new form_filemanager((object)$options);
$output = $PAGE->get_renderer('core', 'files');

$html = '<div class="form-filemanager" data-fieldtype="filemanager">' .
$output->render($fm) .
'<input type="hidden" name="' . $elname . '" value="' . $draftitemid . '" />' .
'<input type="hidden" name="' . $elname . 'draft" value="' . $draftitemid . '" />' .
'</div>';

return $html;
}

/**
* Check question's form data for complete response.
* @param \stdClass $responsedata The data entered into the response.
* @return bool
*/
public function response_complete($responsedata) {
$answered = false;
// If $responsedata is a response object, look through the answers.
if (is_a($responsedata, 'mod_questionnaire\responsetype\response\response') &&
isset($responsedata->answers[$this->id]) && !empty($responsedata->answers[$this->id])
) {
$answer = reset($responsedata->answers[$this->id]);
$answered = ((int)$answer->value > 0);
} else if (isset($responsedata->{'q'.$this->id})) {
// If $responsedata is webform data, check that it is not empty.
$draftitemid = (int)$responsedata->{'q' . $this->id};
if ($draftitemid > 0) {
$info = file_get_draft_area_info($draftitemid);
$answered = $info['filecount'] > 0;
}
}
return !($this->required() && ($this->deleted == 'n') && !$answered);
}

/**
* Get file manager options
*
* @return array
*/
public static function get_file_manager_option() {
return [
'mainfile' => '',
'subdirs' => false,
'accepted_types' => ['image', '.pdf'],
'maxfiles' => 1,
];
}

/**
* Response display output.
*
* @param \stdClass $data
* @return string
*/
protected function response_survey_display($data) {
global $PAGE, $CFG;
require_once($CFG->libdir . '/filelib.php');
require_once($CFG->libdir . '/resourcelib.php');
if (isset($data->answers[$this->id])) {
$answer = reset($data->answers[$this->id]);
} else {
return '';
}
$fs = get_file_storage();
$file = $fs->get_file_by_id($answer->value);
$code = '';

if ($file) {
// There is a file.
$moodleurl = moodle_url::make_pluginfile_url(
$file->get_contextid(),
$file->get_component(),
$file->get_filearea(),
$file->get_itemid(),
$file->get_filepath(),
$file->get_filename()
);

$mimetype = $file->get_mimetype();
$title = '';

$mediamanager = core_media_manager::instance($PAGE);
$embedoptions = array(
core_media_manager::OPTION_TRUSTED => true,
core_media_manager::OPTION_BLOCK => true,
);

if (file_mimetype_in_typegroup($mimetype, 'web_image')) { // It's an image.
$code = resourcelib_embed_image($moodleurl->out(), $title);

} else if ($mimetype === 'application/pdf') {
// PDF document.
$code = resourcelib_embed_pdf($moodleurl->out(), $title, get_string('view'));

} else if ($mediamanager->can_embed_url($moodleurl, $embedoptions)) {
// Media (audio/video) file.
$code = $mediamanager->embed_url($moodleurl, $title, 0, 0, $embedoptions);

} else {
// We need a way to discover if we are loading remote docs inside an iframe.
$moodleurl->param('embed', 1);

// Anything else - just try object tag enlarged as much as possible.
$code = resourcelib_embed_general($moodleurl, $title, get_string('view'), $mimetype);
}
}
return '<div class="response text">' . $code . '</div>';
}

/**
* Add the length element as hidden.
*
* @param \MoodleQuickForm $mform
* @param string $helpname
* @return \MoodleQuickForm
*/
protected function form_length(MoodleQuickForm $mform, $helpname = '') {
return question::form_length_hidden($mform);
}

/**
* Add the precise element as hidden.
*
* @param \MoodleQuickForm $mform
* @param string $helpname
* @return \MoodleQuickForm
*/
protected function form_precise(MoodleQuickForm $mform, $helpname = '') {
return question::form_precise_hidden($mform);
}

}
2 changes: 1 addition & 1 deletion classes/question/numerical.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
// Numeric.
$questiontags = new \stdClass();
$precision = $this->precise;
$a = new \StdClass();
$a = new \stdClass();
if (isset($response->answers[$this->id][0])) {
$mynumber = $response->answers[$this->id][0]->value;
if ($mynumber != '') {
Expand Down
2 changes: 2 additions & 0 deletions classes/question/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
define('QUESDATE', 9);
define('QUESNUMERIC', 10);
define('QUESSLIDER', 11);
define('QUESFILE', 12);
define('QUESPAGEBREAK', 99);
define('QUESSECTIONTEXT', 100);

Expand Down Expand Up @@ -119,6 +120,7 @@ abstract class question {
QUESDROP => 'drop',
QUESRATE => 'rate',
QUESDATE => 'date',
QUESFILE => 'file',
QUESNUMERIC => 'numerical',
QUESPAGEBREAK => 'pagebreak',
QUESSECTIONTEXT => 'sectiontext',
Expand Down
Loading
Loading