Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_calendar_restricted.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/page/page.inc';
18 require_once SQ_FUDGE_PATH.'/general/text.inc';
19 require_once SQ_PACKAGES_PATH.'/calendar/lib/calendar_common.inc';
20 require_once SQ_PACKAGES_PATH.'/calendar/page_templates/page_calendar_rolling/page_calendar_rolling.inc';
21 
34 {
35 
36 
43  function __construct($assetid=0)
44  {
45  parent::__construct($assetid);
46  }//end constructor
47 
48 
59  function onRequestKeywords(&$broadcaster, $vars=Array())
60  {
61  if (!isset($vars['keywords'])) {
62  $vars['keywords'] = Array();
63  }
64 
65  // get the bodycopy parent of the broadcaster
66  $broadcaster_parents = $GLOBALS['SQ_SYSTEM']->am->getParents($broadcaster->id);
67  $format_bodycopy_link = reset($GLOBALS['SQ_SYSTEM']->am->getLinks($this->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, 'major', '', 'TRUE'));
68  if (!empty($format_bodycopy_link['minorid']) && isset($broadcaster_parents[$format_bodycopy_link['minorid']])) {
69  // this is the page_contents bodycopy
70  $vars['keywords']['next_link'] = 'Link to the next page of events';
71  $vars['keywords']['prev_link'] = 'Link to the previous page of events';
72  }
73 
74  return parent::onRequestKeywords($broadcaster, $vars);
75 
76  }//end onRequestKeywords()
77 
78 
86  {
87  $res = parent::_getPageContentsReplacements();
88  list($current_start_date, $current_last_date) = $this->_getDisplayDates();
89  $first_valid_date = substr($this->attr('start_date'), 0, 10);
90  $last_valid_date = substr($this->attr('end_date'), 0, 10);
91  $last_normal_start = date('Y-m-d', strtotime(substr($this->attr('end_date'), 0, 10).' -'.($this->attr('days_per_page')-1).' days'));
92 
93  $res['next_link'] = '';
94  if ($current_last_date < $last_valid_date) {
95  $next_date = date('Y-m-d', strtotime($current_start_date.' +'.($this->attr('days_per_page')).' days'));
96  $num_days_next = $this->attr('days_per_page');
97  if ($next_date > $last_normal_start) {
98  $num_days_next = days_between_isos($last_valid_date, $next_date) + 1;
99  }
100  $url = htmlspecialchars(replace_query_string_vars(Array('show_date' => $next_date)));
101  $text = str_replace('%n%', $num_days_next, $this->attr('next_text'));
102  $res['next_link'] = '<a href="'.$url.'">'.$text.'</a>';
103  }
104 
105  $res['prev_link'] = '';
106  if ($current_start_date > $first_valid_date) {
107  $last_date = date('Y-m-d', strtotime($current_start_date.' -'.$this->attr('days_per_page').' days'));
108  $num_days_next = $this->attr('days_per_page');
109  if ($last_date < $first_valid_date) {
110  $last_date = $first_valid_date;
111  $num_days_next = days_between_isos($current_start_date, $last_date) + 1;
112  }
113  $url = htmlspecialchars(replace_query_string_vars(Array('show_date' => $last_date)));
114  $text = str_replace('%n%', $num_days_next, $this->attr('prev_text'));
115  $res['prev_link'] = '<a href="'.$url.'">'.$text.'</a>';
116  }
117 
118  return $res;
119 
120  }//end _getPageContentsReplacements()
121 
122 
130  function _getEvents()
131  {
132  list($first_date, $last_date) = $this->_getDisplayDates();
133  return parent::_getEvents($first_date, $last_date);
134 
135  }//end _getEvents()
136 
137 
145  function _getDisplayDates()
146  {
147  $start_date = substr($this->attr('start_date'), 0, 10);
148  $end_date = substr($this->attr('end_date'), 0, 10);
149  $length = $this->attr('days_per_page');
150  $display_date = array_get_index($_REQUEST, 'show_date', date('Y-m-d'));
151  if ($display_date < $start_date) {
152  $display_date = $start_date;
153  }
154  $last_date = date('Y-m-d', strtotime($display_date.' +'.($length-1).' days'));
155  if ($last_date > $end_date) $last_date = $end_date;
156  return Array($display_date, $last_date);
157 
158  }//end _getDisplayDates()
159 
160 
167  function printBody()
168  {
169  $end_date = substr($this->attr('end_date'), 0, 10);
170  if ($end_date == '----------') {
171  trigger_localised_error('CAL0063', E_USER_WARNING, $this->id);
172  return;
173  }
174  parent::printBody();
175 
176  }//end printBody()
177 
178 
179 }//end class
180 ?>