Skip to content

Commit

Permalink
Fix #1189 - xAPI tracking not working in some cases if page title sta…
Browse files Browse the repository at this point in the history
…rts with a digit
  • Loading branch information
torinfo committed Jan 6, 2023
1 parent 358e349 commit 839a0b9
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 31 deletions.
Expand Up @@ -381,8 +381,7 @@ function NoopTrackingState()
{
return this.findPage(page_nr);
}
var i=0;
for (i=0; i<this.interactions.length; i++)
for (let i=0; i<this.interactions.length; i++)
{
if (this.interactions[i].page_nr == page_nr && this.interactions[i].ia_nr == ia_nr)
return this.interactions[i];
Expand Down Expand Up @@ -1316,8 +1315,8 @@ function XTResults(fullcompletion) {
case "match":
// If unique targets, match answers by target, otherwise match by source
const targets = [];
for (let j = 0; j < state.interactions[i].nrinteractions; j++) {
targets.push(state.interactions[i].correctOptions[c].target);
for (let j = 0; j < state.interactions[i].correctOptions.length; j++) {
targets.push(state.interactions[i].correctOptions[j].target);
}
// Check whether values of targets are unique
const uniqueTargets = targets.length === new Set(targets).size;
Expand Down Expand Up @@ -1363,7 +1362,6 @@ function XTResults(fullcompletion) {
matchSub.correctAnswer = correctAnswer;
results.interactions[nrofquestions - 1].subinteractions.push(matchSub);
}

break;
case "text":
learnerAnswer = state.interactions[i].learnerAnswers;
Expand Down
29 changes: 22 additions & 7 deletions modules/site/xAPI/xttracking_xapi.js
@@ -1,4 +1,21 @@
//TODO: get user email, more verbs (passed/failed, completed, ect), define scormmode for xAPI
/**
* Licensed to The Apereo Foundation under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
* The Apereo Foundation licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

function makeId(page_nr, ia_nr, ia_type, ia_name) {
var tmpid = 'urn:x-xerte:p-' + (page_nr + 1);
Expand Down Expand Up @@ -471,10 +488,8 @@ function XApiTrackingState() {
if (ia_nr < 0) {
return this.findPage(page_nr);
}
var id = makeId(page_nr, ia_nr, "", "");
var i = 0;
for (i = 0; i < this.interactions.length; i++) {
if (this.interactions[i].id.indexOf(id) == 0)
for (let i = 0; i < this.interactions.length; i++) {
if (this.interactions[i].page_nr == page_nr && this.interactions[i].ia_nr == ia_nr)
return this.interactions[i];
}
return null;
Expand Down Expand Up @@ -3702,8 +3717,8 @@ function XTResults(fullcompletion) {
case "match":
// If unique targets, match answers by target, otherwise match by source
const targets = [];
for (let j = 0; j < state.interactions[i].nrinteractions; j++) {
targets.push(state.interactions[i].correctOptions[c].target);
for (let j = 0; j < state.interactions[i].correctOptions.length; j++) {
targets.push(state.interactions[i].correctOptions[j].target);
}
// Check whether values of targets are unique
const uniqueTargets = targets.length === new Set(targets).size;
Expand Down
Expand Up @@ -381,8 +381,7 @@ function NoopTrackingState()
{
return this.findPage(page_nr);
}
var i=0;
for (i=0; i<this.interactions.length; i++)
for (let i=0; i<this.interactions.length; i++)
{
if (this.interactions[i].page_nr == page_nr && this.interactions[i].ia_nr == ia_nr)
return this.interactions[i];
Expand Down Expand Up @@ -1316,8 +1315,8 @@ function XTResults(fullcompletion) {
case "match":
// If unique targets, match answers by target, otherwise match by source
const targets = [];
for (let j = 0; j < state.interactions[i].nrinteractions; j++) {
targets.push(state.interactions[i].correctOptions[c].target);
for (let j = 0; j < state.interactions[i].correctOptions.length; j++) {
targets.push(state.interactions[i].correctOptions[j].target);
}
// Check whether values of targets are unique
const uniqueTargets = targets.length === new Set(targets).size;
Expand Down
7 changes: 3 additions & 4 deletions modules/xerte/scorm1.2/xttracking_scorm1.2.js
Expand Up @@ -340,8 +340,7 @@ function ScormTrackingState()
{
return this.findPage(page_nr);
}
var i=0;
for (i=0; i<this.interactions.length; i++)
for (let i=0; i<this.interactions.length; i++)
{
if (this.interactions[i].page_nr == page_nr && this.interactions[i].ia_nr == ia_nr)
return this.interactions[i];
Expand Down Expand Up @@ -1769,8 +1768,8 @@ function XTResults(fullcompletion) {
case "match":
// If unique targets, match answers by target, otherwise match by source
const targets = [];
for (let j = 0; j < state.interactions[i].nrinteractions; j++) {
targets.push(state.interactions[i].correctOptions[c].target);
for (let j = 0; j < state.interactions[i].correctOptions.length; j++) {
targets.push(state.interactions[i].correctOptions[j].target);
}
// Check whether values of targets are unique
const uniqueTargets = targets.length === new Set(targets).size;
Expand Down
7 changes: 3 additions & 4 deletions modules/xerte/scorm2004.3rd/xttracking_scorm2004.3rd.js
Expand Up @@ -296,8 +296,7 @@ function ScormTrackingState()
{
return this.findPage(page_nr);
}
var i=0;
for (i=0; i<this.interactions.length; i++)
for (let i=0; i<this.interactions.length; i++)
{
if (this.interactions[i].page_nr == page_nr && this.interactions[i].ia_nr == ia_nr)
return this.interactions[i];
Expand Down Expand Up @@ -1711,8 +1710,8 @@ function XTResults(fullcompletion) {
case "match":
// If unique targets, match answers by target, otherwise match by source
const targets = [];
for (let j = 0; j < state.interactions[i].nrinteractions; j++) {
targets.push(state.interactions[i].correctOptions[c].target);
for (let j = 0; j < state.interactions[i].correctOptions.length; j++) {
targets.push(state.interactions[i].correctOptions[j].target);
}
// Check whether values of targets are unique
const uniqueTargets = targets.length === new Set(targets).size;
Expand Down
29 changes: 22 additions & 7 deletions modules/xerte/xAPI/xttracking_xapi.js
@@ -1,4 +1,21 @@
//TODO: get user email, more verbs (passed/failed, completed, ect), define scormmode for xAPI
/**
* Licensed to The Apereo Foundation under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
* The Apereo Foundation licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

function makeId(page_nr, ia_nr, ia_type, ia_name) {
var tmpid = 'urn:x-xerte:p-' + (page_nr + 1);
Expand Down Expand Up @@ -471,10 +488,8 @@ function XApiTrackingState() {
if (ia_nr < 0) {
return this.findPage(page_nr);
}
var id = makeId(page_nr, ia_nr, "", "");
var i = 0;
for (i = 0; i < this.interactions.length; i++) {
if (this.interactions[i].id.indexOf(id) == 0)
for (let i = 0; i < this.interactions.length; i++) {
if (this.interactions[i].page_nr == page_nr && this.interactions[i].ia_nr == ia_nr)
return this.interactions[i];
}
return null;
Expand Down Expand Up @@ -3702,8 +3717,8 @@ function XTResults(fullcompletion) {
case "match":
// If unique targets, match answers by target, otherwise match by source
const targets = [];
for (let j = 0; j < state.interactions[i].nrinteractions; j++) {
targets.push(state.interactions[i].correctOptions[c].target);
for (let j = 0; j < state.interactions[i].correctOptions.length; j++) {
targets.push(state.interactions[i].correctOptions[j].target);
}
// Check whether values of targets are unique
const uniqueTargets = targets.length === new Set(targets).size;
Expand Down

0 comments on commit 839a0b9

Please sign in to comment.