[kronolith] Fwd: multiple backend for kronolith

Jan Schneider jan at horde.org
Mon Apr 7 16:55:17 PDT 2003



----- Weitergeleitete Nachricht von dcolens at cisco.com -----
    Datum: Mon, 07 Apr 2003 15:48:53 +0200
    Von: Didier Colens <dcolens at cisco.com>
Antwort an: dcolens at cisco.com
 Betreff: multiple backend for kronolith
      An: jan at horde.org, chuck at horde.org

Hi,


Following our discussion on the kronolith alias, I thought a bit
more to the multiple calendars with different backends, and I wrote
a fake driver able to host multiple backends, the idea is that the
driver contains an array where each key is a backend type, when the
calendar is created, it creates the calendar objects in the array.

The advantage is I don't modify your code and I can upgrade to
newer release. The problem is I did not write anything to hold the
calendar_id to backend mapping (I use some sort of static mapping
at the moment).

Not sure whether you'll find this useful or not, but it's the only
way I could find to stay compatible with newer releases of kronolith.

I attached the code.


Cheers,
Did

----- Ende der weitergeleiteten Nachricht -----


Jan.

--
http://www.horde.org - The Horde Project
http://www.ammma.de - discover your knowledge
http://www.tip4all.de - Deine private Tippgemeinschaft
-------------- next part --------------
<?php


// Trying a fake driver that can handle multiple calendar backends.


class Kronolith_Driver_multi extends Kronolith_Driver {


    var $type2cal = array(); #keys are the calendar types vals are the current calendar_id opened.
    var $_driver;


    function Kronolith_Driver_multi($params = array())
    {
	$this->_params 		= $params;
	$this->type2cal['twvt'] = &Kronolith_Driver::factory('twvt', $params);
	$this->type2cal['sql'] 	= &Kronolith_Driver::factory('sql', $params);
	$this->_driver 		= 'sql'; //Default driver is sql;
    }

    function open($calendar)
    {
    	$this->_calendar 	= $calendar;
	$this->_driver 		= $this->getCalType($calendar);
	return($this->type2cal[$this->_driver]->open($calendar));
    }

    function listAlarms($date)
    {
	return $this->type2cal[$this->_driver]->listAlarms($date);
    }

    function listEvents($startDate = null, $endDate = null, $hasAlarm = false)
    {
	return $this->type2cal[$this->_driver]->listEvents($startDate, $endDate, $hasAlarm);
    }

    function getEventObject($eventID = null)
    {
	return $this->type2cal[$this->_driver]->getEventObject($eventID);
    }

    function saveEvent($event)
    {
	//print "Driver:".$this->_driver."<br>Calendar:".$this->_calendar."<br>";
 	return $this->type2cal[$this->_driver]->saveEvent($event);
    }

    function nextRecurrence($eventID, $afterDate, $weekstart = KRONOLITH_SUNDAY)
    {
	return $this->type2cal[$this->_driver]->nextRecurrence($eventID, $afterDate, $weekstart);
    }

    function delete($calendar)
    {
	return $this->type2cal[$this->_driver]->delete($calendar);
    }

    function deleteEvent($eventID)
    {
	return $this->type2cal[$this->_driver]->deleteEvent($eventID);
    }

    function _connect()
    {
	return $this->type2cal[$this->_driver]->_connect();
    }

    function close()
    {
	//return $this->type2cal[$this->_driver]->close();
    }

    function _disconnect()
    {
	return $this->type2cal[$this->_driver]->_disconnect();
    }

    function getCalType($calendar)
    {
        // This function should return the backend used for a given 
	// calendar_id or a default backend if it could not be found.
	return('sql');
    }

}



?>


More information about the kronolith mailing list