GRIS_TAGS
extends GRIS_CLASS_TEMPLATE
in package
Class for tags
With this class tags can be managed
PHP 7
Copyright (c) 2018, Jan Peterek
Tags
Table of Contents
- $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
- add_resource_tag() : int
- Add a tag for a given resource id
- count_used_tags() : int
- Counts the number of tags in tag_resource for a given tag id
- debug() : bool
- Output the full dataset without object data (all subobjects are parsed recursively)
- delete_resource_tag() : bool
- Delete a tag for a given resource id
- delete_tag() : bool
- Delete a tag and all relations
- 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_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_resource_tags() : array<string|int, mixed>
- Returns all tags for a given resource id
- 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)
- rename_tag() : bool
- Rename a tag with a given tag id
- replace_tag() : bool
- Replace a tag by another existing tag
- reset() : bool
- Reset the whole object (ID = NULL, full_data is empty)
- search_tags_by_str() : array<string|int, mixed>
- Searches tags by with searchstring
- unset_attribute() : bool
- Unsets an attribute
- initialize() : bool
- Initializes the object by filling the array with data
- array_to_xml() : bool
- Convert an array into an xml representation
- out() : bool
- Preformatted output of the variable (for development)
- tag_entry_exists() : bool
- Checks if a tag entry already exists
- tag_exists() : bool
- Checks if a tag already exists
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
Return values
mixed —add_resource_tag()
Add a tag for a given resource id
public
add_resource_tag([array<string|int, mixed> $data = NULL ]) : int
Parameters
- $data : array<string|int, mixed> = NULL
-
Array with data to write to database
Return values
int —Returns the ID of the new item or NULL
count_used_tags()
Counts the number of tags in tag_resource for a given tag id
public
count_used_tags([string $tag_id = NULL ]) : int
Parameters
- $tag_id : string = NULL
-
The tag id
Return values
int —The counted number
debug()
Output the full dataset without object data (all subobjects are parsed recursively)
public
debug() : bool
Return values
bool —true
delete_resource_tag()
Delete a tag for a given resource id
public
delete_resource_tag([array<string|int, mixed> $data = NULL ]) : bool
Parameters
- $data : array<string|int, mixed> = NULL
-
Array with data to delete from database
Return values
bool —returns false if no tag could be deleted
delete_tag()
Delete a tag and all relations
public
delete_tag([int $tag_id = NULL ]) : bool
Parameters
- $tag_id : int = NULL
-
The tag ID
Return values
bool —returns false if tag could be deleted
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_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_resource_tags()
Returns all tags for a given resource id
public
get_resource_tags([string $resource_id = NULL ]) : array<string|int, mixed>
Parameters
- $resource_id : string = NULL
-
The ID of the resource
Return values
array<string|int, mixed> —The array with the tags
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)
rename_tag()
Rename a tag with a given tag id
public
rename_tag(int $id, string $name) : bool
Parameters
- $id : int
-
The ID of the tag
- $name : string
-
The new name of the tag
Return values
bool —Returns true on success and false on error
replace_tag()
Replace a tag by another existing tag
public
replace_tag(mixed $source_id, mixed $replacement_id) : bool
Parameters
- $source_id : mixed
- $replacement_id : mixed
Return values
bool —Returns true on success and false on error
reset()
Reset the whole object (ID = NULL, full_data is empty)
public
reset() : bool
Return values
bool —Returns true
search_tags_by_str()
Searches tags by with searchstring
public
search_tags_by_str(mixed $term) : array<string|int, mixed>
Parameters
- $term : mixed
Return values
array<string|int, mixed> —found strings
unset_attribute()
Unsets an attribute
public
unset_attribute(string $attribute) : bool
Parameters
- $attribute : string
-
The attributes
Return values
bool —Returns true
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)
out()
Preformatted output of the variable (for development)
private
out([mixed $mixed = NULL ]) : bool
Parameters
- $mixed : mixed = NULL
-
The variable
Return values
bool —true
tag_entry_exists()
Checks if a tag entry already exists
private
tag_entry_exists(int $resource_id, int $tag_id) : bool
Parameters
- $resource_id : int
-
The ID of the resource
- $tag_id : int
-
The ID of the tag
Return values
bool —Returns true if tag exists and false if not
tag_exists()
Checks if a tag already exists
private
tag_exists(int $tag_name) : bool
Parameters
- $tag_name : int
-
The ID of the tag
Return values
bool —Returns the ID of an existing tag or NULL if not