You are here

public function Registration::setRegistrantQty in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 3.x src/Entity/Registration.php \Drupal\rng\Entity\Registration::setRegistrantQty()

@inheritDoc

Overrides RegistrationInterface::setRegistrantQty

File

src/Entity/Registration.php, line 486

Class

Registration
Defines the registration entity class.

Namespace

Drupal\rng\Entity

Code

public function setRegistrantQty($qty) {
  $registrants = $this
    ->getRegistrantIds();
  if ($qty > 0) {
    if (count($registrants) > $qty) {
      throw new MaxRegistrantsExceededException('Cannot set registrant qty below number of current registrants.');
    }
    $event_meta = $this
      ->getEventMeta();
    $max = $event_meta
      ->getRegistrantsMaximum();
    if (!empty($max) && $max > -1 && $qty > $max) {
      throw new MaxRegistrantsExceededException('Cannot set registrations above event maximum');
    }
  }
  $this
    ->set('registrant_qty', $qty);
  return $this;
}