GRIS_CATEGORY
extends GRIS_CLASS_TEMPLATE
in package
Class for assogning categories to data objects
With this class the category table can be managed.
PHP version 7
Copyright (c) 2012, Holger Heuser
Tags
Table of Contents
- dbtable = 'gris_category'
- The constant for the database table
- settings_group = "category"
- The constant for the settings group
- $classname : object
- The name of the class
- $dbconnection : object
- The database object for managing the connection
- $full_data : array<string|int, mixed>
- The dataset of the resource information
- $i18n : object
- The object for translations
- $id : object
- The current object ID
- $language : string
- The current language
- $settings : object
- The object for settings
- $state : object
- The object for state
- $xml_data : string
- The data as xml string
- __construct() : mixed
- The class constructor
- clear_categories() : bool
- Clears ALL categories (use with care)
- debug() : bool
- Output the full dataset without object data (all subobjects are parsed recursively)
- delete_all() : bool
- Deletes all entries for a given object id and table
- delete_entry() : bool
- Delete a category with a given ID
- delete_relation() : mixed
- Deletes a relation
- get() : array<string|int, mixed>|object|string
- Returns an array of the full data or (if given) only certain attributes (separated by "|" for a subattribute)
- get_category_info() : array<string|int, mixed>
- Returns the info of a category for a given ID
- get_category_name() : string
- Returns the name of a category for a given ID
- get_category_name_by_relation_id() : string
- Returns the category name of a relation ID
- get_flat_data() : array<string|int, mixed>
- Get the data in a flat format. From subarrays only the first entry is merged
- get_flat_data_old() : array<string|int, mixed>
- Get the data in a flat format. From subarrays only the first entry is merged
- get_ref_counters() : mixed
- get_related_categories() : array<string|int, mixed>
- Returns all categories for a given object
- get_related_objects() : mixed
- Returns all related objects for a categorie and an object table
- get_used_categories() : array<string|int, mixed>
- Returns all used categories for a given object_table
- id() : int
- Set a new ID or return the current ID if $id is NULL. The numeric value 0 is also set to NULL.
- pull_json() : string
- Returns the object data as JSON
- pull_xml() : string
- Returns the object data as XML
- push_xml() : bool
- Push an xml into the object (experimental, not finished yet)
- reset() : bool
- Reset the whole object (ID = NULL, full_data is empty)
- set() : bool
- Set data in the object (instant persistance)
- set_relation() : mixed
- Set a new relation with a category
- unset_attribute() : bool
- Unsets an attribute
- update() : bool
- Read or update all data from the category table of the db into an array
- initialize() : bool
- Initializes the object by filling the array with data
- array_to_xml() : bool
- Convert an array into an xml representation
- get_category_childs() : array<string|int, mixed>
- Get all childs for a given parent ID
- get_category_data() : mixed
- Get the whole category tree for a given start point
- get_translation() : mixed
- Get the translation for a given category
- out() : bool
- Preformatted output of the variable (for development)
Constants
dbtable
The constant for the database table
public
mixed
dbtable
= 'gris_category'
settings_group
The constant for the settings group
public
mixed
settings_group
= "category"
Properties
$classname
The name of the class
protected
object
$classname
= NULL
Tags
$dbconnection
The database object for managing the connection
protected
object
$dbconnection
= NULL
Tags
$full_data
The dataset of the resource information
protected
array<string|int, mixed>
$full_data
= array()
Tags
$i18n
The object for translations
protected
object
$i18n
Tags
$id
The current object ID
protected
object
$id
Tags
$language
The current language
protected
string
$language
= NULL
Tags
$settings
The object for settings
protected
object
$settings
= null
Tags
$state
The object for state
protected
object
$state
Tags
$xml_data
The data as xml string
protected
string
$xml_data
= NULL
Tags
Methods
__construct()
The class constructor
public
__construct([mixed $language = NULL ]) : mixed
Parameters
- $language : mixed = NULL
Return values
mixed —clear_categories()
Clears ALL categories (use with care)
public
clear_categories() : bool
Return values
bool —Returns true for success and false for error
debug()
Output the full dataset without object data (all subobjects are parsed recursively)
public
debug() : bool
Return values
bool —true
delete_all()
Deletes all entries for a given object id and table
public
delete_all(int $id, int $table) : bool
Parameters
- $id : int
-
The object id
- $table : int
-
The object table
Return values
bool —Returns true for success and false if no id is given
delete_entry()
Delete a category with a given ID
public
delete_entry(int $id) : bool
Parameters
- $id : int
-
The ID of the category to delete
Return values
bool —Returns true on success and false on error
delete_relation()
Deletes a relation
public
delete_relation(string $object_id, array<string|int, mixed> $object_table, array<string|int, mixed> $category_id) : mixed
Parameters
- $object_id : string
-
The ID of the object
- $object_table : array<string|int, mixed>
-
The table (type) of the object
- $category_id : array<string|int, mixed>
-
The ID of the category
Returns true on success and falso on errors
Return values
mixed —get()
Returns an array of the full data or (if given) only certain attributes (separated by "|" for a subattribute)
public
get([string $attribute = NULL ]) : array<string|int, mixed>|object|string
Parameters
- $attribute : string = NULL
-
The attributes separated by [parent|child]
Return values
array<string|int, mixed>|object|string —The dataset or NULL
get_category_info()
Returns the info of a category for a given ID
public
get_category_info(mixed $category_id) : array<string|int, mixed>
Parameters
- $category_id : mixed
Return values
array<string|int, mixed> —Returns the info of the category
get_category_name()
Returns the name of a category for a given ID
public
get_category_name(string $category_ids) : string
Parameters
- $category_ids : string
-
The ID of the category (optional an array of IDs)
Return values
string —Returns the name of the category (or an arry of names)
get_category_name_by_relation_id()
Returns the category name of a relation ID
public
get_category_name_by_relation_id(int $id) : string
Parameters
- $id : int
-
The relation ID
Return values
string —Returns the category name or NULL if not found
get_flat_data()
Get the data in a flat format. From subarrays only the first entry is merged
public
get_flat_data([bool $hierarchy = false ][, mixed $data = NULL ]) : array<string|int, mixed>
Parameters
- $hierarchy : bool = false
-
Return full flat (standard) or array hierarchy (if true)
- $data : mixed = NULL
-
Use other data than $this->full_data
Return values
array<string|int, mixed> —The flat data
get_flat_data_old()
Get the data in a flat format. From subarrays only the first entry is merged
public
get_flat_data_old([bool $hierarchy = false ][, mixed $data = NULL ]) : array<string|int, mixed>
Parameters
- $hierarchy : bool = false
-
Return full flat (standard) or array hierarchy (if true)
- $data : mixed = NULL
-
Use other data than $this->full_data
Return values
array<string|int, mixed> —The flat data
get_ref_counters()
public
get_ref_counters(mixed $catid) : mixed
Parameters
- $catid : mixed
Return values
mixed —get_related_categories()
Returns all categories for a given object
public
get_related_categories(string $object_id, array<string|int, mixed> $object_table) : array<string|int, mixed>
Parameters
- $object_id : string
-
The ID of the object
- $object_table : array<string|int, mixed>
-
The table (type) of the object
Return values
array<string|int, mixed> —Returns an array of categories or NULL
get_related_objects()
Returns all related objects for a categorie and an object table
public
get_related_objects(string $category_ids, array<string|int, mixed> $object_table, int $offset, int $limit[, int $show = 1 ][, string $range = NULL ]) : mixed
Parameters
- $category_ids : string
-
The IDs of the object (string or optional as array)
- $object_table : array<string|int, mixed>
-
The table (type) of the object
- $offset : int
-
The offset of hits
- $limit : int
-
The limit of hits
- $show : int = 1
-
Filter show attribute
- $range : string = NULL
-
The year or the range of years (does not filter persons; e. g. "2020" oder "2020-2023")
Returns an array of IDs (int > 0) or NULL if no matches. Returns -1 on error
Return values
mixed —get_used_categories()
Returns all used categories for a given object_table
public
get_used_categories(array<string|int, mixed> $object_table) : array<string|int, mixed>
Parameters
- $object_table : array<string|int, mixed>
-
The table (type) of the object
Return values
array<string|int, mixed> —Returns an array of categories or NULL
id()
Set a new ID or return the current ID if $id is NULL. The numeric value 0 is also set to NULL.
public
id([string $id = NULL ]) : int
Parameters
- $id : string = NULL
-
The current ID
Return values
int —The ID
pull_json()
Returns the object data as JSON
public
pull_json() : string
Return values
string —The json string
pull_xml()
Returns the object data as XML
public
pull_xml([bool $head = false ]) : string
Parameters
- $head : bool = false
-
Return XML with head (as default, just a node is returned)
Return values
string —The xml string
push_xml()
Push an xml into the object (experimental, not finished yet)
public
push_xml(string $xml) : bool
Parameters
- $xml : string
-
The xml with the object data
Return values
bool —true (or false on error)
reset()
Reset the whole object (ID = NULL, full_data is empty)
public
reset() : bool
Return values
bool —Returns true
set()
Set data in the object (instant persistance)
public
set(array<string|int, mixed> $data) : bool
Parameters
- $data : array<string|int, mixed>
-
The data of the relation
Return values
bool —Returns true for success and false for no data given
set_relation()
Set a new relation with a category
public
set_relation(string $object_id, array<string|int, mixed> $object_table, array<string|int, mixed> $category_id) : mixed
Parameters
- $object_id : string
-
The ID of the object
- $object_table : array<string|int, mixed>
-
The table (type) of the object
- $category_id : array<string|int, mixed>
-
The ID of the category
Sets a relation between a category as subject and an object which is specified by an ID and an object table
Return values
mixed —unset_attribute()
Unsets an attribute
public
unset_attribute(string $attribute) : bool
Parameters
- $attribute : string
-
The attributes
Return values
bool —Returns true
update()
Read or update all data from the category table of the db into an array
public
update([string $id = NULL ]) : bool
Parameters
- $id : string = NULL
-
The ID is always NULL (only for compatibility to class template)
Return values
bool —Returns true for success and false for errors
initialize()
Initializes the object by filling the array with data
protected
initialize() : bool
Return values
bool —true (or false on error)
array_to_xml()
Convert an array into an xml representation
private
array_to_xml(array<string|int, mixed> $data, Pointer &$xml) : bool
Parameters
- $data : array<string|int, mixed>
-
The array with the data
- $xml : Pointer
-
A pointer to the xml
Return values
bool —true (or NULL if empty)
get_category_childs()
Get all childs for a given parent ID
private
get_category_childs(string $id) : array<string|int, mixed>
Parameters
- $id : string
-
The ID of the parent ID (should also work with an int param)
Return values
array<string|int, mixed> —The array with the categories (returns NULL if no units were found)
get_category_data()
Get the whole category tree for a given start point
private
get_category_data([string $start = NULL ][, array<string|int, mixed> $category_tree = NULL ]) : mixed
Parameters
- $start : string = NULL
-
The start ID
- $category_tree : array<string|int, mixed> = NULL
-
The current tree (for recursions)
Returns the category tree from a starting level (recursive)
Return values
mixed —get_translation()
Get the translation for a given category
private
get_translation(string $category_name, array<string|int, mixed> $category_id) : mixed
Parameters
- $category_name : string
-
The name of the category
- $category_id : array<string|int, mixed>
-
The ID of the category
Retruns the translated category name
Return values
mixed —out()
Preformatted output of the variable (for development)
private
out([mixed $mixed = NULL ]) : bool
Parameters
- $mixed : mixed = NULL
-
The variable
Return values
bool —true