ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMiniCalendarGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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/class.ilCalendarUserSettings.php');
25 
34 {
36 
37  protected $seed;
38  protected $mode = null;
39  protected $user_settings = null;
40  protected $tpl = null;
41  protected $lng;
42 
50  public function __construct(ilDate $seed, $a_par_obj)
51  {
52  global $ilUser,$lng;
53 
54  $this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($ilUser->getId());
55  $this->tpl = new ilTemplate('tpl.minical.html',true,true,'Services/Calendar');
56  $this->lng = $lng;
57  $this->lng->loadLanguageModule('dateplaner');
58  $this->seed = $seed;
59  $this->setParentObject($a_par_obj);
60  }
61 
67  function setParentObject($a_parentobject)
68  {
69  $this->parentobject = $a_parentobject;
70  }
71 
77  function getParentObject()
78  {
79  return $this->parentobject;
80  }
81 
85  function getHTML()
86  {
87  global $lng;
88 
89  $ftpl = new ilTemplate("tpl.calendar_block_frame.html", true, true,
90  "Services/Calendar");
91 
92  $tpl = new ilTemplate("tpl.calendar_block.html", true, true,
93  "Services/Calendar");
94  $this->addMiniMonth($tpl);
95 
96  $ftpl->setVariable("BLOCK_TITLE", $lng->txt("calendar"));
97  $ftpl->setVariable("CONTENT", $tpl->get());
98  return $ftpl->get();
99  }
100 
105  function addMiniMonth($a_tpl)
106  {
107  global $ilCtrl, $lng,$ilUser;
108 
109  // weekdays
110  include_once('Services/Calendar/classes/class.ilCalendarUtil.php');
111  $a_tpl->setCurrentBlock('month_header_col');
112  $a_tpl->setVariable('TXT_WEEKDAY', $lng->txt("cal_week_abbrev"));
113  $a_tpl->parseCurrentBlock();
114  for($i = (int) $this->user_settings->getWeekStart();$i < (7 + (int) $this->user_settings->getWeekStart());$i++)
115  {
116  $a_tpl->setCurrentBlock('month_header_col');
117  $a_tpl->setVariable('TXT_WEEKDAY',ilCalendarUtil::_numericDayToString($i,false));
118  $a_tpl->parseCurrentBlock();
119  }
120 
121  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
122  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_MONTH);
123  $this->scheduler->calculate();
124 
125  $counter = 0;
126  foreach(ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE,'m'),
127  $this->seed->get(IL_CAL_FKT_DATE,'Y'),
128  $this->user_settings->getWeekStart())->get() as $date)
129  {
130  $counter++;
131  //$this->showEvents($date);
132 
133 
134  $a_tpl->setCurrentBlock('month_col');
135 
136  if(count($this->scheduler->getByDay($date,$ilUser->getTimeZone())))
137  {
138  $a_tpl->setVariable('DAY_CLASS','calminiapp');
139  #$a_tpl->setVariable('TD_CLASS','calminiapp');
140  }
141 
142  include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
143  if(ilCalendarUtil::_isToday($date))
144  {
145  $a_tpl->setVariable('TD_CLASS','calminitoday');
146  }
147  #elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
148  #{
149  # $a_tpl->setVariable('TD_CLASS','calmininow');
150  #}
151  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_MONTH))
152  {
153  $a_tpl->setVariable('TD_CLASS','calministd');
154  }
155  elseif(ilDateTime::_before($date,$this->seed,IL_CAL_MONTH))
156  {
157  $a_tpl->setVariable('TD_CLASS','calminiprev');
158  }
159  else
160  {
161  $a_tpl->setVariable('TD_CLASS','calmininext');
162  }
163 
164  $day = $date->get(IL_CAL_FKT_DATE,'j');
165  $month = $date->get(IL_CAL_FKT_DATE,'n');
166 
167  $month_day = $day;
168 
169  $ilCtrl->clearParametersByClass('ilcalendardaygui');
170  $ilCtrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
171  $a_tpl->setVariable('OPEN_DAY_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendardaygui',''));
172  $ilCtrl->clearParametersByClass('ilcalendardaygui');
173 
174  $a_tpl->setVariable('MONTH_DAY',$month_day);
175  $a_tpl->parseCurrentBlock();
176 
177  if($counter and !($counter % 7))
178  {
179  $a_tpl->setCurrentBlock('month_row');
180  $ilCtrl->clearParametersByClass('ilcalendarweekgui');
181  $ilCtrl->setParameterByClass('ilcalendarweekgui','seed',$date->get(IL_CAL_DATE));
182  $a_tpl->setVariable('OPEN_WEEK_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendarweekgui',''));
183  $ilCtrl->clearParametersByClass('ilcalendarweekgui');
184  $a_tpl->setVariable('TD_CLASS','calminiweek');
185  $a_tpl->setVariable('WEEK',
186  $date->get(IL_CAL_FKT_DATE,'W'));
187  $a_tpl->parseCurrentBlock();
188  }
189  }
190  $a_tpl->setCurrentBlock('mini_month');
191  $a_tpl->setVariable('TXT_MONTH_OVERVIEW', $lng->txt("cal_month_overview"));
192  $a_tpl->setVariable('TXT_MONTH',
193  $lng->txt('month_'.$this->seed->get(IL_CAL_FKT_DATE,'m').'_long').
194  ' '.$this->seed->get(IL_CAL_FKT_DATE,'Y'));
195  $myseed = clone($this->seed);
196  $ilCtrl->setParameterByClass('ilcalendarmonthgui','seed',$myseed->get(IL_CAL_DATE));
197  $a_tpl->setVariable('OPEN_MONTH_VIEW',$ilCtrl->getLinkTargetByClass('ilcalendarmonthgui',''));
198 
199  $myseed->increment(ilDateTime::MONTH, -1);
200  $ilCtrl->setParameter($this->getParentObject(),'seed',$myseed->get(IL_CAL_DATE));
201 
202  //$a_tpl->setVariable('BL_TYPE', $this->getBlockType());
203  //$a_tpl->setVariable('BL_ID', $this->getBlockId());
204 
205  $a_tpl->setVariable('PREV_MONTH',
206  $ilCtrl->getLinkTarget($this->getParentObject(), ""));
207 
208  $myseed->increment(ilDateTime::MONTH, 2);
209  $ilCtrl->setParameter($this->getParentObject(),'seed',$myseed->get(IL_CAL_DATE));
210  $a_tpl->setVariable('NEXT_MONTH',
211  $ilCtrl->getLinkTarget($this->getParentObject(), ""));
212 
213  $ilCtrl->setParameter($this->getParentObject(), 'seed', "");
214  $a_tpl->parseCurrentBlock();
215  }
216 
217 
218 //
219 //
220 // OLD IMPLEMENTATION
221 //
222 //
223 
231 /*
232  public function setPresentationMode($a_mode)
233  {
234  $this->mode = $a_mode;
235  }
236 */
237 
245 /*
246  public function getHTML()
247  {
248  $this->init();
249  return $this->tpl->get();
250  }
251 */
252 
259 /*
260  protected function init()
261  {
262  include_once('Services/YUI/classes/class.ilYuiUtil.php');
263  ilYuiUtil::initCalendar();
264 
265  // Navigator
266  $this->tpl->setVariable('TXT_CHOOSE_MONTH',$this->lng->txt('yui_cal_choose_month'));
267  $this->tpl->setVariable('TXT_CHOOSE_YEAR',$this->lng->txt('yui_cal_choose_year'));
268  $this->tpl->setVariable('TXT_SUBMIT','OK');
269  $this->tpl->setVariable('TXT_CANCEL',$this->lng->txt('cancel'));
270  $this->tpl->setVariable('TXT_INVALID_YEAR',$this->lng->txt('yuical_invalid_year'));
271 
272  $this->tpl->setVariable('MINICALENDAR','&nbsp;');
273  $this->tpl->setVariable('SEED_MY',$this->seed->get(IL_CAL_FKT_DATE,'m/Y','UTC'));
274  $this->tpl->setVariable('SEED_MDY',$this->seed->get(IL_CAL_FKT_DATE,'m/d/Y','UTC'));
275  $this->tpl->setVariable('MONTHS_LONG',$this->getMonthList());
276  $this->tpl->setVariable('WEEKDAYS_SHORT',$this->getWeekdayList());
277  $this->tpl->setVariable('WEEKSTART',(int) $this->user_settings->getWeekstart());
278  return true;
279  }
280 */
281 
289 /*
290  private function getMonthList()
291  {
292  $this->lng->loadLanguageModule('jscalendar');
293  for($i = 1;$i <= 12; $i++)
294  {
295  if($i < 10)
296  {
297  $i = '0'.$i;
298  }
299  $months[] = $this->lng->txt('l_'.$i);
300  }
301  return '"'.implode('","',$months).'"';
302  }
303 */
304 
312 /*
313  private function getWeekdayList()
314  {
315  $this->lng->loadLanguageModule('jscalendar');
316  foreach(array('su','mo','tu','we','th','fr','sa') as $day)
317  {
318  $days[] = $this->lng->txt('s_'.$day);
319  }
320  return '"'.implode('","',$days).'"';
321  }
322 */
323 }
324 ?>