Skip to content

Commit

Permalink
check count of rented biked for qr system
Browse files Browse the repository at this point in the history
  • Loading branch information
sveneld committed Jun 2, 2024
1 parent ac7d3fc commit c83a7a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Rent/AbstractRentSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
abstract class AbstractRentSystem implements RentSystemInterface
{
private const ERROR = 1;
protected const ERROR = 1;
/**
* @var DbInterface
*/
Expand Down
10 changes: 6 additions & 4 deletions src/Rent/RentSystemQR.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@ public function returnBike($userId, $bikeId, $standName, $note = '', $force = fa

if ($bikeId !== 0) {
$this->logger->error("Bike number could not be provided via QR code", ["userId" => $userId]);
return $this->response(_('Invalid bike number'), ERROR);
return $this->response(_('Invalid bike number'), self::ERROR);
}

$result = $this->db->query("SELECT bikeNum FROM bikes WHERE currentUser=$userId ORDER BY bikeNum");
$bikeNumber = $result->rowCount();
$bikeId = $result->fetchAssoc()['bikeNum'];

if ($bikeNumber > 1) {
if ($bikeNumber === 0) {
return $this->response(_('You currently have no rented bikes.'), self::ERROR);
} elseif ($bikeNumber > 1) {
$message = _('You have') . ' ' . $bikeNumber . ' '
. _('rented bikes currently. QR code return can be used only when 1 bike is rented. Please, use web');
if ($this->connectorsConfig["sms"]) {
$message .= _(' or SMS');
}
$message .= _(' to return the bikes.');

return $this->response($message, ERROR);
return $this->response($message, self::ERROR);
}
$bikeId = $result->fetchAssoc()['bikeNum'];

return parent::returnBike($userId, $bikeId, $standName, $note, $force);
}
Expand Down

0 comments on commit c83a7a1

Please sign in to comment.