A DAViCal API via direct database manipulation.

see \global\http://davical.org/
category OSS
package OSS_API
copyright Copyright (c) 2007 - 2012, Open Source Solutions Limited, Dublin, Ireland
license New BSD License

 Methods

Constructor Initialize DBAL connection.

__construct($dbparams) 

Parameters

$dbparams

Creates calendar and returns calendar data.

createCalendar(array $user, string $name, string | null $privileges, bool $public_events_only, bool $publicly_readable, int | null $timezone, string $description) 

Returns same array structure as createCollection

If principal has delegated principals, function iterates all of them and blocks access to new calendar.

see \global\createCollection()

Parameters

$user

array

Davical user data

$name

string

Calendars name

$privileges

stringnull

Default privileges to access calendar

$public_events_only

bool

Flag to define if calendar contains only public event

$publicly_readable

bool

Flat to define publicly readable status

$timezone

intnull

Time zone id.

$description

string

Calendar description.

Creates user, principal and calendar.

createCalendarUser(array $params, string $cname, int $type) : array

Takes same parameters as $this->createUser(); Returns an array wich contains user, principal and calendar collection data. array [ 'user' => array users data, 'principal' => array principals data, 'calendar' => array calendar collection data ]

see \global\createUser()
see \global\createPrincipal()
see \global\createCalendar()

Parameters

$params

array

User parameters, sames as creatUser parameters.

$cname

string

Calendar name

$type

int

Principle type id

Returns

arrayArray wit data of user, principal and calendar collection.

Creates colenction and returns it data.

createCollection(array $user, string $type, string $name, string | null $privileges, bool $public_events_only, bool $publicly_readable, int | null $timezone, string $description) : array

Returns: array (size=17) 'user_no' => int 1024 'parent_container' => string '/nbdavical/' (length=11) 'dav_name' => string '/nbdavical/calendar/' (length=20) 'dav_etag' => string '-1' (length=2) 'dav_displayname' => string 'Davical User calendar' (length=21) 'is_calendar' => boolean true 'created' => string '2012-12-13 11:39:07.767205+00' (length=29) 'modified' => string '2012-12-13 11:39:07.767205+00' (length=29) 'public_events_only' => boolean false 'publicly_readable' => boolean false 'collection_id' => int 1034 'default_privileges' => null 'is_addressbook' => boolean false 'resourcetypes' => string '<DAV::collection/><urn:ietf:params:xml:ns:carddav:calendar/>' (length=60) 'schedule_transp' => string 'opaque' (length=6) 'timezone' => null 'description' => string '' (length=0)

Parameters

$user

array

Davical user data

$type

string

Collection type

$name

string

Calendars name

$privileges

stringnull

Default privileges to access calendar

$public_events_only

bool

Flag to define if calendar contains only public event

$publicly_readable

bool

Flat to define publicly readable status

$timezone

intnull

Time zone id.

$description

string

Calendar description.

Returns

array

Creates principal and dreturns principles data.

createPrincipal(array $user, int $type, $privileges) : array

Returns: array (size=5) 'principal_id' => int 1 'type_id' => int 1 'user_no' => int 1 'displayname' => string 'DAViCal Administrator' (length=21) 'default_privileges' => string '000000000000000000000000' (length=24)

pram string $privileges Default prinicpals privileges by default is read/write.

Parameters

$user

array

Array of user details.

$type

int

Principal Type id, by default principal type is person.

$privileges

Returns

arrayof prinicpal details

Creates user, principal and calendar.

createPrincipalUser(array $params, int $type) : array

Takes same parameters as $this->createUser(); Returns an array wich contains user, principal and calendar collection data. array [ 'user' => array users data, 'principal' => array principals data, ]

see \global\createUser()
see \global\createPrincipal()

Parameters

$params

array

User parameters, sames as creatUser parameters.

$type

int

Principle type id

Returns

arrayArray wit data of user, principal and calendar collection.

Create user.

createUser(array $params) : array

params: array 'active' => boolean 'email_ok' => string date time e.g.'2012-12-07 00:00:00+00' 'joined' => string date time e.g.'2012-12-07 00:00:00+00' 'updated' => string date time e.g.'2012-12-07 00:00:00+00' 'last_used' => string date time e.g.'2012-12-07 00:00:00+00' 'username' => string mandatory 'password' => string 'fullname' => string 'email' => string 'config_data' => null 'date_format_type' => string e.g. 'E' 'locale' => string e.g. 'en'

