Overview

Packages

  • Data

Classes

  • Horde_Data
  • Horde_Data_Base
  • Horde_Data_Csv
  • Horde_Data_Exception
  • Horde_Data_Icalendar
  • Horde_Data_Imc
  • Horde_Data_Outlookcsv
  • Horde_Data_Translation
  • Horde_Data_Tsv
  • Horde_Data_Vcard
  • Horde_Data_Vnote
  • Horde_Data_Vtodo
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Abstract implementation of the Horde_Data:: API for IMC data -
  4:  * vCards and iCalendar data, etc. Provides a number of utility
  5:  * methods that vCard and iCalendar implementation can share and rely
  6:  * on.
  7:  *
  8:  * Copyright 1999-2012 Horde LLC (http://www.horde.org/)
  9:  *
 10:  * See the enclosed file COPYING for license information (LGPL). If you
 11:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 12:  *
 13:  * @author   Jan Schneider <jan@horde.org>
 14:  * @category Horde
 15:  * @package  Data
 16:  */
 17: class Horde_Data_Imc extends Horde_Data_Base
 18: {
 19:     /**
 20:      * @var
 21:      */
 22:     protected $_iCal = false;
 23: 
 24:     /**
 25:      *
 26:      * @throws Horde_Data_Exception
 27:      */
 28:     public function importData($text)
 29:     {
 30:         $this->_iCal = new Horde_Icalendar();
 31:         if (!$this->_iCal->parsevCalendar($text)) {
 32:             throw new Horde_Data_Exception(Horde_Data_Translation::t("There was an error importing the iCalendar data."));
 33:         }
 34: 
 35:         return $this->_iCal->getComponents();
 36:     }
 37: 
 38:     /**
 39:      * Builds an iCalendar file from a given data structure and
 40:      * returns it as a string.
 41:      *
 42:      * @param array $data     An array containing Horde_Icalendar_Vevent
 43:      *                        objects
 44:      * @param string $method  The iTip method to use.
 45:      *
 46:      * @return string  The iCalendar data.
 47:      */
 48:     public function exportData($data, $method = 'REQUEST')
 49:     {
 50:         $this->_iCal = new Horde_Icalendar();
 51:         $this->_iCal->setAttribute('METHOD', $method);
 52: 
 53:         foreach ($data as $event) {
 54:             $this->_iCal->addComponent($event);
 55:         }
 56: 
 57:         return $this->_iCal->exportvCalendar();
 58:     }
 59: 
 60:     /**
 61:      * Builds an iCalendar file from a given data structure and
 62:      * triggers its download.  It DOES NOT exit the current script but
 63:      * only outputs the correct headers and data.
 64:      *
 65:      * @param string $filename   The name of the file to be downloaded.
 66:      * @param array $data        An array containing Horde_Icalendar_Vevents
 67:      */
 68:     public function exportFile($filename, $data)
 69:     {
 70:         if (!isset($this->_browser)) {
 71:             throw new LogicException('Missing browser parameter.');
 72:         }
 73: 
 74:         $export = $this->exportData($data);
 75:         $this->_browser->downloadHeaders($filename, 'text/calendar', false, strlen($export));
 76:         echo $export;
 77:     }
 78: 
 79:     /**
 80:      * Takes all necessary actions for the given import step,
 81:      * parameters and form values and returns the next necessary step.
 82:      *
 83:      * @param integer $action  The current step. One of the IMPORT_* constants.
 84:      * @param array $param     An associative array containing needed
 85:      *                         parameters for the current step.
 86:      *
 87:      * @return mixed  Either the next step as an integer constant or imported
 88:      *                data set after the final step.
 89:      * @throws Horde_Data_Exception
 90:      */
 91:     public function nextStep($action, $param = array())
 92:     {
 93:         switch ($action) {
 94:         case Horde_Data::IMPORT_FILE:
 95:             parent::nextStep($action, $param);
 96:             $this->importFile($_FILES['import_file']['tmp_name']);
 97:             return $this->_iCal->getComponents();
 98:         }
 99: 
100:         return parent::nextStep($action, $param);
101:     }
102: 
103: }
104: 
API documentation generated by ApiGen