[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Horde/iCalendar/ -> vevent.php (source)

   1  <?php
   2  /**
   3   * Class representing vEvents.
   4   *
   5   * $Horde: framework/iCalendar/iCalendar/vevent.php,v 1.31.10.8 2006/01/01 21:28:47 jan Exp $
   6   *
   7   * Copyright 2003-2006 Mike Cochrane <mike@graftonhall.co.nz>
   8   *
   9   * See the enclosed file COPYING for license information (LGPL). If you
  10   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  11   *
  12   * @author  Mike Cochrane <mike@graftonhall.co.nz>
  13   * @since   Horde 3.0
  14   * @package Horde_iCalendar
  15   */
  16  class Horde_iCalendar_vevent extends Horde_iCalendar {
  17  
  18      function getType()
  19      {
  20          return 'vEvent';
  21      }
  22  
  23      function parsevCalendar($data)
  24      {
  25          parent::parsevCalendar($data, 'VEVENT');
  26      }
  27  
  28      function exportvCalendar()
  29      {
  30          // Default values.
  31          $requiredAttributes = array();
  32          $requiredAttributes['DTSTAMP'] = time();
  33          $requiredAttributes['ORGANIZER'] = 'Unknown Organizer';
  34          $requiredAttributes['UID'] = $this->_exportDateTime(time()) . '@' . (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost');
  35  
  36          $method = !empty($this->_container) ?
  37              $this->_container->getAttribute('METHOD') : 'PUBLISH';
  38  
  39          switch ($method) {
  40          case 'PUBLISH':
  41              $requiredAttributes['DTSTART'] = time();
  42              $requiredAttributes['SUMMARY'] = '';
  43              break;
  44  
  45          case 'REQUEST':
  46              $requiredAttributes['ATTENDEE'] = '';
  47              $requiredAttributes['DTSTART'] = time();
  48              $requiredAttributes['SUMMARY'] = '';
  49              break;
  50  
  51          case 'REPLY':
  52              $requiredAttributes['ATTENDEE'] = '';
  53              break;
  54  
  55          case 'ADD':
  56              $requiredAttributes['DTSTART'] = time();
  57              $requiredAttributes['SEQUENCE'] = 1;
  58              $requiredAttributes['SUMMARY'] = '';
  59              break;
  60  
  61          case 'CANCEL':
  62              $requiredAttributes['ATTENDEE'] = '';
  63              $requiredAttributes['SEQUENCE'] = 1;
  64              break;
  65  
  66          case 'REFRESH':
  67              $requiredAttributes['ATTENDEE'] = '';
  68              break;
  69          }
  70  
  71          foreach ($requiredAttributes as $name => $default_value) {
  72              if (is_a($this->getAttribute($name), 'PEAR_Error')) {
  73                  $this->setAttribute($name, $default_value);
  74              }
  75          }
  76  
  77          return parent::_exportvData('VEVENT');
  78      }
  79  
  80      /**
  81       * Update the status of an attendee of an event.
  82       *
  83       * @param $email    The email address of the attendee.
  84       * @param $status   The participant status to set.
  85       * @param $fullname The full name of the participant to set.
  86       */
  87      function updateAttendee($email, $status, $fullname = '')
  88      {
  89          foreach ($this->_attributes as $key => $attribute) {
  90              if ($attribute['name'] == 'ATTENDEE' && $attribute['value'] == 'MAILTO:' . $email) {
  91                  $this->_attributes[$key]['params']['PARTSTAT'] = $status;
  92                  if (!empty($fullname)) {
  93                      $this->_attributes[$key]['params']['CN'] = $fullname;
  94                  }
  95                  unset($this->_attributes[$key]['params']['RSVP']);
  96                  return;
  97              }
  98          }
  99          $params = array('PARTSTAT' => $status);
 100          if (!empty($fullname)) {
 101              $params['CN'] = $fullname;
 102          }
 103          $this->setAttribute('ATTENDEE', 'MAILTO:' . $email, $params);
 104      }
 105  
 106      /**
 107       * Return the organizer display name or email.
 108       *
 109       * @return string  The organizer name to display for this event.
 110       */
 111      function organizerName()
 112      {
 113          $organizer = $this->getAttribute('ORGANIZER', true);
 114          if (is_a($organizer, 'PEAR_Error')) {
 115              return null;
 116          }
 117  
 118          if (isset($organizer[0]['CN'])) {
 119              return $organizer[0]['CN'];
 120          }
 121  
 122          $organizer = parse_url($this->getAttribute('ORGANIZER'));
 123  
 124          return $organizer['path'];
 125      }
 126  
 127      /**
 128       * Update this event with details from another event.
 129       *
 130       * @param Horde_iCalendar_vEvent $vevent  The vEvent with latest details.
 131       */
 132      function updateFromvEvent($vevent)
 133      {
 134          $newAttributes = $vevent->getAllAttributes();
 135          foreach ($newAttributes as $newAttribute) {
 136              $currentValue = $this->getAttribute($newAttribute['name']);
 137              if (is_a($currentValue, 'PEAR_error')) {
 138                  // Already exists so just add it.
 139                  $this->setAttribute($newAttribute['name'], $newAttribute['value'], $newAttribute['params']);
 140              } else {
 141                  // Already exists so locate and modify.
 142                  $found = false;
 143  
 144                  // Try matching the attribte name and value incase
 145                  // only the params changed (eg attendee updating
 146                  // status).
 147                  foreach ($this->_attributes as $id => $attr) {
 148                      if ($attr['name'] == $newAttribute['name'] &&
 149                          $attr['value'] == $newAttribute['value']) {
 150                          // merge the params
 151                          foreach ($newAttribute['params'] as $param_id => $param_name) {
 152                              $this->_attributes[$id]['params'][$param_id] = $param_name;
 153                          }
 154                          $found = true;
 155                          break;
 156                      }
 157                  }
 158                  if (!$found) {
 159                      // Else match the first attribute with the same
 160                      // name (eg changing start time).
 161                      foreach ($this->_attributes as $id => $attr) {
 162                          if ($attr['name'] == $newAttribute['name']) {
 163                              $this->_attributes[$id]['value'] = $newAttribute['value'];
 164                              // Merge the params.
 165                              foreach ($newAttribute['params'] as $param_id => $param_name) {
 166                                  $this->_attributes[$id]['params'][$param_id] = $param_name;
 167                              }
 168                              break;
 169                          }
 170                      }
 171                  }
 172              }
 173          }
 174      }
 175  
 176      /**
 177       * Update just the attendess of event with details from another
 178       * event.
 179       *
 180       * @param Horde_iCalendar_vEvent $vevent  The vEvent with latest details
 181       */
 182      function updateAttendeesFromvEvent($vevent)
 183      {
 184          $newAttributes = $vevent->getAllAttributes();
 185          foreach ($newAttributes as $newAttribute) {
 186              if ($newAttribute['name'] != 'ATTENDEE') {
 187                  continue;
 188              }
 189              $currentValue = $this->getAttribute($newAttribute['name']);
 190              if (is_a($currentValue, 'PEAR_error')) {
 191                  // Already exists so just add it.
 192                  $this->setAttribute($newAttribute['name'], $newAttribute['value'], $newAttribute['params']);
 193              } else {
 194                  // Already exists so locate and modify.
 195                  $found = false;
 196                  // Try matching the attribte name and value incase
 197                  // only the params changed (eg attendee updating
 198                  // status).
 199                  foreach ($this->_attributes as $id => $attr) {
 200                      if ($attr['name'] == $newAttribute['name'] &&
 201                          $attr['value'] == $newAttribute['value']) {
 202                          // Merge the params.
 203                          foreach ($newAttribute['params'] as $param_id => $param_name) {
 204                              $this->_attributes[$id]['params'][$param_id] = $param_name;
 205                          }
 206                          $found = true;
 207                          break;
 208                      }
 209                  }
 210  
 211                  if (!$found) {
 212                      // Else match the first attribute with the same
 213                      // name (eg changing start time).
 214                      foreach ($this->_attributes as $id => $attr) {
 215                          if ($attr['name'] == $newAttribute['name']) {
 216                              $this->_attributes[$id]['value'] = $newAttribute['value'];
 217                              // Merge the params.
 218                              foreach ($newAttribute['params'] as $param_id => $param_name) {
 219                                  $this->_attributes[$id]['params'][$param_id] = $param_name;
 220                              }
 221                              break;
 222                          }
 223                      }
 224                  }
 225              }
 226          }
 227      }
 228  
 229  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7