Skip to content

Commit 5d0ea80

Browse files
up to dev
1 parent 2888ab0 commit 5d0ea80

2 files changed

Lines changed: 41 additions & 33 deletions

File tree

‎api.php‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,12 @@ function get_word_test_ajax($testsql, $word_mode, $lgid, $wordregex, $testtype):
178178
if (empty($word_record)) {
179179
$output = array(
180180
"word_id" => 0,
181+
"word_lg_abbr" =>'',
181182
"word_text" => '',
182-
"group" => ''
183+
"group" => '',
184+
"startSec" => 0,
185+
"endSec" => 0,
186+
"txID" => -1
183187
);
184188
return $output;
185189
}
@@ -201,9 +205,11 @@ function get_word_test_ajax($testsql, $word_mode, $lgid, $wordregex, $testtype):
201205
$word_record, $sent, $testtype, $word_mode, $wordregex
202206
);
203207
$solution = get_test_solution($testtype, $word_record, $word_mode, $save);
204-
208+
$abbr = getLanguageCode($word_record['WoLgID'], LWT_LANGUAGES_ARRAY);
209+
205210
return array(
206211
"word_id" => $word_record['WoID'],
212+
"word_lg_abbr" =>$abbr,
207213
"solution" => $solution,
208214
"word_text" => $save,
209215
"group" => $html_sentence,
@@ -230,7 +236,7 @@ function word_test_ajax($get_req): array
230236
$get_req['test_key'], $get_req['selection']
231237
);
232238
return get_word_test_ajax(
233-
$test_sql, $get_req['word_mode'],
239+
$test_sql, filter_var($get_req['word_mode'], FILTER_VALIDATE_BOOLEAN),
234240
$get_req['lg_id'],
235241
$get_req['word_regex'], $get_req['type']
236242
);

‎do_test_test.php‎

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -782,30 +782,7 @@ function do_test_test_javascript_clickable($wo_record, $solution, $startSec, $en
782782
$phoneticText = phonetic_reading($wo_record['WoText'], $abbr);
783783
?>
784784
<script type="text/javascript">
785-
const options_phonetic_reading = {
786-
"text": word['word_text'],
787-
"lang": <?php echo json_encode((string) $abbr); ?>
788-
789-
};
790-
$.getJSON(
791-
'api.php/v1/phonetic-reading?' + $.param(options_phonetic_reading)
792-
).done(function (data) {
793-
if (data["phonetic_reading"]) {
794-
$('.word').on('click', read_word);
795-
796-
/**
797-
* Read the word aloud
798-
*/
799-
function read_word() {
800-
if (('speechSynthesis' in window) &&
801-
document.getElementById('utterance-allowed').checked) {
802-
const text = data["phonetic_reading"];
803-
const lang = <?php echo json_encode($abbr); ?>;
804-
readRawTextAloud(text, lang);
805-
}
806-
}
807-
}
808-
});
785+
809786

810787
SOLUTION = <?php echo prepare_textdata_js($solution); ?>;
811788
WID = <?php echo $wid; ?>;
@@ -939,7 +916,7 @@ function do_test_footer($notyettested, $wrong, $correct)
939916
*/
940917
function do_test_test_javascript($count)
941918
{
942-
919+
943920
?>
944921
<script type="text/javascript">
945922
/**
@@ -976,18 +953,43 @@ function prepare_test_frames()
976953
* @param {number} tx_id transaction ID
977954
* @param {number} start_sec starting second
978955
* @param {number} end_sec ending second
956+
* @param {string} word_text word text
957+
* @param {string} word_lg_abbr Word ID
979958
* @param {string} solution Test answer
980959
* @param {string} group
981960
*/
982-
function insert_new_word(word_id,tx_id,start_sec,end_sec, solution, group) {
983-
961+
function insert_new_word(word_id,tx_id,start_sec,end_sec,word_text,word_lg_abbr, solution, group) {
962+
963+
const options_phonetic_reading = {
964+
"text": word_text,
965+
"lang": word_lg_abbr
966+
967+
};
968+
$.getJSON(
969+
'api.php/v1/phonetic-reading?' + $.param(options_phonetic_reading)
970+
).done(function (data) {
971+
if (data["phonetic_reading"]) {
972+
$('.word').on('click', read_word);
973+
974+
/**
975+
* Read the word aloud
976+
*/
977+
function read_word() {
978+
if (('speechSynthesis' in window) &&
979+
document.getElementById('utterance-allowed').checked) {
980+
const text = data["phonetic_reading"];
981+
const lang = word_lg_abbr;
982+
readRawTextAloud(text, lang);
983+
}
984+
}
985+
}
986+
});
984987
const options_media_paths = {
985988
"id": tx_id
986989
};
987990
$.getJSON(
988991
'api.php/v1/media-files?' + $.param(options_media_paths)
989992
).done(function (data) {
990-
console.log(data["paths"])
991993
if (data["paths"]) {
992994
var MEDIA = data["paths"]
993995
sentenceaudio.src = MEDIA;
@@ -1051,7 +1053,7 @@ function (tomorrow_test) {
10511053
);
10521054
} else {
10531055
insert_new_word(
1054-
current_test.word_id,current_test.txID,current_test.startSec,current_test.endSec,current_test.solution, current_test.group
1056+
current_test.word_id,current_test.txID,current_test.startSec,current_test.endSec,current_test.word_text,current_test.word_lg_abbr,current_test.solution, current_test.group
10551057
);
10561058
}
10571059
}
@@ -1101,7 +1103,7 @@ function do_test_finished(total_tests) {
11011103

11021104
/**
11031105
* Do the main content of a test page.
1104-
*
1106+
* Replaced by do_test_test_content_ajax()
11051107
* @global int $debug Show debug informations
11061108
*
11071109
* @return void

0 commit comments

Comments
 (0)