Revision: 18631 http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=18631 Author: johang Date: 2008-07-01 23:35:59 +0000 (Tue, 01 Jul 2008)
Log Message: ----------- Implemented ipc_calendar::convertData and tests for it. Modified Paths: -------------- trunk/calendar/inc/class.ipc_calendar.inc.php trunk/calendar/test/class.ipc_calendar_test.inc.php Modified: trunk/calendar/inc/class.ipc_calendar.inc.php =================================================================== --- trunk/calendar/inc/class.ipc_calendar.inc.php 2008-06-27 22:16:12 UTC (rev 18630) +++ trunk/calendar/inc/class.ipc_calendar.inc.php 2008-07-01 23:35:59 UTC (rev 18631) @@ -175,17 +175,19 @@ */ function convertData($data, $from_type, $to_type) { + // http://www.ietf.org/rfc/rfc2445.txt + /* - - http://www.ietf.org/rfc/rfc2445.txt + watch out -- there are two slightly different internal data + types. */ - // @todo - // convert from $from_type to internal switch($from_type) { case 'text/x-vcalendar': case 'text/calendar': + $internal_data = $this->convertICaltoInternal($data); break; case 'application/x-phpgw-calendar': $internal_data = $data; @@ -199,6 +201,8 @@ switch($to_type) { case 'text/x-vcalendar': case 'text/calendar': + $converted_data = $this->convertInternalToICal( + $internal_data); break; case 'application/x-phpgw-calendar': $converted_data = $internal_data; @@ -209,5 +213,104 @@ return $converted_data; } + + /** + * + */ + function convertICalToInternal($data) + { + $ical = CreateObject('phpgwapi.icalendar', array()); + + $ical->BuildFromText($data); + + if(isset($ical->properties['VCALENDAR'][0])) + { + $prop = $ical->properties['VCALENDAR'][0]; + + if(isset($prop['VEVENT'][0])) + { + $event = $prop['VEVENT'][0]; + } + else + { + return FALSE; + } + } + else + { + return FALSE; + } + + // Parse dates + + $sdate_parsed = date_parse($event['DTSTART']); + + if(isset($event['DTEND'])) + { + $edate_parsed = date_parse($event['DTEND']); + } + else if(isset($event['DURATION'])) + { + $edate_parsed = date_parse($event['DURATION']); + } + else + { + $edate_parsed = NULL; + } + + // Build array of internal data + + return array + ( + 'title' => $event['SUMMARY'], + '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'], + 'status' => $event['PERCENT-COMPLETE'], + 'pri' => $event['PRIORITY'], + 'access' => $event['CLASS'], + 'cat' => NULL, + 'parent' => NULL, + 'main' => NULL, + 'level' => NULL, + 'assigned' => NULL, + 'assigned_group' => NULL, + ); + } + + /** + * Convert internal array structure to iCalendar. + * + * @param $data array Internal array structure of a calendar event. + * @return string The calendar event in iCalendar format. + */ + function convertInternalToICal($internal_data) + { + list($syear, $smonth, $sday) = explode( + '/', $internal_data['start']['str']); + + list($eyear, $emonth, $eday) = explode( + '/', $internal_data['end']['str']); + + /* + percent-complete, priority and class seems so be missing from + + */ + + return CreateObject('phpgwapi.icalendar', array( + 'DTSTART' => sprintf('%d%d%dT000000', $syear, $smonth, $sday), + 'DTEND' => sprintf('%d%d%dT000000', $eyear, $emonth, $eday), + 'SUMMARY' => $internal_data['cal']['title'], + 'DESCRIPTION' => $internal_data['cal']['description'], + /* 'PERCENT-COMPLETE' => $internal_data['status'], + 'PRIORITY' => $internal_data['pri'], + 'CLASS' => strtoupper($internal_data['access']), */ + 'type' => 'VEVENT' + ))->render(); + } } ?> Modified: trunk/calendar/test/class.ipc_calendar_test.inc.php =================================================================== --- trunk/calendar/test/class.ipc_calendar_test.inc.php 2008-06-27 22:16:12 UTC (rev 18630) +++ trunk/calendar/test/class.ipc_calendar_test.inc.php 2008-07-01 23:35:59 UTC (rev 18631) @@ -27,7 +27,20 @@ { private $ipc; - private $sample_ical = ''; + private $sample_ical = 'BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ABC Corporation//NONSGML My Product//EN +BEGIN:VEVENT +DTSTAMP:19980130T134500Z +SEQUENCE:2 +UID:[EMAIL PROTECTED] +ORGANIZER:MAILTO:[EMAIL PROTECTED] +ATTENDEE;PARTSTAT=ACCEPTED:MAILTO:[EMAIL PROTECTED] +DTEND:19980415T235959 +STATUS:NEEDS-ACTION +SUMMARY:Submit Income Taxes +END:VEVENT +END:VCALENDAR'; private $sample_item = array( 'cal' => array( @@ -167,7 +180,7 @@ $this->sample_ical, "text/x-vcalendar", "application/x-phpgw-calendar"); - $this->assertEqual($converted_data["title"], "TITLE!"); + $this->assertEqual($converted_data["title"], "Submit Income Taxes"); // @todo test more properties } _______________________________________________ phpGroupWare-cvs mailing list phpGroupWare-cvs@gnu.org http://lists.gnu.org/mailman/listinfo/phpgroupware-cvs