1: <?php
2: /**
3: * Handles iTip invitation requests/responses.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Itip
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL
11: * @link http://pear.horde.org/index.php?package=Itip
12: */
13:
14: /**
15: * Handles iTip invitation requests/responses.
16: *
17: * Copyright 2010 Klarälvdalens Datakonsult AB
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you did not
20: * receive this file, see
21: * {@link http://www.horde.org/licenses/lgpl21 LGPL}.
22: *
23: * @category Horde
24: * @package Itip
25: * @author Gunnar Wrobel <wrobel@pardus.de>
26: * @license http://www.horde.org/licenses/lgpl21 LGPL
27: * @link http://pear.horde.org/index.php?package=Itip
28: */
29: class Horde_Itip
30: {
31: /**
32: * The iTip response.
33: *
34: * @var Horde_Itip_Response
35: */
36: private $_response;
37:
38: /**
39: * Constructor.
40: *
41: * @param Horde_Itip_Response $response The iTip response.
42: */
43: public function __construct(Horde_Itip_Response $response)
44: {
45: $this->_response = $response;
46: }
47:
48: /**
49: * Return the response as an iCalendar vEvent object.
50: *
51: * @param Horde_Itip_Response_Type $type The response type.
52: *
53: * @return Horde_Icalendar_Vevent The response object.
54: */
55: public function getVeventResponse(
56: Horde_Itip_Response_Type $type
57: )
58: {
59: return $this->_response->getVevent(
60: $type, false
61: );
62: }
63:
64: /**
65: * Return the response as an iCalendar object.
66: *
67: * @param Horde_Itip_Response_Type $type The response type.
68: * @param string $product_id The ID that should be set as
69: * the iCalendar product id.
70: *
71: * @return Horde_Icalendar The response object.
72: */
73: public function getIcalendarResponse(
74: Horde_Itip_Response_Type $type,
75: $product_id
76: )
77: {
78: return $this->_response->getIcalendar(
79: $type, $product_id
80: );
81: }
82:
83: /**
84: * Send the response as a single part MIME message.
85: *
86: * @param Horde_Itip_Response_Type $type The response type.
87: * @param Horde_Itip_Response_Options $options The options for the response.
88: * @param Horde_Mail_Transport $transport The mail transport.
89: *
90: * @return array A list of two object: The mime headers and the mime
91: * message.
92: */
93: public function sendSinglepartResponse(
94: Horde_Itip_Response_Type $type,
95: Horde_Itip_Response_Options $options,
96: Horde_Mail_Transport $transport
97: )
98: {
99: list($headers, $body) = $this->_response->getMessage(
100: $type, $options
101: );
102: $body->send(
103: $this->_response->getRequest()->getOrganizer(),
104: $headers,
105: $transport
106: );
107: }
108:
109: /**
110: * Send the invitation response as a multi part MIME message.
111: *
112: * @param Horde_Itip_Response_Type $type The response type.
113: * @param Horde_Itip_Response_Options $options The options for the response.
114: * @param Horde_Mail_Transport $transport The mail transport.
115: *
116: * @return NULL
117: */
118: public function sendMultipartResponse(
119: Horde_Itip_Response_Type $type,
120: Horde_Itip_Response_Options $options,
121: Horde_Mail_Transport $transport
122: )
123: {
124: list($headers, $body) = $this->_response->getMultiPartMessage(
125: $type, $options
126: );
127: $body->send(
128: $this->_response->getRequest()->getOrganizer(),
129: $headers,
130: $transport
131: );
132: }
133:
134: /**
135: * Factory for generating a response object for an iCalendar invitation.
136: *
137: * @param Horde_Icalendar_Vevent $vevent The iCalendar request.
138: * @param Horde_Itip_Resource $resource The invited resource.
139: *
140: * @return Horde_Itip_Response The prepared response.
141: */
142: static public function prepareResponse(
143: Horde_Icalendar_Vevent $vevent,
144: Horde_Itip_Resource $resource
145: )
146: {
147: return new Horde_Itip_Response(
148: new Horde_Itip_Event_Vevent(
149: $vevent
150: ),
151: $resource
152: );
153: }
154:
155: /**
156: * Factory for generating an iTip handler for an iCalendar invitation.
157: *
158: * @param Horde_Icalendar_Vevent $vevent The iCalendar request.
159: * @param Horde_Itip_Resource $resource The invited resource.
160: *
161: * @return Horde_Itip The iTip handler.
162: */
163: static public function factory(
164: Horde_Icalendar_Vevent $vevent,
165: Horde_Itip_Resource $resource
166: )
167: {
168: return new Horde_Itip(
169: self::prepareResponse($vevent, $resource)
170: );
171: }
172: }