API documentation

LDAPI

LDAPI()

Public Functions

LDAPI\LDAPI::__construct( $config_key = 'default')

Initialize class, create a new LDAP connection using the config set

param $config_key

return

void

LDAPI\LDAPI::__destruct()

Neatly close the LDAP connection

LDAPI\LDAPI::login( $username,  $password)

Attempt to login, return user on success

param $username

param $password

(clear, un-hashed)

return

LDAPUser|false

LDAPI\LDAPI::findUsersByValues( $criteria)

Find users based on field(s)

param $criteria

Associated array of criteria, use second level for “or”

return

LDAPUser[]|false Array of LDAPUser objects

LDAPI\LDAPI::findAllUsers()

Get all active users (no old members), so type < 4

return

LDAPUser[]|false Array of LDAPUser objects

LDAPI\LDAPI::getUser( $id)

Get single specified user by primary key

param $id

return

LDAPUser|false

LDAPI\LDAPI::getUsers( $ids)

Get a list of users by their primary key. Uses only a single LDAP query, and should be efficient than calling getUser() multiple times. The function cannot tell which ids failed

param $ids

List of primary ids

return

LDAPUser[] Array of ldap user objects

LDAPI\LDAPI::getUserByUsername( $username)

Return single user by username

param $username

return

LDAPUser|false

LDAPI\LDAPI::getUserByStudentnumber( $number)

Get user by student number

param $number

Student number (no ‘s’)

return

LDAPUser|false

LDAPI\LDAPI::createUserWithLink( $data = null)

Return a new user object with a link to this LDAPI instance

param $data

return

LDAPUser

LDAPI\LDAPI::deleteUser( $user)

Remove a user from the LDAP - Can not be undone!

param $user

return

bool

LDAPI\LDAPI::saveNewUser( $user,  $password)

Save a new user to the LDAP

param $user

param $password

(clear, un-hashed)

return

bool

LDAPI\LDAPI::_saveNewObject( $object,  $additional_fields = null)

Save a new object to the LDAP

param $object

param $additional_fields

Additional info (with LDAP keys)

return

bool

LDAPI\LDAPI::_saveUpdatedObject( $object)

Save a modified object to the LDAP

param $object

return

bool

LDAPI\LDAPI::saveUpdatedUser( $user)

Save changes of a user to the LDAP

param $user

return

bool

LDAPI\LDAPI::_saveChangeUsername( $user,  $new_username)

Rename an LDAP user

param $user

param $new_username

return

bool

LDAPI\LDAPI::_changeUserPassword( $user,  $newPassword)

Change the users password and save to the LDAP

param $user

param $newPassword

return

bool

LDAPI\LDAPI::_getEmailForward( $user)

Return forwarding email for specific user from the forwarding table

param $user

return

string|false

LDAPI\LDAPI::_saveEmailForward( $user,  $email)

Edit forwarding email for specific user (errors are placed under ‘emailforward’)

param $user

param $email

return

bool

LDAPI\LDAPI::_getUserPhoto( $user,  $thumb)

Get the user photo

param $user

param $thumb

True for small photo, false for large

return

string|false Returns image data as string, simply echo to render

LDAPI\LDAPI::_saveUserPhoto( $user,  $filepath)

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

param $user

param $filepath

return

bool

LDAPI\LDAPI::findCommitteesByValues( $criteria)

Find committees based on field(s)

param $criteria

Associated array of search values, use second level for “or”

return

LDAPCommittee[]|false Array of LDAPCommittee objects

LDAPI\LDAPI::findAllCommittees()

Get all committees

return

LDAPCommittee[]|false Array of LDAPCommittee objects

LDAPI\LDAPI::getCommittee( $id)

Get committee based on the id

param $id

return

LDAPCommittee|false

LDAPI\LDAPI::getCommittees( $ids)

Get committees based on a list of ids. Uses only a single LDAP query, so should be more efficient that calling getCommittee() multiple times. There is failure for the function on invalid ids

param $ids

List of primary keys

return

LDAPCommittee[] List of committee objects

LDAPI\LDAPI::getCommitteeByName( $name)

Get committees by name

param $name

return

LDAPCommittee|false

LDAPI\LDAPI::createCommitteeWithLink( $data = null)

Return a new committee object and link it to this LDAPI instance

param $data

Information, just like in patchEntity

return

LDAPCommittee

LDAPI\LDAPI::deleteCommittee( $committee)

Remove a committee from the LDAP - Can not be undone!

param $committee

return

bool

LDAPI\LDAPI::saveNewCommittee( $committee)

Save a new committee to the LDAP

param $committee

return

bool

LDAPI\LDAPI::saveUpdatedCommittee( $committee)

Save changes of a committee to the LDAP

param $committee

return

bool

LDAPI\LDAPI::_saveRenameCommittee( $committee,  $new_name)

Save the renaming of a committee to the LDAP

param $committee

