3 commits - plugins/calendar plugins/libkolab

Thomas Brüderli bruederli at kolabsys.com
Thu Feb 21 17:35:49 CET 2013


 plugins/calendar/lib/calendar_ical.php                 |    4 -
 plugins/libkolab/lib/kolab_format.php                  |   61 +++++++++++++++--
 plugins/libkolab/lib/kolab_format_contact.php          |   26 +------
 plugins/libkolab/lib/kolab_format_distributionlist.php |   19 +----
 plugins/libkolab/lib/kolab_format_event.php            |    4 -
 plugins/libkolab/lib/kolab_format_file.php             |   17 +---
 plugins/libkolab/lib/kolab_format_journal.php          |   20 +----
 plugins/libkolab/lib/kolab_format_note.php             |   20 +----
 plugins/libkolab/lib/kolab_format_task.php             |    4 -
 plugins/libkolab/lib/kolab_format_xcal.php             |   24 ++----
 10 files changed, 90 insertions(+), 109 deletions(-)

New commits:
commit e1b78250da25f12e856f36ee3eee40e97bd5043a
Merge: c32e3a7 5e9256e
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Thu Feb 21 17:34:25 2013 +0100

    Merge branch 'master' of ssh://git.kolab.org/git/roundcubemail-plugins-kolab



commit c32e3a7dbe56817826c368a30c29e0e86b024dc0
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Thu Feb 21 17:33:17 2013 +0100

    Fix typos and read STATUS:CANCELLED

diff --git a/plugins/calendar/lib/calendar_ical.php b/plugins/calendar/lib/calendar_ical.php
index cec2040..0fea74e 100644
--- a/plugins/calendar/lib/calendar_ical.php
+++ b/plugins/calendar/lib/calendar_ical.php
@@ -205,7 +205,9 @@ class calendar_ical
         
         case 'STATUS':
           if ($attr['value'] == 'TENTATIVE')
-            $event['free_busy'] == 'tentative';
+            $event['free_busy'] = 'tentative';
+          else if ($attr['value'] == 'CANCELLED')
+            $event['cancelled'] = true;
           break;
         
         case 'PRIORITY':


commit 97d0c57eee47328692c8283fc98e1183267b7ed7
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Thu Feb 21 16:28:12 2013 +0100

    Small refactoring: use base class methods to read/set common properties; add support for custom properties in all objects

diff --git a/plugins/libkolab/lib/kolab_format.php b/plugins/libkolab/lib/kolab_format.php
index 601d366..809fb29 100644
--- a/plugins/libkolab/lib/kolab_format.php
+++ b/plugins/libkolab/lib/kolab_format.php
@@ -381,12 +381,33 @@ abstract class kolab_format
      *
      * @param array  Object data as hash array
      */
-    abstract public function set(&$object);
+    public function set(&$object)
+    {
+        $this->init();
 
-    /**
-     *
-     */
-    abstract public function is_valid();
+        if (!empty($object['uid']))
+            $this->obj->setUid($object['uid']);
+
+        // set some automatic values if missing
+        if (method_exists($this->obj, 'setCreated') && !$this->obj->created()) {
+            if (empty($object['created']))
+                $object['created'] = new DateTime('now', self::$timezone);
+            $this->obj->setCreated(self::get_datetime($object['created']));
+        }
+
+        $object['changed'] = new DateTime('now', self::$timezone);
+        $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
+
+        // Save custom properties of the given object
+        if (!empty($object['x-custom'])) {
+            $vcustom = new vectorcs;
+            foreach ($object['x-custom'] as $cp) {
+                if (is_array($cp))
+                    $vcustom->push(new CustomProperty($cp[0], $cp[1]));
+            }
+            $this->obj->setCustomProperties($vcustom);
+        }
+    }
 
     /**
      * Convert the Kolab object into a hash array data structure
@@ -395,7 +416,35 @@ abstract class kolab_format
      *
      * @return array  Kolab object data as hash array
      */
