1: <?php
2: /**
3: * Provides methods to retrieve free/busy data for resources.
4: *
5: * PHP version 5
6: *
7: * @todo Merge this class with Kolab_FreeBusy and Kronolith_FreeBusy into a
8: * single Horde_Freebusy handler.
9: *
10: * @category Kolab
11: * @package Kolab_Filter
12: * @author Gunnar Wrobel <wrobel@pardus.de>
13: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
14: * @link http://pear.horde.org/index.php?package=Kolab_Server
15: */
16:
17: /**
18: * Retrieves free/busy data for an email address.
19: *
20: * Copyright 2004-2010 Klarälvdalens Datakonsult AB
21: *
22: * See the enclosed file COPYING for license information (LGPL>=2.1). If you
23: * did not receive this file,
24: * see http://www.horde.org/licenses/lgpl21.
25: *
26: * @category Kolab
27: * @package Kolab_Filter
28: * @author Gunnar Wrobel <wrobel@pardus.de>
29: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
30: * @link http://pear.horde.org/index.php?package=Kolab_Server
31: */
32: class Horde_Kolab_Resource_Freebusy
33: {
34: /**
35: * Singleton instances.
36: *
37: * @var array
38: */
39: static protected $_instances = array();
40:
41: /**
42: * Class parameters.
43: *
44: * @var array
45: */
46: protected $_params;
47:
48: /**
49: * Constructor.
50: *
51: * @param array $params A hash containing any additional configuration or
52: * connection parameters a subclass might need.
53: */
54: protected function __construct($params)
55: {
56: $this->_params = $params;
57: }
58:
59: /**
60: * Attempts to return a concrete Horde_Kolab_Resource_Getfreebusy instance
61: * based on $driver.
62: *
63: * @param mixed $driver The type of concrete
64: * Horde_Kolab_Resource_Getfreebusy subclass to
65: * return.
66: * @param array $params A hash containing any additional configuration or
67: * connection parameters a subclass might need.
68: *
69: * @return Horde_Kolab_Resource_Getfreebusy The newly created concrete
70: * Horde_Kolab_Resource_Getfreebusy
71: * instance, or false an error.
72: */
73: static public function factory($driver, $params = array())
74: {
75: $driver = ucfirst(basename($driver));
76: $class = ($driver == 'None')
77: ? 'Horde_Kolab_Resource_Freebusy'
78: : 'Horde_Kolab_Resource_Freebusy_' . $driver;
79:
80: require_once dirname(__FILE__) . '/Freebusy/' . $driver . '.php';
81:
82: if (!class_exists($class)) {
83: $class = 'Horde_Kolab_Resource_Freebusy';
84: }
85:
86: return new $class($params);
87: }
88:
89: /**
90: * Attempts to return a reference to a concrete
91: * Horde_Kolab_Resource_Getfreebusy instance based on $driver.
92: *
93: * It will only create a new instance if no Horde_Kolab_Resource_Getfreebusy
94: * instance with the same parameters currently exists.
95: *
96: * This method must be invoked as:
97: * <code>$var = Horde_Kolab_Resource_Getfreebusy::singleton();</code>
98: *
99: * @param mixed $driver The type of concrete
100: * Horde_Kolab_Resource_Getfreebusy subclass to
101: * return.
102: * @param array $params A hash containing any additional configuration or
103: * connection parameters a subclass might need.
104: *
105: * @return Horde_Token The concrete Horde_Kolab_Resource_Getfreebusy
106: * reference, or false on error.
107: */
108: static public function singleton($driver = null, $params = array())
109: {
110: global $conf;
111:
112: if (isset($GLOBALS['KOLAB_FILTER_TESTING'])) {
113: $driver = 'mock';
114: $params['data'] = $GLOBALS['KOLAB_FILTER_TESTING'];
115: }
116:
117: if (empty($driver)) {
118: if (isset($conf['freebusy']['driver'])) {
119: $driver = $conf['freebusy']['driver'];
120: } else {
121: $driver = 'Kolab';
122: }
123: }
124:
125: ksort($params);
126: $sig = hash('md5', serialize(array($driver, $params)));
127:
128: if (!isset(self::$_instances[$sig])) {
129: self::$_instances[$sig] = Horde_Kolab_Resource_Freebusy::factory($driver,
130: $params);
131: }
132:
133: return self::$_instances[$sig];
134: }
135:
136: /**
137: * Retrieve Free/Busy URL for the specified resource id.
138: *
139: * @param string $resource The id of the resource (usually a mail address).
140: *
141: * @return string The Free/Busy URL for that resource.
142: */
143: protected function getUrl($resource)
144: {
145: return '';
146: }
147:
148: /**
149: * Retrieve Free/Busy data for the specified resource.
150: *
151: * @param string $resource Fetch the Free/Busy data for this resource
152: * (usually a mail address).
153: *
154: * @return Horde_Icalendar_vfreebusy The Free/Busy data.
155: */
156: public function get($resource)
157: {
158: /* Return an empty VFB object. */
159: $vCal = new Horde_Icalendar();
160: $vFb = Horde_Icalendar::newComponent('vfreebusy', $vCal);
161: $vFb->setAttribute('ORGANIZER', $resource);
162:
163: return $vFb;
164:
165: }
166: }
167: