Extend $c->default_collections - adding 'calendar_components' and 'default_properties'

'calendar_components' sets the
'urn:ietf:params:xml:ns:caldav:supported-calendar-component-set' property for
the calendar collection (used to distinguish between different type of calendar
collections, for example: todo and event calendars) the value must be a
non-empty array; allowed values: 'VEVENT', 'VTODO', 'VJOURNAL', 'VTIMEZONE',
'VFREEBUSY', 'VPOLL', 'VAVAILABILITY'
for example:
  array('VEVENT')
  array('VTODO')
  array('VEVENT', 'VTODO')
  null or undefined => all default calendar components are supported - see
    $c->default_calendar_components
NOTE: if you want to change the value of this property later, you need to do
it directly in the database ("property" table) or in the client software!

'default_properties' sets custom properties for the collection in the
"property" table the value must be a non-empty associative array of
key => value pairs (key = property name, value = property value) for example
(set the calendar color property used by Apple and other clients):
  'default_properties' => array('http://apple.com/ns/ical/:calendar-color'=>'#ff0000'),
   null or undefined   => no property is stored in the database
NOTE: if you want to change the value of this property later, you need to do
it directly in the database ("property" table) or in the client software!
This commit is contained in:
Ján Máté 2013-09-20 23:00:40 +12:00 committed by Andrew McMillan
parent fd6b10d3e2
commit 64372ba529

View File

@ -118,6 +118,43 @@ function CreateHomeCollections( $username, $defult_timezone = null ) {
if ( $qry->Exec() ) {
$c->messages[] = i18n('Home '.( $v['type']=='calendar' ? 'calendar' : 'addressbook' ).' added.');
dbg_error_log("User",":Write: Created user's home ".( $v['type']=='calendar' ? 'calendar' : 'addressbook' )." at '%s'", $params[':collection_path'] );
// create value for urn:ietf:params:xml:ns:caldav:supported-calendar-component-set property
if($v['type'] == 'calendar' && isset($v['calendar_components']) && $v['calendar_components'] != null && is_array($v['calendar_components']) && count($v['calendar_components'])) {
// convert the array to uppercase and allow only real calendar compontents
$components_clean=array_intersect(array_map("strtoupper", $v['calendar_components']), array('VEVENT', 'VTODO', 'VJOURNAL', 'VTIMEZONE', 'VFREEBUSY', 'VPOLL', 'VAVAILABILITY'));
// convert the $components_clean array to XML string
$result_xml='';
foreach($components_clean as $curr)
$result_xml.=sprintf('<comp name="%s" xmlns="urn:ietf:params:xml:ns:caldav"/>', $curr);
// handle the components XML string as user defined property (see below)
if($result_xml!='')
$v['default_properties']['urn:ietf:params:xml:ns:caldav:supported-calendar-component-set']=$result_xml;
}
// store all user defined properties (note: it also handles 'calendar_components' - see above)
if(isset($v['default_properties']) && $v['default_properties'] != null && is_array($v['default_properties']) && count($v['default_properties'])) {
$sql2='INSERT INTO property (dav_name, property_name, property_value, changed_on, changed_by) ';
$sql2.='VALUES (:collection_path, :property_name, :property_value, current_timestamp, :user_no);';
$params2[':user_no'] = $principal->user_no();
$params2[':collection_path'] = $principal->dav_name().$v['name'].'/';
foreach( $v['default_properties'] AS $key => $val ) {
$params2[':property_name'] = $key;
$params2[':property_value'] = $val;
$qry2 = new AwlQuery( $sql2, $params2 );
if ( $qry2->Exec() ) {
dbg_error_log("User",":Write: Created property '%s' for ".( $v['type']=='calendar' ? 'calendar' : 'addressbook' )." at '%s'", $params2[':property_name'], $params2[':collection_path'] );
}
else {
$c->messages[] = i18n("There was an error writing to the database.");
return false;
}
}
}
}
else {
$c->messages[] = i18n("There was an error writing to the database.");