ShopCategories
in package
Tags
Table of Contents
Properties
- $arrCategory : array<string|int, mixed>
- ShopCategory Tree array
- $arrTrail : array<string|int, mixed>
- The trail from the root (0, zero) to the selected ShopCategory.
Methods
- buildTrailArray() : mixed
- Build the ShopCategories ID trail array.
- buildTreeArray() : bool
- Builds the $arrCategory array as returned by {@link ShopCategories::getTreeArray()}, representing a tree of ShopCategories, not including the root chosen.
- buildTreeArrayRecursive() : bool
- Recursively builds the $arrCategory array as returned by {@link ShopCategories::getTreeArray()}.
- deleteAll() : bool
- Delete all ShopCategories from the database.
- deleteById() : bool
- Deletes the Category with the given ID
- getArrayById() : array<string|int, mixed>
- Returns the array of ShopCategory data for the given ID.
- getAssignedShopCategoriesMenuoptions() : string
- Returns the HTML code for options of two separate menus of available and assigned ShopCategories.
- getByWildcard() : array<string|int, mixed>
- Select an array of ShopCategories matching the wildcards from the database.
- getChildCategoriesById() : array<string|int, mixed>
- Returns an array of children of the ShopCategories with ID $parent_id.
- getChildCategoryIdArray() : array<string|int, mixed>
- Returns an array of IDs of children of this ShopCategory.
- getChildNamed() : mixed
- Returns the ShopCategory with the given parent ID and the given name, if found.
- getMenu() : string
- Returns the HTML code for a dropdown menu listing all ShopCategories.
- getMenuoptions() : string
- Returns the HTML code for a dropdown menu listing all ShopCategories.
- getNameArray() : array<string|int, mixed>
- Returns an array of Category names indexed by their respective IDs
- getNextShopCategoriesId() : int
- Get the next ShopCategories ID after $shopCategoryId according to the sorting order.
- getParentCategoryId() : mixed
- Returns the parent category ID of the ShopCategory specified by its ID,
- getPictureById() : string
- Returns the best match for the Category Image
- getSearchCategoryIdString() : string
- Returns a string listing all ShopCategory IDs contained within the subtree starting with the ShopCategory with ID $parent_id.
- getTrailArray() : mixed
- Returns the ShopCategories ID trail array.
- getTreeArray() : array<string|int, mixed>
- Returns an array representing a tree of ShopCategories, not including the root chosen.
- getTreeNodeCount() : mixed
- Returns the number of elements in the ShopCategory array of this object.
- getVirtualCategoriesSelectionForFlags() : string
- Returns a string with HTML code to display the virtual ShopCategory selection checkboxes.
- getVirtualCategoryIdNameArray() : array<string|int, mixed>
- Returns an array with the IDs and names of all ShopCategories marked as virtual.
- getVirtualCategoryNameArray() : array<string|int, mixed>
- Returns an array with the names of all ShopCategories marked as virtual.
- invalidateTreeArray() : mixed
- Invalidate the current state of the arrShopCategory array and its index.
- makeThumbnailById() : string
- Create thumbnail and update the corresponding ShopCategory records
- toggleStatusById() : bool
- Toggles the Category status for the given ID
Properties
$arrCategory
ShopCategory Tree array
private
static array<string|int, mixed>
$arrCategory
= null
Tags
$arrTrail
The trail from the root (0, zero) to the selected ShopCategory.
private
static array<string|int, mixed>
$arrTrail
= null
Methods
buildTrailArray()
Build the ShopCategories ID trail array.
public
static buildTrailArray(int $shopCategoryId) : mixed
Sets up an array of ShopCategories IDs of the $shopCategoryId, and all its ancestors.
Parameters
- $shopCategoryId : int
-
The ShopCategories ID
Tags
Return values
mixed —The array of all ancestor ShopCategories on success, false otherwise.
buildTreeArray()
Builds the $arrCategory array as returned by {@link ShopCategories::getTreeArray()}, representing a tree of ShopCategories, not including the root chosen.
public
static buildTreeArray([bool $flagFull = false ][, bool $active = true ][, bool $flagVirtual = true ][, int $selected_id = 0 ][, int $parent_id = 0 ][, int $maxlevel = 0 ]) : bool
The resulting array looks like: array( 'id => ShopCategory ID 'name' => Category name, 'shortDescription' => Category short description, 'description' => Category description, 'parent_id' => parent ID 'ord' => order value, 'active' => active flag (boolean), 'picture' => 'picture name', 'flags' => 'Category flags' (string), 'virtual' => virtual flag status (boolean), 'level' => nesting level, ), ... more parents Note that this includes the virtual ShopCategories and their children.
Parameters
- $flagFull : bool = false
-
If true, the full tree is built, only the parts visible for $selected_id otherwise. Defaults to false.
- $active : bool = true
-
Only return ShopCategories with active == true if true. Defaults to true.
- $flagVirtual : bool = true
-
If true, also returns the virtual content of ShopCategories marked as virtual. Defaults to false.
- $selected_id : int = 0
-
The optional selected ShopCategory ID. If set and greater than zero, only the ShopCategories needed to display the Shop page are returned.
- $parent_id : int = 0
-
The optional root ShopCategories ID. Defaults to 0 (zero).
- $maxlevel : int = 0
-
The optional maximum nesting level. 0 (zero) means all. Defaults to 0 (zero).
Tags
Return values
bool —True on success, false otherwise.
buildTreeArrayRecursive()
Recursively builds the $arrCategory array as returned by {@link ShopCategories::getTreeArray()}.
public
static buildTreeArrayRecursive([bool $flagFull = false ][, bool $active = true ][, bool $flagVirtual = true ][, int $selected_id = 0 ][, int $parent_id = 0 ][, int $maxlevel = 0 ][, int $level = 0 ]) : bool
Parameters
- $flagFull : bool = false
-
If true, the full tree is built, only the parts visible for $selected_id otherwise. Defaults to false.
- $active : bool = true
-
Only return ShopCategories with active == true if true. Defaults to true.
- $flagVirtual : bool = true
-
If true, also returns the virtual content of ShopCategories marked as virtual. Defaults to false.
- $selected_id : int = 0
-
The optional selected ShopCategory ID. If set and greater than zero, only the ShopCategories needed to display the Shop page are returned.
- $parent_id : int = 0
-
The optional root ShopCategories ID. Defaults to 0 (zero).
- $maxlevel : int = 0
-
The optional maximum nesting level. 0 (zero) means all. Defaults to 0 (zero).
- $level : int = 0
-
The optional nesting level, initially 0. Defaults to 0 (zero).
Tags
Return values
bool —True on success, false otherwise.
deleteAll()
Delete all ShopCategories from the database.
public
static deleteAll([bool $flagDeleteImages = false ]) : bool
Also removes associated subcategories and Products. Images will only be erased from the disc if the optional $flagDeleteImages parameter evaluates to true.
Parameters
- $flagDeleteImages : bool = false
-
Delete associated image files if true. Defaults to false
Tags
Return values
bool —True on success, false otherwise
deleteById()
Deletes the Category with the given ID
public
static deleteById(int $id[, mixed $flagDeleteImages = false ]) : bool
Does not delete subcategories nor pictures. Use delete() for that. If the Category doesn't exist to begin with, returns null.
Parameters
- $id : int
-
The ShopCategory ID
- $flagDeleteImages : mixed = false
Return values
bool —True on success, false on failure, or null otherwise
getArrayById()
Returns the array of ShopCategory data for the given ID.
public
static getArrayById(int $id) : array<string|int, mixed>
If the ShopCategory array is not initialized, or if an invalid ID is provided, returns null.
Parameters
- $id : int
-
The ShopCategory ID
Tags
Return values
array<string|int, mixed> —The ShopCategory data array on success, null otherwise
getAssignedShopCategoriesMenuoptions()
Returns the HTML code for options of two separate menus of available and assigned ShopCategories.
public
static getAssignedShopCategoriesMenuoptions([string $assigned_category_ids = null ]) : string
The
Parameters
- $assigned_category_ids : string = null
-
An optional comma separated list of ShopCategory IDs assigned to a Product
Tags
Return values
string —The HTML code with all
getByWildcard()
Select an array of ShopCategories matching the wildcards from the database.
public
getByWildcard(mixed $objCategory) : array<string|int, mixed>
Uses the values of $objCategory as pattern for the match. Empty values will be ignored. Tests for identity of the fields, except with the name (pattern match) and the flags (matching records must contain (at least) all of the flags present in the pattern).
Parameters
- $objCategory : mixed
Tags
Return values
array<string|int, mixed> —Array of the resulting Shop Category objects
getChildCategoriesById()
Returns an array of children of the ShopCategories with ID $parent_id.
public
static getChildCategoriesById([int $parent_id = 0 ][, bool $active = true ][, mixed $flagVirtual = true ]) : array<string|int, mixed>
Note that for virtual ShopCategories, this will include their children.
Parameters
- $parent_id : int = 0
-
The parent ShopCategories ID
- $active : bool = true
-
Only return ShopCategories with active==1 if true. Defaults to false.
- $flagVirtual : mixed = true
Tags
Return values
array<string|int, mixed> —An array of ShopCategories objects on success, false on failure.
getChildCategoryIdArray()
Returns an array of IDs of children of this ShopCategory.
public
static getChildCategoryIdArray(int $parent_id[, bool $active = true ]) : array<string|int, mixed>
Note that this includes virtual children of ShopCategories, if applicable.
Parameters
- $parent_id : int
-
The parent Shop Category ID.
- $active : bool = true
-
Only return ShopCategories with active 1 if true. Defaults to false.
Tags
Return values
array<string|int, mixed> —An array of ShopCategory IDs on success, false otherwise.
getChildNamed()
Returns the ShopCategory with the given parent ID and the given name, if found.
public
static getChildNamed(string $strName[, int $parent_id = null ][, bool $active = true ]) : mixed
Returns false if the query fails, or if more than one child Category of that name is be found. If no such Category is encountered, returns null.
Parameters
- $strName : string
-
The root ShopCategory name
- $parent_id : int = null
-
The parent ShopCategory Id, may be 0 (zero) to search the roots. Ignored if null.
- $active : bool = true
-
If true, only active ShopCategories are considered.
Tags
Return values
mixed —The ShopCategory on success, null if none found, false otherwise.
getMenu()
Returns the HTML code for a dropdown menu listing all ShopCategories.
public
static getMenu([int $selected_id = 0 ][, string $name = 'catId' ][, mixed $active = true ]) : string
The
Parameters
- $selected_id : int = 0
-
The selected ShopCategories ID
- $name : string = 'catId'
-
The optional menu name, defaults to 'catId'.
- $active : mixed = true
Tags
Return values
string —The HTML dropdown menu code
getMenuoptions()
Returns the HTML code for a dropdown menu listing all ShopCategories.
public
static getMenuoptions([int $selected_id = 0 ][, bool $active = true ][, int $maxlevel = 0 ][, bool $include_none = false ]) : string
The
Parameters
- $selected_id : int = 0
-
The optional selected ShopCategories ID.
- $active : bool = true
-
If true, only active ShopCategories are included, all otherwise.
- $maxlevel : int = 0
-
The maximum nesting level, defaults to 0 (zero), meaning all.
- $include_none : bool = false
-
Include an option for "no selected" category if true. Defaults to false
Tags
Return values
string —The HTML code with all
getNameArray()
Returns an array of Category names indexed by their respective IDs
public
static getNameArray([bool $activeonly = false ]) : array<string|int, mixed>
Parameters
- $activeonly : bool = false
-
If true, only active categories are included in the array
Tags
Return values
array<string|int, mixed> —The array of Category names
getNextShopCategoriesId()
Get the next ShopCategories ID after $shopCategoryId according to the sorting order.
public
static getNextShopCategoriesId([int $shopCategoryId = 0 ]) : int
Parameters
- $shopCategoryId : int = 0
-
The ShopCategories ID
Tags
Return values
int —The next ShopCategories ID
getParentCategoryId()
Returns the parent category ID of the ShopCategory specified by its ID,
public
static getParentCategoryId(int $shopCategoryId) : mixed
If the ID given corresponds to a top level category, 0 (zero) is returned, as there is no parent. If the ID cannot be found, boolean false is returned.
Parameters
- $shopCategoryId : int
-
The ShopCategory ID
Tags
Return values
mixed —The parent category ID, or boolean false on failure.
getPictureById()
Returns the best match for the Category Image
public
static getPictureById([int $catId = 0 ][, bool $active = true ]) : string
If there is an image specified for the Category itself, its name is returned. Otherwise, the Products in the Category are searched for a valid image, and if one can be found, its name is returned. If neither can be found, the same process is repeated with all subcategories. If no image could be found at all, returns the empty string.
Parameters
- $catId : int = 0
-
The ShopCategory to search
- $active : bool = true
-
Only consider active Categories if true
Tags
Return values
string —The product thumbnail path on success, the empty string otherwise.
getSearchCategoryIdString()
Returns a string listing all ShopCategory IDs contained within the subtree starting with the ShopCategory with ID $parent_id.
public
static getSearchCategoryIdString([int $parent_id = 0 ][, bool $active = true ]) : string
This string is used to limit the range of Product searches. The IDs are comma separated, ready to be used in an SQL query.
Parameters
- $parent_id : int = 0
-
The optional root ShopCategories ID. Defaults to 0 (zero).
- $active : bool = true
-
Only return ShopCategories with active == true if true. Defaults to true.
Tags
Return values
string —The ShopCategory ID list on success, false otherwise.
getTrailArray()
Returns the ShopCategories ID trail array.
public
static getTrailArray([int $selected_id = 0 ]) : mixed
Parameters
- $selected_id : int = 0
-
The selected ShopCategory ID.
Tags
Return values
mixed —The array of ShopCategory IDs on success, false on failure.
getTreeArray()
Returns an array representing a tree of ShopCategories, not including the root chosen.
public
static getTreeArray([bool $flagFull = false ][, bool $active = true ][, bool $flagVirtual = true ][, int $selected_id = 0 ][, int $parent_id = 0 ][, int $maxlevel = 0 ]) : array<string|int, mixed>
Parameters
- $flagFull : bool = false
-
If true, the full tree is built, only the parts visible for $selected_id otherwise. Defaults to false.
- $active : bool = true
-
Only return ShopCategories with active == true if true. Defaults to false.
- $flagVirtual : bool = true
-
If true, also returns the virtual content of ShopCategories marked as virtual. Defaults to false.
- $selected_id : int = 0
-
The optional selected ShopCategory ID. If set and greater than zero, only the ShopCategories needed to display the Shop page are returned.
- $parent_id : int = 0
-
The optional root ShopCategories ID. Defaults to 0 (zero).
- $maxlevel : int = 0
-
The optional maximum nesting level. 0 (zero) means all. Defaults to 0 (zero).
Tags
Return values
array<string|int, mixed> —The array of ShopCategories on success, false on failure.
getTreeNodeCount()
Returns the number of elements in the ShopCategory array of this object.
public
static getTreeNodeCount() : mixed
If the array has not been initialized before, boolean false is returned.
Tags
Return values
mixed —The element count, or false.
getVirtualCategoriesSelectionForFlags()
Returns a string with HTML code to display the virtual ShopCategory selection checkboxes.
public
static getVirtualCategoriesSelectionForFlags(string $strFlags) : string
Parameters
- $strFlags : string
-
The Product Flags
Tags
Return values
string —The HTML checkboxes string
getVirtualCategoryIdNameArray()
Returns an array with the IDs and names of all ShopCategories marked as virtual.
public
static getVirtualCategoryIdNameArray() : array<string|int, mixed>
The array structure is array( ID => Category name, ... more ... ) Note that the array elements are ordered according to the ordinal value.
Tags
Return values
array<string|int, mixed> —The array of virtual ShopCategory IDs/names
getVirtualCategoryNameArray()
Returns an array with the names of all ShopCategories marked as virtual.
public
static getVirtualCategoryNameArray() : array<string|int, mixed>
Note that the names are ordered according to the sorting order field.
Tags
Return values
array<string|int, mixed> —The array of virtual ShopCategory names
invalidateTreeArray()
Invalidate the current state of the arrShopCategory array and its index.
public
static invalidateTreeArray() : mixed
Do this after changing the database tables or in order to get a different subset of the Shop Categories the next time is called.
Tags
makeThumbnailById()
Create thumbnail and update the corresponding ShopCategory records
public
static makeThumbnailById(int $id[, int $maxWidth = 120 ][, int $maxHeight = 80 ][, int $quality = 90 ]) : string
Scans the ShopCategories with the given IDs. If a non-empty picture string with a reasonable extension is encountered, determines whether the corresponding thumbnail is available and up to date or not. If not, tries to load the file and to create a thumbnail. Note that only single file names are supported! Also note that this method returns a string with information about problems that were encountered. It skips records which contain no or invalid image names, thumbnails that cannot be created, and records which refuse to be updated! The reasoning behind this is that this method is currently only called from within some methods. The focus lies on importing; whether or not thumbnails can be created is secondary, as the process can be repeated if there is a problem.
Parameters
- $id : int
-
The ShopCategory ID
- $maxWidth : int = 120
-
The maximum thubnail width
- $maxHeight : int = 80
-
The maximum thubnail height
- $quality : int = 90
-
The thumbnail quality
Tags
Return values
string —Empty string on success, a string with error messages otherwise.
toggleStatusById()
Toggles the Category status for the given ID
public
static toggleStatusById(int $id) : bool
If the Category doesn't exist to begin with, returns null.
Parameters
- $id : int
-
The ShopCategory ID
Return values
bool —True on success, false on failure, or null otherwise