LoanRepositoryImpl
in package
implements
LoanRepository
Class LoanRepositoryImpl
Implements the LoanRepository interface using a PDO connection.
Table of Contents
Interfaces
- LoanRepository
- Interface LoanRepository
Properties
- $bookRepository : BookRepository
- $connection : PDO
- $table : string
- $tableAssoc : string
- $userRepository : UserRepository
Methods
- __construct() : mixed
- Constructor for the LoanRepositoryImpl class.
- createLoan() : bool
- Creates a new loan.
- deleteLoan() : bool
- Deletes a loan by its ID.
- getAllLoans() : array<string|int, mixed>
- Retrieves all loans.
- getLoanById() : Loan
- Retrieves a loan by its ID.
- howManyCopiesOfABookAreOnLoan() : int
- Gets the number of copies of a book that are currently on loan.
- howManyLoansDoesAUserHave() : int
- Gets the number of loans a user currently has.
- toPickUpBooksFromALoan() : array<string|int, mixed>
- Retrieves the books associated with a loan.
- updateLoan() : bool
- Updates an existing loan.
- assemblerLoanWithBooks() : array<string|int, mixed>
- Assembles a loan with the associated books.
- assemblerLoanWithUser() : mixed
- Assembles a loan with the user entity.
- assemblerLoanWithUserAndBooks() : Loan
- Assembles a loan with the user and associated books.
- loanAndBookAssociationCreator() : mixed
- Creates associations between a loan and books.
- loanAndBookAssociationDestroyer() : mixed
- Creates associations between a loan and books.
Properties
$bookRepository
private
BookRepository
$bookRepository
$connection
private
PDO
$connection
$table
private
string
$table
= "loan"
$tableAssoc
private
string
$tableAssoc
= "loan_books"
$userRepository
private
UserRepository
$userRepository
Methods
__construct()
Constructor for the LoanRepositoryImpl class.
public
__construct() : mixed
Initializes the database connection and repositories.
createLoan()
Creates a new loan.
public
createLoan(Loan $loan) : bool
Parameters
- $loan : Loan
-
The loan to be created.
Return values
bool —Returns true if the loan was successfully created, false otherwise.
deleteLoan()
Deletes a loan by its ID.
public
deleteLoan(int $idLoan) : bool
Parameters
- $idLoan : int
-
The ID of the loan to delete.
Return values
bool —Returns true if the loan was successfully deleted, false otherwise.
getAllLoans()
Retrieves all loans.
public
getAllLoans() : array<string|int, mixed>
Return values
array<string|int, mixed>getLoanById()
Retrieves a loan by its ID.
public
getLoanById(int $idLoan) : Loan
Parameters
- $idLoan : int
-
The ID of the loan to retrieve.
Return values
Loan —Returns the loan if found.
howManyCopiesOfABookAreOnLoan()
Gets the number of copies of a book that are currently on loan.
public
howManyCopiesOfABookAreOnLoan(int $idBook) : int
Parameters
- $idBook : int
-
The ID of the book.
Return values
int —Returns the number of copies of the book that are on loan.
howManyLoansDoesAUserHave()
Gets the number of loans a user currently has.
public
howManyLoansDoesAUserHave(int $idUser) : int
Parameters
- $idUser : int
-
The ID of the user.
Return values
int —Returns the number of loans the user has.
toPickUpBooksFromALoan()
Retrieves the books associated with a loan.
public
toPickUpBooksFromALoan(int $idLoan) : array<string|int, mixed>
Parameters
- $idLoan : int
-
The ID of the loan.
Return values
array<string|int, mixed> —Returns an array of books associated with the loan.
updateLoan()
Updates an existing loan.
public
updateLoan(Loan $loan) : bool
Parameters
- $loan : Loan
-
The loan to be updated.
Return values
bool —Returns true if the loan was successfully updated, false otherwise.
assemblerLoanWithBooks()
Assembles a loan with the associated books.
private
assemblerLoanWithBooks(array<string|int, mixed> $resulLoanAssocBook) : array<string|int, mixed>
Parameters
- $resulLoanAssocBook : array<string|int, mixed>
-
The result set of loan and book associations.
Return values
array<string|int, mixed> —The books associated with the loan.
assemblerLoanWithUser()
Assembles a loan with the user entity.
private
assemblerLoanWithUser(int $idUser) : mixed
Parameters
- $idUser : int
-
The ID of the user.
Return values
mixed —The user entity.
assemblerLoanWithUserAndBooks()
Assembles a loan with the user and associated books.
private
assemblerLoanWithUserAndBooks(object $loan) : Loan
Parameters
- $loan : object
-
The loan object.
Return values
Loan —The assembled loan entity.
loanAndBookAssociationCreator()
Creates associations between a loan and books.
private
loanAndBookAssociationCreator(int $idLoan, array<string|int, mixed> $books) : mixed
Parameters
- $idLoan : int
-
The ID of the loan.
- $books : array<string|int, mixed>
-
The books to associate with the loan.
loanAndBookAssociationDestroyer()
Creates associations between a loan and books.
private
loanAndBookAssociationDestroyer(int $idLoan) : mixed
Parameters
- $idLoan : int
-
The ID of the loan.