Esempio n. 1
0
    public function drawIcs(&$master_array, $getdate, $sendHeaders = true, $limitAttendeeToThisEmail = '')
    {
        $this->_init($master_array);
        $this->limitAttendeeToThisEmail = $limitAttendeeToThisEmail;
        $absFile = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($this->conf['view.']['ics.']['icsTemplate']);
        $page = \TYPO3\CMS\Core\Utility\GeneralUtility::getURL($absFile);
        if ($page == '') {
            // return '<h3>calendar: no ics template file found:</h3>'.$this->conf['view.']['ics.']['icsTemplate'];
            // falling back to default:
            $page = 'BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//TYPO3/NONSGML Calendar Base (cal) V###CAL_VERSION###//EN
METHOD:###METHOD###
<!--###EVENT### start-->
<!--###EVENT### end-->
END:VCALENDAR
			';
        }
        $ics_events = '';
        $select = 'tx_cal_event_deviation.*,tx_cal_index.start_datetime,tx_cal_index.end_datetime';
        $table = 'tx_cal_event_deviation right outer join tx_cal_index on tx_cal_event_deviation.uid = tx_cal_index.event_deviation_uid';
        $oldView = $this->conf['view'];
        $this->conf['view'] = 'single_ics';
        foreach ($this->master_array as $eventDate => $eventTimeArray) {
            if (is_subclass_of($eventTimeArray, 'TYPO3\\CMS\\Cal\\Model\\Model')) {
                $ics_events .= $eventTimeArray->renderEventFor('ics');
            } else {
                foreach ($eventTimeArray as $key => $eventArray) {
                    foreach ($eventArray as $eventUid => $event) {
                        if (is_object($event)) {
                            $ics_events .= $event->renderEventFor('ics');
                            $where = 'tx_cal_event_deviation.parentid = ' . $event->getUid() . $this->cObj->enableFields('tx_cal_event_deviation');
                            $deviationResult = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where);
                            if ($deviationResult) {
                                while ($deviationRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($deviationResult)) {
                                    $start = new \TYPO3\CMS\Cal\Model\CalDate(substr($deviationRow['start_datetime'], 0, 8));
                                    $start->setHour(substr($deviationRow['start_datetime'], 8, 2));
                                    $start->setMinute(substr($deviationRow['start_datetime'], 10, 2));
                                    $end = new \TYPO3\CMS\Cal\Model\CalDate(substr($deviationRow['end_datetime'], 0, 8));
                                    $end->setHour(substr($deviationRow['end_datetime'], 8, 2));
                                    $end->setMinute(substr($deviationRow['end_datetime'], 10, 2));
                                    unset($deviationRow['start_datetime']);
                                    unset($deviationRow['end_datetime']);
                                    $new_event = new \TYPO3\CMS\Cal\Model\EventRecDeviationModel($event, $deviationRow, $start, $end);
                                    $ics_events .= $new_event->renderEventFor('ics');
                                }
                                $GLOBALS['TYPO3_DB']->sql_free_result($deviationResult);
                            }
                        }
                    }
                }
            }
        }
        $this->conf['view'] = $oldView;
        $rems = array();
        $rems['###EVENT###'] = strip_tags($ics_events);
        $title = '';
        if (!empty($this->master_array)) {
            if (is_subclass_of($this->master_array[0], 'TYPO3\\CMS\\Cal\\Model\\Model')) {
                $title = $this->master_array[0]->getTitle();
            } else {
                $title = $this->appendCalendarTitle($title);
                $title = $this->appendCategoryTitle($title);
            }
        } else {
            $title = $this->appendCalendarTitle($title);
            $title = $this->appendCategoryTitle($title);
        }
        if ($title == '') {
            $title = $getdate;
        }
        $title .= '.ics';
        $title = strtr($title, array(' ' => '', ',' => '_'));
        if ($sendHeaders) {
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Content-Disposition: attachment; filename=' . $title);
            header('Content-Type: text/ics');
            header('Pragma: ');
            header('Cache-Control:');
        }
        include \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('cal') . 'ext_emconf.php';
        $myem_conf = array_pop($EM_CONF);
        $method = 'PUBLISH';
        if ($this->limitAttendeeToThisEmail) {
            $method = 'REQUEST';
        }
        $return = \TYPO3\CMS\Cal\Utility\Functions::substituteMarkerArrayNotCached($page, array('###CAL_VERSION###' => $myem_conf['version'], '###METHOD###' => $method, '###TIMEZONE###' => $this->cObj->cObjGetSingle($this->conf['view.']['ics.']['timezone'], $this->conf['view.']['ics.']['timezone.'])), $rems, array());
        return \TYPO3\CMS\Cal\Utility\Functions::removeEmptyLines($return);
    }