LoanService
in package
Class LoanService
Provides services for managing loans.
Table of Contents
Properties
- $bookRepository : BookRepository
- $howManyLoansDoesThisUserHave : int
- $loanRepository : LoanRepository
- $userRepository : UserRepository
Methods
- __construct() : mixed
- Constructor for the LoanService class.
- create() : bool
- Creates a new loan.
- delete() : bool
- Deletes a loan by its ID.
- getAllLoans() : array<string|int, mixed>
- Retrieves all loans.
- getLoanById() : Loan
- Retrieves a loan by its ID.
- update() : bool
- Updates an existing loan.
- assemblerArrayBookEntities() : array<string|int, mixed>
- Assembles an array of Book entities from provided book IDs.
- assemblerLoanEntitie() : Loan
- Assembles a Loan entity from provided data, user, and books.
- userTypeChecker() : mixed
- Checks the user's role type and loan amount.
Properties
$bookRepository
private
BookRepository
$bookRepository
$howManyLoansDoesThisUserHave
private
int
$howManyLoansDoesThisUserHave
$loanRepository
private
LoanRepository
$loanRepository
$userRepository
private
UserRepository
$userRepository
Methods
__construct()
Constructor for the LoanService class.
public
__construct(LoanRepository $loanRepository) : mixed
Initializes the loan repository, user repository, and book repository.
Parameters
- $loanRepository : LoanRepository
-
The repository for managing loans.
create()
Creates a new loan.
public
create(object $data) : bool
Parameters
- $data : object
-
The data for creating the loan.
Tags
Return values
bool —Returns true if the loan was successfully created, false otherwise.
delete()
Deletes a loan by its ID.
public
delete(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> —Returns an array of all loans.
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.
update()
Updates an existing loan.
public
update(int $idLoan, object $data) : bool
Parameters
- $idLoan : int
-
The ID of the loan to be updated.
- $data : object
-
The data for updating the loan.
Tags
Return values
bool —Returns true if the loan was successfully updated, false otherwise.
assemblerArrayBookEntities()
Assembles an array of Book entities from provided book IDs.
private
assemblerArrayBookEntities(array<string|int, mixed> $idBooks) : array<string|int, mixed>
Parameters
- $idBooks : array<string|int, mixed>
-
The IDs of the books.
Tags
Return values
array<string|int, mixed> —The assembled array of Book entities.
assemblerLoanEntitie()
Assembles a Loan entity from provided data, user, and books.
private
assemblerLoanEntitie(object $data, User $user, array<string|int, mixed> $books) : Loan
Parameters
- $data : object
-
The data for the loan.
- $user : User
-
The user associated with the loan.
- $books : array<string|int, mixed>
-
The books associated with the loan.
Return values
Loan —The assembled Loan entity.
userTypeChecker()
Checks the user's role type and loan amount.
private
userTypeChecker(string $roleName, int $userLoanAmount) : mixed
Parameters
- $roleName : string
-
The name of the user's role.
- $userLoanAmount : int
-
The loan amount of the user.