Returns: array 'user_no' => int 1 'active' => boolean true 'email_ok' => string '2012-12-07 00:00:00+00' (length=22) 'joined' => string '2012-12-07 11:49:55.231231+00' (length=29) 'updated' => string '2012-12-07 13:27:31.698669+00' (length=29) 'last_used' => string '2012-12-11 10:01:29.831451+00' (length=29) 'username' => string 'usrname' (length=7) 'password' => string 'encrypted' (length=9) 'fullname' => string 'Name susrname' (length=13) 'email' => string 'example@example.ie' (length=18) 'config_data' => null 'date_format_type' => string 'E' (length=1) 'locale' => string 'en' (length=2)

Parameters

$params

array

User parameters

Returns

arrayof user details

Get all users registered in the database as an array.

getAllUsers() : array

Returns: array (size=n) 0 => 'user_no' => int 1 'active' => boolean true 'email_ok' => string '2012-12-07 00:00:00+00' (length=22) 'joined' => string '2012-12-07 11:49:55.231231+00' (length=29) 'updated' => string '2012-12-07 13:27:31.698669+00' (length=29) 'last_used' => string '2012-12-11 10:01:29.831451+00' (length=29) 'username' => string 'usrname' (length=7) 'password' => string 'hashed' (length=9) 'fullname' => string 'Name susrname' (length=13) 'email' => string 'example@example.ie' (length=18) 'config_data' => null 'date_format_type' => string 'E' (length=1) 'locale' => string 'en' (length=2) 1 => ...

Returns

arrayAll users registered in the database

Gets calendar data by collection id

getCalendarById(int $collection_id) : array

Returns: array (size=17) 'user_no' => int 1024 'parent_container' => string '/nbdavical/' (length=11) 'dav_name' => string '/nbdavical/calendar/' (length=20) 'dav_etag' => string '-1' (length=2) 'dav_displayname' => string 'Davical User calendar' (length=21) 'is_calendar' => boolean true 'created' => string '2012-12-13 11:39:07.767205+00' (length=29) 'modified' => string '2012-12-13 11:39:07.767205+00' (length=29) 'public_events_only' => boolean false 'publicly_readable' => boolean false 'collection_id' => int 1034 'default_privileges' => null 'is_addressbook' => boolean false 'resourcetypes' => string '<DAV::collection/><urn:ietf:params:xml:ns:carddav:calendar/>' (length=60) 'schedule_transp' => string 'opaque' (length=6) 'timezone' => null 'description' => string '' (length=0)

Parameters

$collection_id

int

Calendar collection id

Returns

array

Gets calendars data by user id ( user_no )

getCalendarsByUserId(int $user_id) : array

Returns: array( size=n ) 0=> array (size=17) 'user_no' => int 1024 'parent_container' => string '/nbdavical/' (length=11) 'dav_name' => string '/nbdavical/calendar/' (length=20) 'dav_etag' => string '-1' (length=2) 'dav_displayname' => string 'Davical User calendar' (length=21) 'is_calendar' => boolean true 'created' => string '2012-12-13 11:39:07.767205+00' (length=29) 'modified' => string '2012-12-13 11:39:07.767205+00' (length=29) 'public_events_only' => boolean false 'publicly_readable' => boolean false 'collection_id' => int 1034 'default_privileges' => null 'is_addressbook' => boolean false 'resourcetypes' => string '<DAV::collection/><urn:ietf:params:xml:ns:carddav:calendar/>' (length=60) 'schedule_transp' => string 'opaque' (length=6) 'timezone' => null 'description' => string '' (length=0) 1 => array ......

Parameters

$user_id

int

Users id ( user_no )

Returns

array

Gets principals IDs which have privileges to given users principal

getGrantedToPrincipalsIds(int $user_id) : array

Return: array ( size = n ) 0 => ['to_principal' => int 1084 ] 1 => ['to_principal' => int 1084 ] ............. N => array ...

Parameters

$user_id

int

User id ( user_no )

Returns

array

Gets principal data by principal id

getPrincipalById(int $principal_id) : array

Returns: array (size=5) 'principal_id' => int 1 'type_id' => int 1 'user_no' => int 1 'displayname' => string 'DAViCal Administrator' (length=21) 'default_privileges' => string '000000000000000000000000' (length=24)

Parameters

$principal_id

int

Principal id

Returns

array

Gets principal data by user_no

getPrincipalByUserId(int $user_no) : array

Returns: array (size=5) 'principal_id' => int 1 'type_id' => int 1 'user_no' => int 1 'displayname' => string 'DAViCal Administrator' (length=21) 'default_privileges' => string '000000000000000000000000' (length=24)

Parameters

$user_no

int

User id

Returns

array

Gets shared calendars which can be accessed by user

getSharedCalendarsForUser(int $user_id) : array

Calendars with PRIVILEGES_BLOCK are ignored.

