GRIS_ORGANIGRAM
extends GRIS_CLASS_TEMPLATE
in package
Class to manage all organigram actions
With this class organigram data can be initially set or edited in the database
PHP version 7
Copyright (c) 2016, Holger Heuser
Tags
Table of Contents
- dbtable = 'gris_organigram'
- The constant for the database table
- settings_group = "organigram"
- 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
- $department_childs : array<string|int, mixed>
- A list of childs of the departments
- $departments : array<string|int, mixed>
- The default names of the departments
- $organigram_data : array<string|int, mixed>
- The complete organigram as a tree
- $person_id : int
- The person ID
- __construct() : mixed
- The class constructor
- check_organigramForChanges() : bool
- Checks if organigram data is changed
- check_stats() : bool
- Checks if the output of this person is used for reporting in this unit
- debug() : bool
- Output the full dataset without object data (all subobjects are parsed recursively)
- delete_external_persons() : bool
- Deletes all entries of external or inactive persons from organigram
- delete_unit() : bool
- Delete unit of a person from organigram
- delete_unit_entry() : bool
- Deletes an entry from gris_unit_table
- 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_departments() : array<string|int, mixed>
- Returns a list with all departments
- 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_organigram_data() : array<string|int, mixed>
- Get all organizational units as a tree
- get_parent_unit() : int
- Returns the IDs of the parent unit (department)
- get_references() : array<string|int, mixed>
- Get all references of a given unit
- get_unit() : array<string|int, mixed>
- Get the unit informations by a given unit ID
- get_unit_personnames() : array<string|int, mixed>
- Returns all personnames of a department
- get_unit_persons() : array<string|int, mixed>
- Returns all person IDs of a unit
- get_used_units() : array<string|int, mixed>
- Returns a list with all nonempty units
- id() : int
- Set a new ID or return the current ID if $id is NULL. The numeric value 0 is also set to NULL.
- list_subunits() : array<string|int, mixed>
- Returns the IDs of the unit and all its subunits as an array
- list_unit_ids() : array<string|int, mixed>
- Returns the unit IDs of a person ID from organigram (or all, if person ID is 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)
- save_roles() : bool
- Check if an organigram entry with the given IDs exists
- set_stats() : bool
- Set if the output is used for reporting in this unit
- set_unit() : bool
- Create a new unit entry for a person
- set_unit_entry() : bool
- Create a new entry in gris_unit table or updates an existing one (when ID is given)
- unset_attribute() : bool
- Unsets an attribute
- update() : bool
- Builds an organigram tree
- valid_unit() : bool
- Checks wether a unit name is valid or not
- initialize() : bool
- Initializes the object by filling the array with data
- array_to_xml() : bool
- Convert an array into an xml representation
- check_organigram_role() : int
- Checks if the role is already used by another person
- get_subtree_list() : array<string|int, mixed>
- Undocumented function
- get_unit_childs() : array<string|int, mixed>
- Get all units with a given parent ID (direct children)
- organigram_exists() : bool
- Check if an organigram entry with the given IDs exists
- out() : bool
- Preformatted output of the variable (for development)
- search_organigram() : array<string|int, mixed>
- Get all organizational units with the given unit IDs
- wrap_string() : string
- The callback function for array_walk inside get_departments(...)
Constants
dbtable
The constant for the database table
public
mixed
dbtable
= 'gris_organigram'
settings_group
The constant for the settings group
public
mixed
settings_group
= "organigram"
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
$department_childs
A list of childs of the departments
private
array<string|int, mixed>
$department_childs
= array()
Tags
$departments
The default names of the departments
private
array<string|int, mixed>
$departments
= array()
Tags
$organigram_data
The complete organigram as a tree
private
array<string|int, mixed>
$organigram_data
= array()
Tags
$person_id
The person ID
private
int
$person_id
= NULL
Tags
Methods
__construct()
The class constructor
public
__construct([int $person_id = NULL ]) : mixed
Parameters
- $person_id : int = NULL
-
The prson ID
Initializes the objects
Return values
mixed —check_organigramForChanges()
Checks if organigram data is changed
public
check_organigramForChanges(string $person_id, string $unit_id, string $role) : bool
Parameters
- $person_id : string
-
The ID of the person
- $unit_id : string
-
The ID of the unit
- $role : string
-
The organigram role
Return values
bool —Returns true if role changed
check_stats()
Checks if the output of this person is used for reporting in this unit
public
check_stats(int $person_id, int $unit_id) : bool
Parameters
- $person_id : int
-
The person ID
- $unit_id : int
-
The unit ID
Return values
bool —Returns true if person is counted or false if not
debug()
Output the full dataset without object data (all subobjects are parsed recursively)
public
debug() : bool
Return values
bool —true
delete_external_persons()
Deletes all entries of external or inactive persons from organigram
public
delete_external_persons() : bool
Return values
bool —Returns true or false
delete_unit()
Delete unit of a person from organigram
public
delete_unit(int $unit_id, int $person_id) : bool
Parameters
- $unit_id : int
-
The ID of the unit
- $person_id : int
-
The ID of the person
Return values
bool —Returns true or false
delete_unit_entry()
Deletes an entry from gris_unit_table
public
delete_unit_entry(int $unit_id) : bool
Parameters
- $unit_id : int
-
The ID of the unit
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_departments()
Returns a list with all departments
public
get_departments([bool $teams = false ]) : array<string|int, mixed>
Parameters
- $teams : bool = false
-
Include all subunits (teams)
Return values
array<string|int, mixed> —The list of departments
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_organigram_data()
Get all organizational units as a tree
public
get_organigram_data(int $id[, string $language = NULL ][, string $used = NULL ][, string $show_deprecated = true ]) : array<string|int, mixed>
Parameters
- $id : int
-
The ID to start the recursion (default is 0)
- $language : string = NULL
-
The current language for the output
- $used : string = NULL
-
Return only units that are currently used (default is NULL, GET parameter is "used")
- $show_deprecated : string = true
-
Return units that are not longer valid (default is true)
Return values
array<string|int, mixed> —An array with all organizational units
get_parent_unit()
Returns the IDs of the parent unit (department)
public
get_parent_unit(array<string|int, mixed> $unit_id) : int
Parameters
- $unit_id : array<string|int, mixed>
-
The ID of the child unit
Return values
int —The ID of the parent unit
get_references()
Get all references of a given unit
public
get_references(int $id[, bool $ref_count = false ][, bool $check_subunits = false ]) : array<string|int, mixed>
Parameters
- $id : int
-
The ID of the unit
- $ref_count : bool = false
-
Return only the count of references
- $check_subunits : bool = false
-
Check also the subunits on references (for deleting)
Return values
array<string|int, mixed> —The array with all references or false on error
get_unit()
Get the unit informations by a given unit ID
public
get_unit(string $ids[, string $names_only = false ]) : array<string|int, mixed>
Parameters
- $ids : string
-
The ID of the unit (optional an array of IDs)
- $names_only : string = false
-
Return only the names of the unit
Return values
array<string|int, mixed> —The array with the unit information (or an arry of multiple unit informations) returns NULL if no units were found
get_unit_personnames()
Returns all personnames of a department
public
get_unit_personnames(array<string|int, mixed> $units) : array<string|int, mixed>
Parameters
- $units : array<string|int, mixed>
-
The list of unit IDs (string for a single department is also accepted)
Return values
array<string|int, mixed> —Returns an array of person IDs
get_unit_persons()
Returns all person IDs of a unit
public
get_unit_persons(string $unit[, bool $complete = false ][, array<string|int, mixed> $roles = NULL ][, bool $invert = false ][, bool $list = false ][, bool $filter_stats = false ][, bool $filter_show = true ]) : array<string|int, mixed>
Parameters
- $unit : string
-
The ID of the unit
- $complete : bool = false
-
Include all subunits (childs)
- $roles : array<string|int, mixed> = NULL
-
A list of allowed roles (all others will not appear in the array)
- $invert : bool = false
-
Invert the list of roles (NOT IN)
- $list : bool = false
-
Return a plain list (no gender information)
- $filter_stats : bool = false
-
Filter persons where the unit is not counted in statistics (organigram box is unchecked)
- $filter_show : bool = true
-
Filter persons where show in the internet is unchecked (default is true)
Return values
array<string|int, mixed> —Returns a list of person IDs for the units ordered by their personnames
get_used_units()
Returns a list with all nonempty units
public
get_used_units() : array<string|int, mixed>
Return values
array<string|int, mixed> —The list of nonempty unit IDs
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
list_subunits()
Returns the IDs of the unit and all its subunits as an array
public
list_subunits(array<string|int, mixed> $units, array<string|int, mixed> $unit_id[, bool $hit = false ]) : array<string|int, mixed>
Parameters
- $units : array<string|int, mixed>
-
The array of units to parse (tree)
- $unit_id : array<string|int, mixed>
-
The ID of the unit to find inside the tree
- $hit : bool = false
-
Shows if there is a hit
Return values
array<string|int, mixed> —The list of departments
list_unit_ids()
Returns the unit IDs of a person ID from organigram (or all, if person ID is null)
public
list_unit_ids([string $person_id = NULL ]) : array<string|int, mixed>
Parameters
- $person_id : string = NULL
-
The ID of the person
Return values
array<string|int, mixed> —The list of unit ids
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
save_roles()
Check if an organigram entry with the given IDs exists
public
save_roles(string $unit_id, array<string|int, mixed> $roles) : bool
Parameters
- $unit_id : string
-
The ID of the the unit
- $roles : array<string|int, mixed>
-
The roles for this unit
Return values
bool —Returns true oder false
set_stats()
Set if the output is used for reporting in this unit
public
set_stats(int $person_id, int $unit_id, int $checked) : bool
Parameters
- $person_id : int
-
The person ID
- $unit_id : int
-
The unit ID
- $checked : int
-
The state of the checkbox
Return values
bool —Returns true or false
set_unit()
Create a new unit entry for a person
public
set_unit(array<string|int, mixed> $data) : bool
Field Type Null Default
gris_person_id bigint(20) Nein gris_unit_id bigint(20) Nein gris_organigram_role varchar(255) Nein 'Mitarbeiter'
Parameters
- $data : array<string|int, mixed>
-
The data for the person entry
Return values
bool —Returns true or false
set_unit_entry()
Create a new entry in gris_unit table or updates an existing one (when ID is given)
public
set_unit_entry(array<string|int, mixed> $data) : bool
Field Type Null Default
gris_unit_id bigint(20) Nein gris_unit_name varchar(255) Nein gris_unit_acronym varchar(255) Ja NULL gris_unit_type varchar(255) Nein gris_unit_parent_id bigint(20) Ja NULL gris_unit_deprecated tinyint(1) Nein 0
Parameters
- $data : array<string|int, mixed>
-
The data for the person entry
Return values
bool —Returns true or false
unset_attribute()
Unsets an attribute
public
unset_attribute(string $attribute) : bool
Parameters
- $attribute : string
-
The attributes
Return values
bool —Returns true
update()
Builds an organigram tree
public
update([int $person_id = NULL ]) : bool
Parameters
- $person_id : int = NULL
-
The person ID
Return values
bool —Returns true (or false on error)
valid_unit()
Checks wether a unit name is valid or not
public
valid_unit(string $name) : bool
Parameters
- $name : string
-
The name of the unit
Return values
bool —Returns true for valid units and false for invalid ones
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)
check_organigram_role()
Checks if the role is already used by another person
private
check_organigram_role(string $unit_id, string $role[, string $person_id = NULL ]) : int
Parameters
- $unit_id : string
-
The ID of the unit
- $role : string
-
The coming role of the person in the organigram
- $person_id : string = NULL
-
The person ID
Return values
int —Returns the ID of the person or NULL if no person found
get_subtree_list()
Undocumented function
private
get_subtree_list(array<string|int, mixed> $id_list) : array<string|int, mixed>
Parameters
- $id_list : array<string|int, mixed>
-
The array with the IDs (initial it is only on ID as a starting leaf)
Return values
array<string|int, mixed> —Returns an array with unit IDs
get_unit_childs()
Get all units with a given parent ID (direct children)
private
get_unit_childs(string $id[, bool $complete = true ]) : array<string|int, mixed>
Parameters
- $id : string
-
The ID of the parent ID (should also work with an int param)
- $complete : bool = true
-
Return only the ID if false
Return values
array<string|int, mixed> —The array with the units (returns NULL if no units were found)
organigram_exists()
Check if an organigram entry with the given IDs exists
private
organigram_exists(string $person_id, string $unit_id) : bool
Parameters
- $person_id : string
-
The ID of the the person
- $unit_id : string
-
The ID of the the unit
Return values
bool —Returns true oder false
out()
Preformatted output of the variable (for development)
private
out([mixed $mixed = NULL ]) : bool
Parameters
- $mixed : mixed = NULL
-
The variable
Return values
bool —true
search_organigram()
Get all organizational units with the given unit IDs
private
search_organigram(array<string|int, mixed> $array, array<string|int, mixed> $search_values, string $search_key[, booean $tree = true ]) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>
-
The array to search in
- $search_values : array<string|int, mixed>
-
The list of valid values
- $search_key : string
-
The name of the array key to search in
- $tree : booean = true
-
Return a tree (with parents of the hits) or (if false) only a single unit (the first hit)
Return values
array<string|int, mixed> —An array with all organizational units that have a listed ID
wrap_string()
The callback function for array_walk inside get_departments(...)
private
wrap_string(pointer &$item, bool $key) : string
Parameters
- $item : pointer
-
The pointer to the current array value
- $key : bool
-
The current array key
Return values
string —The wrapped value (wrapped by "'")