API documentation¶
LDAPI¶
-
LDAPI()¶ Public Functions
-
LDAPI\LDAPI::__construct( $config_key = 'default') Initialize class, create a new LDAP connection using the config set
- Return
void
- Parameters
$config_key:
-
LDAPI\LDAPI::__destruct() Neatly close the LDAP connection
-
LDAPI\LDAPI::checkConnection() Check of connection is proper
- Return
bool
-
LDAPI\LDAPI::login( $username, $password) Attempt to login, return user on success
- Return
LDAPUser|false
- Parameters
$username:$password: (clear, un-hashed)
-
LDAPI\LDAPI::findUsersByValues( $criteria) Find users based on field(s)
-
LDAPI\LDAPI::findAllUsers() Get all active users (no old members), so type < 4
-
LDAPI\LDAPI::getUser( $id) Get single specified user by primary key
- Return
LDAPUser|false
- Parameters
$id:
-
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- Return
LDAPUser[] Array of ldap user objects
- Parameters
$ids: List of primary ids
-
LDAPI\LDAPI::getUserByUsername( $username) Return single user by username
- Return
LDAPUser|false
- Parameters
$username:
-
LDAPI\LDAPI::getUserByStudentnumber( $number) Get user by student number
- Return
LDAPUser|false
- Parameters
$number: Student number (no ‘s’)
-
LDAPI\LDAPI::createUserWithLink( $data = null) Return a new user object with a link to this LDAPI instance
- Return
- Parameters
$data:
-
LDAPI\LDAPI::deleteUser( $user) Remove a user from the LDAP - Can not be undone!
- Return
bool
- Parameters
$user:
-
LDAPI\LDAPI::saveNewUser( $user, $password) Save a new user to the LDAP
- Return
bool
- Parameters
$user:$password: (clear, un-hashed)
-
LDAPI\LDAPI::_saveNewObject( $object, $additional_fields = null) Save a new object to the LDAP
- Return
bool
- Parameters
$object:$additional_fields: Additional info (with LDAP keys)
-
LDAPI\LDAPI::_saveUpdatedObject( $object) Save a modified object to the LDAP
- Return
bool
- Parameters
$object:
-
LDAPI\LDAPI::saveUpdatedUser( $user) Save changes of a user to the LDAP
- Return
bool
- Parameters
$user:
-
LDAPI\LDAPI::_saveChangeUsername( $user, $new_username) Rename an LDAP user
- Return
bool
- Parameters
$user:$new_username:
-
LDAPI\LDAPI::_changeUserPassword( $user, $newPassword) Change the users password and save to the LDAP
- Return
bool
- Parameters
$user:$newPassword:
-
LDAPI\LDAPI::_getEmailForward( $user) Return forwarding email for specific user from the forwarding table
- Return
string|false
- Parameters
$user:
-
LDAPI\LDAPI::_saveEmailForward( $user, $email) Edit forwarding email for specific user (errors are placed under ‘emailforward’)
- Return
bool
- Parameters
$user:$email:
-
LDAPI\LDAPI::_getUserPhoto( $user, $thumb) Get the user photo
- Return
string|false Returns image data as string, simply echo to render
- Parameters
$user:$thumb: True for small photo, false for large
-
LDAPI\LDAPI::_saveUserPhoto( $user, $filepath) Save new photo to the ldap (errors are placed under ‘photo’)
- Return
bool
- Parameters
$user:$filepath:
-
LDAPI\LDAPI::findCommitteesByValues( $criteria) Find committees based on field(s)
- Return
LDAPCommittee[]|false Array of LDAPCommittee objects
- Parameters
$criteria: Associated array of search values, use second level for “or”
-
LDAPI\LDAPI::findAllCommittees() Get all committees
- Return
LDAPCommittee[]|false Array of LDAPCommittee objects
-
LDAPI\LDAPI::getCommittee( $id) Get committee based on the id
- Return
LDAPCommittee|false
- Parameters
$id:
-
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- Return
LDAPCommittee[] List of committee objects
- Parameters
$ids: List of primary keys
-
LDAPI\LDAPI::getCommitteeByName( $name) Get committees by name
- Return
LDAPCommittee|false
- Parameters
$name:
-
LDAPI\LDAPI::createCommitteeWithLink( $data = null) Return a new committee object and link it to this LDAPI instance
- Return
- Parameters
$data: Information, just like in patchEntity
-
LDAPI\LDAPI::deleteCommittee( $committee) Remove a committee from the LDAP - Can not be undone!
- Return
bool
- Parameters
$committee:
-
LDAPI\LDAPI::saveNewCommittee( $committee) Save a new committee to the LDAP
- Return
bool
- Parameters
$committee:
-
LDAPI\LDAPI::saveUpdatedCommittee( $committee) Save changes of a committee to the LDAP
- Return
bool
- Parameters
$committee:
-
LDAPI\LDAPI::_saveRenameCommittee( $committee, $new_name) Save the renaming of a committee to the LDAP
- Return
bool
- Parameters
$committee:$new_name:
-
LDAPI\LDAPI::paginate(& $list, $options) Paginate the array of objects. This cannot be more efficiently by e.g. query modification.
- Return
int|false Return number of pages or
falseit no pagination was performed- Parameters
$list: Array to be paginated$options: List of settings
-
LDAPI\LDAPI::setLimit( $limit) Set size limit for this ldap instance. Persists between searches, reset to prevent this.
- Parameters
$limit: Size limit, set to false to disable limit
Public Static Functions
-
static LDAPI\LDAPI::createUser( $data = null) Return a new user object
- Return
- Parameters
$data: Information, like for patchEntity
-
static LDAPI\LDAPI::createCommittee( $data = null) Return a new committee object
- Return
- Parameters
$data: Information, just like in patchEntity
-
LDAPUser¶
-
LDAPI::LDAPUser : public LDAPI\LDAPObject Public Functions
-
const const LDAPI\LDAPUser::__construct( $ldap_entry = null, & $ldapi_link = null) Extend parent construct, make sure aliases array is actually an array
- Return
void
- Parameters
$ldap_entry:$ldapi_link: Link to LDAPI instance
-
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’)
- Return
bool
- Parameters
$email:
-
LDAPI\LDAPUser::changePassword( $newPassword, $currentPassword = null) Change password and save to the LDAP
- Return
bool
- Parameters
$newPassword:$currentPassword: Test old password first, cancel change on failure
-
LDAPI\LDAPUser::collectCommittees() Get the current committees, committees are placed under $this->committees
- Return
void
-
LDAPI\LDAPUser::getPhoto( $thumb = false) Get photo
- Return
string|false Returns image data as string, simply echo to render
- Parameters
$thumb: True for small photo, false for large
-
LDAPI\LDAPUser::savePhoto( $filepath) Save new photo to the ldap (errors are placed under ‘photo’)
- Return
bool
- Parameters
$filepath:
-
LDAPI\LDAPUser::saveChangeUsername( $new_username) Rename an LDAP user (recursive: committees are modified as well) (validation is done, errors are placed under ‘username’)
- Return
bool
- Parameters
$new_username:
-
LDAPI\LDAPUser::getFullname() - Return
string
-
LDAPI\LDAPUser::getFormalname() - Return
string
-
LDAPI\LDAPUser::getSex() - Return
string
-
LDAPI\LDAPUser::getBirthdate() - Return
DateTime
- Exceptions
Exception: Of the remote datetime string is invalid
-
LDAPI\LDAPUser::getJoindate() - Return
DateTime
- Exceptions
Exception: Of the remote datetime string is invalid
-
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
-
$sex = 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
Public Static Functions
-
static LDAPI\LDAPUser::init() Initialize protected static values
-
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
- Parameters
$ldap_entry: LDAP array$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.
- Return
bool
- Parameters
string|string[]|LDAPUser[]: $new_members Array or single, username or LDAPUser object$check: False to disable check, useful for external aliases
-
LDAPI\LDAPCommittee::removeMembers( $old_members) Remove member(s) from a committee and save it to the LDAP
- Return
bool
- Parameters
string|string[]|LDAPUser[]: $old_members List or single item, username or LDAPUser
-
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’)
- Return
bool
- Parameters
$new_name:
-
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
- Return
void
- Parameters
$ldap_entry: LDAP array$ldapi_link: Link to LDAPI instance
-
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
- Return
bool False on validation errors
- Parameters
$data:
-
LDAPI\LDAPObject::_validate( $fields = null) Verify the content, errors are saved in $this->errors
- Return
bool False on errors
- Parameters
$fields: Verify these fields only, if null all dirty fields are processed
-
LDAPI\LDAPObject::_setErrors( $field, $errors) Add validation errors
- Return
void
- Parameters
$field: For property or field$errors: Error message(s)
-
LDAPI\LDAPObject::getErrors( $val = null) Return validation errors
- Return
array|false Array of errors or false if none exist
- Parameters
$val: Return errors for this field or return all errors
-
LDAPI\LDAPObject::_dirty() Return dirty fields with their new values
- Return
array
- Parameters
void:
-
LDAPI\LDAPObject::_clearDirty() Clear all dirty fields
- Return
void
- Parameters
void:
-
LDAPI\LDAPObject::_getDNPrefix() Return prefix needed for LDAP binds
- Return
string
-
LDAPI\LDAPObject::_dirtyToLDAPArray() Collect all dirty fields and return an array compatible with ldap_save
The keys of the array will be ldap keys.
- 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.
- Return
string|false|array
- Parameters
$ldap_key: string|null Leave empty to return all
-
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.
- Return
string|false|array
- Parameters
$display_key: string|null Leave empty to return all
-
Rules¶
-
Rules()¶ Public Static Functions
-
static LDAPI\Rules::is_string( $val) String validation
- Return
true|string
- Parameters
$val:
-
static LDAPI\Rules::is_number( $val) Number validation
- Return
true|string
- Parameters
$val:
-
static LDAPI\Rules::string_length( $val, $options) String length validation
- Return
true|string
- Parameters
$val:$options: [0 => min, 1 => max]
-
static LDAPI\Rules::range( $val, $options) Numeric range validation
- Return
true|string
- Parameters
$val:$options: [0 => min, 1 => max]
-
static LDAPI\Rules::array_unique( $val) Verify array elements are unique
- Return
true|string
- Parameters
$val:
-
static LDAPI\Rules::is_array( $val) Array validation
- Return
true|string
- Parameters
$val:
-
static LDAPI\Rules::valid_iban( $val) IBAN validation
- Return
true|string
- Parameters
$val:
-
static LDAPI\Rules::is_phonenumber( $val) Phonenumber validation
- Return
true|string
- Parameters
$val:
-
static LDAPI\Rules::is_studentnumber( $val) Studentnumber validation
- Return
true|string
- Parameters
$val:
-
static LDAPI\Rules::is_email( $val) Email validation
- Return
true|string
- Parameters
$val:
-
static LDAPI\Rules::is_valid_date( $val) Date validation
- Return
true|string
- Parameters
$val:
-