Represents a pet with with methods to interact with the database.
More...
Represents a pet with with methods to interact with the database.
Definition at line 9 of file pet.php.
◆ create()
Create a new pet record in the database based on the form data.
If a cover image is uploaded, it will be used as the filename for the pet's cover. Otherwise, the default cover image will be used.
- Returns
- int The ID of the newly inserted pet record
Definition at line 148 of file pet.php.
◆ delete()
| static Pet::delete |
( |
|
$petId | ) |
|
|
static |
Deletes a pet from the database based on the provided pet ID.
- Parameters
-
| int | $petId | The ID of the pet to be deleted. |
- Returns
- void
Definition at line 194 of file pet.php.
◆ getAllPets()
| static Pet::getAllPets |
( |
| ) |
|
|
static |
Retrieves all pets from the database.
- Returns
- array $pets An array containing all the pets retrieved from the database.
Definition at line 16 of file pet.php.
◆ getPet()
| static Pet::getPet |
( |
|
$petId | ) |
|
|
static |
Retrieves a pet from the database based on the provided pet ID.
- Parameters
-
| int | $petId | The ID of the pet to retrieve. |
- Returns
- array $pet Pet information if found, or null if not found.
Definition at line 35 of file pet.php.
◆ getStory()
| static Pet::getStory |
( |
|
$petId | ) |
|
|
static |
Retrieves the story of a pet based on the provided pet ID.
- Parameters
-
| int | $petId | The ID of the pet whose story is to be retrieved. |
- Returns
- array $pet The story of the pet identified by the given ID.
Definition at line 54 of file pet.php.
◆ update()
| static Pet::update |
( |
|
$petId | ) |
|
|
static |
Update the pet information in the database based on the provided pet ID.
- Parameters
-
| int | $petId | The ID of the pet to update. |
- Exceptions
-
PDOException If there is an error with the database operation.
Definition at line 173 of file pet.php.
◆ validate()
Validates the input data for name, species, age, and cover image. Returns an error message if any validation fails.
- Returns
- string $output Error message if validation fails, empty string if validation passes.
Validates the length of the input name from the $_POST array. If the length is less than 4 or greater than 128 characters, an error message is appended to the output.
Validates the length of the species input from the $_POST array. If the length is less than 2 or greater than 48 characters, an error message is appended to the $output variable.
Validates if the input age value is numeric.
Handles the upload of a cover image file.
This function checks if a cover image file is uploaded, validates its format and size, and moves the file to the "images" directory if it meets the criteria.
- Returns
- string Returns an error message if the file is invalid or not uploaded.
Definition at line 73 of file pet.php.
The documentation for this class was generated from the following file: