function opigno_scorm_sco_cmi_set in Opigno 7
Set a CMI data value for the given SCO.
Parameters
int $uid:
int $sco_id:
string $cmi_key:
string $value:
Return value
bool
1 call to opigno_scorm_sco_cmi_set()
- opigno_scorm_ajax_sco_cmi in modules/
scorm/ includes/ opigno_scorm.ajax.inc - AJAX callback: CMI communication.
File
- modules/
scorm/ opigno_scorm.module, line 384 - Opigno SCORM API.
Code
function opigno_scorm_sco_cmi_set($uid, $sco_id, $cmi_key, $value) {
// Allow modules to alter the value. If the $value is set to NULL, it is assumed
// a module takes over the persisting of the data and the insertion query
// will be skipped.
$context = array(
'uid' => $uid,
'sco_id' => $sco_id,
'original_value' => $value,
);
drupal_alter('opigno_scorm_sco_cmi_set', $value, $cmi_key, $context);
if (isset($value)) {
$serialized = 0;
if (is_array($value) || is_object($value)) {
$value = serialize($value);
$serialized = 1;
}
elseif (is_bool($value)) {
$value = (int) $value;
}
$result = db_merge('opigno_scorm_sco_cmi_data')
->key(array(
'uid' => $uid,
'sco_id' => $sco_id,
'cmi_key' => $cmi_key,
))
->fields(array(
'uid' => $uid,
'sco_id' => $sco_id,
'cmi_key' => $cmi_key,
'value' => $value,
'serialized' => $serialized,
))
->execute();
return !!$result;
}
else {
return TRUE;
}
}