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

Merge upstream to catalyst main #3

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
f26ae44
first version of 4.9.0 generic
Aug 23, 2023
1b6f6d1
chore: update quizzes lib
Sep 5, 2023
839aaff
chore: update lib
Sep 14, 2023
05b8542
chore: update lib
Sep 14, 2023
951d89d
fix: remove configuration.ini
Sep 14, 2023
b551927
chore: use production version 4.9.0
Sep 21, 2023
7be549f
Merge pull request #80 from wiris/v4.9.0
ptorrent-at-wiris Sep 21, 2023
13372cb
chore: update version to 4.9.0
ptorrent-at-wiris Sep 21, 2023
94ef356
fix: prevent php 8.1 deprecation notice
Sep 22, 2023
6310cc0
chore: update quizzes lib (include fix for strrpos too)
Sep 27, 2023
43f3938
Merge pull request #81 from wiris/v4.9.1
ptorrent-at-wiris Sep 27, 2023
3317f64
chore: update version to 4.9.1
ptorrent-at-wiris Sep 27, 2023
a8f0d76
fix: restore chars in files that have beed wrongly converted to utf8
Sep 28, 2023
94fcdf5
chore: update version to 4.9.2
ptorrent-at-wiris Sep 28, 2023
f472502
fix: use status variable instead of hidden
Oct 5, 2023
55d307e
fix: backwards compatibility between question_definition hidden and s…
Oct 9, 2023
fbebb7c
Merge pull request #82 from wiris/MOODLE_403
ptorrent-at-wiris Oct 17, 2023
f5be368
Update version.php
ptorrent-at-wiris Oct 17, 2023
5502c37
chore: bump lib to 4.10.0
Nov 22, 2023
543507b
chore: update quizzes lib
Dec 15, 2023
014b48b
chore: update version.php
Dec 15, 2023
1b47602
chore: update quizzes lib to v4.10.0
Jan 8, 2024
38ccb69
Merge branch 'main' into v4.10.0
ptorrent-at-wiris Jan 8, 2024
2fce0ff
Merge pull request #83 from wiris/v4.10.0
ptorrent-at-wiris Jan 9, 2024
bf44b6b
chore: restore integration.ini file
Jan 9, 2024
069f8be
chore: sync Http.class.php with wiris filter
Jan 11, 2024
ca3bc55
chore: bump version to 4.10.1
Jan 26, 2024
de10907
feat: add moodle version, wq version and qtype as request metadata
Feb 29, 2024
c259e29
fix: handle multiple attempt regrade for multianswer
Mar 12, 2024
d117033
chore: bump library to v4.11.0
Mar 12, 2024
2bc6ee9
refactor: move common answer cache logic to step.php
Mar 13, 2024
6584d81
chore: update quizzes lib to 4.11.0 published
Mar 22, 2024
6a0bc5d
chore: bump version to 4.11.0
Mar 22, 2024
1eafd23
Merge pull request #84 from wiris/v4.11.0
ptorrent-at-wiris Mar 22, 2024
8ed0d96
fix: replace str_contains method wth strpos method to be compatible w…
gvilaseca-at-wiris Mar 28, 2024
aa09168
chore: delete unnecessary comparison
gvilaseca-at-wiris Mar 28, 2024
df94360
Merge pull request #85 from wiris/fix/replace-str_contains-for-strpos
ptorrent-at-wiris Mar 28, 2024
75c5f38
chore: bump version to 4.11.1
ptorrent-at-wiris Mar 28, 2024
e068a44
ops: use new runner in ci workflow
Apr 22, 2024
525c556
chore: comply with moodle code standards
Apr 22, 2024
67e8ed7
chore: comply with moodle code standards (2)
Apr 23, 2024
31d021e
chore: comply with moodle code standards (3)
Apr 23, 2024
f4bcb23
ops: run tests for all supported moodle/php versions
Apr 23, 2024
0c48e5f
ops: run main on pgsql
Apr 23, 2024
9ba6e82
ops: do not run php8.3/moodle 402
Apr 23, 2024
06d9ddc
chore: remove deprecate php function
Apr 23, 2024
6e5d879
fix: remove uncontrolled exception when locks cannot be acquired
Apr 29, 2024
255bb27
fix: use proper way of computing the question_step_data length
May 2, 2024
d825b49
chore: update wq lib to 4.11.2
May 15, 2024
2bd072d
chore: bump quizzes lib to final 4.11.2 version
May 17, 2024
2488107
Merge pull request #86 from wiris/v4.11.2
ptorrent-at-wiris May 17, 2024
868eca4
chore: bump version to v4.11.2
ptorrent-at-wiris May 17, 2024
36b4fa7
chore: bump version to 4.11.3
Aug 2, 2024
e91fdd5
fix: delegate update_attempt_state_data_for_new_version implementatio…
Sep 16, 2024
544484d
fix: prevent warning when extraprefix is null
Sep 16, 2024
ee2cf5c
feat: add option to log wiris quizzes server errors to php logs
Sep 16, 2024
229986e
feat: show offending request for server errors
Sep 16, 2024
47d5e00
fix: pass proper parameter to format_text function in renderer
Sep 25, 2024
e87526a
fix: implement regrade check to prevent exception happening at regrad…
Sep 25, 2024
676882b
chore: bump version to v4.11.4
Sep 30, 2024
f5148c6
Merge pull request #88 from wiris/v4.11.4
ptorrent-at-wiris Sep 30, 2024
3b0872d
fix : issue 78 failing privacy provider test. adding method get_users…
gbarat87 Sep 1, 2023
c2c9754
fix : issue 78 failing privacy provider test. adding method delete_da…
gbarat87 Sep 4, 2023
fcdeeea
add approveduserlist
gbarat87 Sep 4, 2023
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
57 changes: 39 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,65 @@ on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest

