Loading src/Entity/CodeCollection.php +5 −5 Original line number Diff line number Diff line Loading @@ -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()); } /** Loading @@ -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()); } Loading @@ -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()); } /** Loading @@ -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()); } /** Loading @@ -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()); } /** Loading src/Plugin/codes_pool/CodesStorage/CodesStorageInterface.php +6 −2 Original line number Diff line number Diff line Loading @@ -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. Loading src/Plugin/codes_pool/CodesStorage/Database.php +14 −4 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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(); } Loading @@ -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) Loading @@ -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) Loading src/Plugin/codes_pool/CodesStorage/Remote.php +4 −4 Original line number Diff line number Diff line Loading @@ -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. } /** Loading src/Plugin/codes_pool/CollectionSource/Api.php +7 −7 Original line number Diff line number Diff line Loading @@ -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 Loading
src/Entity/CodeCollection.php +5 −5 Original line number Diff line number Diff line Loading @@ -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()); } /** Loading @@ -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()); } Loading @@ -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()); } /** Loading @@ -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()); } /** Loading @@ -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()); } /** Loading
src/Plugin/codes_pool/CodesStorage/CodesStorageInterface.php +6 −2 Original line number Diff line number Diff line Loading @@ -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. Loading
src/Plugin/codes_pool/CodesStorage/Database.php +14 −4 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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(); } Loading @@ -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) Loading @@ -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) Loading
src/Plugin/codes_pool/CodesStorage/Remote.php +4 −4 Original line number Diff line number Diff line Loading @@ -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. } /** Loading
src/Plugin/codes_pool/CollectionSource/Api.php +7 −7 Original line number Diff line number Diff line Loading @@ -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