Return: array ( size = n ) 0 => array (size=25) 'by_principal' => int 1100 'by_collection' => int 1101 'to_principal' => int 1084 'privileges' => string '000000001111111011100111' (length=24) 'is_group' => null 'principal_id' => int 1084 'type_id' => int 1 'user_no' => int 1051 'displayname' => string 'Davical Box' (length=11) 'default_privileges' => null 'parent_container' => string '/sdcc@sdcc.ie/' (length=14) 'dav_name' => string '/sdcc@sdcc.ie/calendar/' (length=23) 'dav_etag' => string '-1' (length=2) 'dav_displayname' => string 'South Dublin County Council calendar' (length=36) 'is_calendar' => boolean true 'created' => string '2012-12-14 16:24:20.325642+00' (length=29) 'modified' => string '2012-12-14 16:24:20.325642+00' (length=29) 'public_events_only' => boolean false 'publicly_readable' => boolean false 'collection_id' => int 1101 'is_addressbook' => boolean false 'resourcetypes' => string '<DAV::collection/><urn:ietf:params:xml:ns:carddav:calendar/>'' (length=61) 'schedule_transp' => string 'opaque' (length=6) 'timezone' => null 'description' => string '' (length=0) 1 => array ...

Parameters

$user_id

int

User id ( user_no )

Returns

array

Gets user by Id ( user_no )

getUserById(int $user_id) : array

Returns: array (size=13) 'user_no' => int 1 'active' => boolean true 'email_ok' => string '2012-12-07 00:00:00+00' (length=22) 'joined' => string '2012-12-07 11:49:55.231231+00' (length=29) 'updated' => string '2012-12-07 13:27:31.698669+00' (length=29) 'last_used' => string '2012-12-11 10:01:29.831451+00' (length=29) 'username' => string 'usrname' (length=7) 'password' => string 'encrypted' (length=9) 'fullname' => string 'Name susrname' (length=13) 'email' => string 'example@example.ie' (length=18) 'config_data' => null 'date_format_type' => string 'E' (length=1) 'locale' => string 'en' (length=2)

Parameters

$user_id

int

User id (user_no)

Returns

array

Gets user by username

getUserByUsername(string $username) : array

Returns: array (size=13) 'user_no' => int 1 'active' => boolean true 'email_ok' => string '2012-12-07 00:00:00+00' (length=22) 'joined' => string '2012-12-07 11:49:55.231231+00' (length=29) 'updated' => string '2012-12-07 13:27:31.698669+00' (length=29) 'last_used' => string '2012-12-11 10:01:29.831451+00' (length=29) 'username' => string 'usrname' (length=7) 'password' => string 'encrypted' (length=9) 'fullname' => string 'Name susrname' (length=13) 'email' => string 'example@example.ie' (length=18) 'config_data' => null 'date_format_type' => string 'E' (length=1) 'locale' => string 'en' (length=2)

Parameters

$username

string

Username

Returns

array

Gets users who has access to shared calendar by calendar id.

getUsersForSharedCalendar(int $collection_id) : array

Users with PRIVILEGES_BLOCK are ignored.

Return: array ( size = n ) 0 => array (size=22) 'by_principal' => int 1094 'by_collection' => int 1095 'to_principal' => int 1089 'privileges' => string '000000001111111011100111' (length=24) 'is_group' => null 'principal_id' => int 1089 'type_id' => int 1 'user_no' => int 1048 'displayname' => string 'Nerijus Barauskas' (length=17) 'default_privileges' => string '000000000000000000000000' (length=24) 'active' => boolean true 'email_ok' => null 'joined' => string '2012-12-14 13:25:53.173706+00' (length=29) 'updated' => string '2012-12-14 13:25:53.173706+00' (length=29) 'last_used' => null 'username' => string 'nerijus@opensolutions.ie' (length=24) 'password' => string '**qwerty78' (length=10) 'fullname' => string 'Nerijus Barauskas' (length=17) 'email' => string 'nerijus@opensolutions.ie' (length=24) 'config_data' => null 'date_format_type' => string 'E' (length=1) 'locale' => null 1 => aray ....

Parameters

$collection_id

int

Collection id

Returns

array

Grants privileges to principal or collection

grantPrivileges(int $to_user_id, string $privileges, int $by_user_id, int $by_collection_id, bool $is_group) : bool

Grants privleges to principal if by_user_id is set or grant privileges to collection if by_collection_id is set. Users IDs should be passed, principal IDs will be loaded from database.

NOTICE: $by_user_id or $by_collection_id are mandatory params, if both is null it will thorw an Exception.

Parameters

$to_user_id

int

Users for who privleges will be grant.

$privileges

string

Privileges to grant.

$by_user_id

int

User by who privileges will be grant.

