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