PageRenderTime 846ms CodeModel.GetById 162ms app.highlight 428ms RepoModel.GetById 178ms app.codeStats 1ms

/halogy/application/modules/events/controllers/events.php

https://bitbucket.org/haloweb/halogy-1.0/
PHP | 397 lines | 244 code | 73 blank | 80 comment | 20 complexity | e75d6f94b821404968638860c8790f55 MD5 | raw file
  1<?php
  2/**
  3 * Halogy
  4 *
  5 * A user friendly, modular content management system for PHP 5.0
  6 * Built on CodeIgniter - http://codeigniter.com
  7 *
  8 * @package		Halogy
  9 * @author		Haloweb Ltd.
 10 * @copyright	Copyright (c) 2008-2011, Haloweb Ltd.
 11 * @license		http://halogy.com/license
 12 * @link		http://halogy.com/
 13 * @since		Version 1.0
 14 * @filesource
 15 */
 16
 17// ------------------------------------------------------------------------
 18
 19class Events extends Controller {
 20
 21	var $partials = array();
 22	
 23	function Events()
 24	{
 25		parent::Controller();
 26
 27		// get siteID, if available
 28		if (defined('SITEID'))
 29		{
 30			$this->siteID = SITEID;
 31		}
 32
 33		// get site permissions and redirect if it don't have access to this module
 34		if (!$this->permission->sitePermissions)
 35		{
 36			show_error('You do not have permission to view this page');
 37		}
 38		if (!in_array($this->uri->segment(1), $this->permission->sitePermissions))
 39		{
 40			show_error('You do not have permission to view this page');
 41		}		
 42
 43		// load models and modules
 44		$this->load->library('tags');
 45		$this->load->library('calendar', array('show_next_prev' => TRUE, 'next_prev_url' => '/events'));		
 46		$this->load->model('events_model', 'events');
 47		$this->load->module('pages');		
 48
 49		// load partials - archive
 50		if ($archive = $this->events->get_archive())
 51		{
 52			foreach($archive as $date)
 53			{
 54				$this->partials['events:archive'][] = array(
 55					'archive:link' => site_url('/events/'.$date['year'].'/'.$date['month'].'/'),
 56					'archive:title' => $date['dateStr'],
 57					'archive:count' => $date['numEvents']
 58				);
 59			}
 60		}
 61
 62		// load partials - latest
 63		if ($latest = $this->events->get_headlines())
 64		{
 65			foreach($latest as $event)
 66			{
 67				$this->partials['events:latest'][] = array(
 68					'latest:link' => site_url('events/viewevent/'.$event['eventID']),
 69					'latest:title' => $event['eventTitle'],
 70					'latest:date' => dateFmt($event['eventDate'], ($this->site->config['dateOrder'] == 'MD') ? 'M jS Y' : 'jS M Y'),
 71				);
 72			}
 73		}	
 74
 75		// load partials - calendar
 76		$month = ($this->uri->segment(3) && intval($this->uri->segment(2))) ? $this->uri->segment(3) : date('m', time());
 77		$year = ($this->uri->segment(2) && intval($this->uri->segment(2))) ? $this->uri->segment(2) : date('Y', time());
 78		$monthEvents = array();
 79		if ($data['month'] = $this->events->get_month($month, $year))
 80		{
 81			foreach($data['month'] as $event)
 82			{
 83				$monthEvents[dateFmt($event['eventDate'], 'j')] = '/events/'.dateFmt($event['eventDate'], 'Y/m/d');
 84			}
 85		}
 86		@$this->partials['events:calendar'] = $this->calendar->generate($year, $month, $monthEvents);
 87	}
 88
 89	function index()
 90	{
 91		// get partials
 92		$output = $this->partials;
 93						
 94		// get latest events
 95		$events = $this->events->get_events(10);
 96		$output['events:events'] = $this->_populate_events($events);
 97
 98		// send events to page
 99		$data['events'] = $events;
100
101		// set pagination
102		$output['pagination'] = ($pagination = $this->pagination->create_links()) ? $pagination : '';
103
104		// set title
105		$output['page:title'] = $this->site->config['siteName'].' | Events';
106		$output['page:heading'] = 'Upcoming Events';
107		
108		// display with cms layer
109		$this->pages->view('events', $output, TRUE);	
110	}
111	
112	function featured()
113	{
114		// get partials
115		$output = $this->partials;
116						
117		// get latest events
118		$events = $this->events->get_featured_events();
119		$output['events:featured'] = $this->_populate_events($events);
120
121		// send events to page
122		$data['events'] = $events;
123
124		// set pagination
125		$output['pagination'] = ($pagination = $this->pagination->create_links()) ? $pagination : '';
126
127		// set title
128		$output['page:title'] = $this->site->config['siteName'].' | Events';
129		$output['page:heading'] = 'Featured Events';
130		
131		// display with cms layer
132		$this->pages->view('events_featured', $output, TRUE);	
133	}
134
135	function viewevent($eventID = '')
136	{
137		// get partials
138		$output = $this->partials;
139				
140		// get event
141		if ($event = $this->events->get_event($eventID))
142		{				
143
144			// populate template
145			$output['event:title'] = $event['eventTitle'];
146			$output['event:link'] = site_url('events/viewevent/'.$event['eventID']);
147			$output['event:location'] = $event['location'];
148			$output['event:date'] = dateFmt($event['eventDate'], ($this->site->config['dateOrder'] == 'MD') ? 'M jS Y' : 'jS M Y'). 
149						(($event['time']) ? ' ('.$event['time'].')' : '').
150						(($event['eventEnd'] > 0) ? ' - '.dateFmt($event['eventEnd'], ($this->site->config['dateOrder'] == 'MD') ? 'M jS Y' : 'jS M Y') : '');
151			$output['event:body'] = $this->template->parse_body($event['description']);
152			$output['event:excerpt'] = $this->template->parse_body($event['excerpt']);
153			$output['event:author'] = $this->events->lookup_user($event['userID'], TRUE);
154			$output['event:author-id'] = $event['userID'];
155
156			// set title	
157			$output['page:title'] = $this->site->config['siteName'].' Events - '.$event['eventTitle'];
158			$output['keywords'] = $event['tags'];
159			
160			$data['event'] = $event;
161			$data['tags'] = explode(' ', $event['tags']);	
162						
163			// display with cms layer
164			$this->pages->view('events_single', $output, TRUE);
165		}
166		else
167		{
168			show_404();
169		}
170	}
171
172	function tag($tag = '')
173	{		
174		// get partials
175		$output = $this->partials;
176
177		// get tags
178		$events = $this->events->get_events_by_tag($tag);
179		$output['events:events'] = $this->_populate_events($events);
180
181		// set title
182		$output['page:title'] = $this->site->config['siteName'].' | Events';
183		$output['page:heading'] = 'Events on "'.$tag.'"';		
184
185		// set pagination
186		$output['pagination'] = ($pagination = $this->pagination->create_links()) ? $pagination : '';
187						
188		// display with cms layer
189		$this->pages->view('events', $output, TRUE);
190	}
191
192	function month()
193	{
194		// get partials
195		$output = $this->partials;
196
197		// get event based on uri
198		$year = $this->uri->segment(2);
199		$month = $this->uri->segment(3);		
200
201		// get tags
202		$events = $this->events->get_events_by_date($year, $month);
203		$output['events:events'] = $this->_populate_events($events);
204
205		// set title
206		$output['page:title'] = $this->site->config['siteName'].' | Events - '.date('F Y', mktime(0,0,0,$month,1,$year));
207		$output['page:heading'] = date('F Y', mktime(0,0,0,$month,1,$year));			
208
209		// set pagination
210		$output['pagination'] = ($pagination = $this->pagination->create_links()) ? $pagination : '';		
211
212		// display with cms layer
213		$this->pages->view('events', $output, TRUE);	
214	}
215	
216	function year()
217	{
218		// get partials
219		$output = $this->partials;
220
221		// get event based on uri
222		$year = $this->uri->segment(2);	
223
224		// get tags
225		$events = $this->events->get_events_by_date($year);
226		$output['events:events'] = $this->_populate_events($events);
227
228		// set title
229		$output['page:title'] = $this->site->config['siteName'].' | Events - '.date('Y', mktime(0,0,0,1,1,$year));
230		$output['page:heading'] = date('Y', mktime(0,0,0,1,1,$year));			
231
232		// set pagination
233		$output['pagination'] = ($pagination = $this->pagination->create_links()) ? $pagination : '';		
234
235		// display with cms layer
236		$this->pages->view('events', $output, TRUE);	
237	}
238
239	function day()
240	{
241		// get partials
242		$output = $this->partials;
243
244		// get event based on uri
245		$year = $this->uri->segment(2);
246		$month = $this->uri->segment(3);
247		$day = $this->uri->segment(4);	
248
249		// get tags
250		$events = $this->events->get_events_by_date($year, $month, $day);
251		$output['events:events'] = $this->_populate_events($events);
252
253		// set title
254		$output['page:title'] = $this->site->config['siteName'].' | Events - '.date('D jS F Y', mktime(0,0,0,$month,$day,$year));
255		$output['page:heading'] = date('D jS F Y', mktime(0,0,0,$month,$day,$year));
256
257		// set pagination
258		$output['pagination'] = ($pagination = $this->pagination->create_links()) ? $pagination : '';	
259				
260		// display with cms layer
261		$this->pages->view('events', $output, TRUE);	
262	}
263
264	function search($query = '')
265	{
266		// get partials
267		$output = $this->partials;
268
269		// set tags
270		$query = ($query) ? $query : $this->input->post('query');
271
272		// get result from tags
273		$objectIDs = $this->tags->search('events', $query);
274
275		$events = $this->events->search_events($query, $objectIDs);
276		$output['events:events'] = $this->_populate_events($events);
277		$output['query'] = $query;		
278		
279		// set title
280		$output['page:title'] = $this->site->config['siteName'].' | Events - Searching Events for "'.$output['query'].'"';
281		$output['page:heading'] = 'Search events for: "'.$output['query'].'"';
282
283		// set pagination
284		$output['pagination'] = ($pagination = $this->pagination->create_links()) ? $pagination : '';	
285		
286		// display with cms layer
287		$this->pages->view('events_search', $output, TRUE);		
288	}
289
290	function ac_search()
291	{
292		$tags = strtolower($_POST["q"]);
293        if (!$tags)
294        {
295        	return FALSE;
296        }
297
298		if ($objectIDs = $this->tags->search('events', $tags))
299		{		
300			// form dropdown and myql get countries
301			if ($searches = $this->events->search_events($objectIDs))
302			{
303				// go foreach
304				foreach($searches as $search)
305				{
306					$items[$search['tags']] = array('id' => $search['eventID'], 'name' => $search['eventTitle']);
307				}
308				foreach ($items as $key=>$value)
309				{
310					$id = $value['id'];
311					$name = $value['name'];
312					/* If you want to force the results to the query
313					if (strpos(strtolower($key), $tags) !== false)
314					{
315						echo "$key|$id|$name\n";
316					}*/
317					$this->output->set_output("$key|$id|$name\n");
318				}
319			}
320		}
321	}
322	
323	function feed()
324	{
325		$tagdata = array();
326
327		$this->load->helper('xml');
328		
329		$data['encoding'] = 'utf-8';
330		$data['feed_name'] = $this->site->config['siteName'] . ' | Events RSS Feed';
331		$data['feed_url'] = site_url('/events');
332		$data['page_description'] = 'Events RSS Feed for '.$this->site->config['siteName'].'.';
333		$data['page_language'] = 'en';
334		$data['creator_email'] = $this->site->config['siteEmail'];
335		$data['events'] = $this->events->get_events(10);
336		
337        $this->output->set_header('Content-Type: application/rss+xml');
338		$this->load->view('rss', $data);
339	}
340
341    function _populate_events($events = '')
342    {
343    	if ($events && is_array($events))
344    	{
345			$x = 0;
346			foreach($events as $event)
347			{
348				// set month
349				//$months[dateFmt($event['eventDate'], 'n')] = dateFmt($event['eventDate'], 'F');
350				
351				// populate template array
352				$data[$x] = array(
353					'event:link' => site_url('events/viewevent/'.$event['eventID']),
354					'event:title' => $event['eventTitle'],
355					'event:location' => $event['location'],
356					'event:date' => dateFmt($event['eventDate'], ($this->site->config['dateOrder'] == 'MD') ? 'M jS Y' : 'jS M Y'). 
357						(($event['time']) ? ' ('.$event['time'].')' : '').
358						(($event['eventEnd'] > 0) ? ' - '.dateFmt($event['eventEnd'], ($this->site->config['dateOrder'] == 'MD') ? 'M jS Y' : 'jS M Y') : ''),
359					'event:day' => dateFmt($event['eventDate'], 'd'),
360					'event:month' => dateFmt($event['eventDate'], 'M'),
361					'event:year' => dateFmt($event['eventDate'], 'y'),																
362					'event:body' => $this->template->parse_body($event['description'], TRUE, site_url('events/viewevent/'.$event['eventID'])),
363					'event:excerpt' => $this->template->parse_body($event['excerpt'], TRUE, site_url('events/viewevent/'.$event['eventID'])),
364					'event:author' => $this->events->lookup_user($event['userID'], TRUE),
365					'event:author-id' => $event['userID']
366				);
367	
368				// get tags
369				if ($event['tags'])
370				{
371					$tags = explode(' ', $event['tags']);
372
373					$i = 0;
374					foreach ($tags as $tag)
375					{
376						$data[$x]['event:tags'][$i]['tag:link'] = site_url('blog/tag/'.$tag);
377						$data[$x]['event:tags'][$i]['tag'] = $tag;
378						
379						$i++;
380					}
381				}
382
383				// set month
384				//$data[$x]['event:month'] = ($months[$x-1]['event:month'] != dateFmt($event['eventDate'], 'n')) ? dateFmt($event['eventDate'], 'F') : '';
385	
386				$x++;
387			}
388
389			return $data;
390		}
391		else
392		{
393			return FALSE;
394		}
395    }
396
397}