-    abstract public function to_array($data = array());
+    public function to_array($data = array())
+    {
+        $this->init();
+
+        // read object properties into local data object
+        $object = array(
+            'uid'     => $this->obj->uid(),
+            'changed' => self::php_datetime($this->obj->lastModified()),
+        );
+
+        // not all container support the created property
+        if (method_exists($this->obj, 'created')) {
+            $object['created'] = self::php_datetime($this->obj->created());
+        }
+
+        // read custom properties
+        $vcustom = $this->obj->customProperties();
+        for ($i=0; $i < $vcustom->size(); $i++) {
+            $cp = $vcustom->get($i);
+            $object['x-custom'][] = array($cp->identifier, $cp->value);
+        }
+
+        return $object;
+    }
+
+    /**
+     * Object validation method to be implemented by derived classes
+     */
+    abstract public function is_valid();
 
     /**
      * Callback for kolab_storage_cache to get object specific tags to cache
diff --git a/plugins/libkolab/lib/kolab_format_contact.php b/plugins/libkolab/lib/kolab_format_contact.php
index 7994b97..e816294 100644
--- a/plugins/libkolab/lib/kolab_format_contact.php
+++ b/plugins/libkolab/lib/kolab_format_contact.php
@@ -85,20 +85,8 @@ class kolab_format_contact extends kolab_format
      */
     public function set(&$object)
     {
-        $this->init();
-
-        // set some automatic values if missing
-        if (false && !$this->obj->created()) {
-            if (!empty($object['created']))
-                $object['created'] = new DateTime('now', self::$timezone);
-            $this->obj->setCreated(self::get_datetime($object['created']));
-        }
-
-        if (!empty($object['uid']))
-            $this->obj->setUid($object['uid']);
-
-        $object['changed'] = new DateTime('now', self::$timezone);
-        $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
+        // set common object properties
+        parent::set($object);
 
         // do the hard work of setting object values
         $nc = new NameComponents;
@@ -276,14 +264,10 @@ class kolab_format_contact extends kolab_format
         if (!empty($this->data))
             return $this->data;
 
-        $this->init();
+        // read common object props into local data object
+        $object = parent::to_array();
 
-        // read object properties into local data object
-        $object = array(
-            'uid'       => $this->obj->uid(),
-            'name'      => $this->obj->name(),
-            'changed'   => self::php_datetime($this->obj->lastModified()),
-        );
+        $object['name'] = $this->obj->name();
 
         $nc = $this->obj->nameComponents();
         $object['surname']    = join(' ', self::vector2array($nc->surnames()));
diff --git a/plugins/libkolab/lib/kolab_format_distributionlist.php b/plugins/libkolab/lib/kolab_format_distributionlist.php
index f91f697..d25bd47 100644
--- a/plugins/libkolab/lib/kolab_format_distributionlist.php
+++ b/plugins/libkolab/lib/kolab_format_distributionlist.php
@@ -39,14 +39,8 @@ class kolab_format_distributionlist extends kolab_format
      */
     public function set(&$object)
     {
-        $this->init();
-
-        // set some automatic values if missing
-        if (!empty($object['uid']))
-            $this->obj->setUid($object['uid']);
-
-        $object['changed'] = new DateTime('now', self::$timezone);
-        $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
+        // set common object properties
+        parent::set($object);
 
         $this->obj->setName($object['name']);
 
@@ -93,12 +87,11 @@ class kolab_format_distributionlist extends kolab_format
         if (!empty($this->data))
             return $this->data;
 
-        $this->init();
+        // read common object props into local data object
+        $object = parent::to_array();
 
-        // read object properties
-        $object = array(
-            'uid'       => $this->obj->uid(),
-            'changed'   => self::php_datetime($this->obj->lastModified()),
+        // add object properties
+        $object += array(
             'name'      => $this->obj->name(),
             'member'    => array(),
             '_type'     => 'distribution-list',
diff --git a/plugins/libkolab/lib/kolab_format_event.php b/plugins/libkolab/lib/kolab_format_event.php
index d750f8e..6b1db88 100644
--- a/plugins/libkolab/lib/kolab_format_event.php
+++ b/plugins/libkolab/lib/kolab_format_event.php
@@ -61,8 +61,6 @@ class kolab_format_event extends kolab_format_xcal
      */
     public function set(&$object)
     {
-        $this->init();
-
         // set common xcal properties
         parent::set($object);
 
@@ -116,8 +114,6 @@ class kolab_format_event extends kolab_format_xcal
         if (!empty($this->data))
             return $this->data;
 
-        $this->init();
-
         // read common xcal props
         $object = parent::to_array();
 
diff --git a/plugins/libkolab/lib/kolab_format_file.php b/plugins/libkolab/lib/kolab_format_file.php
index 22d1e7c..191c7fe 100644
--- a/plugins/libkolab/lib/kolab_format_file.php
+++ b/plugins/libkolab/lib/kolab_format_file.php
@@ -44,14 +44,9 @@ class kolab_format_file extends kolab_format
      */
     public function set(&$object)
     {
-        $this->init();
+        // set common object properties
+        parent::set($object);
 
-        // set some automatic values if missing
-        if (!empty($object['uid']))
-            $this->obj->setUid($object['uid']);
-
-        $object['changed'] = new DateTime('now', self::$timezone);
-        $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
         $this->obj->setClassification($this->sensitivity_map[$object['sensitivity']]);
         $this->obj->setCategories(self::array2vector($object['categories']));
 
@@ -106,15 +101,13 @@ class kolab_format_file extends kolab_format
         if (!empty($this->data))
             return $this->data;
 
-        $this->init();
+        // read common object props into local data object
+        $object = parent::to_array();
 
         $sensitivity_map = array_flip($this->sensitivity_map);
 
         // read object properties
-        $object = array(
-            'uid'         => $this->obj->uid(),
-            'created'     => self::php_datetime($this->obj->created()),
-            'changed'     => self::php_datetime($this->obj->lastModified()),
+        $object += array(
             'sensitivity' => $sensitivity_map[$this->obj->classification()],
             'categories'  => self::vector2array($this->obj->categories()),
             'notes'       => $this->obj->note(),
diff --git a/plugins/libkolab/lib/kolab_format_journal.php b/plugins/libkolab/lib/kolab_format_journal.php
index 01cdc3d..3528d16 100644
--- a/plugins/libkolab/lib/kolab_format_journal.php
+++ b/plugins/libkolab/lib/kolab_format_journal.php
@@ -39,14 +39,8 @@ class kolab_format_journal extends kolab_format
      */
     public function set(&$object)
     {
-        $this->init();
-
-        // set some automatic values if missing
-        if (!empty($object['uid']))
-            $this->obj->setUid($object['uid']);
-
-        $object['changed'] = new DateTime('now', self::$timezone);
-        $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
+        // set common object properties
+        parent::set($object);
 
         // TODO: set object propeties
 
@@ -76,14 +70,8 @@ class kolab_format_journal extends kolab_format
         if (!empty($this->data))
             return $this->data;
 
-        $this->init();
-
-        // read object properties
-        $object = array(
-            'uid'     => $this->obj->uid(),
-            'created' => self::php_datetime($this->obj->created()),
-            'changed' => self::php_datetime($this->obj->lastModified()),
-        );
+        // read common object props into local data object
+        $object = parent::to_array();
 
         // TODO: read object properties
 
diff --git a/plugins/libkolab/lib/kolab_format_note.php b/plugins/libkolab/lib/kolab_format_note.php
index 5a9c0bc..cee6345 100644
--- a/plugins/libkolab/lib/kolab_format_note.php
+++ b/plugins/libkolab/lib/kolab_format_note.php
@@ -39,14 +39,8 @@ class kolab_format_note extends kolab_format
      */
     public function set(&$object)
     {
-        $this->init();
-
-        // set some automatic values if missing
-        if (!empty($object['uid']))
-            $this->obj->setUid($object['uid']);
-
-        $object['changed'] = new DateTime('now', self::$timezone);
-        $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
+        // set common object properties
+        parent::set($object);
 
         // TODO: set object propeties
 
@@ -76,14 +70,8 @@ class kolab_format_note extends kolab_format
         if (!empty($this->data))
             return $this->data;
 
-        $this->init();
-
-        // read object properties
-        $object = array(
-            'uid'       => $this->obj->uid(),
-            'created'   => self::php_datetime($this->obj->created()),
-            'changed'   => self::php_datetime($this->obj->lastModified()),
-        );
+        // read common object props into local data object
+        $object = parent::to_array();
 
         // TODO: read object properties
 
diff --git a/plugins/libkolab/lib/kolab_format_task.php b/plugins/libkolab/lib/kolab_format_task.php
index d66cafd..0fa2806 100644
--- a/plugins/libkolab/lib/kolab_format_task.php
+++ b/plugins/libkolab/lib/kolab_format_task.php
@@ -38,8 +38,6 @@ class kolab_format_task extends kolab_format_xcal
      */
     public function set(&$object)
     {
-        $this->init();
-
         // set common xcal properties
         parent::set($object);
 
@@ -81,8 +79,6 @@ class kolab_format_task extends kolab_format_xcal
         if (!empty($this->data))
             return $this->data;
 
-        $this->init();
-
         // read common xcal props
         $object = parent::to_array();
 
diff --git a/plugins/libkolab/lib/kolab_format_xcal.php b/plugins/libkolab/lib/kolab_format_xcal.php
index a6450af..b3d3c27 100644
--- a/plugins/libkolab/lib/kolab_format_xcal.php
+++ b/plugins/libkolab/lib/kolab_format_xcal.php
@@ -94,13 +94,13 @@ abstract class kolab_format_xcal extends kolab_format
      */
     public function to_array($data = array())
     {
+        // read common object props
+        $object = parent::to_array();
+
         $status_map = array_flip($this->status_map);
         $sensitivity_map = array_flip($this->sensitivity_map);
 
-        $object = array(
-            'uid'         => $this->obj->uid(),
-            'created'     => self::php_datetime($this->obj->created()),
-            'changed'     => self::php_datetime($this->obj->lastModified()),
+        $object += array(
             'sequence'    => intval($this->obj->sequence()),
             'title'       => $this->obj->summary(),
             'location'    => $this->obj->location(),
@@ -216,20 +216,12 @@ abstract class kolab_format_xcal extends kolab_format
      */
     public function set(&$object)
     {
-        $is_new = !$this->obj->uid();
+        $this->init();
 
-        // set some automatic values if missing
-        if (!$this->obj->created()) {
-            if (!empty($object['created']))
-                $object['created'] = new DateTime('now', self::$timezone);
-            $this->obj->setCreated(self::get_datetime($object['created']));
-        }
-
-        if (!empty($object['uid']))
-            $this->obj->setUid($object['uid']);
+        $is_new = !$this->obj->uid();
 
-        $object['changed'] = new DateTime('now', self::$timezone);
-        $this->obj->setLastModified(self::get_datetime($object['changed'], new DateTimeZone('UTC')));
+        // set common object properties
+        parent::set($object);
 
         // increment sequence on updates
         $object['sequence'] = !$is_new ? $this->obj->sequence()+1 : 0;





More information about the commits mailing list