Documentation

LDAPUser extends LDAPObject
in package

LDAP User class

This is the user class. Each user returning from the LDAPI will be an instance of this class. It extends LDAPObject

Tags
author

ITco itco@astatine.utwente.nl

author

Robert Roos robert.roos@astatine.utwente.nl

copyright

September 2017 - 2018, S.A. Astatine

license

PHP License 3.01

Table of Contents

AUTHORIZATION_TYPES  = [0 => 'None', 1 => 'Membership', 2 => 'ASS', 3 => 'Both', 4 => 'Everything']
Different financial authorization types - The type is saved as an integer in the LDAP
BIND_KEY  = 'people'
Key to the type of bind address (actual bind address is read by LDAPI)
FIRST_CLASS  = 2004
Year of class 1 (first _lichting_ of AT)
FIXED_FIELDS  = ['id', 'username']
List of fields that cannot be patched directly (when altered directly changes are not saved!)
LDAP_KEYS  = [ // LDAP Required 'c' => 'country', 'cn' => 'firstname', 'geboortedatum' => 'birthdate', 'geslacht' => 'sex', 'givenname' => 'names', 'initials' => 'initials', 'joindate' => 'joindate', 'l' => 'city', 'lidmaatschap' => 'membership', 'mail' => 'email', 'mailvoorvoegsel' => 'emailaliases', 'postaladdress' => 'address', 'postalcode' => 'postalcode', 'sn' => 'lastname', 'studentnummer' => 'studentnumber', 'uid' => 'username', 'attentie' => 'attentie', // Optional for LDAP, but required now // LDAP Optional 'bic' => 'bic', 'ibanreknummer' => 'iban', 'lichting' => 'class', 'machtiging' => 'authorization', 'mobile' => 'phonenumber', 'nationaliteit' => 'nationality', //'reknummer' => 'bankaccount', // Should be redundant 'telephonenumber' => 'phonenumber_home', 'tv' => 'insertions', 'uidnumber' => 'id', ]
Maps LDAP keys to properties ('ldap_key' => 'property')
MEMBERSHIP_TYPES  = [0 => 'Regular membership', 1 => 'Extraordinary membership', 2 => 'Alumnus', 3 => 'Employee membership', 4 => 'Old member']
Different member types - The type is saved as an integer in the LDAP
SEARCH_PREFIX  = '(objectClass=Astatine)'
Search addition needed for ldap_search (contains object type)
$address  : mixed
$attentie  : mixed
$authorization  : mixed
$bic  : mixed
$birthdate  : mixed
$city  : mixed
$class  : mixed
$committees  : array<string|int, LDAPCommittee>|null
Array of committees, can be filled by calling ->collectCommittees()
$country  : mixed
$email  : mixed
$emailaliases  : mixed
$firstname  : mixed
$iban  : mixed
$id  : int|null
Primary id of this object
$initials  : mixed
$insertions  : mixed
$joindate  : mixed
$lastname  : mixed
$membership  : mixed
$names  : mixed
$nationality  : mixed
$phonenumber  : mixed
$phonenumber_home  : mixed
$postalcode  : mixed
$sex  : mixed
$studentnumber  : mixed
$username  : mixed
$dirty  : array<string|int, mixed>
Altered fields, queue to be saved, 'field' => 'new_value'
$DISPLAY_KEYS  : array<string|int, mixed>
Redeclare keys so they are separate from the parent class
$errors  : array<string|int, mixed>
Validation errors, ordered by field as key
$ldapi_link  : LDAPI
Link to LDAPI instance
$validators  : array<string|int, mixed>
Validators to apply: 'field' => [list of rules]
__construct()  : void
Extend parent construct, make sure aliases array is actually an array
__debugInfo()  : array<string|int, mixed>
Override default debug to make result more clear
__toString()  : string
Response when object is used as string (return full name)
_clearDirty()  : void
Clear all dirty fields
_dirty()  : array<string|int, mixed>
Return dirty fields with their new values
_dirtyToLDAPArray()  : array<string|int, mixed>
Collect all dirty fields and return an array compatible with ldap_save
_getDisplayKey()  : string|false|array<string|int, mixed>
Find a display key (property) based on ldap_key
_getDNPrefix()  : string
Return prefix needed for LDAP binds
_getLdapKey()  : string|false|array<string|int, mixed>
Find an ldap key based on a display key (property)
_setErrors()  : void
Add validation errors
_validate()  : bool
Verify the content, errors are saved in $this->errors
changePassword()  : bool
Change password and save to the LDAP
collectCommittees()  : void
Get the current committees, committees are placed under $this->committees
getAstatineEmail()  : string
getAuthorization()  : string
getBirthdate()  : DateTime
getClassYear()  : string
getEmailForward()  : string|false
Return forwarding email from the forwarding table
getErrors()  : array<string|int, mixed>|false
Return validation errors
getFormalname()  : string
getFullname()  : string
getJoindate()  : DateTime
getMembership()  : string
getPhoto()  : string|false
Get photo
getSex()  : string
init()  : mixed
Initialize protected static values
patchEntity()  : bool
Alter or insert data, validate it and mark it to be saved
saveChangeUsername()  : bool
Rename an LDAP user (recursive: committees are modified as well) (validation is done, errors are placed under 'username')
saveEmailForward()  : bool
Edit forwarding email (errors are placed under 'emailforward')
savePhoto()  : bool
Save new photo to the ldap (errors are placed under 'photo')
_buildObjectFromLdapData()  : void
Fill instance according to LDAP data
getDate()  : DateTime|null
Convert field to DateTime object

Constants

AUTHORIZATION_TYPES

Different financial authorization types - The type is saved as an integer in the LDAP

public mixed AUTHORIZATION_TYPES = [0 => 'None', 1 => 'Membership', 2 => 'ASS', 3 => 'Both', 4 => 'Everything']

BIND_KEY

Key to the type of bind address (actual bind address is read by LDAPI)

public string BIND_KEY = 'people'

FIRST_CLASS

Year of class 1 (first _lichting_ of AT)

public mixed FIRST_CLASS = 2004

FIXED_FIELDS

List of fields that cannot be patched directly (when altered directly changes are not saved!)

public array<string|int, string> FIXED_FIELDS = ['id', 'username']

LDAP_KEYS

Maps LDAP keys to properties ('ldap_key' => 'property')

public array<string|int, mixed> LDAP_KEYS = [ // LDAP Required 'c' => 'country', 'cn' => 'firstname', 'geboortedatum' => 'birthdate', 'geslacht' => 'sex', 'givenname' => 'names', 'initials' => 'initials', 'joindate' => 'joindate', 'l' => 'city', 'lidmaatschap' => 'membership', 'mail' => 'email', 'mailvoorvoegsel' => 'emailaliases', 'postaladdress' => 'address', 'postalcode' => 'postalcode', 'sn' => 'lastname', 'studentnummer' => 'studentnumber', 'uid' => 'username', 'attentie' => 'attentie', // Optional for LDAP, but required now // LDAP Optional 'bic' => 'bic', 'ibanreknummer' => 'iban', 'lichting' => 'class', 'machtiging' => 'authorization', 'mobile' => 'phonenumber', 'nationaliteit' => 'nationality', //'reknummer' => 'bankaccount', // Should be redundant 'telephonenumber' => 'phonenumber_home', 'tv' => 'insertions', 'uidnumber' => 'id', ]

MEMBERSHIP_TYPES

Different member types - The type is saved as an integer in the LDAP

public mixed MEMBERSHIP_TYPES = [0 => 'Regular membership', 1 => 'Extraordinary membership', 2 => 'Alumnus', 3 => 'Employee membership', 4 => 'Old member']

SEARCH_PREFIX

Search addition needed for ldap_search (contains object type)

public string SEARCH_PREFIX = '(objectClass=Astatine)'

Properties

$authorization

public mixed $authorization = null

$birthdate

public mixed $birthdate = null

$committees

Array of committees, can be filled by calling ->collectCommittees()

public array<string|int, LDAPCommittee>|null $committees = null

$emailaliases

public mixed $emailaliases = null

$firstname

public mixed $firstname = null

$id

Primary id of this object

public int|null $id = null

$insertions

public mixed $insertions = null

$membership

public mixed $membership = null

$nationality

public mixed $nationality = null

$phonenumber

public mixed $phonenumber = null

$phonenumber_home

public mixed $phonenumber_home = null

$postalcode

public mixed $postalcode = null

$studentnumber

public mixed $studentnumber = null

$dirty

Altered fields, queue to be saved, 'field' => 'new_value'

protected array<string|int, mixed> $dirty = []

$DISPLAY_KEYS

Redeclare keys so they are separate from the parent class

protected static array<string|int, mixed> $DISPLAY_KEYS = []
Tags
see
LDAPObject::$DISPLAY_KEYS

$errors

Validation errors, ordered by field as key

protected array<string|int, mixed> $errors = []

$validators

Validators to apply: 'field' => [list of rules]

protected static array<string|int, mixed> $validators = ['attentie' => ['is_number' => [], 'range' => [0, 1]], 'address' => ['is_string' => [], 'string_length' => [1, 99]], 'authorization' => ['optional' => [], 'is_number' => []], 'bic' => ['optional' => [], 'is_string' => [], 'string_length' => [8, 11]], 'birthdate' => ['is_string' => [], 'string_length' => [8, 10], 'is_valid_date' => []], 'city' => ['is_string' => [], 'string_length' => [2, 30]], 'class' => ['optional' => [], 'is_number' => [], 'range' => [1, 999]], 'country' => ['is_string' => [], 'string_length' => [2, 2]], 'email' => ['is_email' => []], 'emailaliases' => ['is_array' => [], 'array_unique' => []], 'firstname' => ['is_string' => [], 'string_length' => [1, 50]], 'iban' => ['optional' => [], 'is_string' => [], 'valid_iban' => []], 'id' => ['optional' => [], 'is_number' => []], 'initials' => ['is_string' => [], 'string_length' => [1, 10]], 'insertions' => ['optional' => [], 'is_string' => [], 'string_length' => [1, 20]], 'joindate' => ['optional' => [], 'is_string' => [], 'string_length' => [8, 10], 'is_valid_date' => []], 'lastname' => ['is_string' => [], 'string_length' => [2, 50]], 'membership' => ['is_number' => [], 'range' => [0, 4]], 'names' => ['is_string' => [], 'string_length' => [1, 50]], 'nationality' => ['optional' => [], 'is_string' => [], 'string_length' => [1, 30]], 'phonenumber' => ['optional' => [], 'is_phonenumber' => []], 'phonenumber_home' => ['optional' => [], 'is_phonenumber' => []], 'postalcode' => ['is_string' => [], 'string_length' => [1, 7]], 'sex' => ['is_number' => [], 'range' => [0, 1]], 'studentnumber' => ['is_studentnumber' => []], 'username' => ['is_string' => [], 'string_length' => [5, 50]]]

Methods

__construct()

Extend parent construct, make sure aliases array is actually an array

public __construct([array<string|int, mixed>|null $ldap_entry = null ][, LDAPI|null &$ldapi_link = null ]) : void
Parameters
$ldap_entry : array<string|int, mixed>|null = null
$ldapi_link : LDAPI|null = null

Link to LDAPI instance

Return values
void

__debugInfo()

Override default debug to make result more clear

public __debugInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>

__toString()

Response when object is used as string (return full name)

public __toString() : string
Return values
string

_clearDirty()

Clear all dirty fields

public _clearDirty() : void
Return values
void

_dirty()

Return dirty fields with their new values

public _dirty() : array<string|int, mixed>
Return values
array<string|int, mixed>

_dirtyToLDAPArray()

Collect all dirty fields and return an array compatible with ldap_save

public _dirtyToLDAPArray() : array<string|int, mixed>

The keys of the array will be ldap keys.

Return values
array<string|int, mixed>

_getDisplayKey()

Find a display key (property) based on ldap_key

public static _getDisplayKey([ $ldap_key = null ]) : string|false|array<string|int, mixed>

If a key could not be found, false is returned and a warning is triggered.

The LDAP_KEYS array contains display keys as values, hence it's used here.

Parameters
$ldap_key : = null

string|null Leave empty to return all

Return values
string|false|array<string|int, mixed>

_getDNPrefix()

Return prefix needed for LDAP binds

public _getDNPrefix() : string
Return values
string

_getLdapKey()

Find an ldap key based on a display key (property)

public static _getLdapKey([ $display_key = null ]) : string|false|array<string|int, mixed>

If a key could not be found, false is returned and a warning is triggered.

The DISPLAY_KEYS array contains ldap keys as values, hence it's used here.

Parameters
$display_key : = null

string|null Leave empty to return all

Return values
string|false|array<string|int, mixed>

_setErrors()

Add validation errors

public _setErrors(string $field, array<string|int, mixed>|string $errors) : void
Parameters
$field : string

For property or field

$errors : array<string|int, mixed>|string

Error message(s)

Return values
void

_validate()

Verify the content, errors are saved in $this->errors

public _validate([array<string|int, mixed>|null $fields = null ]) : bool
Parameters
$fields : array<string|int, mixed>|null = null

Verify these fields only, if null all dirty fields are processed

Return values
bool

False on errors

changePassword()

Change password and save to the LDAP

public changePassword(string $newPassword[, string|null $currentPassword = null ]) : bool
Parameters
$newPassword : string
$currentPassword : string|null = null

Test old password first, cancel change on failure

Return values
bool

collectCommittees()

Get the current committees, committees are placed under $this->committees

public collectCommittees() : void
Return values
void

getAstatineEmail()

public getAstatineEmail() : string
Return values
string

getAuthorization()

public getAuthorization() : string
Return values
string

getBirthdate()

public getBirthdate() : DateTime
Return values
DateTime

getClassYear()

public getClassYear() : string
Return values
string

getEmailForward()

Return forwarding email from the forwarding table

public getEmailForward() : string|false
Return values
string|false

getErrors()

Return validation errors

public getErrors([string|null $val = null ]) : array<string|int, mixed>|false
Parameters
$val : string|null = null

Return errors for this field or return all errors

Return values
array<string|int, mixed>|false

Array of errors or false if none exist

getFormalname()

public getFormalname() : string
Return values
string

getFullname()

public getFullname() : string
Return values
string

getJoindate()

public getJoindate() : DateTime
Return values
DateTime

getMembership()

public getMembership() : string
Return values
string

getPhoto()

Get photo

public getPhoto([bool $thumb = false ]) : string|false
Parameters
$thumb : bool = false

True for small photo, false for large

Return values
string|false

Returns image data as string, simply echo to render

getSex()

public getSex() : string
Return values
string

init()

Initialize protected static values

public static init() : mixed
Return values
mixed

patchEntity()

Alter or insert data, validate it and mark it to be saved

public patchEntity(array<string|int, mixed> $data) : bool
Parameters
$data : array<string|int, mixed>
Return values
bool

False on validation errors

saveChangeUsername()

Rename an LDAP user (recursive: committees are modified as well) (validation is done, errors are placed under 'username')

public saveChangeUsername(string $new_username) : bool
Parameters
$new_username : string
Return values
bool

saveEmailForward()

Edit forwarding email (errors are placed under 'emailforward')

public saveEmailForward(string $email) : bool
Parameters
$email : string
Return values
bool

savePhoto()

Save new photo to the ldap (errors are placed under 'photo')

public savePhoto(string $filepath) : bool
Parameters
$filepath : string
Return values
bool

_buildObjectFromLdapData()

Fill instance according to LDAP data

protected _buildObjectFromLdapData(array<string|int, mixed> $entry) : void
Parameters
$entry : array<string|int, mixed>

LDAP entry array (single entry!)

Return values
void

getDate()

Convert field to DateTime object

protected getDate(string $key) : DateTime|null
Parameters
$key : string
Return values
DateTime|null

Search results