$by_collection_id

int

Collection by which privileges will be grant.

$is_group

bool

Flag if to user is group

Exceptions

\OSS_Execpion if $by_user_id and $by_collection_id is null

Returns

bool

Hash password for davical user.

hashPassword(string $password, string $method) : string
Static

It hashes three davical supported types hash: * First and most unsecured hash is plain it just add two start infont of password. * Second is md5 result is (where is a random series of characters not including '') then the rest of the string is a hash of (password + salt), i.e. a salted hash. * Third is SSHA result is is "*" and the is "{SSHA}". Read the code in /usr/share/awl/inc/AWLUtilities.php if you want to understand that format more deeply!

Parameters

$password

string

Users password to login.

$method

string

Hash method

Returns

stringreturn hashed string.

Removes calendar

removeCalendar(int $collection_id) : bool

Calls removeCollection() method

see \global\removeCollection()

Parameters

$collection_id

int

Collection id to remove

Returns

booltrue if removed.

Removes collection

removeCollection(int $collection_id) : bool

Parameters

$collection_id

int

Collection id to remove

Returns

booltrue if removed.

Remove grant privileges

removeGrantPrivileges(int $to_user_id, int $by_user_id, $by_collection_id) : bool

Grants privleges for prinicipal to collection or for principal to principal Users IDs should be passed, principal IDs will be loaded from database.

NOTICE: $by_user_id or $by_collection_id are mandatory params, if both is null it will thorw an Exception.

Parameters

$to_user_id

int

Users for who privleges will be removed.

$by_user_id

int

User by who privileges will be removed.

$by_collection_id

Exceptions

\OSS_Execpion if $by_user_id and $by_collection_id is null

Returns

bool

Removes users

removeUser(int $user_id) : bool

Parameters

$user_id

int

User id to remove (user_no)

Returns

booltrue if removed.

Sets user active state.

setUserActiveState(int $user_id, bool $active) : bool

Parameters

$user_id

int

User id ( user_no )

$active

bool

Active state true for active, false for inactive.

Returns

boolture if success

Sets user password.

setUserPassword(int $user_id, string $hashed_password) : bool

Parameters

$user_id

int

User id ( user_no )

$hashed_password

string

Hashed pasword.

Returns

boolture if success

Shares / delegates calendar

shareCalendar($user_no, $collection_id, $privileges) : bool

Then sharing calendar then function iterate all users delegate principals if new calendar's owner is already in list then it just update privileges. Otherwise it grants principal privileges to read only then iterate to all calendars and block the access for them, and finally set correct privileges to given calendar.

Parameters

$user_no

$collection_id

$privileges

Returns

bool

Unshare calendar.

unshareCalendar($user_no, $collection_id) : bool

Sets existent privileges to PRIVILEGES_BLOCK.

Parameters

$user_no

$collection_id

Returns

bool

Update grant privileges to principal or collection

updateGrantPrivileges(int $to_user_id, string $privileges, int $by_user_id, int $by_collection_id) : bool

Updated grants privleges to principal if by_user_id is set or grant privileges to collection if by_collection_id is set. Users IDs should be passed, principal IDs will be loaded from database.

NOTICE: $by_user_id or $by_collection_id are mandatory params, if both is null it will thorw an Exception.

Parameters

$to_user_id

int

Users for who privleges will be updated.

$privileges

string

Privileges to set.

$by_user_id

int

User by who privileges will be updated.

$by_collection_id

int

Collection by which privileges will be updated.

Exceptions

\OSS_Execpion if $by_user_id and $by_collection_id is null

Returns

bool

 Properties

 

Names of Privieleges

$PRIVILEGES 

 Constants

 

COLLECTION_TYPE_ADDRESSBOOK

COLLECTION_TYPE_ADDRESSBOOK 
 

Collection types

COLLECTION_TYPE_CALENDAR 
 

PASSWORD_HASH_MD5

PASSWORD_HASH_MD5 
 

PASSWORD_HASH_PLAIN

PASSWORD_HASH_PLAIN 
 

Password hashing methods

PASSWORD_HASH_SSHA 
 

PRINCIPAL_TYPE_GROUP

PRINCIPAL_TYPE_GROUP 
 

Principal type IDs

PRINCIPAL_TYPE_PERSON 
 

PRINCIPAL_TYPE_RESOURCE

PRINCIPAL_TYPE_RESOURCE 
 

PRIVILEGES_BLOCK

PRIVILEGES_BLOCK 
 

PRIVILEGES_NONE

PRIVILEGES_NONE 
 

PRIVILEGES_RO

PRIVILEGES_RO 
 

Privileges constants which refelects DAViCal database scheme

PRIVILEGES_RW