phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] [18614] First step in transition to libawl.


From: Johan Gunnarsson
Subject: [Phpgroupware-cvs] [18614] First step in transition to libawl.
Date: Mon, 16 Jun 2008 22:17:49 +0000

Revision: 18614
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=18614
Author:   johang
Date:     2008-06-16 22:17:45 +0000 (Mon, 16 Jun 2008)

Log Message:
-----------
First step in transition to libawl.

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

Modified: trunk/todo/inc/class.ipc_todo.inc.php
===================================================================
--- trunk/todo/inc/class.ipc_todo.inc.php       2008-06-16 22:14:39 UTC (rev 
18613)
+++ trunk/todo/inc/class.ipc_todo.inc.php       2008-06-16 22:17:45 UTC (rev 
18614)
@@ -1,14 +1,17 @@
 <?php
        /**
-        * Todo IPC
+        * phpGroupWare (http://phpgroupware.org/)
+        * Todo module
         *
         * @author    Johan Gunnarsson <address@hidden>
         * @copyright Copyright (c) 2007 Free Software Foundation, Inc.
         * @license   GNU General Public License 3 or later
         * @package   todo
-        * @version   $ $
+        * @version   $id$
         */
-
+       
+       phpgw::import_class('phpgwapi.ipc_');
+       
        /**
         * IPC of the todo application.
         */
@@ -20,13 +23,6 @@
                var $botodo;
 
                /**
-                * {i,v}Calendar convertion.
-                *
-                * @access private
-                */
-               var $bo_ical;
-
-               /**
                 * Constructor.
                 *
                 * @access public
@@ -34,52 +30,32 @@
                function ipc_todo()
                {
                        $this->botodo = CreateObject('todo.botodo');
-
-                       $this->bo_ical = CreateObject('calendar.boicalendar');
                }
 
                /**
                 * 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 int  ID of the added data.
+                * @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)
-               {
-                       switch($type)
+               {
+                       $data_internal = $this->convertData($data, $type,
+                               'application/x-phpgw-todo');
+                       
+                       if($data_internal)
                        {
-                               case 'text/x-vcalendar':
-                               case 'text/calendar':
-                                       $x = $this->bo_ical->parse($data, 
$type);
-                                       break;
-                               default:
-                                       return FALSE;
+                               return $this->botodo->save($data_internal);
                        }
                        
-                       var_dump($x);
-                       
-                       // return $this->botodo->save($item);
+                       return FALSE;
                }
 
                /**
-                * Convert data from a mime type to another.
-                *
-                * @access         public
-                * @param $data    Data for converting, the datatype depends on 
the
-                *                 input mime type.
-                * @param $typeIn  Specifies the input mime type of the passed 
data.
-                * @param $typeOut Specifies the output mime type of the passed 
data.
-                * @return string  Converted data from application, the datatype
-                *                 depends on the passed output mime type.
-                */
-               function convertData($data, $typeIn, $typeOut)
-               {
-               }
-
-               /**
                 * Get data from the application in a certain mime type format.
                 *
                 * @param $id    ID of data to get from the application.
@@ -90,6 +66,15 @@
                 */
                function getData($id, $type)
                {
+                       $internal_data = $this->botodo->read($id);
+                       
+                       if($internal_data)
+                       {
+                               return $this->convertData($internal_data,
+                                       'application/x-phpgw-todo', $type);
+                       }
+                       
+                       return FALSE;
                }
 
                /**
@@ -102,21 +87,15 @@
                 *               all data IDs.
                 * @return array List of data IDs.
                 */
-               function getIdList($time=-1)
+               function getIdList($time = -1)
                {
-                       $all_notes = $this->bonotes->sonotes->read(array());
-                       $note_count = count($all_notes);
-                       $all_note_ids = array();
-
-                       for($i = 0; $i < $note_count; $i++)
-                       {
-                               if($all_notes[$i]['date'] > $time)
-                               {
-                                       $all_note_ids[] = 
intval($all_notes[$i]['note_id']);
-                               }
+                       function extract_id($todo) {
+                               return (int)$todo['id'];
                        }
-
-                       return $all_note_ids;
+                       
+                       $list = $this->botodo->_list();
+                       
+                       return array_map('extract_id', $list);
                }
 
                /**
@@ -142,6 +121,17 @@
                 */
                function replaceData($id, $data, $type)
                {
+                       $internal_data = $this->convertData($data, $type,
+                               'application/x-phpgw-todo');
+                       
+                       if($internal_data)
+                       {
+                               $internal_data['id'] = $id;
+                               
+                               return $this->botodo->save($internal_data);
+                       }
+                       
+                       return FALSE;
                }
 
                /**
@@ -152,7 +142,90 @@
                 */
                function existData($id)
                {
-                       return !is_null($this->bonotes->read_single($id));
+                       return $this->bonotes->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)
+               {
+                       // 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
+                                               return FALSE;
+                                       }
+
+                                       $sdate_parsed = 
date_parse($event['DTSTAMP']);
+                                       $edate_parsed = 
date_parse($event['DUE']);
+
+                                       // there's stuff in ical that's not 
possible to translate
+                                       // to phpgw.
+
+                                       $internal_data = array(
+                                               'title' => $event['SUMMARY'],
+                                               'descr' => '',
+                                               '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,
+                                       );
+                                       
+                                       break;
+                               case 'application/x-phpgw-todo':
+                                       $internal_data = $data;
+                                       break;
+                               default:
+                                       return FALSE;
+                       }
+                       
+                       // 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;
+                                       break;
+                               case 'application/x-phpgw-todo':
+                                       $converted_data = $internal_data;
+                                       break;
+                               default:
+                                       return FALSE;
+                       }
+                       
+                       return $converted_data;
+               }
        }
 ?>






reply via email to

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