1: <?php
2: /**
3: * Basic iTip response type definition.
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: * Basic iTip response type definition.
16: *
17: * Copyright 2010 Kolab Systems AG
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: abstract class Horde_Itip_Response_Type_Base
30: implements Horde_Itip_Response_Type
31: {
32: /**
33: * The request we are going to answer.
34: *
35: * @var Horde_Itip_Event
36: */
37: private $_request;
38:
39: /**
40: * The invited resource.
41: *
42: * @var Horde_Itip_Resource
43: */
44: private $_resource;
45:
46: /**
47: * An optional comment that should appear in the response subject.
48: *
49: * @var string
50: */
51: private $_comment;
52:
53: /**
54: * Constructor.
55: *
56: * @param Horde_Itip_Resource $resource The invited resource.
57: * @param string $comment A comment for the subject line.
58: */
59: public function __construct(
60: Horde_Itip_Resource $resource,
61: $comment = null
62: )
63: {
64: $this->_resource = $resource;
65: $this->_comment = $comment;
66: }
67:
68: /**
69: * Set the request.
70: *
71: * @param Horde_Itip_Event $request The request this instance will respond
72: * to.
73: *
74: * @return NULL
75: */
76: public function setRequest(
77: Horde_Itip_Event $request
78: )
79: {
80: $this->_request = $request;
81: }
82:
83: /**
84: * Get the request for this response.
85: *
86: * @return Horde_Itip_Event The request this instance will
87: * respond to.
88: *
89: * @throws Horde_Itip_Exception If the request has not been
90: * set yet.
91: */
92: public function getRequest()
93: {
94: if (empty($this->_request)) {
95: throw new Horde_Itip_Exception(
96: 'The iTip request is still undefined!'
97: );
98: }
99: return $this->_request;
100: }
101:
102: /**
103: * Return the subject of the response without using the comment.
104: *
105: * @return string The subject.
106: */
107: public function getBriefSubject()
108: {
109: return sprintf(
110: '%s: %s',
111: $this->getShortSubject(),
112: $this->getRequest()->getSummary()
113: );
114: }
115: /**
116: * Return the subject of the response.
117: *
118: * @return string The subject.
119: */
120: public function getSubject()
121: {
122: if ($this->_comment === null) {
123: return $this->getBriefSubject();
124: } else {
125: return sprintf(
126: '%s [%s]: %s',
127: $this->getShortSubject(),
128: $this->_comment,
129: $this->getRequest()->getSummary()
130: );
131: }
132: }
133:
134: /**
135: * Return an additional message for the response.
136: *
137: * @param boolean $is_update Indicates if the request was an update.
138: *
139: * @return string The message.
140: */
141: public function getMessage($is_update = false)
142: {
143: if ($this->_comment === null) {
144: return sprintf(
145: "%s %s:\n\n%s",
146: $this->_resource->getCommonName(),
147: $this->getShortMessage($is_update),
148: $this->getRequest()->getSummary()
149: );
150: } else {
151: return sprintf(
152: "%s %s:\n\n%s\n\n%s",
153: $this->_resource->getCommonName(),
154: $this->getShortMessage($is_update),
155: $this->getRequest()->getSummary(),
156: $this->_comment
157: );
158: }
159: }
160: }