Kronolith::responseFromICal PHP Method

responseFromICal() public static method

Maps an iCalendar attendee response string to the corresponding Kronolith value.
public static responseFromICal ( string $response ) : string
$response string The attendee response.
return string The Kronolith response value.
    public static function responseFromICal($response)
    {
        switch (Horde_String::upper($response)) {
            case 'ACCEPTED':
                return self::RESPONSE_ACCEPTED;
            case 'DECLINED':
                return self::RESPONSE_DECLINED;
            case 'TENTATIVE':
                return self::RESPONSE_TENTATIVE;
            case 'NEEDS-ACTION':
            default:
                return self::RESPONSE_NONE;
        }
    }

Usage Example

コード例 #1
0
ファイル: Api.php プロジェクト: horde/horde
 /**
  * Updates an attendee's response status for a specified event.
  *
  * @param Horde_Icalendar_Vevent $response  A Horde_Icalendar_Vevent
  *                                          object, with a valid UID
  *                                          attribute that points to an
  *                                          existing event.  This is
  *                                          typically the vEvent portion
  *                                          of an iTip meeting-request
  *                                          response, with the attendee's
  *                                          response in an ATTENDEE
  *                                          parameter.
  * @param string $sender                    The email address of the
  *                                          person initiating the
  *                                          update. Attendees are only
  *                                          updated if this address
  *                                          matches.
  *
  * @throws Kronolith_Exception
  */
 public function updateAttendee($response, $sender = null)
 {
     try {
         $uid = $response->getAttribute('UID');
     } catch (Horde_Icalendar_Exception $e) {
         throw new Kronolith_Exception($e);
     }
     $events = Kronolith::getDriver()->getByUID($uid, null, true);
     /* First try the user's own calendars. */
     $ownerCalendars = Kronolith::listInternalCalendars(true, Horde_Perms::EDIT);
     $event = null;
     foreach ($events as $ev) {
         if (isset($ownerCalendars[$ev->calendar])) {
             $event = $ev;
             break;
         }
     }
     /* If not successful, try all calendars the user has access to. */
     if (empty($event)) {
         $editableCalendars = Kronolith::listInternalCalendars(false, Horde_Perms::EDIT);
         foreach ($events as $ev) {
             if (isset($editableCalendars[$ev->calendar])) {
                 $event = $ev;
                 break;
             }
         }
     }
     if (empty($event) || $event->private && $event->creator != $GLOBALS['registry']->getAuth()) {
         throw new Horde_Exception_PermissionDenied();
     }
     $atnames = $response->getAttribute('ATTENDEE');
     if (!is_array($atnames)) {
         $atnames = array($atnames);
     }
     $atparms = $response->getAttribute('ATTENDEE', true);
     $found = false;
     $error = _("No attendees have been updated because none of the provided email addresses have been found in the event's attendees list.");
     foreach ($atnames as $index => $attendee) {
         if ($response->getAttribute('VERSION') < 2) {
             $addr_ob = new Horde_Mail_Rfc822_Address($attendee);
             if (!$addr_ob->valid) {
                 continue;
             }
             $attendee = $addr_ob->bare_address;
             $name = $addr_ob->personal;
         } else {
             $attendee = str_ireplace('mailto:', '', $attendee);
             $name = isset($atparms[$index]['CN']) ? $atparms[$index]['CN'] : null;
         }
         if ($event->hasAttendee($attendee)) {
             if (is_null($sender) || $sender == $attendee) {
                 $event->addAttendee($attendee, Kronolith::PART_IGNORE, Kronolith::responseFromICal($atparms[$index]['PARTSTAT']), $name);
                 $found = true;
             } else {
                 $error = _("The attendee hasn't been updated because the update was not sent from the attendee.");
             }
         }
     }
     $event->save();
     if (!$found) {
         throw new Kronolith_Exception($error);
     }
 }