Custom storage API to persist values from LPs.

skala
jkbockstael 14 years ago
parent d3f7972d4b
commit 6757dd98d7
  1. 14
      main/install/db_main.sql
  2. 7
      main/install/migrate-db-1.8.6.2-1.8.7-pre.sql
  3. 63
      main/newscorm/js/storageapi.js
  4. 7
      main/newscorm/lp_controller.php
  5. 63
      main/newscorm/storageapi.php

@ -2522,3 +2522,17 @@ CREATE TABLE `user_rel_event_type` (
INSERT INTO `event_type` VALUES (1, 'course_deleted','courseDeletedTitle','courseDeletedComment'),(2,'course_created','courseCreatedTitle','courseCreatedComment'),(3,'user_deleted','userDeletedTitle','userDeletedComment'),(4,'user_created','userCreatedTitle','userCreatedComment'), (5, 'session_created','sessionCreatedTitle','sessionCreatedComment'), (6,'session_deleted','sessionDeletedTitle','sessionDeletedComment'), (7,'session_category_created','sessionCategoryCreatedTitle','sessionCategoryCreatedComment'),(8,'session_category_deleted','sessionCategoryDeletedTitle','sessionCategoryDeletedComment'),(9,'settings_changed','settingsChangedTitle','settingsChangedComment'),(10,'user_subscribed','userSubscribedTitle','userSubscribedComment'), (11,'user_unsubscribed','userUnsubscribedTitle','userUnsubscribedComment');
INSERT INTO `event_type_message` (`id`,`event_type_id`, `language_id`, `message`,`subject`) VALUES (1,4,10,'Bonjour, \r\n\r\nL\'utilisateur %username% (%firstname% %lastname%) a é créé.\r\nEmail : %mail%\r\n\r\nBien à vous.',''),(2,1,10,'Delete formation',''),(3,2,10,'Create formation',''),(4,3,10,'Bonjour, \r\n\r\nL\'utilisateur %username% (%firstname% %lastname%) a été supprimé.\r\n\r\nBien à vous.',''),(6,5,10,'Create session test',''),(7,6,10,'Delete session',''),(8,7,10,'Create category session',''),(9,8,10,'Delete category session',''),(10,9,10,'Change setting',''),(11,10,10,'Subscribe',''),(12,11,10,'Unsubscribe','');
--
-- Table structure for LP custom storage API
--
DROP TABLE IF EXISTS stored_value;
CREATE TABLE stored_values (
user_id INT NOT NULL,
sco_id INT NOT NULL,
course_id CHAR(40) NOT NULL,
sv_key CHAR(64) NOT NULL,
sv_value TEXT NOT NULL
);
ALTER TABLE stored_values ADD KEY (user_id, sco_id, course_id, sv_key);
ALTER TABLE stored_values ADD UNIQUE (user_id, sco_id, course_id, sv_key);

@ -198,3 +198,10 @@ INSERT INTO course_setting(variable,value,category) VALUES ('email_alert_student
ALTER TABLE lp ADD COLUMN hide_toc_frame TINYINT NOT NULL DEFAULT 0;
alter table lp_item_view modify column suspend_data longtext;
--
-- Table structure for LP custom storage API
--
CREATE TABLE stored_values (user_id INT NOT NULL, sco_id INT NOT NULL, course_id CHAR(40) NOT NULL, sv_key CHAR(64) NOT NULL, sv_value TEXT NOT NULL );
ALTER TABLE stored_values ADD KEY (user_id, sco_id, course_id, sv_key);
ALTER TABLE stored_values ADD UNIQUE (user_id, sco_id, course_id, sv_key);

@ -0,0 +1,63 @@
// Storage API
// JavaScript API
lms_storage_testCall = function(content) {
alert(content);
}
lms_storage_setValue = function(sv_key, sv_value) {
var result;
$.ajax({
async: false,
url: "storageapi.php",
data: {
action: "set",
svkey: sv_key,
svvalue: sv_value,
svuser: sv_user,
svcourse: sv_course,
svsco: sv_sco
},
success: function(data) {
result = (data != '0');
}
});
return result;
}
lms_storage_getValue = function(sv_key) {
var result;
$.ajax({
async: false,
url: "storageapi.php",
data: {
action: "get",
svkey: sv_key,
svuser: sv_user,
svcourse: sv_course,
svsco: sv_sco
},
success: function(data) {
result = data;
}
});
return result;
}
lms_storage_getAll = function() {
var result;
$.ajax({
async: false,
url: "storageapi.php",
data: {
action: "getall",
svuser: sv_user,
svcourse: sv_course,
svsco: sv_sco
},
success: function(data) {
result = eval(data);
}
});
return result;
}

@ -48,6 +48,13 @@ $(window).load(function () {
});
</script>';
// Storage API
$htmlHeadXtra[] = '<script type="text/javascript">
var sv_user = \''.api_get_user_id().'\';
var sv_course = \''.api_get_course_id().'\';
var sv_sco = \''.$_REQUEST['lp_id'].'\';
</script>';
$htmlHeadXtra[] = '<script type="text/javascript" src="js/storageapi.js"></script>';
//flag to allow for anonymous user - needs to be set before global.inc.php

@ -0,0 +1,63 @@
<?php
// Storage API
// PHP Backend
require_once('../inc/global.inc.php');
switch ($_REQUEST['action']) {
case "get":
print storage_get($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey']);
break;
case "set":
print storage_set($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey'], $_REQUEST['svvalue']);
break;
case "getall":
print storage_getall($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco']);
break;
default:
// Do nothing
}
function storage_get($sv_user, $sv_course, $sv_sco, $sv_key) {
$mainDB = Database::get_main_database();
$sql = "select sv_value
from $mainDB.stored_values
where user_id= '$sv_user'
and sco_id = '$sv_sco'
and course_id = '$sv_course'
and sv_key = '$sv_key'";
$res = Database::query($sql);
if (mysql_num_rows($res) > 0) {
$row = Database::fetch_assoc($res);
return $row['sv_value'];
}
else {
return null;
}
}
function storage_set($sv_user, $sv_course, $sv_sco, $sv_key, $sv_value) {
$mainDB = Database::get_main_database();
$sql = "replace into $mainDB.stored_values
(user_id, sco_id, course_id, sv_key, sv_value)
values
('$sv_user','$sv_sco','$sv_course','$sv_key','$sv_value')";
$res = Database::query($sql);
return mysql_affected_rows();
}
function storage_getall($sv_user, $sv_course, $sv_sco) {
$mainDB = Database::get_main_database();
$sql = "select sv_key, sv_value
from $mainDB.stored_values
where user_id= '$sv_user'
and sco_id = '$sv_sco'
and course_id = '$sv_course'";
$res = Database::query($sql);
$data = array();
while ($row = Database::fetch_assoc($res)) {
$data[] = $row;
}
return json_encode($data);
}
?>
Loading…
Cancel
Save