services:
postgres:
image: postgres:12
image: postgres:13
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
POSTGRES_USER: "postgres"
POSTGRES_HOST_AUTH_METHOD: "trust"
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3

strategy:
fail-fast: false
matrix:
php: ['7.3', '7.4', '8.0']
php: ["7.4", "8.0", 8.1', "8.2", "8.3"]
moodle-branch:
[
'MOODLE_39_STABLE',
'MOODLE_310_STABLE',
'MOODLE_311_STABLE',
'MOODLE_400_STABLE',
'MOODLE_401_STABLE'
"MOODLE_401_STABLE",
"MOODLE_402_STABLE",
"MOODLE_403_STABLE",
"MOODLE_404_STABLE",
"main",
]
database: [pgsql]
exclude:
# Exclude Moodle+PHP incompatible versions
# See: https://docs.moodle.org/dev/Moodle_and_PHP
- moodle-branch: 'MOODLE_401_STABLE'
php: '7.3'
- moodle-branch: 'MOODLE_39_STABLE'
php: '8.0'
- moodle-branch: 'MOODLE_310_STABLE'
php: '8.0'
# See: https://moodledev.io/general/development/policies/php
- moodle-branch: "MOODLE_401_STABLE"
php: "8.2"
- moodle-branch: "MOODLE_401_STABLE"
php: "8.3"
- moodle-branch: "MOODLE_402_STABLE"
php: "7.4"
- moodle-branch: "MOODLE_402_STABLE"
php: "8.3"
- moodle-branch: "MOODLE_403_STABLE"
php: "7.4"
- moodle-branch: "MOODLE_403_STABLE"
php: "8.3"
- moodle-branch: "MOODLE_404_STABLE"
php: "7.4"
- moodle-branch: "MOODLE_404_STABLE"
php: "8.0"
- moodle-branch: "main"
include:
# Only test master against latest PHP until we know which
# versions are supported in the next release
- moodle-branch: "main"
php: "8.3"
database: "pgsql"

steps:
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v7.0.7

- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
path: plugin

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
gpl.txt
bu-git.xml
**.DS_Store
**.DS_Store

quizzes/configuration.ini
5 changes: 2 additions & 3 deletions classes/moodlelockprovider.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@ class moodlelockprovider {
* **/
// @codingStandardsIgnoreStart
public function getLock($id) {
// @codingStandardsIgnoreStop
// @codingStandardsIgnoreStop
$timeout = 10;

$resource = $id;

$lockfactory = new \core\lock\db_record_lock_factory('qtype_wq_persistenvariables');
$lock = $lockfactory->get_lock($resource, $timeout);
if ($lock === false) {
$lock->release();
throw new moodle_exception('couldnotaquirelock', 'qtype_wq', '','Could not acquire lock');
throw new moodle_exception('couldnotaquirelock', 'qtype_wq', '', 'Could not acquire lock');
}

return new moodlelock($lock);
Expand Down
48 changes: 47 additions & 1 deletion classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
use core_privacy\local\request\contextlist;
use core_privacy\local\request\deletion_criteria;
use core_privacy\local\request\helper;
use core_privacy\local\request\userlist;
use core_privacy\local\request\approved_userlist;
use core_privacy\local\request\writer;

class provider implements
// This plugin stores personal data.
\core_privacy\local\metadata\provider,
\core_privacy\local\request\plugin\provider {
\core_privacy\local\request\plugin\provider,
\core_privacy\local\request\core_userlist_provider {

// This trait must be included to provide the relevant polyfill for the metadata provider.
// All required methods must start with an underscore.
Expand Down Expand Up @@ -246,4 +249,47 @@ public static function _delete_data_for_user(approved_contextlist $contextlist)
$records->close();
}
}

/**
* Get the list of users within a specific context.
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
* @return void
*/
public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();
if(!$context instanceof \context_user) {
return;
}

$params = ['contextid' => $context->instanceid];
$sql = "SELECT q.createdby userid
FROM {question_categories} qc";

if ($CFG->version >= 2022041900) {
$sql .= " INNER JOIN {question_bank_entries} qbe ON qbe.questioncategoryid = qc.id
INNER JOIN {question_versions} qv ON qv.questionbankentryid = qbe.id
INNER JOIN {question} q ON q.id = qv.questionid
INNER JOIN {qtype_wq} wq ON q.id = wq.question";
} else {
$sql .= " INNER JOIN {question} q ON qc.id = q.category
INNER JOIN {qtype_wq} wq ON q.id = wq.question";
}

$sql .= " WHERE qc.contextid = :contextid ";
$userlist->add_from_sql('userid', $sql, $params);

}

/**
* Delete multiple users within a single context.
* @param approved_userlist $userlist The approved context and user information to delete information for.
* @return void
*/
public static function delete_data_for_users(approved_userlist $userlist) {
$context = $userlist->get_context();

if ($context instanceof \context_user) {
static::_delete_data_for_user($context->instanceid);
}
}
}
6 changes: 3 additions & 3 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function xmldb_qtype_wq_upgrade($oldversion) {

if ($oldversion < 2017011300) {

// Define table qtype_wq_variables to be created.
// Define table qtype_wq_variables to be created.
$table = new xmldb_table('qtype_wq_variables');

// Adding fields to table qtype_wq_variables.
Expand All @@ -102,12 +102,12 @@ function xmldb_qtype_wq_upgrade($oldversion) {

function get_entities_table($table, $flags) {
if ((version_compare(PHP_VERSION, '5.3.4') >= 0)) {
return get_html_translation_taquestionble($table, $flags, 'UTF-8');
return get_html_translation_table($table, $flags, 'UTF-8');
} else {
$isotable = get_html_translation_table($table, $flags);
$utftable = array();
foreach ($isotable as $key => $value) {
$utftable[utf8_encode($key)] = utf8_encode($value);
$utftable[mb_convert_encoding($key, 'UTF-8', 'ISO-8859-1')] = mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1');
}
return $utftable;
}
Expand Down
3 changes: 0 additions & 3 deletions info.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,6 @@ function wrs_createtablerow($testname, $reporttext, $solutionlink, $condition) {

$output .= html_writer::start_tag('tr', array('class' => 'wrs_filter wrs_plugin'));

require_once($CFG->dirroot . '/lib/editor/tinymce/lib.php');
$tinyeditor = new tinymce_texteditor();

$rb = com_wiris_quizzes_api_Quizzes::getInstance();

$questionxml = '<question><wirisCasSession>&lt;session lang=&quot;en&quot; version=&quot;2.0&quot;' .
Expand Down
3 changes: 3 additions & 0 deletions lang/en/qtype_wq.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@
$string['privacy:metadata:qtype_wq:xml'] = 'Wiris Quizzes Question XML';

$string['auxiliar_text'] = 'Write an optional reasoning for your answer:';

$string['log_server_errors'] = 'Log server errors';
$string['log_server_errors_help'] = 'Extensively log errors coming from the WirisQuizzes service to your server logs. This might cause an increase in the size of your log files but might help the Wiris team troubleshoot issues.';
45 changes: 39 additions & 6 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class qtype_wq_question extends question_graded_automatically {
public function __construct(question_definition $base = null) {
$this->base = $base;
}

/**
* Initializes Wiris Quizzes question calling the service in order to get the value
* of the variables to render the question.
Expand Down Expand Up @@ -116,7 +117,7 @@ public function apply_attempt_state(question_attempt_step $step) {
$response = $this->call_wiris_service($request);
$this->wirisquestioninstance->update($response);
// Save the result.
$step->set_qt_var('_qi', $this->wirisquestioninstance->serialize());
$step->set_qt_var('_qi', $this->wirisquestioninstance->serialize());
}
}

Expand Down Expand Up @@ -239,9 +240,8 @@ public function is_same_response(array $prevresponse, array $newresponse) {
!empty($newresponse['_sqi']) && $newresponse['_sqi'] == $prevresponse['_sqi']));
$auxiliarcompare = ((empty($newresponse['auxiliar_text']) && empty($prevresponse['auxiliar_text'])) ||
(!empty($prevresponse['auxiliar_text']) &&
!empty($newresponse['auxiliar_text']) && $newresponse['auxiliar_text'] == $prevresponse['auxiliar_text']));
!empty($newresponse['auxiliar_text']) && $newresponse['auxiliar_text'] == $prevresponse['auxiliar_text']));
return $baseresponse && $sqicompare && $auxiliarcompare;

}

public function summarise_response(array $response) {
Expand Down Expand Up @@ -277,8 +277,14 @@ public function get_right_answer_summary() {
return $this->expand_variables_text($text);
}
public function format_hint(question_hint $hint, question_attempt $qa) {
return $this->format_text($hint->hint, $hint->hintformat, $qa,
'question', 'hint', $hint->id);
return $this->format_text(
$hint->hint,
$hint->hintformat,
$qa,
'question',
'hint',
$hint->id
);
}
/**
* interface question_automatically_gradable_with_countback
Expand Down Expand Up @@ -315,7 +321,7 @@ public function join_all_text() {
public function join_question_text() {
$text = $this->questiontext;
foreach ($this->hints as $hint) {
$tet .= ' ' . $hint->hint;
$text .= ' ' . $hint->hint;
}
return $text;
}
Expand All @@ -332,15 +338,26 @@ public function join_feedback_text() {
public function call_wiris_service($request) {
global $COURSE;
global $USER;
global $CFG;

$builder = com_wiris_quizzes_api_Quizzes::getInstance();
$metaproperty = ((!empty($COURSE) ? $COURSE->id : '') . '/' . (!empty($question) ? $question->id : ''));

// Add meta properties.
$request->addMetaProperty('questionref', $metaproperty);
$request->addMetaProperty('userref', (!empty($USER) ? $USER->id : ''));
$request->addMetaProperty('qtype', $this->qtype->name());
$request->addMetaProperty(
'wqversion',
// @codingStandardsIgnoreLine
$builder->getConfiguration()->get(com_wiris_quizzes_api_ConfigurationKeys::$VERSION)
);
$request->addMetaProperty('moodleversion', explode(' ', $CFG->release)[0]);

$service = $builder->getQuizzesService();

$isdebugmodeenabled = get_config('qtype_wq', 'debug_mode_enabled') == '1';
$islogmodeenabled = get_config('qtype_wq', 'log_server_errors') == '1';

if ($isdebugmodeenabled) {
// @codingStandardsIgnoreLine
Expand All @@ -366,6 +383,10 @@ public function call_wiris_service($request) {
print_object($e);
}

if ($islogmodeenabled) {
error_log('WIRISQUIZZES SERVER ERROR --- REQUEST: --- ' . $request->serialize());
}

throw new moodle_exception('wirisquestionincorrect', 'qtype_wq', $link, $a, '');
}

Expand All @@ -375,4 +396,16 @@ public function call_wiris_service($request) {
}
return $response;
}


public function update_attempt_state_data_for_new_version(
question_attempt_step $oldstep,
question_definition $otherversion
) {
return $this->base->update_attempt_state_data_for_new_version($oldstep, $otherversion->base);
}

public function validate_can_regrade_with_other_version(question_definition $otherversion): ?string {
return $this->base->validate_can_regrade_with_other_version($otherversion->base);
}
}
14 changes: 10 additions & 4 deletions questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function get_question_options($question) {
$question->options->wirisquestion = $record->xml;
$question->options->wirisoptions = $record->options;
} else {
$OUTPUT->notification( get_string('failedtoloadwirisquizzesfromxml', 'qtype_wq') . ' ' . $question->id . '.');
$OUTPUT->notification(get_string('failedtoloadwirisquizzesfromxml', 'qtype_wq') . ' ' . $question->id . '.');
return false;
}
}
Expand All @@ -99,6 +99,8 @@ protected function make_question_instance($questiondata) {
}

protected function initialise_question_instance(question_definition $question, $questiondata) {
global $CFG;

$this->base->initialise_question_instance($question->base, $questiondata);

$question->id = &$question->base->id;
Expand All @@ -118,7 +120,11 @@ protected function initialise_question_instance(question_definition $question, $
$question->penalty = &$question->base->penalty;
$question->stamp = &$question->base->stamp;
$question->version = &$question->base->version;
$question->hidden = &$question->base->hidden;
if ($CFG->version >= 2022041900 /* v4.0.0 */) {
$question->status = &$question->base->status;
} else {
$question->hidden = &$question->base->hidden;
}
$question->timecreated = &$question->base->timecreated;
$question->timemodified = &$question->base->timemodified;
$question->createdby = &$question->base->createdby;
Expand Down Expand Up @@ -159,7 +165,7 @@ public function display_question_editing_page($mform, $question, $wizardnow) {
$PAGE->requires->js('/question/type/wq/quizzes/service.php?name=quizzes.js&service=resource');
}

public function export_to_xml($question, qformat_xml $format, $extra=null) {
public function export_to_xml($question, qformat_xml $format, $extra = null) {
global $DB;
$xml = $DB->get_record('qtype_wq', array('question' => $question->id), 'xml')->xml;

Expand Down Expand Up @@ -257,7 +263,7 @@ protected function wrsqz_hidden_initial_cas_value($data) {

protected function decode_html_entities($xml) {
$htmlentitiestable = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, 'UTF-8');
$xmlentitiestable = get_html_translation_table(HTML_SPECIALCHARS , ENT_COMPAT, 'UTF-8');
$xmlentitiestable = get_html_translation_table(HTML_SPECIALCHARS, ENT_COMPAT, 'UTF-8');
$entitiestable = array_diff($htmlentitiestable, $xmlentitiestable);
$decodetable = array_flip($entitiestable);
$xml = str_replace(array_keys($decodetable), array_values($decodetable), $xml);
Expand Down
6 changes: 3 additions & 3 deletions quizzes/lib/Date.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public function getTime() {
public function __call($m, $a) {
if(isset($this->$m) && is_callable($this->$m))
return call_user_func_array($this->$m, $a);
else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m]))
return call_user_func_array($this->»dynamics[$m], $a);
else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m]))
return call_user_func_array($this->»dynamics[$m], $a);
else if('toString' == $m)
return $this->__toString();
else
throw new HException('Unable to call «'.$m.'»');
throw new HException('Unable to call «'.$m.'»');
}
static function now() {
return Date::fromPhpTime(round(microtime(true), 3));
Expand Down
Loading
Loading