tab_groups
in package
Class tab_groups Represents a group of tab objects in a tabbed interface.
This class provides methods for interacting with the groups
table in the database.
Table of Contents
Properties
- $allowedcols : array<string|int, mixed>
- $db : db_master
Methods
- __construct() : void
- Class constructor.
- __destruct() : mixed
- Destructor method for the class.
- all() : array<string|int, mixed>|bool
- Retrieve all records from the `groups` table sorted by the specified column.
- delete() : bool
- Delete records from the "groups" table based on the specified column and value.
- get() : array<string|int, mixed>|bool
- Retrieve a record from the `groups` table based on the specified value and column.
- insert() : bool
- Insert a new record into the `groups` table.
- update() : bool
- Update a record in the "groups" table based on the specified column and value.
Properties
$allowedcols
protected
array<string|int, mixed>
$allowedcols
= ['id', 'name', 'icon', 'sort']
An array of allowed column names
$db
protected
db_master
$db
The database connection object
Methods
__construct()
Class constructor.
public
__construct() : void
Initializes the object by assigning the global database object to the local property.
__destruct()
Destructor method for the class.
public
__destruct() : mixed
Unsets the 'db' property, effectively freeing up the memory used by the database connection.
Note that this method does not return any value.
all()
Retrieve all records from the `groups` table sorted by the specified column.
public
all([string $col = 'sort' ]) : array<string|int, mixed>|bool
If the specified column is not one of the allowed columns, it will default to sorting by the 'sort' column.
Parameters
- $col : string = 'sort'
-
The column to sort the results by. Default is 'sort'.
Return values
array<string|int, mixed>|bool —An array of records sorted by the specified column if there are any records, false otherwise.
delete()
Delete records from the "groups" table based on the specified column and value.
public
delete(string $val[, string $col = 'id' ]) : bool
Parameters
- $val : string
-
The value to search for in the specified column. It will be escaped to prevent SQL injection.
- $col : string = 'id'
-
The column to search in. The default value is "id". If the specified column is not allowed, it will default to "id".
Return values
bool —Returns true if the deletion was successful, false otherwise.
get()
Retrieve a record from the `groups` table based on the specified value and column.
public
get(string $val[, string $col = 'id' ]) : array<string|int, mixed>|bool
If the specified column is not one of the allowed columns, it will default to searching by the 'id' column.
Parameters
- $val : string
-
The value to search for in the specified column.
- $col : string = 'id'
-
The column to search in. Default is 'id'.
Return values
array<string|int, mixed>|bool —An array representing the matching record if found, false otherwise.
insert()
Insert a new record into the `groups` table.
public
insert(string $name, string $icon, string $sort) : bool
Parameters
- $name : string
-
The name of the group.
- $icon : string
-
The icon associated with the group.
- $sort : string
-
The sorting order of the group.
Return values
bool —Returns true if the record was inserted successfully, false otherwise.
update()
Update a record in the "groups" table based on the specified column and value.
public
update(string $col, string $val, string $id) : bool
Parameters
- $col : string
-
The column to update. If the specified column is not allowed, it will default to "name".
- $val : string
-
The new value for the specified column. It will be escaped to prevent SQL injection.
- $id : string
-
The ID of the record to update.
Return values
bool —Returns true if the update was successful, false otherwise.