aboutsummaryrefslogtreecommitdiff
path: root/lib/calendar/CalendarExport.class.php
blob: c9c10f6aac8ccf869d9c8127387c5a7a2128bc69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?
# Lifter002: TODO
# Lifter007: TODO

/**
 * CalendarExport.class.php
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * @author      Peter Thienel <thienel@data-quest.de>, Suchi & Berg GmbH <info@data-quest.de>
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 * @package     calendar
 */

class CalendarExport
{
    protected $_writer;
    protected $export;
    private $count;

    public function __construct(&$writer)
    {
        $this->_writer = $writer;
    }

    public function exportFromDatabase($range_id = null, $start = 0, $end = Calendar::CALENDAR_END, $event_types = null, $except = NULL)
    {
        global $_calendar_error, $user;

        if (!$range_id) {
            $range_id = $user->id;
        }
        $calendar = new SingleCalendar($range_id);

        $this->_export($this->_writer->writeHeader());
        $calendar->getEvents($event_types, $start, $end);

        foreach ($calendar->events as $event) {
            $this->_export($this->_writer->write($event));
        }
        $this->count = sizeof($calendar->events);

        $this->_export($this->_writer->writeFooter());
    }

    public function exportFromObjects($events)
    {
        global $_calendar_error;

        $this->_export($this->_writer->writeHeader());

        $this->count = 0;
        foreach ($events as $event) {
            $this->_export($this->_writer->write($event));
            $this->count++;
        }

        if (!sizeof($events)) {
            $message = _('Es wurden keine Termine exportiert.');
        } else {
            $message = sprintf(ngettext('Es wurde 1 Termin exportiert', 'Es wurden %s Termine exportiert', sizeof($events)), sizeof($events));
        }

        $this->_export($this->_writer->writeFooter());
    }

    public function _export($exp)
    {
        if (!empty($exp)) {
            $this->export[] = $exp;
        }
    }

    public function getExport()
    {
        return $this->export;
    }

    public function getCount()
    {
        return $this->count;
    }
}