function opigno_scorm_scorm_cmi_set in Opigno 7
Set a CMI data value for the given SCORM.
Parameters
int $uid:
int $scorm_id:
string $cmi_key:
string $value:
Return value
bool
3 calls to opigno_scorm_scorm_cmi_set()
- hook_opigno_scorm_ui_commit in modules/
scorm/ ui/ opigno_scorm_ui.api.php - Implements hook_opigno_scorm_ui_commit().
- opigno_scorm_quiz_opigno_scorm_ui_commit in modules/
scorm/ quiz/ opigno_scorm_quiz.module - Implements hook_opigno_scorm_ui_commit().
- opigno_scorm_ui_opigno_scorm_ui_commit in modules/
scorm/ ui/ opigno_scorm_ui.module - Implements hook_opigno_scorm_ui_commit().
File
- modules/
scorm/ opigno_scorm.module, line 297 - Opigno SCORM API.
Code
function opigno_scorm_scorm_cmi_set($uid, $scorm_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,
'scorm_id' => $scorm_id,
'original_value' => $value,
);
drupal_alter('opigno_scorm_scorm_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_scorm_cmi_data')
->key(array(
'uid' => $uid,
'scorm_id' => $scorm_id,
'cmi_key' => $cmi_key,
))
->fields(array(
'uid' => $uid,
'scorm_id' => $scorm_id,
'cmi_key' => $cmi_key,
'value' => $value,
'serialized' => $serialized,
))
->execute();
return !!$result;
}
else {
return TRUE;
}
}