function course_save_objects in Course 7
Same name and namespace in other branches
- 8.3 course.module \course_save_objects()
- 8.2 course.module \course_save_objects()
- 6 course.module \course_save_objects()
- 7.2 course.module \course_save_objects()
- 3.x course.module \course_save_objects()
Saves course objects.
Parameters
CourseObject[] $objects: An array of course object definitions.
Course $course: (optional) An instantiated Course, from course_get_course().
1 call to course_save_objects()
- course_node_update in ./
course.module - Implements hook_node_update().
File
- ./
course.module, line 857 - course.module Core functionality for Courses.
Code
function course_save_objects(array $objects, Course $course = NULL) {
foreach ($objects as $object) {
// Check if this course object already exists in the database.
if (isset($object->coid)) {
// Check if this object does not belong to the current node.
if ($object->nid != $course
->getNode()->nid) {
// We are importing or cloning. Ensure the necessary keys are empty,
// in order to prepare a new object using this object's definitions.
$unset = array(
'coid',
'nid',
'uuid',
'uniqid',
);
foreach ($unset as $key) {
if (isset($object->{$key})) {
unset($object->{$key});
}
}
// Replace the nid key, to properly associate the current course node
// with this course object.
$object->nid = $course
->getNode()->nid;
}
}
$object
->save();
}
}