phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] [18620] convert to ical and updated test cases for th


From: Johan Gunnarsson
Subject: [Phpgroupware-cvs] [18620] convert to ical and updated test cases for that.
Date: Tue, 24 Jun 2008 00:11:21 +0000

Revision: 18620
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=18620
Author:   johang
Date:     2008-06-24 00:11:21 +0000 (Tue, 24 Jun 2008)

Log Message:
-----------
convert to ical and updated test cases for that.

Modified Paths:
--------------
    trunk/todo/inc/class.ipc_todo.inc.php
    trunk/todo/test/class.ipc_todo_test.inc.php

Modified: trunk/todo/inc/class.ipc_todo.inc.php
===================================================================
--- trunk/todo/inc/class.ipc_todo.inc.php       2008-06-24 00:06:27 UTC (rev 
18619)
+++ trunk/todo/inc/class.ipc_todo.inc.php       2008-06-24 00:11:21 UTC (rev 
18620)
@@ -157,48 +157,68 @@
                 */
                function convertData($data, $from_type, $to_type)
                {
+                       /*
+                        - http://www.ietf.org/rfc/rfc2445.txt
+                        - category in phpgw is integer. not directly 
transferable
+                          to vtodo. categories property is string of name.
+                       */
+
                        // convert from $from_type to internal
+                       
                        switch($from_type) {
                                case 'text/x-vcalendar':
                                case 'text/calendar':
                                        $ical = 
CreateObject('phpgwapi.icalendar', array());
                                        
                                        $ical->BuildFromText($data);
-
-                                       
if(isset($ical->properties['VCALENDAR'][0]['VTODO'][0])) {
-                                               $event = 
$ical->properties['VCALENDAR'][0]['VTODO'][0];
-                                       } else 
if(isset($ical->properties['VCALENDAR'][0]['VEVENT'][0])) {
-                                               $event = 
$ical->properties['VCALENDAR'][0]['VEVENT'][0];
-                                       } else {
-                                               // neither vevent nor vtodo 
found
+                                       
+                                       
if(isset($ical->properties['VCALENDAR'][0]))
+                                       {
+                                               $prop = 
$ical->properties['VCALENDAR'][0];
+                                               
+                                               if(isset($prop['VTODO'][0]))
+                                               {
+                                                       $event = 
$prop['VTODO'][0];
+                                               }
+                                               else 
if(isset($prop['VEVENT'][0]))
+                                               {
+                                                       $event = 
$prop['VEVENT'][0];
+                                               }
+                                               else
+                                               {
+                                                       return FALSE;
+                                               }
+                                       }
+                                       else
+                                       {
                                                return FALSE;
                                        }
+                                       
+                                       // Parse dates
 
-                                       $sdate_parsed = 
date_parse($event['DTSTAMP']);
+                                       $sdate_parsed = 
date_parse($event['DTSTART']);
                                        $edate_parsed = 
date_parse($event['DUE']);
+                                       
+                                       // Build array of internal data
 
-                                       // there's stuff in ical that's not 
possible to translate
-                                       // to phpgw.
-
                                        $internal_data = array(
                                                'title' => $event['SUMMARY'],
-                                               'descr' => '',
+                                               'descr' => 
$event['DESCRIPTION'],
                                                'syear' => 
$sdate_parsed['year'],
                                                'smonth' => 
$sdate_parsed['month'],
                                                'sday' => $sdate_parsed['day'],
                                                'eyear' => 
$edate_parsed['year'],
                                                'emonth' => 
$edate_parsed['month'],
                                                'eday' => $edate_parsed['day'],
-                                               'daysfromstart' => 0,
-                                               'status' => '100',
-                                               'pri' => '0',
-                                               'access' => 'private',
-                                               'cat' => 0,
-                                               'parent' => 0,
-                                               'main' => 0,
-                                               'level' => 0,
-                                               'assigned' => 0,
-                                               'assigned_group' => 0,
+                                               'status' => 
$event['PERCENT-COMPLETE'],
+                                               'pri' => $event['PRIORITY'],
+                                               'access' => $event['CLASS'],
+                                               'cat' => NULL,
+                                               'parent' => NULL,
+                                               'main' => NULL,
+                                               'level' => NULL,
+                                               'assigned' => NULL,
+                                               'assigned_group' => NULL,
                                        );
                                        
                                        break;
@@ -210,14 +230,30 @@
                        }
                        
                        // convert from internal to $to_type
+                       
                        switch($to_type) {
                                case 'text/x-vcalendar':
                                case 'text/calendar':
-                                       $ical = 
CreateObject('phpgwapi.icalendar', array());
-
-                                       // TODO
-
-                                       $converted_data = $internal_data;
+                                       $converted_data = 
CreateObject('phpgwapi.icalendar', array(
+                                               'DTSTART' => sprintf(
+                                                       '%d%d%dT000000',
+                                                       $internal_data['syear'],
+                                                       
$internal_data['smonth'],
+                                                       $internal_data['sday']),
+                                               'DUE' => sprintf(
+                                                       '%d%d%dT000000',
+                                                       $internal_data['eyear'],
+                                                       
$internal_data['emonth'],
+                                                       $internal_data['eday']),
+                                               'SUMMARY' => 
$internal_data['title'],
+                                               'DESCRIPTION' => 
$internal_data['descr'],
+                                               'PERCENT-COMPLETE' => 
$internal_data['status'],
+                                               'PRIORITY' => 
$internal_data['pri'],
+                                               'CLASS' => 
strtoupper($internal_data['access']),
+                                               
+                                               'type' => 'VTODO'
+                                       ))->render();
+                                       
                                        break;
                                case 'application/x-phpgw-todo':
                                        $converted_data = $internal_data;

Modified: trunk/todo/test/class.ipc_todo_test.inc.php
===================================================================
--- trunk/todo/test/class.ipc_todo_test.inc.php 2008-06-24 00:06:27 UTC (rev 
18619)
+++ trunk/todo/test/class.ipc_todo_test.inc.php 2008-06-24 00:11:21 UTC (rev 
18620)
@@ -174,7 +174,7 @@
                        $this->assertFalse($this->ipc->existData($id));
                }
                
-               function test_convertData_to_ical_1()
+               function test_convertData_from_ical_1()
                {
                        $converted_data = $this->ipc->convertData(
                                $this->sample_ical, "text/x-vcalendar",
@@ -185,13 +185,14 @@
                        // @todo test more properties
                }
                
-               function test_convertData_from_ical_1()
+               function test_convertData_to_ical_1()
                {
                        $converted_data = $this->ipc->convertData(
                                $this->sample_item, "application/x-phpgw-todo",
                                "text/x-vcalendar");
                        
-                       $this->assertEqual($converted_data["summary"], "a test 
...");
+                       $this->assertTrue(strpos($converted_data,
+                               'SUMMARY:a test') !== FALSE);
                        
                        // @todo test more properties
                }






reply via email to

[Prev in Thread] Current Thread [Next in Thread]