Index: openacs-4/packages/acs-tcl/tcl/json-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/json-procs.tcl,v diff -u -N -r1.4 -r1.5 --- openacs-4/packages/acs-tcl/tcl/json-procs.tcl 20 Aug 2011 20:21:57 -0000 1.4 +++ openacs-4/packages/acs-tcl/tcl/json-procs.tcl 22 Aug 2011 23:46:39 -0000 1.5 @@ -452,6 +452,27 @@ } } +ad_proc util::json::sql_values_to_json_values {row} { + + Converts empty values to "null", consistent with how oracle, mysql, and + the nspostgres bindvar hack treats them. + + @param row A row (list) returned by a sql SELECT. + + @return A new list with empty strings converted to null. + +} { + set new_row {} + foreach value $row { + if { $value == "" } { + lappend new_row null + } else { + lappend new_row $value + } + } + return $new_row +} + ad_proc util::json::array::create {values} { Construct a JSON object with the given values list Index: openacs-4/packages/scorm-player/tcl/rte-api-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/scorm-player/tcl/rte-api-procs.tcl,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/scorm-player/tcl/rte-api-procs.tcl 8 Jul 2010 01:14:22 -0000 1.3 +++ openacs-4/packages/scorm-player/tcl/rte-api-procs.tcl 22 Aug 2011 23:46:40 -0000 1.4 @@ -76,7 +76,7 @@ } { if { [db_0or1row get_suspend_data {}] } { db_dml delete_suspend_data {} - return $data + return [util::json::sql_values_to_json_values $data] } return } @@ -202,6 +202,10 @@ set attribute_names {} + # list of modifiers for the attributes. + + set attribute_modifiers {} + # select_attributes is the list of munged attribute names to use in the rowset # descriptor for the query. @@ -212,8 +216,9 @@ # ignored for cp_package, which is very much a special case. foreach attribute $attribute_list { - foreach {name dummy} $attribute {} + foreach {name modifier} $attribute {} lappend attribute_names $name + lappend attribute_modifiers $modifier lappend select_attributes cmi_${table}.[scorm_core::db_name -name $name] } lappend schema $table [util::json::array::create $attribute_names] @@ -222,6 +227,19 @@ lappend data $table set rows {} foreach row $rowset { + for { set i 0} { $i < [llength $row] } { incr i } { + switch [lindex $attribute_modifiers $i] { + INTERVAL { + set row [lreplace $row $i $i \ + [scorm_player::seconds_to_interval -timestamp [lindex $row $i]]] + } + default { + if { [lindex $row $i] == "" } { + set row [lreplace $row $i $i null] + } + } + } + } lappend rows [util::json::array::create $row] } lappend data [util::json::array::create $rows] Index: openacs-4/packages/scorm-player/tcl/scorm-player-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/scorm-player/tcl/scorm-player-procs.tcl,v diff -u -N -r1.4 -r1.5 --- openacs-4/packages/scorm-player/tcl/scorm-player-procs.tcl 9 Jul 2010 18:44:39 -0000 1.4 +++ openacs-4/packages/scorm-player/tcl/scorm-player-procs.tcl 22 Aug 2011 23:46:40 -0000 1.5 @@ -189,3 +189,20 @@ return $seconds } +ad_proc scorm_player::seconds_to_interval { + -timestamp:required +} { + Convert a database interval into a SCORM 2004 style interval. + + Note: only works for hours, minutes and fractional seconds thus far. +} { + if { $timestamp eq "" } { + return null + } + set splits [split $timestamp :] + if { [llength $splits] > 3 } { + return --code error \ + "scorm_player::seconds_to_interval only handles hours, minutes, seconds" + } + return "PT[lindex $splits 0]H[lindex $splits 1]M[lindex $splits 2]S" +}