public function testParse() { $attendees = Kronolith_Attendee_List::parse('Jürgen Doe <*****@*****.**>, Jane Doe,Jack Doe <*****@*****.**>, jenny@example.com', $this->getMockBuilder('Horde_Notification_Handler')->disableOriginalConstructor()->getMock()); $this->assertInstanceOf('Kronolith_Attendee_List', $attendees); $this->assertEquals(4, count($attendees)); $expectedAttendees = $this->_getAttendees(); foreach ($expectedAttendees as &$attendee) { $attendee->role = Kronolith::PART_REQUIRED; $attendee->response = Kronolith::RESPONSE_NONE; } $attendees = iterator_to_array($attendees); unset($expectedAttendees[5], $expectedAttendees[4]); $this->assertEquals($expectedAttendees, array_values($attendees)); $this->assertEquals(array('email:juergen@example.com', 'name:Jane Doe', 'email:jack@example.com', 'email:jenny@example.com'), array_keys($attendees)); }
switch ($actionID) { case 'add': // Add new attendees and/or resources. Multiple attendees can be seperated // on a single line by whitespace and/or commas. Resources are added one // at a time (at least for now). $newUser = trim(Horde_Util::getFormData('newUser')); $newAttendees = trim(Horde_Util::getFormData('newAttendees')); $newResource = trim(Horde_Util::getFormData('resourceselect')); if (!is_null($newUser)) { if (!($user = Kronolith::validateUserAttendee($newUser))) { $notification->push(sprintf(_("The user \"%s\" does not exist."), $newUser), 'horde.error'); } else { $attendees->add($user); } } $newAttendees = Kronolith_Attendee_List::parse($newAttendees, $notification); $session->set('kronolith', 'attendees', $attendees->add($newAttendees)); // Any new resources? if (!empty($newResource)) { /* Get the requested resource */ $resource = Kronolith::getDriver('Resource')->getResource($newResource); /* Do our best to see what the response will be. Note that this * response is only guarenteed once the event is saved. */ $event = Kronolith::getDriver()->getEvent(); $event->start = $start; $event->end = $end; $event->start->setTimezone(date_default_timezone_get()); $event->end->setTimezone(date_default_timezone_get()); $response = $resource->getResponse($event); $resources[$resource->getId()] = array('attendance' => Kronolith::PART_REQUIRED, 'response' => $response, 'name' => $resource->get('name')); $session->set('kronolith', 'resources', $resources);
/** * Reads form/post data and updates this event's properties. * * @param Kronolith_Event|null $existing If this is an exception event * this is taken as the base event. * @since 4.2.6 * */ public function readForm(Kronolith_Event $existing = null) { global $notification, $prefs, $registry, $session; // Event owner. $targetcalendar = Horde_Util::getFormData('targetcalendar'); if (strpos($targetcalendar, '\\')) { list(, $this->creator) = explode('\\', $targetcalendar, 2); } elseif (!isset($this->_id)) { $this->creator = $registry->getAuth(); } // Basic fields. $this->title = Horde_Util::getFormData('title', $this->title); $this->description = Horde_Util::getFormData('description', $this->description); $this->location = Horde_Util::getFormData('location', $this->location); $this->timezone = Horde_Util::getFormData('timezone', $this->timezone); $this->private = (bool) Horde_Util::getFormData('private'); // if the field is empty you are the organizer (and so organizer should be null) $this->organizer = Horde_Util::getFormData('organizer', $this->organizer) ?: null; // URL. $url = Horde_Util::getFormData('eventurl', $this->url); if (strlen($url)) { // Analyze and re-construct. $url = @parse_url($url); if ($url) { if (function_exists('http_build_url')) { if (empty($url['path'])) { $url['path'] = '/'; } $url = http_build_url($url); } else { $new_url = ''; if (isset($url['scheme'])) { $new_url .= $url['scheme'] . '://'; } if (isset($url['user'])) { $new_url .= $url['user']; if (isset($url['pass'])) { $new_url .= ':' . $url['pass']; } $new_url .= '@'; } if (isset($url['host'])) { // Convert IDN hosts to ASCII. if (function_exists('idn_to_ascii')) { $url['host'] = @idn_to_ascii($url['host']); } elseif (Horde_Mime::is8bit($url['host'])) { //throw new Kronolith_Exception(_("Invalid character in URL.")); $url['host'] = ''; } $new_url .= $url['host']; } if (isset($url['path'])) { $new_url .= $url['path']; } if (isset($url['query'])) { $new_url .= '?' . $url['query']; } if (isset($url['fragment'])) { $new_url .= '#' . $url['fragment']; } $url = $new_url; } } } $this->url = $url; // Status. $this->status = Horde_Util::getFormData('status', $this->status); // Attendees. $attendees = $session->get('kronolith', 'attendees'); if (!$attendees) { $attendees = new Kronolith_Attendee_List(); } $newattendees = Horde_Util::getFormData('attendees'); $userattendees = Horde_Util::getFormData('users'); if (!is_null($newattendees) || !is_null($userattendees)) { if ($newattendees) { $newattendees = Kronolith_Attendee_List::parse(trim($newattendees), $notification); } else { $newattendees = new Kronolith_Attendee_List(); } if ($userattendees) { foreach (explode(',', $userattendees) as $user) { if (!($newUser = Kronolith::validateUserAttendee($user))) { $notification->push(sprintf(_("The user \"%s\" does not exist."), $newUser), 'horde.error'); } else { $newattendees->add($newUser); } } } // First add new attendees missing in the current list. foreach ($newattendees as $attendee) { if (!$attendees->has($attendee)) { $attendees->add($attendee); } } // Now check for attendees in the current list that don't exist in // the new attendee list anymore. $finalAttendees = new Kronolith_Attendee_List(); foreach ($attendees as $attendee) { if (!$newattendees->has($attendee)) { continue; } if (Kronolith::isUserEmail($this->creator, $attendee->email)) { $attendee->response = Horde_Util::getFormData('attendance'); } $finalAttendees->add($attendee); } $attendees = $finalAttendees; } $this->attendees = $attendees; // Event start. $allDay = Horde_Util::getFormData('whole_day'); if ($start_date = Horde_Util::getFormData('start_date')) { // From ajax interface. $this->start = Kronolith::parseDate($start_date . ' ' . Horde_Util::getFormData('start_time'), true, $this->timezone); if ($allDay) { $this->start->hour = $this->start->min = $this->start->sec = 0; } } elseif ($start = Horde_Util::getFormData('start')) { // From traditional interface. $start_year = $start['year']; $start_month = $start['month']; $start_day = $start['day']; $start_hour = Horde_Util::getFormData('start_hour'); $start_min = Horde_Util::getFormData('start_min'); $am_pm = Horde_Util::getFormData('am_pm'); if (!$prefs->getValue('twentyFour')) { if ($am_pm == 'PM') { if ($start_hour != 12) { $start_hour += 12; } } elseif ($start_hour == 12) { $start_hour = 0; } } if (Horde_Util::getFormData('end_or_dur') == 1) { if ($allDay) { $start_hour = 0; $start_min = 0; $dur_day = 0; $dur_hour = 24; $dur_min = 0; } else { $dur_day = (int) Horde_Util::getFormData('dur_day'); $dur_hour = (int) Horde_Util::getFormData('dur_hour'); $dur_min = (int) Horde_Util::getFormData('dur_min'); } } $this->start = new Horde_Date(array('hour' => $start_hour, 'min' => $start_min, 'month' => $start_month, 'mday' => $start_day, 'year' => $start_year), $this->timezone); } // Event end. if ($end_date = Horde_Util::getFormData('end_date')) { // From ajax interface. $this->end = Kronolith::parseDate($end_date . ' ' . Horde_Util::getFormData('end_time'), true, $this->timezone); if ($allDay) { $this->end->hour = $this->end->min = $this->end->sec = 0; $this->end->mday++; } } elseif (Horde_Util::getFormData('end_or_dur') == 1) { // Event duration from traditional interface. $this->end = new Horde_Date(array('hour' => $start_hour + $dur_hour, 'min' => $start_min + $dur_min, 'month' => $start_month, 'mday' => $start_day + $dur_day, 'year' => $start_year)); } elseif ($end = Horde_Util::getFormData('end')) { // From traditional interface. $end_year = $end['year']; $end_month = $end['month']; $end_day = $end['day']; $end_hour = Horde_Util::getFormData('end_hour'); $end_min = Horde_Util::getFormData('end_min'); $end_am_pm = Horde_Util::getFormData('end_am_pm'); if (!$prefs->getValue('twentyFour')) { if ($end_am_pm == 'PM') { if ($end_hour != 12) { $end_hour += 12; } } elseif ($end_hour == 12) { $end_hour = 0; } } $this->end = new Horde_Date(array('hour' => $end_hour, 'min' => $end_min, 'month' => $end_month, 'mday' => $end_day, 'year' => $end_year), $this->timezone); if ($this->end->compareDateTime($this->start) < 0) { $this->end = new Horde_Date($this->start); } } $this->allday = false; // Alarm. if (!is_null($alarm = Horde_Util::getFormData('alarm'))) { if ($alarm) { $value = Horde_Util::getFormData('alarm_value'); $unit = Horde_Util::getFormData('alarm_unit'); if ($value == 0) { $value = $unit = 1; } $this->alarm = $value * $unit; // Notification. if (Horde_Util::getFormData('alarm_change_method')) { $types = Horde_Util::getFormData('event_alarms'); $methods = array(); if (!empty($types)) { foreach ($types as $type) { $methods[$type] = array(); switch ($type) { case 'notify': $methods[$type]['sound'] = Horde_Util::getFormData('event_alarms_sound'); break; case 'mail': $methods[$type]['email'] = Horde_Util::getFormData('event_alarms_email'); break; case 'popup': break; } } } $this->methods = $methods; } else { $this->methods = array(); } } else { $this->alarm = 0; $this->methods = array(); } } // Recurrence. $this->recurrence = $this->readRecurrenceForm($this->start, $this->timezone, $this->recurrence); // Convert to local timezone. $this->setTimezone(false); $this->_handleResources($existing); // Tags. $this->tags = Horde_Util::getFormData('tags', $this->tags); // Geolocation if (Horde_Util::getFormData('lat') && Horde_Util::getFormData('lon')) { $this->geoLocation = array('lat' => Horde_Util::getFormData('lat'), 'lon' => Horde_Util::getFormData('lon'), 'zoom' => Horde_Util::getFormData('zoom')); } $this->initialized = true; }