MOBILE-2404 db: Use lowercase in DB of modules and question

main
Dani Palou 2018-05-29 15:29:58 +02:00
parent 7ef4726bf5
commit 4cc9934d22
13 changed files with 148 additions and 143 deletions

View File

@ -384,7 +384,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
// Check if there's any offline data for this submission. // Check if there's any offline data for this submission.
promises.push(this.assignOfflineProvider.getSubmission(assign.id, this.submitId).then((data) => { promises.push(this.assignOfflineProvider.getSubmission(assign.id, this.submitId).then((data) => {
this.hasOffline = data && data.pluginData && Object.keys(data.pluginData).length > 0; this.hasOffline = data && data.plugindata && Object.keys(data.plugindata).length > 0;
this.submittedOffline = data && data.submitted; this.submittedOffline = data && data.submitted;
}).catch(() => { }).catch(() => {
// No offline data found. // No offline data found.
@ -561,8 +561,8 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
this.originalGrades.grade = this.grade.grade; this.originalGrades.grade = this.grade.grade;
} }
this.grade.applyToAll = data.applyToAll; this.grade.applyToAll = data.applytoall;
this.grade.addAttempt = data.addAttempt; this.grade.addAttempt = data.addattempt;
this.originalGrades.applyToAll = this.grade.applyToAll; this.originalGrades.applyToAll = this.grade.applyToAll;
this.originalGrades.addAttempt = this.grade.addAttempt; this.originalGrades.addAttempt = this.grade.addAttempt;

View File

@ -128,13 +128,13 @@ export class AddonModAssignFeedbackCommentsComponent extends AddonModAssignFeedb
return this.assignOfflineProvider.getSubmissionGrade(this.assign.id, this.userId).catch(() => { return this.assignOfflineProvider.getSubmissionGrade(this.assign.id, this.userId).catch(() => {
// No offline data found. // No offline data found.
}).then((offlineData) => { }).then((offlineData) => {
if (offlineData && offlineData.pluginData && offlineData.pluginData.assignfeedbackcomments_editor) { if (offlineData && offlineData.plugindata && offlineData.plugindata.assignfeedbackcomments_editor) {
// Save offline as draft. // Save offline as draft.
this.isSent = false; this.isSent = false;
this.feedbackDelegate.saveFeedbackDraft(this.assign.id, this.userId, this.plugin, this.feedbackDelegate.saveFeedbackDraft(this.assign.id, this.userId, this.plugin,
offlineData.pluginData.assignfeedbackcomments_editor); offlineData.plugindata.assignfeedbackcomments_editor);
return offlineData.pluginData.assignfeedbackcomments_editor.text; return offlineData.plugindata.assignfeedbackcomments_editor.text;
} }
// No offline data found, return online text. // No offline data found, return online text.

View File

@ -128,8 +128,8 @@ export class AddonModAssignFeedbackCommentsHandler implements AddonModAssignFeed
return this.assignOfflineProvider.getSubmissionGrade(assign.id, userId).catch(() => { return this.assignOfflineProvider.getSubmissionGrade(assign.id, userId).catch(() => {
// No offline data found. // No offline data found.
}).then((data) => { }).then((data) => {
if (data && data.pluginData && data.pluginData.assignfeedbackcomments_editor) { if (data && data.plugindata && data.plugindata.assignfeedbackcomments_editor) {
return data.pluginData.assignfeedbackcomments_editor.text; return data.plugindata.assignfeedbackcomments_editor.text;
} }
// No offline data found, get text from plugin. // No offline data found, get text from plugin.

View File

@ -156,7 +156,7 @@ export class AddonModAssignEditPage implements OnInit, OnDestroy {
// Check if there's any offline data for this submission. // Check if there's any offline data for this submission.
return this.assignOfflineProvider.getSubmission(this.assign.id, this.userId).then((data) => { return this.assignOfflineProvider.getSubmission(this.assign.id, this.userId).then((data) => {
this.hasOffline = data && data.pluginData && Object.keys(data.pluginData).length > 0; this.hasOffline = data && data.plugindata && Object.keys(data.plugindata).length > 0;
}).catch(() => { }).catch(() => {
// No offline data found. // No offline data found.
this.hasOffline = false; this.hasOffline = false;

View File

@ -35,23 +35,23 @@ export class AddonModAssignOfflineProvider {
name: this.SUBMISSIONS_TABLE, name: this.SUBMISSIONS_TABLE,
columns: [ columns: [
{ {
name: 'assignId', name: 'assignid',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
name: 'courseId', name: 'courseid',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
name: 'userId', name: 'userid',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
name: 'pluginData', name: 'plugindata',
type: 'TEXT' type: 'TEXT'
}, },
{ {
name: 'onlineTimemodified', name: 'onlinetimemodified',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
@ -67,25 +67,25 @@ export class AddonModAssignOfflineProvider {
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
name: 'submissionStatement', name: 'submissionstatement',
type: 'INTEGER' type: 'INTEGER'
} }
], ],
primaryKeys: ['assignId', 'userId'] primaryKeys: ['assignid', 'userid']
}, },
{ {
name: this.SUBMISSIONS_GRADES_TABLE, name: this.SUBMISSIONS_GRADES_TABLE,
columns: [ columns: [
{ {
name: 'assignId', name: 'assignid',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
name: 'courseId', name: 'courseid',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
name: 'userId', name: 'userid',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
@ -93,19 +93,19 @@ export class AddonModAssignOfflineProvider {
type: 'REAL' type: 'REAL'
}, },
{ {
name: 'attemptNumber', name: 'attemptnumber',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
name: 'addAttempt', name: 'addattempt',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
name: 'workflowState', name: 'workflowstate',
type: 'TEXT' type: 'TEXT'
}, },
{ {
name: 'applyToAll', name: 'applytoall',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
@ -113,7 +113,7 @@ export class AddonModAssignOfflineProvider {
type: 'TEXT' type: 'TEXT'
}, },
{ {
name: 'pluginData', name: 'plugindata',
type: 'TEXT' type: 'TEXT'
}, },
{ {
@ -121,7 +121,7 @@ export class AddonModAssignOfflineProvider {
type: 'INTEGER' type: 'INTEGER'
} }
], ],
primaryKeys: ['assignId', 'userId'] primaryKeys: ['assignid', 'userid']
} }
]; ];
@ -143,7 +143,7 @@ export class AddonModAssignOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId(); userId = userId || site.getUserId();
return site.getDb().deleteRecords(this.SUBMISSIONS_TABLE, {assignId, userId}); return site.getDb().deleteRecords(this.SUBMISSIONS_TABLE, {assignid: assignId, userid: userId});
}); });
} }
@ -159,7 +159,7 @@ export class AddonModAssignOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId(); userId = userId || site.getUserId();
return site.getDb().deleteRecords(this.SUBMISSIONS_GRADES_TABLE, {assignId, userId}); return site.getDb().deleteRecords(this.SUBMISSIONS_GRADES_TABLE, {assignid: assignId, userid: userId});
}); });
} }
@ -181,7 +181,7 @@ export class AddonModAssignOfflineProvider {
// Get assign id. // Get assign id.
results = results.map((object) => { results = results.map((object) => {
return object.assignId; return object.assignid;
}); });
// Get unique values. // Get unique values.
@ -206,7 +206,7 @@ export class AddonModAssignOfflineProvider {
// Parse the plugin data. // Parse the plugin data.
submissions.forEach((submission) => { submissions.forEach((submission) => {
submission.pluginData = this.textUtils.parseJSON(submission.pluginData, {}); submission.plugindata = this.textUtils.parseJSON(submission.plugindata, {});
}); });
return submissions; return submissions;
@ -227,7 +227,7 @@ export class AddonModAssignOfflineProvider {
// Parse the plugin data and outcomes. // Parse the plugin data and outcomes.
submissions.forEach((submission) => { submissions.forEach((submission) => {
submission.outcomes = this.textUtils.parseJSON(submission.outcomes, {}); submission.outcomes = this.textUtils.parseJSON(submission.outcomes, {});
submission.pluginData = this.textUtils.parseJSON(submission.pluginData, {}); submission.plugindata = this.textUtils.parseJSON(submission.plugindata, {});
}); });
return submissions; return submissions;
@ -243,12 +243,12 @@ export class AddonModAssignOfflineProvider {
*/ */
getAssignSubmissions(assignId: number, siteId?: string): Promise<any[]> { getAssignSubmissions(assignId: number, siteId?: string): Promise<any[]> {
return this.sitesProvider.getSiteDb(siteId).then((db) => { return this.sitesProvider.getSiteDb(siteId).then((db) => {
return db.getRecords(this.SUBMISSIONS_TABLE, {assignId}); return db.getRecords(this.SUBMISSIONS_TABLE, {assignid: assignId});
}).then((submissions) => { }).then((submissions) => {
// Parse the plugin data. // Parse the plugin data.
submissions.forEach((submission) => { submissions.forEach((submission) => {
submission.pluginData = this.textUtils.parseJSON(submission.pluginData, {}); submission.plugindata = this.textUtils.parseJSON(submission.plugindata, {});
}); });
return submissions; return submissions;
@ -264,13 +264,13 @@ export class AddonModAssignOfflineProvider {
*/ */
getAssignSubmissionsGrade(assignId: number, siteId?: string): Promise<any[]> { getAssignSubmissionsGrade(assignId: number, siteId?: string): Promise<any[]> {
return this.sitesProvider.getSiteDb(siteId).then((db) => { return this.sitesProvider.getSiteDb(siteId).then((db) => {
return db.getRecords(this.SUBMISSIONS_GRADES_TABLE, {assignId}); return db.getRecords(this.SUBMISSIONS_GRADES_TABLE, {assignid: assignId});
}).then((submissions) => { }).then((submissions) => {
// Parse the plugin data and outcomes. // Parse the plugin data and outcomes.
submissions.forEach((submission) => { submissions.forEach((submission) => {
submission.outcomes = this.textUtils.parseJSON(submission.outcomes, {}); submission.outcomes = this.textUtils.parseJSON(submission.outcomes, {});
submission.pluginData = this.textUtils.parseJSON(submission.pluginData, {}); submission.plugindata = this.textUtils.parseJSON(submission.plugindata, {});
}); });
return submissions; return submissions;
@ -289,11 +289,11 @@ export class AddonModAssignOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId(); userId = userId || site.getUserId();
return site.getDb().getRecord(this.SUBMISSIONS_TABLE, {assignId, userId}); return site.getDb().getRecord(this.SUBMISSIONS_TABLE, {assignid: assignId, userid: userId});
}).then((submission) => { }).then((submission) => {
// Parse the plugin data. // Parse the plugin data.
submission.pluginData = this.textUtils.parseJSON(submission.pluginData, {}); submission.plugindata = this.textUtils.parseJSON(submission.plugindata, {});
return submission; return submission;
}); });
@ -331,12 +331,12 @@ export class AddonModAssignOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId(); userId = userId || site.getUserId();
return site.getDb().getRecord(this.SUBMISSIONS_GRADES_TABLE, {assignId, userId}); return site.getDb().getRecord(this.SUBMISSIONS_GRADES_TABLE, {assignid: assignId, userid: userId});
}).then((submission) => { }).then((submission) => {
// Parse the plugin data and outcomes. // Parse the plugin data and outcomes.
submission.outcomes = this.textUtils.parseJSON(submission.outcomes, {}); submission.outcomes = this.textUtils.parseJSON(submission.outcomes, {});
submission.pluginData = this.textUtils.parseJSON(submission.pluginData, {}); submission.plugindata = this.textUtils.parseJSON(submission.plugindata, {});
return submission; return submission;
}); });
@ -410,18 +410,18 @@ export class AddonModAssignOfflineProvider {
const now = this.timeUtils.timestamp(); const now = this.timeUtils.timestamp();
return { return {
assignId: assignId, assignid: assignId,
courseId: courseId, courseid: courseId,
userId: userId, userid: userId,
onlineTimemodified: timemodified, onlinetimemodified: timemodified,
timecreated: now, timecreated: now,
timemodified: now timemodified: now
}; };
}).then((submission) => { }).then((submission) => {
// Mark the submission. // Mark the submission.
submission.submitted = submitted ? 1 : 0; submission.submitted = submitted ? 1 : 0;
submission.submissionStatement = acceptStatement ? 1 : 0; submission.submissionstatement = acceptStatement ? 1 : 0;
submission.pluginData = submission.pluginData ? JSON.stringify(submission.pluginData) : '{}'; submission.plugindata = submission.plugindata ? JSON.stringify(submission.plugindata) : '{}';
return site.getDb().insertRecord(this.SUBMISSIONS_TABLE, submission); return site.getDb().insertRecord(this.SUBMISSIONS_TABLE, submission);
}); });
@ -448,14 +448,14 @@ export class AddonModAssignOfflineProvider {
const now = this.timeUtils.timestamp(), const now = this.timeUtils.timestamp(),
entry = { entry = {
assignId: assignId, assignid: assignId,
courseId: courseId, courseid: courseId,
pluginData: pluginData ? JSON.stringify(pluginData) : '{}', plugindata: pluginData ? JSON.stringify(pluginData) : '{}',
userId: userId, userid: userId,
submitted: submitted ? 1 : 0, submitted: submitted ? 1 : 0,
timecreated: now, timecreated: now,
timemodified: now, timemodified: now,
onlineTimemodified: timemodified onlinetimemodified: timemodified
}; };
return site.getDb().insertRecord(this.SUBMISSIONS_TABLE, entry); return site.getDb().insertRecord(this.SUBMISSIONS_TABLE, entry);
@ -484,16 +484,16 @@ export class AddonModAssignOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
const now = this.timeUtils.timestamp(), const now = this.timeUtils.timestamp(),
entry = { entry = {
assignId: assignId, assignid: assignId,
userId: userId, userid: userId,
courseId: courseId, courseid: courseId,
grade: grade, grade: grade,
attemptNumber: attemptNumber, attemptnumber: attemptNumber,
addAttempt: addAttempt ? 1 : 0, addattempt: addAttempt ? 1 : 0,
workflowState: workflowState, workflowstate: workflowState,
applyToAll: applyToAll ? 1 : 0, applytoall: applyToAll ? 1 : 0,
outcomes: outcomes ? JSON.stringify(outcomes) : '{}', outcomes: outcomes ? JSON.stringify(outcomes) : '{}',
pluginData: pluginData ? JSON.stringify(pluginData) : '{}', plugindata: pluginData ? JSON.stringify(pluginData) : '{}',
timemodified: now timemodified: now
}; };

View File

@ -213,7 +213,7 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
return Promise.reject(null); return Promise.reject(null);
} }
courseId = submissions.length > 0 ? submissions[0].courseId : grades[0].courseId; courseId = submissions.length > 0 ? submissions[0].courseid : grades[0].courseid;
return this.assignProvider.getAssignmentById(courseId, assignId, siteId).then((assignData) => { return this.assignProvider.getAssignmentById(courseId, assignId, siteId).then((assignData) => {
assign = assignData; assign = assignData;
@ -264,7 +264,7 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
* @return {Promise<any>} Promise resolved if success, rejected otherwise. * @return {Promise<any>} Promise resolved if success, rejected otherwise.
*/ */
protected syncSubmission(assign: any, offlineData: any, warnings: string[], siteId?: string): Promise<any> { protected syncSubmission(assign: any, offlineData: any, warnings: string[], siteId?: string): Promise<any> {
const userId = offlineData.userId, const userId = offlineData.userid,
pluginData = {}; pluginData = {};
let discardError, let discardError,
submission; submission;
@ -274,7 +274,7 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
submission = this.assignProvider.getSubmissionObjectFromAttempt(assign, status.lastattempt); submission = this.assignProvider.getSubmissionObjectFromAttempt(assign, status.lastattempt);
if (submission.timemodified != offlineData.onlineTimemodified) { if (submission.timemodified != offlineData.onlinetimemodified) {
// The submission was modified in Moodle, discard the submission. // The submission was modified in Moodle, discard the submission.
discardError = this.translate.instant('addon.mod_assign.warningsubmissionmodified'); discardError = this.translate.instant('addon.mod_assign.warningsubmissionmodified');
@ -300,7 +300,7 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
return promise.then(() => { return promise.then(() => {
if (assign.submissiondrafts && offlineData.submitted) { if (assign.submissiondrafts && offlineData.submitted) {
// The user submitted the assign manually. Submit it for grading. // The user submitted the assign manually. Submit it for grading.
return this.assignProvider.submitForGradingOnline(assign.id, offlineData.submissionStatement, siteId); return this.assignProvider.submitForGradingOnline(assign.id, offlineData.submissionstatement, siteId);
} }
}).then(() => { }).then(() => {
// Submission data sent, update cached data. No need to block the user for this. // Submission data sent, update cached data. No need to block the user for this.
@ -355,7 +355,7 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
protected syncSubmissionGrade(assign: any, offlineData: any, warnings: string[], courseId: number, siteId?: string) protected syncSubmissionGrade(assign: any, offlineData: any, warnings: string[], courseId: number, siteId?: string)
: Promise<any> { : Promise<any> {
const userId = offlineData.userId; const userId = offlineData.userid;
let discardError; let discardError;
return this.assignProvider.getSubmissionStatus(assign.id, userId, false, true, true, siteId).then((status) => { return this.assignProvider.getSubmissionStatus(assign.id, userId, false, true, true, siteId).then((status) => {
@ -394,9 +394,9 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
}); });
}).then(() => { }).then(() => {
// Now submit the grade. // Now submit the grade.
return this.assignProvider.submitGradingFormOnline(assign.id, userId, offlineData.grade, offlineData.attemptNumber, return this.assignProvider.submitGradingFormOnline(assign.id, userId, offlineData.grade, offlineData.attemptnumber,
offlineData.addAttempt, offlineData.workflowState, offlineData.applyToAll, offlineData.outcomes, offlineData.addattempt, offlineData.workflowstate, offlineData.applytoall, offlineData.outcomes,
offlineData.pluginData, siteId).then(() => { offlineData.plugindata, siteId).then(() => {
// Grades sent, update cached data. No need to block the user for this. // Grades sent, update cached data. No need to block the user for this.
this.assignProvider.getSubmissionStatus(assign.id, userId, false, true, true, siteId); this.assignProvider.getSubmissionStatus(assign.id, userId, false, true, true, siteId);

View File

@ -47,10 +47,10 @@ export class AddonModAssignSubmissionFileComponent extends AddonModAssignSubmiss
this.assignOfflineProvider.getSubmission(this.assign.id).catch(() => { this.assignOfflineProvider.getSubmission(this.assign.id).catch(() => {
// Error getting data, assume there's no offline submission. // Error getting data, assume there's no offline submission.
}).then((offlineData) => { }).then((offlineData) => {
if (offlineData && offlineData.pluginData && offlineData.pluginData.files_filemanager) { if (offlineData && offlineData.plugindata && offlineData.plugindata.files_filemanager) {
// It has offline data. // It has offline data.
let promise; let promise;
if (offlineData.pluginData.files_filemanager.offline) { if (offlineData.plugindata.files_filemanager.offline) {
promise = this.assignHelper.getStoredSubmissionFiles(this.assign.id, promise = this.assignHelper.getStoredSubmissionFiles(this.assign.id,
AddonModAssignSubmissionFileHandler.FOLDER_NAME); AddonModAssignSubmissionFileHandler.FOLDER_NAME);
} else { } else {
@ -58,7 +58,7 @@ export class AddonModAssignSubmissionFileComponent extends AddonModAssignSubmiss
} }
return promise.then((offlineFiles) => { return promise.then((offlineFiles) => {
const onlineFiles = offlineData.pluginData.files_filemanager.online || []; const onlineFiles = offlineData.plugindata.files_filemanager.online || [];
offlineFiles = this.fileUploaderProvider.markOfflineFiles(offlineFiles); offlineFiles = this.fileUploaderProvider.markOfflineFiles(offlineFiles);
this.files = onlineFiles.concat(offlineFiles); this.files = onlineFiles.concat(offlineFiles);

View File

@ -237,9 +237,9 @@ export class AddonModAssignSubmissionFileHandler implements AddonModAssignSubmis
return this.assignOfflineProvider.getSubmission(assign.id, submission.userid).catch(() => { return this.assignOfflineProvider.getSubmission(assign.id, submission.userid).catch(() => {
// No offline data found. // No offline data found.
}).then((offlineData) => { }).then((offlineData) => {
if (offlineData && offlineData.pluginData && offlineData.pluginData.files_filemanager) { if (offlineData && offlineData.plugindata && offlineData.plugindata.files_filemanager) {
// Has offline data, return the number of files. // Has offline data, return the number of files.
return offlineData.pluginData.files_filemanager.offline + offlineData.pluginData.files_filemanager.online.length; return offlineData.plugindata.files_filemanager.offline + offlineData.plugindata.files_filemanager.online.length;
} }
// No offline data, return the number of online files. // No offline data, return the number of online files.
@ -333,7 +333,7 @@ export class AddonModAssignSubmissionFileHandler implements AddonModAssignSubmis
prepareSyncData(assign: any, submission: any, plugin: any, offlineData: any, pluginData: any, siteId?: string) prepareSyncData(assign: any, submission: any, plugin: any, offlineData: any, pluginData: any, siteId?: string)
: void | Promise<any> { : void | Promise<any> {
const filesData = offlineData && offlineData.pluginData && offlineData.pluginData.files_filemanager; const filesData = offlineData && offlineData.plugindata && offlineData.plugindata.files_filemanager;
if (filesData) { if (filesData) {
// Has some data to sync. // Has some data to sync.
let files = filesData.online || [], let files = filesData.online || [],

View File

@ -68,8 +68,8 @@ export class AddonModAssignSubmissionOnlineTextComponent extends AddonModAssignS
return this.assignOfflineProvider.getSubmission(this.assign.id).catch(() => { return this.assignOfflineProvider.getSubmission(this.assign.id).catch(() => {
// No offline data found. // No offline data found.
}).then((offlineData) => { }).then((offlineData) => {
if (offlineData && offlineData.pluginData && offlineData.pluginData.onlinetext_editor) { if (offlineData && offlineData.plugindata && offlineData.plugindata.onlinetext_editor) {
return offlineData.pluginData.onlinetext_editor.text; return offlineData.plugindata.onlinetext_editor.text;
} }
// No offline data found, return online text. // No offline data found, return online text.

View File

@ -188,8 +188,8 @@ export class AddonModAssignSubmissionOnlineTextHandler implements AddonModAssign
return this.assignOfflineProvider.getSubmission(assign.id, submission.userid).catch(() => { return this.assignOfflineProvider.getSubmission(assign.id, submission.userid).catch(() => {
// No offline data found. // No offline data found.
}).then((data) => { }).then((data) => {
if (data && data.pluginData && data.pluginData.onlinetext_editor) { if (data && data.plugindata && data.plugindata.onlinetext_editor) {
return data.pluginData.onlinetext_editor.text; return data.plugindata.onlinetext_editor.text;
} }
// No offline data found, get text from plugin. // No offline data found, get text from plugin.

View File

@ -39,7 +39,7 @@ export class AddonModScormOfflineProvider {
name: this.ATTEMPTS_TABLE, name: this.ATTEMPTS_TABLE,
columns: [ columns: [
{ {
name: 'scormId', name: 'scormid',
type: 'INTEGER', type: 'INTEGER',
notNull: true notNull: true
}, },
@ -49,12 +49,12 @@ export class AddonModScormOfflineProvider {
notNull: true notNull: true
}, },
{ {
name: 'userId', name: 'userid',
type: 'INTEGER', type: 'INTEGER',
notNull: true notNull: true
}, },
{ {
name: 'courseId', name: 'courseid',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
@ -70,13 +70,13 @@ export class AddonModScormOfflineProvider {
type: 'TEXT' type: 'TEXT'
}, },
], ],
primaryKeys: ['scormId', 'userId', 'attempt'] primaryKeys: ['scormid', 'userid', 'attempt']
}, },
{ {
name: this.TRACKS_TABLE, name: this.TRACKS_TABLE,
columns: [ columns: [
{ {
name: 'scormId', name: 'scormid',
type: 'INTEGER', type: 'INTEGER',
notNull: true notNull: true
}, },
@ -86,12 +86,12 @@ export class AddonModScormOfflineProvider {
notNull: true notNull: true
}, },
{ {
name: 'userId', name: 'userid',
type: 'INTEGER', type: 'INTEGER',
notNull: true notNull: true
}, },
{ {
name: 'scoId', name: 'scoid',
type: 'INTEGER', type: 'INTEGER',
notNull: true notNull: true
}, },
@ -113,7 +113,7 @@ export class AddonModScormOfflineProvider {
type: 'INTEGER' type: 'INTEGER'
}, },
], ],
primaryKeys: ['scormId', 'userId', 'attempt', 'scoId', 'element'] primaryKeys: ['scormid', 'userid', 'attempt', 'scoid', 'element']
} }
]; ];
@ -145,7 +145,9 @@ export class AddonModScormOfflineProvider {
this.logger.debug('Change attempt number from ' + attempt + ' to ' + newAttempt + ' in SCORM ' + scormId); this.logger.debug('Change attempt number from ' + attempt + ' to ' + newAttempt + ' in SCORM ' + scormId);
// Update the attempt number. // Update the attempt number.
const db = site.getDb(); const db = site.getDb(),
currentAttemptConditions = {scormid: scormId, userid: userId, attempt: attempt},
newAttemptConditions = {scormid: scormId, userid: userId, attempt: newAttempt};
let newData: any = { let newData: any = {
attempt: newAttempt, attempt: newAttempt,
timemodified: this.timeUtils.timestamp() timemodified: this.timeUtils.timestamp()
@ -154,7 +156,7 @@ export class AddonModScormOfflineProvider {
// Block the SCORM so it can't be synced. // Block the SCORM so it can't be synced.
this.syncProvider.blockOperation(AddonModScormProvider.COMPONENT, scormId, 'changeAttemptNumber', site.id); this.syncProvider.blockOperation(AddonModScormProvider.COMPONENT, scormId, 'changeAttemptNumber', site.id);
return db.updateRecords(this.ATTEMPTS_TABLE, newData, {scormId, userId, attempt}).then(() => { return db.updateRecords(this.ATTEMPTS_TABLE, newData, currentAttemptConditions).then(() => {
// Now update the attempt number of all the tracks and mark them as not synced. // Now update the attempt number of all the tracks and mark them as not synced.
newData = { newData = {
@ -162,9 +164,9 @@ export class AddonModScormOfflineProvider {
synced: 0 synced: 0
}; };
return db.updateRecords(this.TRACKS_TABLE, newData, {scormId, userId, attempt}).catch((error) => { return db.updateRecords(this.TRACKS_TABLE, newData, currentAttemptConditions).catch((error) => {
// Failed to update the tracks, restore the old attempt number. // Failed to update the tracks, restore the old attempt number.
return db.updateRecords(this.ATTEMPTS_TABLE, { attempt }, {scormId, userId, attempt: newAttempt}).then(() => { return db.updateRecords(this.ATTEMPTS_TABLE, { attempt: attempt }, newAttemptConditions).then(() => {
return Promise.reject(error); return Promise.reject(error);
}); });
}); });
@ -199,10 +201,10 @@ export class AddonModScormOfflineProvider {
// Create attempt in DB. // Create attempt in DB.
const db = site.getDb(), const db = site.getDb(),
entry: any = { entry: any = {
scormId: scorm.id, scormid: scorm.id,
userId: userId, userid: userId,
attempt: attempt, attempt: attempt,
courseId: scorm.course, courseid: scorm.course,
timecreated: this.timeUtils.timestamp(), timecreated: this.timeUtils.timestamp(),
timemodified: this.timeUtils.timestamp(), timemodified: this.timeUtils.timestamp(),
snapshot: null snapshot: null
@ -256,10 +258,10 @@ export class AddonModScormOfflineProvider {
db = site.getDb(); db = site.getDb();
// Delete the attempt. // Delete the attempt.
promises.push(db.deleteRecords(this.ATTEMPTS_TABLE, {scormId, userId, attempt})); promises.push(db.deleteRecords(this.ATTEMPTS_TABLE, {scormid: scormId, userid: userId, attempt: attempt}));
// Delete all the tracks. // Delete all the tracks.
promises.push(db.deleteRecords(this.TRACKS_TABLE, {scormId, userId, attempt})); promises.push(db.deleteRecords(this.TRACKS_TABLE, {scormid: scormId, userid: userId, attempt: attempt}));
return Promise.all(promises); return Promise.all(promises);
}); });
@ -352,11 +354,11 @@ export class AddonModScormOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId(); userId = userId || site.getUserId();
return site.getDb().getRecord(this.ATTEMPTS_TABLE, {scormId, userId, attempt}).then((entry) => { return site.getDb().getRecord(this.ATTEMPTS_TABLE, {scormid: scormId, userid: userId, attempt: attempt});
entry.snapshot = this.textUtils.parseJSON(entry.snapshot); }).then((entry) => {
entry.snapshot = this.textUtils.parseJSON(entry.snapshot);
return entry; return entry;;
});
}); });
} }
@ -389,7 +391,7 @@ export class AddonModScormOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId(); userId = userId || site.getUserId();
return site.getDb().getRecords(this.ATTEMPTS_TABLE, {scormId, userId}); return site.getDb().getRecords(this.ATTEMPTS_TABLE, {scormid: scormId, userid: userId});
}).then((attempts) => { }).then((attempts) => {
attempts.forEach((attempt) => { attempts.forEach((attempt) => {
attempt.snapshot = this.textUtils.parseJSON(attempt.snapshot); attempt.snapshot = this.textUtils.parseJSON(attempt.snapshot);
@ -454,8 +456,8 @@ export class AddonModScormOfflineProvider {
userId = userId || site.getUserId(); userId = userId || site.getUserId();
const conditions: any = { const conditions: any = {
scormId: scormId, scormid: scormId,
userId: userId, userid: userId,
attempt: attempt attempt: attempt
}; };
@ -513,7 +515,7 @@ export class AddonModScormOfflineProvider {
// Gather user data retrieved from DB, grouping it by scoid. // Gather user data retrieved from DB, grouping it by scoid.
entries.forEach((entry) => { entries.forEach((entry) => {
const scoId = entry.scoId; const scoId = entry.scoid;
if (!response[scoId]) { if (!response[scoId]) {
// Initialize SCO. // Initialize SCO.
@ -690,9 +692,9 @@ export class AddonModScormOfflineProvider {
value: any, synchronous?: boolean): boolean | Promise<any> { value: any, synchronous?: boolean): boolean | Promise<any> {
const entry = { const entry = {
userId: userId, userid: userId,
scormId: scormId, scormid: scormId,
scoId: scoId, scoid: scoId,
attempt: attempt, attempt: attempt,
element: element, element: element,
value: typeof value == 'undefined' ? null : JSON.stringify(value), value: typeof value == 'undefined' ? null : JSON.stringify(value),
@ -789,10 +791,10 @@ export class AddonModScormOfflineProvider {
this.logger.debug('Mark SCO ' + scoId + ' as synced for attempt ' + attempt + ' in SCORM ' + scormId); this.logger.debug('Mark SCO ' + scoId + ' as synced for attempt ' + attempt + ' in SCORM ' + scormId);
return site.getDb().updateRecords(this.TRACKS_TABLE, {synced: 1}, { return site.getDb().updateRecords(this.TRACKS_TABLE, {synced: 1}, {
scormId: scormId, scormid: scormId,
userId: userId, userid: userId,
attempt: attempt, attempt: attempt,
scoId: scoId, scoid: scoId,
synced: 0 synced: 0
}); });
}); });
@ -914,7 +916,7 @@ export class AddonModScormOfflineProvider {
snapshot: JSON.stringify(this.removeDefaultData(userData)) snapshot: JSON.stringify(this.removeDefaultData(userData))
}; };
return site.getDb().updateRecords(this.ATTEMPTS_TABLE, newData, { scormId, userId, attempt }); return site.getDb().updateRecords(this.ATTEMPTS_TABLE, newData, { scormid: scormId, userid: userId, attempt: attempt });
}); });
} }
} }

View File

@ -379,13 +379,13 @@ export class AddonModScormSyncProvider extends CoreSyncBaseProvider {
// We need to add the synced data to the snapshot. // We need to add the synced data to the snapshot.
return this.scormOfflineProvider.getScormStoredData(scormId, attempt, false, true, siteId).then((synced) => { return this.scormOfflineProvider.getScormStoredData(scormId, attempt, false, true, siteId).then((synced) => {
synced.forEach((entry) => { synced.forEach((entry) => {
if (!data[entry.scoId]) { if (!data[entry.scoid]) {
data[entry.scoId] = { data[entry.scoid] = {
scoid: entry.scoId, scoid: entry.scoid,
userdata: {} userdata: {}
}; };
} }
data[entry.scoId].userdata[entry.element] = entry.value; data[entry.scoid].userdata[entry.element] = entry.value;
}); });
return this.scormOfflineProvider.setAttemptSnapshot(scormId, attempt, data, siteId); return this.scormOfflineProvider.setAttemptSnapshot(scormId, attempt, data, siteId);
@ -461,12 +461,12 @@ export class AddonModScormSyncProvider extends CoreSyncBaseProvider {
// Get the IDs of all the SCORMs that have something to be synced. // Get the IDs of all the SCORMs that have something to be synced.
attempts.forEach((attempt) => { attempts.forEach((attempt) => {
if (ids.indexOf(attempt.scormId) == -1) { if (ids.indexOf(attempt.scormid) == -1) {
ids.push(attempt.scormId); ids.push(attempt.scormid);
scorms.push({ scorms.push({
id: attempt.scormId, id: attempt.scormid,
courseId: attempt.courseId courseId: attempt.courseid
}); });
} }
}); });
@ -517,11 +517,11 @@ export class AddonModScormSyncProvider extends CoreSyncBaseProvider {
// Get data to send (only elements with dots like cmi.core.exit, in Mobile we store more data to make offline work). // Get data to send (only elements with dots like cmi.core.exit, in Mobile we store more data to make offline work).
entries.forEach((entry) => { entries.forEach((entry) => {
if (entry.element.indexOf('.') > -1) { if (entry.element.indexOf('.') > -1) {
if (!scos[entry.scoId]) { if (!scos[entry.scoid]) {
scos[entry.scoId] = []; scos[entry.scoid] = [];
} }
scos[entry.scoId].push({ scos[entry.scoid].push({
element: entry.element, element: entry.element,
value: entry.value value: entry.value
}); });

View File

@ -73,7 +73,7 @@ export class CoreQuestionProvider {
notNull: true notNull: true
}, },
{ {
name: 'attemptId', name: 'attemptid',
type: 'INTEGER', type: 'INTEGER',
notNull: true notNull: true
}, },
@ -83,11 +83,11 @@ export class CoreQuestionProvider {
notNull: true notNull: true
}, },
{ {
name: 'componentId', name: 'componentid',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
name: 'userId', name: 'userid',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
@ -99,7 +99,7 @@ export class CoreQuestionProvider {
type: 'TEXT' type: 'TEXT'
} }
], ],
primaryKeys: ['component', 'attemptId', 'slot'] primaryKeys: ['component', 'attemptid', 'slot']
}, },
{ {
name: this.QUESTION_ANSWERS_TABLE, name: this.QUESTION_ANSWERS_TABLE,
@ -110,7 +110,7 @@ export class CoreQuestionProvider {
notNull: true notNull: true
}, },
{ {
name: 'attemptId', name: 'attemptid',
type: 'INTEGER', type: 'INTEGER',
notNull: true notNull: true
}, },
@ -120,15 +120,15 @@ export class CoreQuestionProvider {
notNull: true notNull: true
}, },
{ {
name: 'componentId', name: 'componentid',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
name: 'userId', name: 'userid',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
name: 'questionSlot', name: 'questionslot',
type: 'INTEGER' type: 'INTEGER'
}, },
{ {
@ -144,7 +144,7 @@ export class CoreQuestionProvider {
type: 'INTEGER' type: 'INTEGER'
} }
], ],
primaryKeys: ['component', 'attemptId', 'name'] primaryKeys: ['component', 'attemptid', 'name']
} }
]; ];
@ -310,7 +310,7 @@ export class CoreQuestionProvider {
*/ */
getAnswer(component: string, attemptId: number, name: string, siteId?: string): Promise<any> { getAnswer(component: string, attemptId: number, name: string, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecord(this.QUESTION_ANSWERS_TABLE, {component, attemptId, name}); return site.getDb().getRecord(this.QUESTION_ANSWERS_TABLE, {component: component, attemptid: attemptId, name: name});
}); });
} }
@ -324,7 +324,7 @@ export class CoreQuestionProvider {
*/ */
getAttemptAnswers(component: string, attemptId: number, siteId?: string): Promise<any[]> { getAttemptAnswers(component: string, attemptId: number, siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.QUESTION_ANSWERS_TABLE, {component, attemptId}); return site.getDb().getRecords(this.QUESTION_ANSWERS_TABLE, {component: component, attemptid: attemptId});
}); });
} }
@ -338,7 +338,7 @@ export class CoreQuestionProvider {
*/ */
getAttemptQuestions(component: string, attemptId: number, siteId?: string): Promise<any[]> { getAttemptQuestions(component: string, attemptId: number, siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.QUESTION_TABLE, {component, attemptId}); return site.getDb().getRecords(this.QUESTION_TABLE, {component: component, attemptid: attemptId});
}); });
} }
@ -389,7 +389,7 @@ export class CoreQuestionProvider {
*/ */
getQuestion(component: string, attemptId: number, slot: number, siteId?: string): Promise<any> { getQuestion(component: string, attemptId: number, slot: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecord(this.QUESTION_TABLE, {component, attemptId, slot}); return site.getDb().getRecord(this.QUESTION_TABLE, {component: component, attemptid: attemptId, slot: slot});
}); });
} }
@ -405,8 +405,9 @@ export class CoreQuestionProvider {
*/ */
getQuestionAnswers(component: string, attemptId: number, slot: number, filter?: boolean, siteId?: string): Promise<any[]> { getQuestionAnswers(component: string, attemptId: number, slot: number, filter?: boolean, siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.QUESTION_ANSWERS_TABLE, {component, attemptId, questionSlot: slot}) return site.getDb().getRecords(this.QUESTION_ANSWERS_TABLE, {component: component, attemptid: attemptId,
.then((answers) => { questionslot: slot}).then((answers) => {
if (filter) { if (filter) {
// Get only answers that isn't "extra" data like sequencecheck or certainty. // Get only answers that isn't "extra" data like sequencecheck or certainty.
return this.getBasicAnswersFromArray(answers); return this.getBasicAnswersFromArray(answers);
@ -467,7 +468,7 @@ export class CoreQuestionProvider {
*/ */
removeAttemptAnswers(component: string, attemptId: number, siteId?: string): Promise<any> { removeAttemptAnswers(component: string, attemptId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.QUESTION_ANSWERS_TABLE, {component, attemptId}); return site.getDb().deleteRecords(this.QUESTION_ANSWERS_TABLE, {component: component, attemptid: attemptId});
}); });
} }
@ -481,7 +482,7 @@ export class CoreQuestionProvider {
*/ */
removeAttemptQuestions(component: string, attemptId: number, siteId?: string): Promise<any> { removeAttemptQuestions(component: string, attemptId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.QUESTION_TABLE, {component, attemptId}); return site.getDb().deleteRecords(this.QUESTION_TABLE, {component: component, attemptid: attemptId});
}); });
} }
@ -496,7 +497,8 @@ export class CoreQuestionProvider {
*/ */
removeAnswer(component: string, attemptId: number, name: string, siteId?: string): Promise<any> { removeAnswer(component: string, attemptId: number, name: string, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.QUESTION_ANSWERS_TABLE, {component, attemptId, name}); return site.getDb().deleteRecords(this.QUESTION_ANSWERS_TABLE, {component: component, attemptid: attemptId,
name: name});
}); });
} }
@ -511,7 +513,7 @@ export class CoreQuestionProvider {
*/ */
removeQuestion(component: string, attemptId: number, slot: number, siteId?: string): Promise<any> { removeQuestion(component: string, attemptId: number, slot: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.QUESTION_TABLE, {component, attemptId, slot}); return site.getDb().deleteRecords(this.QUESTION_TABLE, {component: component, attemptid: attemptId, slot: slot});
}); });
} }
@ -526,7 +528,8 @@ export class CoreQuestionProvider {
*/ */
removeQuestionAnswers(component: string, attemptId: number, slot: number, siteId?: string): Promise<any> { removeQuestionAnswers(component: string, attemptId: number, slot: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.QUESTION_ANSWERS_TABLE, {component, attemptId, questionSlot: slot}); return site.getDb().deleteRecords(this.QUESTION_ANSWERS_TABLE, {component: component, attemptid: attemptId,
questionslot: slot});
}); });
} }
@ -568,10 +571,10 @@ export class CoreQuestionProvider {
const value = answers[name], const value = answers[name],
entry = { entry = {
component: component, component: component,
componentId: componentId, componentid: componentId,
attemptId: attemptId, attemptid: attemptId,
userId: userId, userid: userId,
questionSlot: this.getQuestionSlotFromName(name), questionslot: this.getQuestionSlotFromName(name),
name: name, name: name,
value: value, value: value,
timemodified: timemodified timemodified: timemodified
@ -602,7 +605,7 @@ export class CoreQuestionProvider {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
const entry = { const entry = {
component: component, component: component,
componentId: componentId, componentid: componentId,
attemptid: attemptId, attemptid: attemptId,
userid: userId, userid: userId,
number: question.number, number: question.number,