You are here

public function CourseObject::getFulfillment in Course 8.2

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

Get a user's fulfillment for this course object. If the user has not started this course object, a new, unsaved fulfillment will be return.

Parameters

stdClass $account: User account to get fulfillment for.

Return value

CourseObjectFulfillment

File

src/Entity/CourseObject.php, line 620

Class

CourseObject
Parent abstract base class of all course objects.

Namespace

Drupal\course\Entity

Code

public function getFulfillment(AccountInterface $account) {
  $entities = \Drupal::entityTypeManager()
    ->getStorage('course_object_fulfillment')
    ->loadByProperties([
    'coid' => $this
      ->id(),
    'uid' => $account
      ->id(),
  ]);
  if ($entities) {
    return reset($entities);
  }
  else {
    return CourseObjectFulfillment::create(array(
      'coid' => $this
        ->id(),
      'uid' => $account
        ->id(),
      'object_type' => $this
        ->get('object_type')
        ->getString(),
    ));
  }
}