public function Course::setActive in Course 8.2
Same name and namespace in other branches
- 8.3 src/Entity/Course.php \Drupal\course\Entity\Course::setActive()
- 3.x src/Entity/Course.php \Drupal\course\Entity\Course::setActive()
Set the active CourseObject in this Course.
Parameters
int $id: A numeric course object ID.
4 calls to Course::setActive()
- Course::getActive in src/
Entity/ Course.php - Get the active CourseObject.
- Course::getNavigation in src/
Entity/ Course.php - Generate navigation links.
- Course::getNext in src/
Entity/ Course.php - Get the next course object, from the active course object.
- Course::getPrev in src/
Entity/ Course.php - Get the previous course object, from the active course object.
File
- src/
Entity/ Course.php, line 107
Class
- Course
- Defines the Course entity class.
Namespace
Drupal\course\EntityCode
public function setActive($id = NULL) {
if (!$id && isset($_SESSION['course'][$this
->id()]['taking']['active'])) {
$id = $_SESSION['course'][$this
->id()]['taking']['active'];
}
$old = NULL;
$storeNext = FALSE;
foreach ($this
->getObjects() as $courseObject) {
if (!$courseObject
->getOption('enabled')) {
// Skip disabled objects.
continue;
}
if ($id == $courseObject
->id()) {
// Active - save old, store next.
if ($old) {
$this->prev = $old;
}
$storeNext = TRUE;
$this->active = $courseObject;
}
elseif ($storeNext) {
$this->next = clone $courseObject;
$storeNext = FALSE;
}
$old = clone $courseObject;
}
}