ILIAS  Release_3_10_x_branch Revision 61812
 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("IMG_BLOCK", ilUtil::getImagePath("icon_cals_s.gif"));
97  $ftpl->setVariable("BLOCK_TITLE", $lng->txt("calendar"));
98  $ftpl->setVariable("CONTENT", $tpl->get());
99  return $ftpl->get();
100  }
101 
106  function addMiniMonth($a_tpl)
107  {
108  global $ilCtrl, $lng,$ilUser;
109 
110  // weekdays
111  include_once('Services/Calendar/classes/class.ilCalendarUtil.php');
112  for($i = (int) $this->user_settings->getWeekStart();$i < (7 + (int) $this->user_settings->getWeekStart());$i++)
113  {
114  $a_tpl->setCurrentBlock('month_header_col');
115  $a_tpl->setVariable('TXT_WEEKDAY',ilCalendarUtil::_numericDayToString($i,false));
116  $a_tpl->parseCurrentBlock();
117  }
118  $a_tpl->setCurrentBlock('month_header_col');
119  $a_tpl->setVariable('TXT_WEEKDAY', "&nbsp;");
120  $a_tpl->parseCurrentBlock();
121 
122  include_once('Services/Calendar/classes/class.ilCalendarSchedule.php');
123  $this->scheduler = new ilCalendarSchedule($this->seed,ilCalendarSchedule::TYPE_MONTH);
124  $this->scheduler->calculate();
125 
126  $counter = 0;
127  foreach(ilCalendarUtil::_buildMonthDayList($this->seed->get(IL_CAL_FKT_DATE,'m'),
128  $this->seed->get(IL_CAL_FKT_DATE,'Y'),
129  $this->user_settings->getWeekStart())->get() as $date)
130  {
131  $counter++;
132  //$this->showEvents($date);
133 
134 
135  $a_tpl->setCurrentBlock('month_col');
136 
137  if(count($this->scheduler->getByDay($date,$ilUser->getTimeZone())))
138  {
139  $a_tpl->setVariable('DAY_CLASS','calminiapp');
140  #$a_tpl->setVariable('TD_CLASS','calminiapp');
141  }
142 
143  include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
144  if(ilCalendarUtil::_isToday($date))
145  {
146  $a_tpl->setVariable('TD_CLASS','calminitoday');
147  }
148  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_DAY))
149  {
150  $a_tpl->setVariable('TD_CLASS','calmininow');
151  }
152  elseif(ilDateTime::_equals($date,$this->seed,IL_CAL_MONTH))
153  {
154  $a_tpl->setVariable('TD_CLASS','calministd');
155  }
156  elseif(ilDateTime::_before($date,$this->seed,IL_CAL_MONTH))
157  {
158  $a_tpl->setVariable('TD_CLASS','calminiprev');
159  }
160  else
161  {
162  $a_tpl->setVariable('TD_CLASS','calmininext');
163  }
164 
165  $day = $date->get(IL_CAL_FKT_DATE,'j');
166  $month = $date->get(IL_CAL_FKT_DATE,'n');
167 
168  $month_day = $day;
169 
170  $ilCtrl->clearParametersByClass('ilcalendardaygui');
171  $ilCtrl->setParameterByClass('ilcalendardaygui','seed',$date->get(IL_CAL_DATE));
172  $a_tpl->setVariable('OPEN_DAY_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendardaygui',''));
173  $ilCtrl->clearParametersByClass('ilcalendardaygui');
174 
175  $a_tpl->setVariable('MONTH_DAY',$month_day);
176  //$this->tpl->setVariable('NEW_SRC',ilUtil::getImagePath('new.gif','calendar'));
177  //$this->tpl->setVariable('NEW_ALT',$this->lng->txt('cal_new_app'));
178  //$this->ctrl->clearParametersByClass('ilcalendarappointmentgui');
179  //$this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$date->get(IL_CAL_DATE));
180  //$this->tpl->setVariable('ADD_LINK',$this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui','add'));
181 
182  //$this->tpl->setVariable('OPEN_SRC',ilUtil::getImagePath('open.gif','calendar'));
183  $a_tpl->parseCurrentBlock();
184 
185  if($counter and !($counter % 7))
186  {
187  $a_tpl->setCurrentBlock('month_row');
188  $ilCtrl->clearParametersByClass('ilcalendarweekgui');
189  $ilCtrl->setParameterByClass('ilcalendarweekgui','seed',$date->get(IL_CAL_DATE));
190  $a_tpl->setVariable('OPEN_WEEK_VIEW', $ilCtrl->getLinkTargetByClass('ilcalendarweekgui',''));
191  $ilCtrl->clearParametersByClass('ilcalendarweekgui');
192  $a_tpl->setVariable('TD_CLASS','calminiweek');
193  $a_tpl->setVariable('WEEK',
194  $date->get(IL_CAL_FKT_DATE,'W'));
195  $a_tpl->parseCurrentBlock();
196  }
197  }
198  $a_tpl->setCurrentBlock('mini_month');
199 
200  $a_tpl->setVariable('TXT_MONTH',
201  $lng->txt('month_'.$this->seed->get(IL_CAL_FKT_DATE,'m').'_long').
202  ' '.$this->seed->get(IL_CAL_FKT_DATE,'Y'));
203  $myseed = clone($this->seed);
204  $ilCtrl->setParameterByClass('ilcalendarmonthgui','seed',$myseed->get(IL_CAL_DATE));
205  $a_tpl->setVariable('OPEN_MONTH_VIEW',$ilCtrl->getLinkTargetByClass('ilcalendarmonthgui',''));
206 
207  $myseed->increment(ilDateTime::MONTH, -1);
208  $ilCtrl->setParameter($this->getParentObject(),'seed',$myseed->get(IL_CAL_DATE));
209 
210  //$a_tpl->setVariable('BL_TYPE', $this->getBlockType());
211  //$a_tpl->setVariable('BL_ID', $this->getBlockId());
212 
213  $a_tpl->setVariable('PREV_MONTH',
214  $ilCtrl->getLinkTarget($this->getParentObject(), ""));
215 
216  $myseed->increment(ilDateTime::MONTH, 2);
217  $ilCtrl->setParameter($this->getParentObject(),'seed',$myseed->get(IL_CAL_DATE));
218  $a_tpl->setVariable('NEXT_MONTH',
219  $ilCtrl->getLinkTarget($this->getParentObject(), ""));
220 
221  $ilCtrl->setParameter($this->getParentObject(), 'seed', "");
222  $a_tpl->parseCurrentBlock();
223  }
224 
225 
226 //
227 //
228 // OLD IMPLEMENTATION
229 //
230 //
231 
239 /*
240  public function setPresentationMode($a_mode)
241  {
242  $this->mode = $a_mode;
243  }
244 */
245 
253 /*
254  public function getHTML()
255  {
256  $this->init();
257  return $this->tpl->get();
258  }
259 */
260 
267 /*
268  protected function init()
269  {
270  include_once('Services/YUI/classes/class.ilYuiUtil.php');
271  ilYuiUtil::initCalendar();
272 
273  // Navigator
274  $this->tpl->setVariable('TXT_CHOOSE_MONTH',$this->lng->txt('yui_cal_choose_month'));
275  $this->tpl->setVariable('TXT_CHOOSE_YEAR',$this->lng->txt('yui_cal_choose_year'));
276  $this->tpl->setVariable('TXT_SUBMIT','OK');
277  $this->tpl->setVariable('TXT_CANCEL',$this->lng->txt('cancel'));
278  $this->tpl->setVariable('TXT_INVALID_YEAR',$this->lng->txt('yuical_invalid_year'));
279 
280  $this->tpl->setVariable('MINICALENDAR','&nbsp;');
281  $this->tpl->setVariable('SEED_MY',$this->seed->get(IL_CAL_FKT_DATE,'m/Y','UTC'));
282  $this->tpl->setVariable('SEED_MDY',$this->seed->get(IL_CAL_FKT_DATE,'m/d/Y','UTC'));
283  $this->tpl->setVariable('MONTHS_LONG',$this->getMonthList());
284  $this->tpl->setVariable('WEEKDAYS_SHORT',$this->getWeekdayList());
285  $this->tpl->setVariable('WEEKSTART',(int) $this->user_settings->getWeekstart());
286  return true;
287  }
288 */
289 
297 /*
298  private function getMonthList()
299  {
300  $this->lng->loadLanguageModule('jscalendar');
301  for($i = 1;$i <= 12; $i++)
302  {
303  if($i < 10)
304  {
305  $i = '0'.$i;
306  }
307  $months[] = $this->lng->txt('l_'.$i);
308  }
309  return '"'.implode('","',$months).'"';
310  }
311 */
312 
320 /*
321  private function getWeekdayList()
322  {
323  $this->lng->loadLanguageModule('jscalendar');
324  foreach(array('su','mo','tu','we','th','fr','sa') as $day)
325  {
326  $days[] = $this->lng->txt('s_'.$day);
327  }
328  return '"'.implode('","',$days).'"';
329  }
330 */
331 }
332 ?>