From 55f4540e81759f6df9268ffec6932f08c24c4413 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Wed, 17 Jun 2009 12:06:24 +0200
Subject: [PATCH] Allow to return dates formatted as Horde_Date.
---
.../Kolab_Server/lib/Horde/Kolab/Server/Object.php | 46 +++++++++++++++++++++-
.../Kolab/Server/Object/Kolabinetorgperson.php | 14 +++++++
framework/Kolab_Server/package.xml | 4 ++
.../test/Horde/Kolab/Server/PersonTest.php | 24 +++++++++++
4 files changed, 87 insertions(+), 1 deletion(-)
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php
index 063b8e01c..2e541bf95 100644
--- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php
+++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php
@@ -45,6 +45,15 @@ class Horde_Kolab_Server_Object
/** The time the object was created */
const ATTRIBUTE_CREATIONDATE = 'createTimestamp';
+ /** The time the object was last modified */
+ const ATTRIBUTE_MODIFICATIONDATE = 'modifyTimestamp';
+
+ /** The time the object was created */
+ const ATTRDATE_CREATIONDATE = 'createTimestampDate';
+
+ /** The time the object was last modified */
+ const ATTRDATE_MODIFICATIONDATE = 'modifyTimestampDate';
+
/** Access rules for this object */
const ATTRIBUTE_ACI = 'OpenLDAPaci';
@@ -127,6 +136,7 @@ class Horde_Kolab_Server_Object
'defined' => array(
self::ATTRIBUTE_OC,
self::ATTRIBUTE_CREATIONDATE,
+ self::ATTRIBUTE_MODIFICATIONDATE,
self::ATTRIBUTE_ACI,
),
/**
@@ -139,6 +149,18 @@ class Horde_Kolab_Server_Object
self::ATTRIBUTE_ID => array(
'method' => 'getId',
),
+ self::ATTRDATE_CREATIONDATE => array(
+ 'method' => 'getDate',
+ 'args' => array(
+ self::ATTRIBUTE_CREATIONDATE,
+ ),
+ ),
+ self::ATTRDATE_MODIFICATIONDATE => array(
+ 'method' => 'getDate',
+ 'args' => array(
+ self::ATTRIBUTE_MODIFICATIONDATE,
+ ),
+ ),
),
/**
* Attributes that are written using the information from several other
@@ -564,6 +586,26 @@ class Horde_Kolab_Server_Object
}
/**
+ * Get a derived attribute date by converting it into a Horde_Date object.
+ *
+ * @param string $key Name of the attribute that holds the
+ * date.
+ *
+ * @return mixed A Horde_Date object or false if the date was not
+ * converted successfully.
+ */
+ protected function getDate($key)
+ {
+ $date = $this->_get($key);
+ if (empty($date) || !class_exists('Horde_Date')) {
+ return false;
+ }
+
+ $result = new Horde_Date($date);
+ return $result;
+ }
+
+ /**
* Set a collapsed attribute value.
*
* @param string $key The attribute to collapse into.
@@ -923,7 +965,9 @@ class Horde_Kolab_Server_Object
}
}
- $changes['attributes'] = array_unique($changes['attributes']);
+ if (!empty($changes['attributes'])) {
+ $changes['attributes'] = array_unique($changes['attributes']);
+ }
return $changes;
}
diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php
index 9b25c367e..c5caf908c 100644
--- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php
+++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Kolabinetorgperson.php
@@ -86,6 +86,9 @@ class Horde_Kolab_Server_Object_Kolabinetorgperson extends Horde_Kolab_Server_Ob
/** The date of birth */
const ATTRIBUTE_DATEOFBIRTH = 'apple-birthday';
+ /** The date of birth as Horde_Date */
+ const ATTRDATE_DATEOFBIRTH = 'apple-birthdayDate';
+
/** The place of birth */
const ATTRIBUTE_PLACEOFBIRTH = 'birthPlace';
@@ -202,6 +205,17 @@ class Horde_Kolab_Server_Object_Kolabinetorgperson extends Horde_Kolab_Server_Ob
'locked' => array(
self::ATTRIBUTE_MAIL,
),
+ /**
+ * Derived attributes are calculated based on other attribute values.
+ */
+ 'derived' => array(
+ self::ATTRDATE_DATEOFBIRTH => array(
+ 'method' => 'getDate',
+ 'args' => array(
+ self::ATTRIBUTE_DATEOFBIRTH,
+ ),
+ ),
+ ),
'object_classes' => array(
self::OBJECTCLASS_KOLABINETORGPERSON,
),
diff --git a/framework/Kolab_Server/package.xml b/framework/Kolab_Server/package.xml
index 7c3823578..bd754e0cc 100644
--- a/framework/Kolab_Server/package.xml
+++ b/framework/Kolab_Server/package.xml
@@ -159,6 +159,10 @@ http://pear.php.net/dtd/package-2.0.xsd">