ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarExport.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once './Services/Calendar/classes/iCal/class.ilICalWriter.php';
25 include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
26 include_once './Services/Calendar/classes/class.ilCalendarEntry.php';
27 include_once './Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
28 
37 {
38  protected $calendars = array();
39  protected $writer = null;
40 
41  public function __construct($a_calendar_ids)
42  {
43  $this->calendars = $a_calendar_ids;
44  $this->writer = new ilICalWriter();
45  }
46 
47  public function export()
48  {
49  $this->writer->addLine('BEGIN:VCALENDAR');
50  $this->writer->addLine('VERSION:2.0');
51  $this->writer->addLine('PRODID:-//ilias.de/NONSGML ILIAS Calendar V4.1//EN');
52 
53  $this->addTimezone();
54  $this->addCategories();
55 
56  $this->writer->addLine('END:VCALENDAR');
57  }
58 
59  protected function addTimezone()
60  {
61  // TODO
62  }
63 
64  protected function addCategories()
65  {
66  foreach($this->calendars as $category_id)
67  {
69  ilCalendarCategories::_getInstance()->getSubitemCategories($category_id)
70  ) as $app_id)
71  {
72  $app = new ilCalendarEntry($app_id);
73  if($app->isMilestone())
74  {
75  $this->createVTODO($app);
76  }
77  else
78  {
79  $this->createVEVENT($app);
80  }
81  }
82  }
83  }
84 
85  protected function createVTODO($app)
86  {
87  // TODO
88  return true;
89  }
90 
91  protected function createVEVENT($app)
92  {
93  global $ilUser;
94 
95  $this->writer->addLine('BEGIN:VEVENT');
96  // TODO only domain
97  $this->writer->addLine('UID:'.ilICalWriter::escapeText(
98  $app->getEntryId().'_'.CLIENT_ID.'@'.ILIAS_HTTP_PATH));
99 
100  #$last_mod = $app->getLastUpdate()->get(IL_CAL_FKT_DATE,'Ymd\THis\Z',ilTimeZone::UTC);
101  $last_mod = $app->getLastUpdate()->get(IL_CAL_FKT_DATE,'Ymd\THis\Z',$ilUser->getTimeZone());
102  $this->writer->addLine('LAST-MODIFIED:'.$last_mod);
103 
104  if($app->isFullday())
105  {
106  // According to RFC 5545 3.6.1 DTEND is not inklusive.
107  // But ILIAS stores inklusive dates in the database.
108  $app->getEnd()->increment(IL_CAL_DAY,1);
109 
110  #$start = $app->getStart()->get(IL_CAL_FKT_DATE,'Ymd\Z',ilTimeZone::UTC);
111  $start = $app->getStart()->get(IL_CAL_FKT_DATE,'Ymd',$ilUser->getTimeZone());
112  #$end = $app->getEnd()->get(IL_CAL_FKT_DATE,'Ymd\Z',ilTimeZone::UTC);
113  $end = $app->getEnd()->get(IL_CAL_FKT_DATE,'Ymd',$ilUser->getTimeZone());
114 
115  $this->writer->addLine('DTSTART;VALUE=DATE:' . $start);
116  $this->writer->addLine('DTEND;VALUE=DATE:'.$end);
117  }
118  else
119  {
120  #$start = $app->getStart()->get(IL_CAL_FKT_DATE,'Ymd\THis\Z',ilTimeZone::UTC);
121  $start = $app->getStart()->get(IL_CAL_FKT_DATE,'Ymd\THis',$ilUser->getTimeZone());
122  #$end = $app->getEnd()->get(IL_CAL_FKT_DATE,'Ymd\THis\Z',ilTimeZone::UTC);
123  $end = $app->getEnd()->get(IL_CAL_FKT_DATE,'Ymd\THis',$ilUser->getTimeZone());
124  $this->writer->addLine('DTSTART;TZID='.$ilUser->getTimezone().':'. $start);
125  $this->writer->addLine('DTEND;TZID='.$ilUser->getTimezone().':'.$end);
126  }
127 
128 
129  $this->createRecurrences($app);
130 
131  $this->writer->addLine('SUMMARY:'.ilICalWriter::escapeText($app->getPresentationTitle()));
132  if(strlen($app->getDescription()))
133  $this->writer->addLine('DESCRIPTION:'.ilICalWriter::escapeText($app->getDescription()));
134  if(strlen($app->getLocation()))
135  $this->writer->addLine('LOCATION:'.ilICalWriter::escapeText($app->getLocation()));
136 
137  // TODO: URL
138  $this->buildAppointmentUrl($app);
139 
140  $this->writer->addLine('END:VEVENT');
141 
142  }
143 
144  protected function createRecurrences($app)
145  {
146  include_once './Services/Calendar/classes/class.ilCalendarRecurrences.php';
147  foreach(ilCalendarRecurrences::_getRecurrences($app->getEntryId()) as $rec)
148  {
149  foreach(ilCalendarRecurrenceExclusions::getExclusionDates($app->getEntryId()) as $excl)
150  {
151  $this->writer->addLine($excl->toICal());
152  }
153  $this->writer->addLine($rec->toICal());
154  }
155  }
156 
157 
158  public function getExportString()
159  {
160  return $this->writer->__toString();
161  }
162 
168  protected function buildAppointmentUrl(ilCalendarEntry $entry)
169  {
172  );
173 
174  if($cat->getType() != ilCalendarCategory::TYPE_OBJ)
175  {
176  $this->writer->addLine('URL;VALUE=URI:'.ILIAS_HTTP_PATH);
177  }
178  else
179  {
180  $refs = ilObject::_getAllReferences($cat->getObjId());
181 
182  include_once './classes/class.ilLink.php';
183  $this->writer->addLine(
184  'URL;VALUE=URI:'.ilLink::_getLink(current((array) $refs))
185  );
186  }
187  }
188 }