param $new_name

return

bool

LDAPI\LDAPI::paginate(& $list,  $options)

Paginate the array of objects

This cannot be more efficiently by e.g. query modification.

The possible options are: sort => Field to sort on direction => Direction to sort on limit => Number of entries per page page => The page to return

When the last page is reached the page will be smaller than limit.

param $list

Array to be paginated

param $options

List of settings

return

int|false Return number of pages or false it no pagination was performed

LDAPI\LDAPI::setLimit( $limit)

Set size limit for this ldap instance

Persists between searches, reset to prevent this. Limiting the number of records is not an efficient way of pagination! Simple benchmarks give the impression that PHP-side pagination is faster than LDAP side.

param $limit

Size limit, set to false to disable limit

Public Static Functions

static LDAPI\LDAPI::createUser( $data = null)

Return a new user object

param $data

Information, like for patchEntity

return

LDAPUser

static LDAPI\LDAPI::createCommittee( $data = null)

Return a new committee object

param $data

Information, just like in patchEntity

return

LDAPCommittee

LDAPUser

LDAPI::LDAPUser : public LDAPI\LDAPObject

Public Functions

LDAPI\LDAPUser::__construct( $ldap_entry = null, & $ldapi_link = null)

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

param $ldap_entry

param $ldapi_link

Link to LDAPI instance

return

void

LDAPI\LDAPUser::__toString()

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

return

string

LDAPI\LDAPUser::__debugInfo()
LDAPI\LDAPUser::getEmailForward()

Return forwarding email from the forwarding table

return

string|false

LDAPI\LDAPUser::saveEmailForward( $email)

Edit forwarding email (errors are placed under ‘emailforward’)

param $email

return

bool

LDAPI\LDAPUser::changePassword( $newPassword,  $currentPassword = null)

Change password and save to the LDAP

param $newPassword

param $currentPassword

Test old password first, cancel change on failure

return

bool

LDAPI\LDAPUser::collectCommittees()

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

return

void

LDAPI\LDAPUser::getPhoto( $thumb = false)

Get photo

param $thumb

True for small photo, false for large

return

string|false Returns image data as string, simply echo to render

LDAPI\LDAPUser::savePhoto( $filepath)

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

param $filepath

return

bool

LDAPI\LDAPUser::saveChangeUsername( $new_username)

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

param $new_username

return

bool

LDAPI\LDAPUser::getFullname()
return

string

LDAPI\LDAPUser::getFormalname()
return

string

LDAPI\LDAPUser::getSex()

Deprecated:

Sex/gender/geslacht is no longer stored in the LDAP

return

string

LDAPI\LDAPUser::getBirthdate()
return

DateTime

LDAPI\LDAPUser::getJoindate()
return

DateTime

LDAPI\LDAPUser::_getDNPrefix()
return

string

LDAPI\LDAPUser::getAuthorization()
return

string

LDAPI\LDAPUser::getMembership()
return

string

LDAPI\LDAPUser::getAstatineEmail()
return

string

LDAPI\LDAPUser::getClassYear()
return

string

Public Members

