Unverified Commit 237d0bb2 authored by Shabana Navas's avatar Shabana Navas Committed by Vijay Mani
Browse files

Issue #3226669 by shabana.navas, vijaycs85: Entity ID is omitted when...

Issue #3226669 by shabana.navas, vijaycs85: Entity ID is omitted when dispensing code and looking up code count
parent 22829328
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -206,7 +206,7 @@ class CodeCollection extends ContentEntityBase implements CodeCollectionInterfac
   * @throws \Drupal\Core\TypedData\Exception\MissingDataException
   */
  public function getCodesCount() {
    return $this->getSourcePlugin()->getCount();
    return $this->getSourcePlugin()->getCount($this->id());
  }

  /**
@@ -218,7 +218,7 @@ class CodeCollection extends ContentEntityBase implements CodeCollectionInterfac
   * @throws \Drupal\Core\TypedData\Exception\MissingDataException
   */
  public function getCountCodeAvailable() {
    return $this->getSourcePlugin()->getCountCodeAvailable();
    return $this->getSourcePlugin()->getCountCodeAvailable($this->id());

  }

@@ -231,7 +231,7 @@ class CodeCollection extends ContentEntityBase implements CodeCollectionInterfac
   * @throws \Drupal\Core\TypedData\Exception\MissingDataException
   */
  public function hasCodeAvailable() {
    return $this->getSourcePlugin()->hasCodeAvailable();
    return $this->getSourcePlugin()->hasCodeAvailable($this->id());
  }

  /**
@@ -246,7 +246,7 @@ class CodeCollection extends ContentEntityBase implements CodeCollectionInterfac
   * @throws \Drupal\Core\TypedData\Exception\MissingDataException
   */
  public function dispenseCode(array $params = []) {
    return $this->getSourcePlugin()->dispenseCode($params);
    return $this->getSourcePlugin()->dispenseCode($params, $this->id());
  }

  /**
@@ -261,7 +261,7 @@ class CodeCollection extends ContentEntityBase implements CodeCollectionInterfac
   * @throws \Drupal\Core\TypedData\Exception\MissingDataException
   */
  public function dispenseCodes(array $params = []) {
    return $this->getSourcePlugin()->dispenseCodes($params);
    return $this->getSourcePlugin()->dispenseCodes($params, $this->id());
  }

  /**
+6 −2
Original line number Diff line number Diff line
@@ -25,22 +25,26 @@ interface CodesStorageInterface {
   *
   * @param array $params
   *   Optional information for the dispenseCode implementation.
   * @param int|null $entity_id
   *   An entity ID to get the count for, if one exists.
   *
   * @return string
   *   The code.
   */
  public function dispenseCode(array $params = []): string;
  public function dispenseCode(array $params = [], ?int $entity_id = NULL): string;

  /**
   * Dispense codes.
   *
   * @param array $params
   *   Optional information for the dispenseCodes implementation.
   * @param int|null $entity_id
   *   An entity ID to get the count for, if one exists.
   *
   * @return array
   *   The array of codes.
   */
  public function dispenseCodes(array $params = []) : array;
  public function dispenseCodes(array $params = [], ?int $entity_id = NULL) : array;

  /**
   * Deletes the non-dispensed codes.
+14 −4
Original line number Diff line number Diff line
@@ -83,12 +83,16 @@ class Database implements CodesStorageInterface {
  /**
   * Count of total row.
   *
   * @param int $entity_id
   *   The code collection entity ID.
   *
   * @return int
   *   The total count.
   */
  public function count() {
  public function count(int $entity_id) {
    return $this->getConnection()
      ->select($this->tableName, 'c')
      ->condition('c.entity_id', $entity_id)
      ->countQuery()
      ->execute()
      ->fetchField();
@@ -97,12 +101,16 @@ class Database implements CodesStorageInterface {
  /**
   * Count of available code.
   *
   * @param int $entity_id
   *   The code collection entity ID.
   *
   * @return int
   *   The count.
   */
  public function countAvailable() {
  public function countAvailable(int $entity_id) {
    $query = $this->getConnection()
      ->select($this->tableName, 'c')
      ->condition('c.entity_id', $entity_id)
      ->condition('c.status', 0);
    return $query->countQuery()->execute()->fetchField();
  }
@@ -117,9 +125,10 @@ class Database implements CodesStorageInterface {
  /**
   * {@inheritdoc}
   */
  public function dispenseCode(array $params = []): string {
  public function dispenseCode(array $params = [], ?int $entity_id = NULL): string {
    $result = $this->getConnection()->select($this->tableName, 'c')
      ->fields('c', ['id', 'code'])
      ->condition('c.entity_id', $entity_id)
      ->condition('c.status', 0)
      ->orderBy('c.id')
      ->forUpdate(TRUE)
@@ -136,9 +145,10 @@ class Database implements CodesStorageInterface {
  /**
   * {@inheritdoc}
   */
  public function dispenseCodes(array $params = []): array {
  public function dispenseCodes(array $params = [], ?int $entity_id = NULL): array {
    $results = $this->getConnection()->select($this->tableName, 'c')
      ->fields('c', ['id', 'code'])
      ->condition('c.entity_id', $entity_id)
      ->condition('c.status', 0)
      ->orderBy('c.id')
      ->forUpdate(TRUE)
+4 −4
Original line number Diff line number Diff line
@@ -15,15 +15,15 @@ class Remote extends CodesStorageBase {
  /**
   * {@inheritdoc}
   */
  public function dispenseCode(array $params = []): string {
    // @todo: Implement API call to get code.
  public function dispenseCode(array $params = [], ?int $entity_id = NULL): string {
    // @todo Implement API call to get code.
  }

  /**
   * {@inheritdoc}
   */
  public function dispenseCodes(array $params = []): array {
    // @todo: Implement API call to get code.
  public function dispenseCodes(array $params = [], ?int $entity_id = NULL): array {
    // @todo Implement API call to get code.
  }

  /**
+7 −7
Original line number Diff line number Diff line
@@ -82,37 +82,37 @@ class Api extends CollectionSourceBase {
  /**
   * {@inheritdoc}
   */
  public function getCount(): int {
    // @todo: Implement getCount() method.
  public function getCount(?int $entity_id = NULL): int {
    // @todo Implement getCount() method.
    return CodesStorageInterface::CODE_COUNT_UNLIMITED;
  }

  /**
   * {@inheritdoc}
   */
  public function getCountCodeAvailable(): int {
  public function getCountCodeAvailable(?int $entity_id = NULL): int {
    return CodesStorageInterface::CODE_COUNT_UNLIMITED;
  }

  /**
   * {@inheritdoc}
   */
  public function hasCodeAvailable(): bool {
    // @todo: make sure API is alive.
  public function hasCodeAvailable(?int $entity_id = NULL): bool {
    // @todo make sure API is alive.
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function dispenseCode(array $params = []): string {
  public function dispenseCode(array $params = [], ?int $entity_id = NULL): string {
    // @todo call API to get a code.
  }

  /**
   * {@inheritdoc}
   */
  public function dispenseCodes(array $params = []): array {
  public function dispenseCodes(array $params = [], ?int $entity_id = NULL): array {
    // @todo call API to get a code.
  }

Loading