function opigno_scorm_sco_save in Opigno 7
Save a SCO information.
Parameters
object $sco:
Return value
bool
1 call to opigno_scorm_sco_save()
- opigno_scorm_extract in modules/
scorm/ includes/ opigno_scorm.manifest.inc - Extract the SCORM package from the file.
File
- modules/
scorm/ opigno_scorm.module, line 153 - Opigno SCORM API.
Code
function opigno_scorm_sco_save($sco) {
// The attributes is not a field in the database, but
// a representation of a table relationship.
// Cache them here and unset the property for the
// DB query.
$attributes = $sco->attributes;
unset($sco->attributes);
if (!empty($sco->id)) {
$res = db_update('opigno_scorm_package_scos')
->fields((array) $sco)
->condition('id', $sco->id)
->execute();
}
else {
$id = db_insert('opigno_scorm_package_scos')
->fields((array) $sco)
->execute();
$sco->id = $id;
$res = !!$id;
}
if ($res && !empty($attributes)) {
// Remove all old attributes, to prevent duplicates.
db_delete('opigno_scorm_package_sco_attributes')
->condition('sco_id', $sco->id)
->execute();
foreach ($attributes as $key => $value) {
$serialized = 0;
if (is_array($value) || is_object($value)) {
$value = serialize($value);
$serialized = 1;
}
elseif (is_bool($value)) {
$value = (int) $value;
}
db_insert('opigno_scorm_package_sco_attributes')
->fields(array(
'sco_id' => $sco->id,
'attribute' => $key,
'value' => $value,
'serialized' => $serialized,
))
->execute();
}
}
return $res;
}