GRIS_PERSON
extends GRIS_CLASS_TEMPLATE
in package
Class to manage informations about persons in the database
With this class all personal information can be initially set or edited in the database
PHP version 7
Copyright (c) 2012, Holger Heuser Unter Sachsenhausen 6-8 50667 Cologne, Germany
Tags
Table of Contents
- dbtable = 'gris_person'
- The constant for the database table
- settings_group = "person"
- 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
- $settings : object
- The object for settings
- $state : object
- The object for state
- $xml_data : string
- The data as xml string
- $history : object
- The object for history
- __construct() : mixed
- The class constructor
- change_person_id() : bool
- Change the current person ID
- current_person() : bool
- Return the current person
- debug() : bool
- Output the full dataset without object data (all subobjects are parsed recursively)
- delete_person() : bool
- Delete an external person completely
- delete_personname() : bool
- Delete personname
- 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_all_persons() : array<string|int, mixed>
- Get the IDs of all internal persons
- get_alpha_nav() : array<string|int, mixed>
- Get an alphabetical navigation structure
- get_alpha_persons() : array<string|int, mixed>
- Get all person with a name starting with a given character
- 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_full_person_data() : array<string|int, mixed>
- Returns all data (person and personname) for a given personname ID
- get_generic_data() : array<string|int, mixed>
- Get generic data for a given mail address
- get_generic_data_by_id() : array<string|int, mixed>
- Get generic data for a given id
- get_max_personname_order() : int
- Get the highest order number for a given person ID
- get_person_id_from_name() : int
- Get the person ID that is related to a given personname ID
- get_personname() : array<string|int, mixed>
- Get all data for a given personname ID
- get_personname_count() : int
- Get the count of personnames according to the current given person ID
- get_personname_data() : array<string|int, mixed>
- Returns a list of all personnames for a given person ID
- get_personname_references() : int
- Get the count of refrences to resources according to a given personnames ID
- get_personnames_by_person_id() : array<string|int, mixed>
- Get the all personnames with attributes for a given person ID
- get_possible_duplicates() : array<string|int, mixed>
- Returns a list of possible duplicate personnames, compared by various criteria
- get_references() : array<string|int, mixed>
- Get all references of the current person
- id() : int
- Set a new ID or return the current ID if $id is NULL. The numeric value 0 is also set to NULL.
- is_external() : bool
- Checks if the person is external (has at least one name set to external)
- is_own_personname() : int
- Checks if the given personname ID belongs to the current person ID
- mark_whitespaces() : string
- Replaces leading, trailing or double whitespaces of names with colored html entities
- persist() : string
- Save the complete person form data to the database
- person_exists() : bool
- Check if the person exists in the table gris_person
- personname_exists() : int
- Check if the personname exists in the database
- 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 person data
- set_external() : bool
- Set all personnames to external
- set_internal() : bool
- Set all personnames to internal
- set_personname() : int
- Create a new personname entry
- unset_attribute() : bool
- Unsets an attribute
- update() : bool
- Read or update all data from the person table of the db into an array
- update_basedata() : bool
- Update the base data of a person from ldap
- update_personname() : bool
- Updates an existing personname entry
- utf8_to_extended_ascii() : mixed
- Convert an UTF-8 encoded string to a single-byte string suitable for functions such as levenshtein https://www.php.net/manual/de/function.levenshtein.php#113702
- initialize() : bool
- Initializes the object by filling the array with data
- array_to_xml() : bool
- Convert an array into an xml representation
- get_person_id_from_mailname() : int
- Get the person ID that is related to a given personname ID
- out() : bool
- Preformatted output of the variable (for development)
- re_order() : int
- Renews the order of a set of personnames for a given person ID to avoid missing numbers after delete operations
- update_personname_order() : int
- Update the order a personname entry
Constants
dbtable
The constant for the database table
public
mixed
dbtable
= 'gris_person'
settings_group
The constant for the settings group
public
mixed
settings_group
= "person"
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
$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
$history
The object for history
private
object
$history
= null
Tags
Methods
__construct()
The class constructor
public
__construct([string $person_id = -1 ][, string $name = NULL ][, int $update = false ]) : mixed
Parameters
- $person_id : string = -1
-
The person ID
- $name : string = NULL
-
An optional name to identify the person (e. g.for frontend webservices)
- $update : int = false
-
Update basedata from ldap
Initializes the objects
Return values
mixed —change_person_id()
Change the current person ID
public
change_person_id(string $person_id) : bool
Parameters
- $person_id : string
-
The ID of the person (should also work with an int param)
Return values
bool —true
current_person()
Return the current person
public
current_person() : bool
Return values
bool —true
debug()
Output the full dataset without object data (all subobjects are parsed recursively)
public
debug() : bool
Return values
bool —true
delete_person()
Delete an external person completely
public
delete_person(string $id) : bool
Parameters
- $id : string
-
The ID of the person
Return values
bool —Returns true or false (if there are references left)
delete_personname()
Delete personname
public
delete_personname(string $id) : bool
Parameters
- $id : string
-
The ID of the personname entry
Return values
bool —Returns true or false
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_all_persons()
Get the IDs of all internal persons
public
get_all_persons([string $char = NULL ][, bool $data = true ]) : array<string|int, mixed>
Parameters
- $char : string = NULL
-
The first character of the lastname
- $data : bool = true
-
Return base data instead of the ID (ID, name, firstname, title, email)
Return values
array<string|int, mixed> —true
get_alpha_nav()
Get an alphabetical navigation structure
public
get_alpha_nav() : array<string|int, mixed>
Return values
array<string|int, mixed> —The array with the characters
get_alpha_persons()
Get all person with a name starting with a given character
public
get_alpha_persons(string $alpha) : array<string|int, mixed>
Parameters
- $alpha : string
-
The given character
Return values
array<string|int, mixed> —The array with the IDs
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_full_person_data()
Returns all data (person and personname) for a given personname ID
public
get_full_person_data(int $personname_id) : array<string|int, mixed>
Parameters
- $personname_id : int
-
The ID of the personname
Return values
array<string|int, mixed> —The array with person and personname data
get_generic_data()
Get generic data for a given mail address
public
get_generic_data([string $mail = NULL ]) : array<string|int, mixed>
Parameters
- $mail : string = NULL
-
The mail address (with or without @...)
Return values
array<string|int, mixed> —The array with the generic attributes
get_generic_data_by_id()
Get generic data for a given id
public
get_generic_data_by_id(string $id) : array<string|int, mixed>
Parameters
- $id : string
-
The id
Return values
array<string|int, mixed> —The array with the generic attributes or NULL on error and empty result
get_max_personname_order()
Get the highest order number for a given person ID
public
get_max_personname_order(string $id) : int
Parameters
- $id : string
-
The ID of the person dataset (should also work with an int param)
Return values
int —The highest order number (returns 0 if no number was found)
get_person_id_from_name()
Get the person ID that is related to a given personname ID
public
get_person_id_from_name(string $id) : int
Parameters
- $id : string
-
The ID of the personname (should also work with an int param)
Return values
int —The ID of the person dataset (returns 0 if no person dataset was found)
get_personname()
Get all data for a given personname ID
public
get_personname([string $id = NULL ]) : array<string|int, mixed>
Parameters
- $id : string = NULL
-
The ID of the personname (should also work with an int param)
Return values
array<string|int, mixed> —The array with the personname attributes
get_personname_count()
Get the count of personnames according to the current given person ID
public
get_personname_count() : int
Return values
int —The number of personnames for the person
get_personname_data()
Returns a list of all personnames for a given person ID
public
get_personname_data([string $personname_id = NULL ]) : array<string|int, mixed>
Parameters
- $personname_id : string = NULL
-
The ID of the person dataset (should also work with an int param)
Return values
array<string|int, mixed> —The array with html list items (returns NULL if no names were found)
get_personname_references()
Get the count of refrences to resources according to a given personnames ID
public
get_personname_references(string $id) : int
Parameters
- $id : string
-
The ID of the personname (should also work with an int param)
Return values
int —The number of personnames for the person
get_personnames_by_person_id()
Get the all personnames with attributes for a given person ID
public
get_personnames_by_person_id(string $person_id[, bool $first = false ][, bool $id_only = false ]) : array<string|int, mixed>
Parameters
- $person_id : string
-
The ID of the personname (should also work with an int param)
- $first : bool = false
-
Return only the first entry
- $id_only : bool = false
-
Return only the personname IDs
Return values
array<string|int, mixed> —The array with the personname attributes
get_possible_duplicates()
Returns a list of possible duplicate personnames, compared by various criteria
public
get_possible_duplicates([string $threshold = 5 ]) : array<string|int, mixed>
Parameters
- $threshold : string = 5
-
Threshold value for levenshtein comparison (current default = 5)
Return values
array<string|int, mixed> —The array with list items (empty array if no names were found)
get_references()
Get all references of the current person
public
get_references([bool $ref_count = false ][, int $personname_id = NULL ]) : array<string|int, mixed>
Parameters
- $ref_count : bool = false
-
Return only the count of references
- $personname_id : int = NULL
-
An optional personname ID if no person ID is given (e.g. external persons)
Return values
array<string|int, mixed> —The array with all references or false on error
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
is_external()
Checks if the person is external (has at least one name set to external)
public
is_external() : bool
Return values
bool —Returns true if external and false if not
is_own_personname()
Checks if the given personname ID belongs to the current person ID
public
is_own_personname(string $personname_id) : int
Parameters
- $personname_id : string
-
The ID of the personname (should also work with an int param)
Return values
int —Returns 0 if personname ID doesn't belong to person ID, otherwise value is 1
mark_whitespaces()
Replaces leading, trailing or double whitespaces of names with colored html entities
public
mark_whitespaces(string $lastname, string $firstname) : string
Parameters
- $lastname : string
-
The last name
- $firstname : string
-
The first name
Return values
string —Returns composed name (<lastname, firstname>) with html elements for markings
persist()
Save the complete person form data to the database
public
persist() : string
Return values
string —Returns success oder error message
person_exists()
Check if the person exists in the table gris_person
public
person_exists(string $person_id) : bool
Parameters
- $person_id : string
-
The ID of the person.
Return values
bool —Returns true if the person exists
personname_exists()
Check if the personname exists in the database
public
personname_exists(array<string|int, mixed> $data) : int
Parameters
- $data : array<string|int, mixed>
-
The attributes to filter (key-value)
Return values
int —Returns an ID (>0) for success, 0 for not found and -1 if $data is empty
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 person data
public
set(array<string|int, mixed> $data[, bool $writethrough = false ]) : bool
Parameters
- $data : array<string|int, mixed>
-
New key/values for the person
- $writethrough : bool = false
-
Write the object to the database immediately
Return values
bool —Returns true or false
set_external()
Set all personnames to external
public
set_external(mixed $person_id) : bool
Parameters
- $person_id : mixed
Return values
bool —Returns true on success or false on error
set_internal()
Set all personnames to internal
public
set_internal(mixed $person_id) : bool
Parameters
- $person_id : mixed
Return values
bool —Returns true on success or false on error
set_personname()
Create a new personname entry
public
set_personname(array<string|int, mixed> $data[, array<string|int, mixed> $fields = NULL ]) : int
Parameters
- $data : array<string|int, mixed>
-
The data for the personname entry
- $fields : array<string|int, mixed> = NULL
-
The used fields for the check if personname exists (by default all fields from $data are checked)
Return values
int —The ID of the personname entry (returns -1 for errors)
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 person table of the db into an array
public
update([string $id = NULL ]) : bool
Parameters
- $id : string = NULL
-
The ID of the person (should also work with an int param)
Return values
bool —Returns true for success and false for address not found
update_basedata()
Update the base data of a person from ldap
public
update_basedata([bool $update = true ][, bool $use_session = true ][, array<string|int, mixed> $external_data = NULL ]) : bool
Possible fields for $data:
Parameters
- $update : bool = true
-
Update data (default) or just return the data array
- $use_session : bool = true
-
Use data from session (user must be logged in, optional external data can be used for cli ans scripts)
- $external_data : array<string|int, mixed> = NULL
-
Extenal data (if $use_data is set true)
Return values
bool —Returns the data ($update = false) or true if data is persistant
update_personname()
Updates an existing personname entry
public
update_personname(string $personname_id, array<string|int, mixed> $data) : bool
Parameters
- $personname_id : string
-
The the personname ID
- $data : array<string|int, mixed>
-
The data
Return values
bool —Returns true (or false for error)
utf8_to_extended_ascii()
Convert an UTF-8 encoded string to a single-byte string suitable for functions such as levenshtein https://www.php.net/manual/de/function.levenshtein.php#113702
public
utf8_to_extended_ascii(mixed $str, mixed &$map) : mixed
Parameters
- $str : mixed
- $map : mixed
Return values
mixed —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_person_id_from_mailname()
Get the person ID that is related to a given personname ID
private
get_person_id_from_mailname(string $name) : int
Parameters
- $name : string
-
The mailaddress of the person (without @ and domain)
Return values
int —The ID of the person dataset (returns 0 if no person dataset was found)
out()
Preformatted output of the variable (for development)
private
out([mixed $mixed = NULL ]) : bool
Parameters
- $mixed : mixed = NULL
-
The variable
Return values
bool —true
re_order()
Renews the order of a set of personnames for a given person ID to avoid missing numbers after delete operations
private
re_order() : int
Return values
int —Retruns the highest order number
update_personname_order()
Update the order a personname entry
private
update_personname_order(string $personname_id, array<string|int, mixed> $order[, bool $persist = false ]) : int
Param fields for $data:
Field Type Null Default
gris_personname_order tinyint(4) YES NULL
Parameters
- $personname_id : string
-
The ID of the personname (should also work with an int param)
- $order : array<string|int, mixed>
-
The order number (should also work with an int param)
- $persist : bool = false
-
Persist data immediately
Return values
int —Returns true for success, false for an error