You are here

function Course::getEnrollment in Course 3.x

Same name and namespace in other branches
  1. 8.3 src/Entity/Course.php \Drupal\course\Entity\Course::getEnrollment()
  2. 8.2 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

2 calls to Course::getEnrollment()
Course::enroll in src/Entity/Course.php
Enroll a user in this course.
Course::isEnrolled in src/Entity/Course.php
Check if a user is enrolled.

File

src/Entity/Course.php, line 509

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);
  }
}