<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* MODULE NAME : eventrooms_model.php
*
* DESCRIPTION : eventrooms model
*
* MODIFICATION HISTORY
* V1.0 2008-11-13 2:00 AM - Leane Verhulst - Created
*
* @package ConCentric
* @subpackage eventrooms model component Class
* @author Leane Verhulst
* @copyright Copyright (c) 2008
* @license http://www.gnu.org/licenses/gpl.html
*/
class Eventrooms_model extends base_model
{
// -------------------------------------------------------------------------
function Eventrooms_model()
{
parent::Base_model();
// Include all tables that are linked to from events
$this->_TABLES = array(
'eventRooms' => $this->config->item('concentric_table_prefix') . 'eventRooms',
'events' => $this->config->item('concentric_table_prefix') . 'events',
'rooms' => $this->config->item('concentric_table_prefix') . 'rooms',
'tracks' => $this->config->item('concentric_table_prefix') . 'tracks'
);
// Cache to store already fetched items
$this->_CACHE = array();
}
// -------------------------------------------------------------------------
/*
* Fetch events that are assigned to a room.
*/
function fetchEventRooms($where = '', $orderby = 'event.name ASC, room.sortOrder ASC')
{
// Build a query to get the data
$this->db->select('eventroom.id, event.id AS event_id, event.name AS event_name, room.id AS room_id, room.name AS room_name, room.sortOrder AS room_sortorder, room.alternateName');
$this->db->from($this->_TABLES['eventRooms'] . ' eventroom');
$this->db->join($this->_TABLES['events'] . ' event', 'event.id = eventroom.eventID', 'left');
$this->db->join($this->_TABLES['rooms'] . ' room', 'room.id = eventroom.roomID', 'left');
$this->db->order_by($orderby);
if ($where)
$this->db->where($where, NULL, FALSE);
$query = $this->db->get();
//flashMsg('info',$this->db->last_query());
return $query;
}
// -------------------------------------------------------------------------
/*
* Fetch active event(s) with a startDateTime and which is assigned to a room
*/
function fetchScheduledEvents($where = '')
{
$this->db->select('event.id, room.sortOrder, event.startDateTime, event.eventLength, event.setupTime, event.teardownTime, room.id as roomID');
$this->db->from($this->_TABLES['eventRooms'] . ' eventroom');
$this->db->join($this->_TABLES['events'] . ' event', 'event.id = eventroom.eventID', 'left');
$this->db->join($this->_TABLES['rooms'] . ' room', 'room.id = eventroom.roomID', 'left');
$this->db->where('event.startDateTime != "0000-00-00 00:00:00"');
$this->db->where('event.activeQ = 1');
if ($where)
$this->db->where($where, NULL, FALSE);
$query = $this->db->get();
//flashMsg('info',$this->db->last_query());
return $query;
}
// -------------------------------------------------------------------------
/*
* Fetch active event(s) that are public with a startDateTime and which is assigned to a room
*/
function fetchPublicScheduledEvents($where = '')
{
$this->db->select('event.id, room.sortOrder, event.startDateTime, event.eventLength, event.setupTime, event.teardownTime, room.id as roomID');
$this->db->from($this->_TABLES['eventRooms'] . ' eventroom');
$this->db->join($this->_TABLES['events'] . ' event', 'event.id = eventroom.eventID', 'left');
$this->db->join($this->_TABLES['rooms'] . ' room', 'room.id = eventroom.roomID', 'left');
$this->db->join($this->_TABLES['tracks'] . ' track', 'event.trackID = track.id', 'left');
$this->db->where('event.startDateTime != "0000-00-00 00:00:00"');
$this->db->where('event.activeQ = 1');
$this->db->where('track.publicQ = 1');
if ($where)
$this->db->where($where, NULL, FALSE);
$query = $this->db->get();
//flashMsg('info',$this->db->last_query());
return $query;
}
// -------------------------------------------------------------------------
/*
* Fetch active rooms with active, scheduled events
* Report used by Room controller
*/
function fetchScheduledRooms($where = '', $orderby = 'eventdate ASC, room.sortOrder ASC')
{
$this->db->distinct();
$this->db->select('DATE(event.startDateTime) as eventdate, DAYNAME(event.startDateTime) as eventday, room.sortOrder, room.id, room.name, room.alternateName');
$this->db->from($this->_TABLES['eventRooms'] . ' eventroom');
$this->db->join($this->_TABLES['events'] . ' event', 'event.id = eventroom.eventID', 'left');
$this->db->join($this->_TABLES['rooms'] . ' room', 'room.id = eventroom.roomID', 'left');
$this->db->join($this->_TABLES['tracks'] . ' track', 'event.trackID = track.id', 'left');
$this->db->where('event.startDateTime != "0000-00-00 00:00:00"');
$this->db->where('event.activeQ = 1');
$this->db->where('event.hideQ = 0');
$this->db->where('track.publicQ = 1');
if ($where)
$this->db->where($where, NULL, FALSE);
if ($orderby)
$this->db->order_by($orderby);
$query = $this->db->get();
//flashMsg('info',$this->db->last_query());
return $query;
}
// -------------------------------------------------------------------------
/*
* Fetch active, scheduled events by room
* Report used by Room controller
*/
function fetchScheduledRooms2($where = '', $orderby = 'startDateTime ASC, name ASC')
{
$this->db->select('event.id, event.name, event.startDateTime, event.eventLength');
$this->db->from($this->_TABLES['eventRooms'] . ' eventroom');
$this->db->join($this->_TABLES['events'] . ' event', 'event.id = eventroom.eventID', 'left');
$this->db->join($this->_TABLES['rooms'] . ' room', 'room.id = eventroom.roomID', 'left');
$this->db->join($this->_TABLES['tracks'] . ' track', 'event.trackID = track.id', 'left');
$this->db->where('event.startDateTime != "0000-00-00 00:00:00"');
$this->db->where('event.activeQ = 1');
$this->db->where('track.publicQ = 1');
$this->db->where('event.hideQ = 0');
if ($where)
$this->db->where($where, NULL, FALSE);
if ($orderby)
$this->db->order_by($orderby);
$query = $this->db->get();
//flashMsg('info',$this->db->last_query());
return $query;
}
// -------------------------------------------------------------------------
/*
* Fetch active event(s) that are for publication with a startDateTime and
* which is assigned to a room
*/
function fetchPublicationScheduledEvents($where = '', $sort = 'category')
{
if ($sort == 'all')
{
$orderby = 'event.startDateTime ASC, room.sortOrder ASC, event.name ASC';
}
else
{
$orderby = 'event.categoryID ASC, event.startDateTime ASC, room.sortOrder ASC, event.name ASC';
}
$this->db->distinct();
$this->db->select('event.id, event.startDateTime, event.eventLength, event.categoryID');
$this->db->from($this->_TABLES['eventRooms'] . ' eventroom');
$this->db->join($this->_TABLES['events'] . ' event', 'event.id = eventroom.eventID', 'left');
$this->db->join($this->_TABLES['rooms'] . ' room', 'room.id = eventroom.roomID', 'left');
$this->db->join($this->_TABLES['tracks'] . ' track', 'event.trackID = track.id', 'left');
$this->db->where('event.startDateTime != "0000-00-00 00:00:00"');
$this->db->where('event.activeQ = 1');
$this->db->where('event.hideQ = 0');
if ($where)
$this->db->where($where, NULL, FALSE);
if ($orderby)
$this->db->orderby($orderby);
$query = $this->db->get();
//flashMsg('info',$this->db->last_query());
return $query;
}
// -------------------------------------------------------------------------
/**
* Convert the query object to a array of room strings using event id as key
*/
function convertRoomsToStr($where = '', $orderby = 'event.name ASC, room.sortOrder ASC')
{
$rows = $this->fetchEventRooms($where, $orderby);
$data = array();
//loop thru query results and build array
foreach ($rows->result_array() as $row)
{
$data[$row['event_id']][] = $row['room_name'];
}
//loop thru array and change values to strings
foreach ($data as $key => $value)
{
$returndata[$key] = implode(', ', $value);
}
//flashMsg('info','<pre>'.print_r($returndata, TRUE).'</pre>');
return $returndata;
}
// -------------------------------------------------------------------------
/**
* Convert the query object to a array of room strings with alternate name using event id as key
*/
function convertRoomsToStrAlternate($where = '', $orderby = 'event.name ASC, room.sortOrder ASC')
{
$rows = $this->fetchEventRooms($where, $orderby);
$data = array();
//loop thru query results and build array
foreach ($rows->result_array() as $row)
{
$str = (isset($row['alternateName']) && $row['alternateName'] != '' ? ' (' . $row['alternateName'] . ')' : '');
$data[$row['event_id']][] = $row['room_name'] . $str;
}
//loop thru array and change values to strings
foreach ($data as $key => $value)
{
$returndata[$key] = implode(', ', $value);
}
//flashMsg('info','<pre>'.print_r($returndata, TRUE).'</pre>');
return $returndata;
}
}
/* End of file eventrooms_model.php */
/* Location: ./system/application/models/eventrooms_model.php */