Revision: 18628
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=18628
Author:   johang
Date:     2008-06-27 20:32:15 +0000 (Fri, 27 Jun 2008)

Log Message:
-----------
Added ipc class for calendar module

Added Paths:
-----------
    trunk/calendar/inc/class.ipc_calendar.inc.php

Added: trunk/calendar/inc/class.ipc_calendar.inc.php
===================================================================
--- trunk/calendar/inc/class.ipc_calendar.inc.php                               
(rev 0)
+++ trunk/calendar/inc/class.ipc_calendar.inc.php       2008-06-27 20:32:15 UTC 
(rev 18628)
@@ -0,0 +1,210 @@
+<?php
+       /**
+        * phpGroupWare (http://phpgroupware.org/)
+        * Calendar module
+        *
+        * @author    Johan Gunnarsson <[EMAIL PROTECTED]>
+        * @copyright Copyright (c) 2007 Free Software Foundation, Inc.
+        * @license   GNU General Public License 3 or later
+        * @package   calendar
+        * @version   $id$
+        */
+
+       phpgw::import_class('phpgwapi.ipc_');
+
+       /**
+        * IPC of the calendar application.
+        */
+       class ipc_calendar extends ipc_
+       {
+               /**
+                * @access private
+                */
+               var $bocalendar;
+
+               /**
+                * Constructor.
+                *
+                * @access public
+                */
+               function ipc_calendar()
+               {
+                       $this->bocalendar = CreateObject('calendar.bocalendar');
+               }
+
+               /**
+                * Add data in a certain mime type format to the application.
+                *
+                * @access public
+                * @param $data  Data for adding to the application, the 
datatype depends
+                *               on the mime type.
+                * @param $type  Specifies the mime type of the passed data.
+                * @return mixed ID of the added data or false on failure or 
wrong
+                *               type.
+                */
+               function addData($data, $type)
+               {
+                       $data_internal = $this->convertData($data, $type,
+                               'application/x-phpgw-calendar');
+
+                       if($data_internal)
+                       {
+                               $this->bocalendar->update($data_internal, 
FALSE);
+
+                               return 
$GLOBALS['phpgw_info']['cal_new_event_id'];
+                       }
+
+                       return FALSE;
+               }
+
+               /**
+                * Get data from the application in a certain mime type format.
+                *
+                * @param $id    ID of data to get from the application.
+                * @param $type  Specifies the mime type of the returned data.
+                * @return mixed Data from application, the datatype depends on 
the
+                *               passed mime type, false if no data exists for 
the
+                *               passed id.
+                */
+               function getData($id, $type)
+               {
+                       $internal_data = $this->bocalendar->read_entry($id);
+
+                       if($internal_data)
+                       {
+                               return $this->convertData($internal_data,
+                                       'application/x-phpgw-calendar', $type);
+                       }
+
+                       return FALSE;
+               }
+
+               /**
+                * Return a list with the available id's in the application. The
+                * optional lastmod parameter allows a limitations of the data 
id list.
+                * The list contains all the id's of the modified data since 
the passed
+                * lastmod timestamp.
+                *
+                * @param $time  Last modification time. Default is -1 which 
return
+                *               all data IDs.
+                * @return array List of data IDs.
+                */
+               function getIdList($time = -1)
+               {
+                       if($time != -1)
+                       {
+                               $date = getdate($time);
+
+                               return $this->bocalendar->list_events(
+                                       $date['year'],
+                                       $date['month'],
+                                       $date['day']);
+                       }
+
+                       return $this->bocalendar->list_events(0, 0, 0);
+               }
+
+               /**
+                * Remove data of the passed ID.
+                *
+                * @param $id      ID of data to remove from the application.
+                * @return boolean True if the data is removed, otherwise false.
+                */
+               function removeData($id)
+               {
+                       $exists = $this->existData($id);
+
+                       $d = $this->bocalendar->delete_entry($id);
+
+                       $this->bocalendar->expunge();
+
+                       return $exists;
+               }
+
+               /**
+                * Replace the existing data of the passed id with the passed 
data in
+                * a certain mime type format.
+                *
+                * @param $id      ID of data to replace.
+                * @param $data    The new data, the datatype depends on the 
passed
+                *                 mime type.
+                * @param $type    Specifies the mime type of the passed data.
+                * @return boolean True if the data is replaced, otherwise 
false.
+                */
+               function replaceData($id, $data, $type)
+               {
+                       $internal_data = $this->convertData($data, $type,
+                               'application/x-phpgw-calendar');
+
+                       if($internal_data)
+                       {
+                               $exists = $this->existData($id);
+
+                               $internal_data['cal']['id'] = $id;
+
+                               $this->bocalendar->update($internal_data);
+
+                               return $exists;
+                       }
+
+                       return FALSE;
+               }
+
+               /**
+                * Checks if data for the passed id exists.
+                *
+                * @param $id      ID to check
+                * @return boolean True if the data with id exist, otherwise 
false
+                */
+               function existData($id)
+               {
+                       return $this->bocalendar->exists($id);
+               }
+
+               /**
+                * Convert one item from one format to another.
+                *
+                * @param $data      Data to convert.
+                * @param $from_type Mime type to convert form.
+                * @param $to_type   Mime type to convert to.
+                * @return mixed     The converted data in the format specified 
by
+                *                   $to_type.
+                */
+               function convertData($data, $from_type, $to_type)
+               {
+                       /*
+                        - http://www.ietf.org/rfc/rfc2445.txt
+                       */
+
+                       // @todo
+
+                       // convert from $from_type to internal
+
+                       switch($from_type) {
+                               case 'text/x-vcalendar':
+                               case 'text/calendar':
+                                       break;
+                               case 'application/x-phpgw-calendar':
+                                       $internal_data = $data;
+                                       break;
+                               default:
+                                       return FALSE;
+                       }
+
+                       // convert from internal to $to_type
+
+                       switch($to_type) {
+                               case 'text/x-vcalendar':
+                               case 'text/calendar':
+                                       break;
+                               case 'application/x-phpgw-calendar':
+                                       $converted_data = $internal_data;
+                                       break;
+                               default:
+                                       return FALSE;
+                       }
+
+                       return $converted_data;
+               }
+       }
+?>




_______________________________________________
phpGroupWare-cvs mailing list
phpGroupWare-cvs@gnu.org
http://lists.gnu.org/mailman/listinfo/phpgroupware-cvs

Reply via email to