$address   = null
$attentie   = null
$authorization   = null
$bic   = null
$birthdate   = null
$city   = null
$class   = null
$country   = null
$email   = null
$emailaliases   = null
$firstname   = null
$iban   = null
$initials   = null
$insertions   = null
$joindate   = null
$lastname   = null
$membership   = null
$names   = null
$nationality   = null
$phonenumber   = null
$phonenumber_home   = null
$postalcode   = null
$studentnumber   = null
$username   = null
$committees   = null
const LDAP_KEYS  = ['c' => 'country'
const SEARCH_PREFIX   = '(objectClass=Astatine)'
const BIND_KEY   = 'people'
const FIXED_FIELDS  = ['id','username']
const MEMBERSHIP_TYPES  = [0 => 'Regular membership'

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

const const AUTHORIZATION_TYPES  = [0 => 'None'

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

const const const SEXES  = [0 => 'Male'

Different values for sex - The type is saved as an integer in the LDAP

Deprecated:

The sex/gender/geslacht field has been removed from the LDAP!

const const const const FIRST_CLASS   = 2004

Year of class 1 (first lichting of AT)

Public Static Functions

static LDAPI\LDAPUser::init()

Initialize protected static values

static LDAPI\LDAPUser::getCurrentClass()

Compute the current class (‘lichting’), based on the current date

return

int

LDAPCommittee

LDAPI::LDAPCommittee : public LDAPI\LDAPObject

Public Functions

LDAPI\LDAPCommittee::__construct( $ldap_entry = null, & $ldapi_link = null)

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

param $ldap_entry

LDAP array

param $ldapi_link

Link to LDAPI instance

LDAPI\LDAPCommittee::__toString()

Response when object is used as string (return name)

return

string

LDAPI\LDAPCommittee::__debugInfo()

Override the standard PHP debug information to skip boring stuff

LDAPI\LDAPCommittee::collectMembers()

Collect user object of members and save to property

return

void

LDAPI\LDAPCommittee::addMembers( $new_members,  $check = true)

Add new member(s) to a committee and save it to the LDAP, also works on committee aliasing, pass committee name in this case

The method will return true if at least one update has been made. It no new members were passed or checks failed for each entry, the method will return false.

param string|string[]|LDAPUser|LDAPUser[]

$new_members Array or single, username or LDAPUser object

param $check

False to disable check, useful for external aliases

return

bool

LDAPI\LDAPCommittee::removeMembers( $old_members)

Remove member(s) from a committee and save it to the LDAP

param string|string[]|LDAPUser|LDAPUser[]

$old_members List or single item, username or LDAPUser

return

bool

LDAPI\LDAPCommittee::saveRename( $new_name)

Change the name of the committee and save it to the LDAP (recursively, aliases are modified accordingly) (errors are saved under ‘name’)

param $new_name

return

bool

LDAPI\LDAPCommittee::_getDNPrefix()

Return prefix needed for LDAP binds

return

string

Public Members

$name   = null
$member_usernames   = null
$members   = null
const LDAP_KEYS  = ['cn' => 'name'
const SEARCH_PREFIX   = '(objectClass=posixGroup)(description=com)'
const BIND_KEY   = 'groups'
const FIXED_FIELDS  = ['id','name','member_usernames']

Public Static Functions

static LDAPI\LDAPCommittee::init()

Initialize protected static values

LDAPObject

LDAPObject()

Subclassed by LDAPI\LDAPCommittee, LDAPI\LDAPUser

Public Functions

LDAPI\LDAPObject::__construct( $ldap_entry = null, & $ldapi_link = null)

Initialize object from LDAP result

param $ldap_entry

LDAP array

param $ldapi_link

Link to LDAPI instance

return

void

LDAPI\LDAPObject::__debugInfo()

Override default debug to make result more clear

return

array

LDAPI\LDAPObject::patchEntity( $data)

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

param $data

return

bool False on validation errors

LDAPI\LDAPObject::_validate( $fields = null)

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

param $fields

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

return

bool False on errors

LDAPI\LDAPObject::_setErrors( $field,  $errors)

Add validation errors

param $field

For property or field

param $errors

Error message(s)

return

void

LDAPI\LDAPObject::getErrors( $val = null)

Return validation errors

param $val

Return errors for this field or return all errors

return

array|false Array of errors or false if none exist

LDAPI\LDAPObject::_dirty()

Return dirty fields with their new values

param void

return

array

LDAPI\LDAPObject::_clearDirty()

Clear all dirty fields

param void

return

void

LDAPI\LDAPObject::_getDNPrefix()

Return prefix needed for LDAP binds

return

string

LDAPI\LDAPObject::_dirtyToLDAPArray( $is_add = false)

Collect all dirty fields and return an array compatible with ldap_save

The keys of the array will be ldap keys.

param $is_add

When true, omit empty fields - When false (default), empty fields are set to []

return

array

Public Members

$id   = null
const FIXED_FIELDS   = []
const LDAP_KEYS   = []
const SEARCH_PREFIX   = ''
const BIND_KEY   = ''

Public Static Functions

static LDAPI\LDAPObject::_getDisplayKey( $ldap_key = null)

Find a display key (property) based on ldap_key

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.

param $ldap_key

string|null Leave empty to return all

return

string|false|array

static LDAPI\LDAPObject::_getLdapKey( $display_key = null)

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

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.

param $display_key

string|null Leave empty to return all

return

string|false|array

static LDAPI\LDAPObject::isEmpty( $value)

Return true if (and only if) value is either null, "" or []

param $value

return

bool

Rules

Rules()

Public Static Functions

static LDAPI\Rules::is_string( $val)

String validation

param $val

return

true|string

static LDAPI\Rules::is_number( $val)

Number validation

param $val

return

true|string

static LDAPI\Rules::string_length( $val,  $options)

String length validation

param $val

param $options

[0 => min, 1 => max]

return

true|string

static LDAPI\Rules::range( $val,  $options)

Numeric range validation

param $val

param $options

[0 => min, 1 => max]

return

true|string

static LDAPI\Rules::array_unique( $val)

Verify array elements are unique

param $val

return

true|string

static LDAPI\Rules::is_array( $val)

Array validation

param $val

return

true|string

static LDAPI\Rules::valid_iban( $val)

IBAN validation

param $val

return

true|string

static LDAPI\Rules::is_phonenumber( $val)

Phonenumber validation

param $val

return

true|string

static LDAPI\Rules::is_studentnumber( $val)

Studentnumber validation

param $val

return

true|string

static LDAPI\Rules::is_email( $val)

Email validation

param $val

return

true|string

static LDAPI\Rules::is_valid_date( $val)

Date validation

param $val

return

true|string