You are here

function Course::getEnrollment in Course 8.2

Same name and namespace in other branches
  1. 8.3 src/Entity/Course.php \Drupal\course\Entity\Course::getEnrollment()
  2. 3.x src/Entity/Course.php \Drupal\course\Entity\Course::getEnrollment()

Load an enrollment.

@todo maybe move to CourseStorage

Parameters

AccountInterface $account:

Return value

\Drupal\course\Entity\CourseEnrollment

1 call to Course::getEnrollment()
Course::enroll in src/Entity/Course.php
Enroll a user in this course.

File

src/Entity/Course.php, line 452

Class

Course
Defines the Course entity class.

Namespace

Drupal\course\Entity

Code

function getEnrollment(AccountInterface $account) {
  $entities = Drupal::entityTypeManager()
    ->getStorage('course_enrollment')
    ->loadByProperties([
    'cid' => $this
      ->id(),
    'uid' => $account
      ->id(),
  ]);
  if ($entities) {
    return reset($entities);
  }
}