ProfileImages
final class ProfileImages extends Model
Supports CRUD operations on profile image records.
Constants
| BLACKLIST |
Constant for blacklist |
| WHITELIST |
Constant for whitelist |
Properties
| static protected DB | $_db | The instance of the DB class. |
from Model |
| int | $id | ID for this image. |
|
| protected string | $_modelName | The name of the model. |
from Model |
| static protected bool | $_softDelete | Soft delete mode set to true. |
|
| static protected string | $_table | Name of the table. |
|
| protected bool | $_validates | Flag to indicate if validation is successful. |
from Model |
| protected array | $_validationErrors | The array of validation errors. |
from Model |
| static protected array | $allowedFileTypes | The allowed file types. |
|
| int | $deleted | Deleted value, defaults to 0. |
|
| static protected int | $maxAllowedFileSize | Max allowed size. |
|
| string | $name | Name of the file. |
|
| int | $sort | Sorted position. |
|
| static protected string | $_uploadPath | Upload path. |
|
| string | $url | The URL for the profile image. |
|
| int | $user_id | ID of user associated with image. |
Methods
Generates error messages that occur during form validation.
Update the object with an associative array.
Implements beforeSave function described in Model parent class.
Gets an associative array of field values for insert or updating.
Wrapper for the find function that is found in the DB class.
Performs a database query against a specified table using the same query-building logic as the default find method.
Retrieves list of all records within a table related to a user.
Wrapper for the findFirst function that is found in the DB class.
Returns number of records in a table. A wrapper function for findTotal function in DB class.
Runs a validator object and sets validates boolean and adds error message if validator fails.
Wrapper for update and insert functions. A failed form validation will cause this function to return false.
Adds to the conditions to avoid getting soft deleted rows returned
Updates one or more rows in this model's underlying table using your framework's params-style conditions.
Function that is called on save. If validation fails the save function will not proceed. This function is just a signature and must be implemented by models that run form validation because since it is called from within this class.
Deletes a profile image by id.
Sets delete field in profile_images table to 1 when user is deleted from users table. Accepts parameter for toggling on or off unlink to permanently image file.
Returns currently set profile image for a user.
Finds all profile images for a user.
Getter function for $allowedFileTypes array
Getter function for $maxAllowedFileSize.
Updates sort order by user id.
Details
in
Model at line 68
__construct()
Default constructor.
in
Model at line 82
void
addErrorMessage(string $field, string $message)
Generates error messages that occur during form validation.
in
Model at line 95
void
afterDelete()
Called before delete.
in
Model at line 102
void
afterSave()
Called before save.
in
Model at line 114
Model
assign(array $params, array $list = [], string $assignmentFilter = self::BLACKLIST)
Update the object with an associative array.
in
Model at line 137
void
beforeDelete()
This runs before delete, needs to return a boolean
at line 86
void
beforeSave()
Implements beforeSave function described in Model parent class.
Generates timestamps.
in
Model at line 178
bool
delete()
Wrapper for database delete function. If not softDelete we set it.
If row is set to softDelete we call the database delete function.
in
Model at line 196
static array
getColumns()
Gets columns from table.
in
Model at line 206
array
getColumnsForSave()
Gets an associative array of field values for insert or updating.
in
Model at line 247
array
getErrorMessages()
Displays error messages when form validation fails.
in
Model at line 257
static protected array
_fetchStyleParams(array $params)
Used to set default fetchStyle param.
in
Model at line 271
static array|bool
find(array $params = [])
Wrapper for the find function that is found in the DB class.
in
Model at line 285
static object|bool
findById(int $id)
Get result from database by primary key ID.
in
Model at line 301
static array|bool
findByTable(string $table, array $params = [])
Performs a database query against a specified table using the same query-building logic as the default find method.
This method is useful when querying a different table than the one defined by the model's static::$_table property (e.g., joining or selecting from related tables).
in
Model at line 317
static array
findAllByUserId(int $user_id, array $params = [])
Retrieves list of all records within a table related to a user.
in
Model at line 335
static object|bool
findFirst(array $params = [])
Wrapper for the findFirst function that is found in the DB class.
in
Model at line 350
static int
findTotal(array $params = [])
Returns number of records in a table. A wrapper function for findTotal function in DB class.
in
Model at line 365
bool
insert(array $fields)
Wrapper for database insert function.
in
Model at line 377
bool
isNew()
Checks if an object is a new insertion or an existing record.
in
Model at line 386
void
onConstruct()
Runs when the object is constructed.
in
Model at line 394
protected void
populateObjData(array|object $result)
Populates object with data.
in
Model at line 420
void
runValidation(object $validator)
Runs a validator object and sets validates boolean and adds error message if validator fails.
in
Model at line 435
bool
save()
Wrapper for update and insert functions. A failed form validation will cause this function to return false.
in
Model at line 470
static protected array
_softDeleteParams(array $params)
Adds to the conditions to avoid getting soft deleted rows returned
in
Model at line 496
void
timeStamps()
Sets values for timestamp fields.
in
Model at line 512
bool
update(array $fields)
Wrapper for the update function found in the DB class.
in
Model at line 542
static int
updateWhere(array $fields, array $params)
Updates one or more rows in this model's underlying table using your framework's params-style conditions.
This method delegates to the DB::updateWhere() method and allows
you to pass both the fields to update and a parameterized WHERE
clause (using conditions and bind arrays just like find/findFirst).
Example:
Queue::updateWhere(
['reserved_at' => date('Y-m-d H:i:s')],
['conditions' => 'id = ?', 'bind' => [$jobId]]
);
in
Model at line 552
bool
validationPassed()
Getter function for the $_validates boolean instance variable.
in
Model at line 563
void
validator()
Function that is called on save. If validation fails the save function will not proceed. This function is just a signature and must be implemented by models that run form validation because since it is called from within this class.
at line 97
static bool
deleteById(int $id)
Deletes a profile image by id.
at line 121
static void
deleteImages(int $user_id, bool $unlink = false)
Sets delete field in profile_images table to 1 when user is deleted from users table. Accepts parameter for toggling on or off unlink to permanently image file.
at line 145
static ProfileImages|bool
findCurrentProfileImage(int $user_id)
Returns currently set profile image for a user.
at line 160
static bool|array
findByUserId(int $user_id)
Finds all profile images for a user.
at line 173
static array
getAllowedFileTypes()
Getter function for $allowedFileTypes array
at line 183
static int
getMaxAllowedFileSize()
Getter function for $maxAllowedFileSize.
at line 196
static void
updateSortByUserId(int $user_id, array $sortOrder = [])
Updates sort order by user id.
at line 217
static void
uploadProfileImage(int $user_id, Uploads $uploads)
Performs upload operation for a profile image.