1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Kronolith_Event_Sql extends Kronolith_Event
14: {
15: 16: 17: 18: 19:
20: public $calendarType = 'internal';
21:
22: 23: 24: 25: 26: 27: 28: 29:
30: public function __construct($driver, $eventObject = null)
31: {
32:
33: if (!isset($alarm) && isset($GLOBALS['prefs'])) {
34: $this->alarm = $GLOBALS['prefs']->getValue('default_alarm');
35: }
36:
37: parent::__construct($driver, $eventObject);
38:
39: if (!empty($this->calendar) &&
40: isset($GLOBALS['all_calendars'][$this->calendar])) {
41: $this->_backgroundColor = $GLOBALS['all_calendars'][$this->calendar]->background();
42: $this->_foregroundColor = $GLOBALS['all_calendars'][$this->calendar]->foreground();
43: }
44: }
45:
46: 47: 48: 49: 50: 51:
52: public function fromDriver($SQLEvent)
53: {
54: $driver = $this->getDriver();
55:
56: $this->allday = (bool)$SQLEvent['event_allday'];
57: if (!$this->allday && $driver->getParam('utc')) {
58: $tz_local = date_default_timezone_get();
59: $this->start = new Horde_Date($SQLEvent['event_start'], 'UTC');
60: $this->start->setTimezone($tz_local);
61: $this->end = new Horde_Date($SQLEvent['event_end'], 'UTC');
62: $this->end->setTimezone($tz_local);
63: } else {
64: $this->start = new Horde_Date($SQLEvent['event_start']);
65: $this->end = new Horde_Date($SQLEvent['event_end']);
66: }
67:
68: $this->durMin = ($this->end->timestamp() - $this->start->timestamp()) / 60;
69:
70: $this->title = $driver->convertFromDriver($SQLEvent['event_title']);
71: $this->id = $SQLEvent['event_id'];
72: $this->uid = $SQLEvent['event_uid'];
73: $this->creator = $SQLEvent['event_creator_id'];
74:
75: if (!empty($SQLEvent['event_recurtype'])) {
76: $this->recurrence = new Horde_Date_Recurrence($this->start);
77: $this->recurrence->setRecurType((int)$SQLEvent['event_recurtype']);
78: $this->recurrence->setRecurInterval((int)$SQLEvent['event_recurinterval']);
79: if (isset($SQLEvent['event_recurenddate']) &&
80: $SQLEvent['event_recurenddate'] != '9999-12-31 23:59:59') {
81: if ($driver->getParam('utc')) {
82: $recur_end = new Horde_Date($SQLEvent['event_recurenddate'], 'UTC');
83: if ($recur_end->min == 0) {
84:
85: $recur_end = new Horde_Date($SQLEvent['event_recurenddate']);
86: $recur_end->hour = 23;
87: $recur_end->min = 59;
88: $recur_end->sec = 59;
89: } else {
90: $recur_end->setTimezone(date_default_timezone_get());
91: }
92: } else {
93: $recur_end = new Horde_Date($SQLEvent['event_recurenddate']);
94: $recur_end->hour = 23;
95: $recur_end->min = 59;
96: $recur_end->sec = 59;
97: }
98: $this->recurrence->setRecurEnd($recur_end);
99: }
100: if (isset($SQLEvent['event_recurcount'])) {
101: $this->recurrence->setRecurCount((int)$SQLEvent['event_recurcount']);
102: }
103: if (isset($SQLEvent['event_recurdays'])) {
104: $this->recurrence->recurData = (int)$SQLEvent['event_recurdays'];
105: }
106: if (!empty($SQLEvent['event_exceptions'])) {
107: $this->recurrence->exceptions = explode(',', $SQLEvent['event_exceptions']);
108: }
109: }
110:
111: if (isset($SQLEvent['event_location'])) {
112: $this->location = $driver->convertFromDriver($SQLEvent['event_location']);
113: }
114: if (isset($SQLEvent['event_url'])) {
115: $this->url = $SQLEvent['event_url'];
116: }
117: if (isset($SQLEvent['event_private'])) {
118: $this->private = (bool)($SQLEvent['event_private']);
119: }
120: if (isset($SQLEvent['event_status'])) {
121: $this->status = (int)$SQLEvent['event_status'];
122: }
123: if (isset($SQLEvent['event_attendees'])) {
124: $this->attendees = array_change_key_case($driver->convertFromDriver(unserialize($SQLEvent['event_attendees'])));
125: }
126: if (isset($SQLEvent['event_resources'])) {
127: $this->_resources = array_change_key_case($driver->convertFromDriver(unserialize($SQLEvent['event_resources'])));
128: }
129: if (isset($SQLEvent['event_description'])) {
130: $this->description = $driver->convertFromDriver($SQLEvent['event_description']);
131: }
132: if (isset($SQLEvent['event_alarm'])) {
133: $this->alarm = (int)$SQLEvent['event_alarm'];
134: }
135: if (isset($SQLEvent['event_alarm_methods'])) {
136: $this->methods = $driver->convertFromDriver(unserialize($SQLEvent['event_alarm_methods']));
137: }
138: if (isset($SQLEvent['event_baseid'])) {
139: $this->baseid = $SQLEvent['event_baseid'];
140: }
141: if (isset($SQLEvent['event_exceptionoriginaldate'])) {
142: $this->exceptionoriginaldate = new Horde_Date($SQLEvent['event_exceptionoriginaldate']);
143: }
144:
145: $this->initialized = true;
146: $this->stored = true;
147: }
148:
149: 150: 151:
152: public function toProperties()
153: {
154: $driver = $this->getDriver();
155: $properties = array();
156:
157:
158: $properties['event_creator_id'] = $driver->convertToDriver($this->creator);
159: $properties['event_title'] = $driver->convertToDriver($this->title);
160: $properties['event_description'] = $driver->convertToDriver($this->description);
161: $properties['event_location'] = $driver->convertToDriver($this->location);
162: $properties['event_url'] = (string)$this->url;
163: $properties['event_private'] = (int)$this->private;
164: $properties['event_status'] = $this->status;
165: $properties['event_attendees'] = serialize($driver->convertToDriver($this->attendees));
166: $properties['event_resources'] = serialize($driver->convertToDriver($this->getResources()));
167: $properties['event_modified'] = $_SERVER['REQUEST_TIME'];
168:
169: if ($this->isAllDay()) {
170: $properties['event_start'] = $this->start->strftime('%Y-%m-%d %H:%M:%S');
171: $properties['event_end'] = $this->end->strftime('%Y-%m-%d %H:%M:%S');
172: $properties['event_allday'] = 1;
173: } else {
174: if ($driver->getParam('utc')) {
175: $start = clone $this->start;
176: $end = clone $this->end;
177: $start->setTimezone('UTC');
178: $end->setTimezone('UTC');
179: } else {
180: $start = $this->start;
181: $end = $this->end;
182: }
183: $properties['event_start'] = $start->strftime('%Y-%m-%d %H:%M:%S');
184: $properties['event_end'] = $end->strftime('%Y-%m-%d %H:%M:%S');
185: $properties['event_allday'] = 0;
186: }
187:
188:
189: $properties['event_alarm'] = (int)$this->alarm;
190:
191:
192: $properties['event_alarm_methods'] = serialize($driver->convertToDriver($this->methods));
193:
194:
195: if (!$this->recurs()) {
196: $properties['event_recurtype'] = 0;
197: } else {
198: $recur = $this->recurrence->getRecurType();
199: if ($this->recurrence->hasRecurEnd()) {
200: if ($driver->getParam('utc')) {
201: $recur_end = clone $this->recurrence->recurEnd;
202: $recur_end->setTimezone('UTC');
203: } else {
204: $recur_end = $this->recurrence->recurEnd;
205: }
206: } else {
207: $recur_end = new Horde_Date(array('year' => 9999, 'month' => 12, 'mday' => 31, 'hour' => 23, 'min' => 59, 'sec' => 59));
208: }
209:
210: $properties['event_recurtype'] = $recur;
211: $properties['event_recurinterval'] = $this->recurrence->getRecurInterval();
212: $properties['event_recurenddate'] = $recur_end->format('Y-m-d H:i:s');
213: $properties['event_recurcount'] = $this->recurrence->getRecurCount();
214:
215: switch ($recur) {
216: case Horde_Date_Recurrence::RECUR_WEEKLY:
217: $properties['event_recurdays'] = $this->recurrence->getRecurOnDays();
218: break;
219: }
220: $properties['event_exceptions'] = implode(',', $this->recurrence->getExceptions());
221: }
222:
223:
224: if (!empty($this->baseid)) {
225: $properties['event_baseid'] = $this->baseid;
226: $properties['event_exceptionoriginaldate'] = $this->exceptionoriginaldate;
227: }
228:
229: return $properties;
230: }
231:
232: }
233: