Site Status and Room numbers implemented

This commit is contained in:
Deon George
2014-09-05 15:13:25 +10:00
parent 2115c70db0
commit 30f6717c9f
10 changed files with 166 additions and 18 deletions

View File

@@ -71,6 +71,10 @@ class Model_Account extends Model_Auth_UserDefault {
return $alo->saved();
}
public function isAdmin() {
return FALSE;
}
/**
* This function will extract the available methods for this account
* This is used both for menu options and method security

View File

@@ -8,7 +8,7 @@
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Auth_UserDefault extends Model_Auth_User {
abstract class Model_Auth_UserDefault extends Model_Auth_User {
// Validation rules
public function rules() {
return array(
@@ -38,5 +38,7 @@ class Model_Auth_UserDefault extends Model_Auth_User {
public function complete_login() {
return $this->log('Logged In');
}
abstract public function isAdmin();
}
?>

View File

@@ -0,0 +1,19 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Room Configuration by date
*
* @package Membership Database
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Room_Dates extends ORM {
// @todo: Code A (availble) start/end dates cannot overlap with existing records - put in validation that it cannot be saved.
public function avail($day) {
return $this->{'d_'.$day};
}
}
?>

View File

@@ -0,0 +1,59 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Company Rooms
*
* @package Membership Database
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Rooms extends ORM {
protected $_has_many = array(
'dates'=>array('model'=>'Room_Dates','far_key'=>'id','foreign_key'=>'room_id'),
);
public function room_dates(Model_Setup $so,$date,$days=0) {
$result = array();
$date_end = $date+$days*86400;
$open_dates = $so->open_dates($date,$days);
foreach ($this->dates->where('code','=','A')->where_startstop($date,$date_end)->find_all() as $o) {
$x = $date;
while ($x<$date_end) {
// If we havent made the start date yet, we need to advance
if (! $open_dates[$x]
OR ($o->date_start > $x AND (is_null($o->date_stop) OR $o->date_stop > $date_end))
OR ((is_null($o->date_start) OR $o->date_start > $x) AND $o->date_stop > $date_end)
OR (! is_null($o->date_start) AND ! is_null($o->date_stop))) {
if (! isset($result[$x]) OR ! $result[$x])
$result[$x] = 0;
$x += 86400;
continue;
}
// Check that this record covers our current date
if ($o->date_stop < $x AND ! is_null($o->date_stop))
break;
$result[$x] = $o->avail(date('w',$x));
$x += 86400;
}
}
// If we broke out and our date $days hasnt ben evaluated, we are closed
while ($x<$date_end) {
if (! isset($result[$x]) OR ! $result[$x])
$result[$x] = 0;
$x += 86400;
}
return $result;
}
}
?>

View File

@@ -22,6 +22,11 @@ class Model_Setup extends ORM {
'language'=>array('foreign_key'=>'id','far_key'=>'language_id'),
);
protected $_has_many = array(
'dates'=>array('model'=>'Site_Dates','far_key'=>'id','foreign_key'=>'site_id'),
'rooms'=>array('far_key'=>'id','foreign_key'=>'site_id'),
);
protected $_compress_column = array(
'module_config',
'site_details',
@@ -92,6 +97,36 @@ class Model_Setup extends ORM {
return $result;
}
public function open_dates($date,$days=0) {
$result = array();
$date_end = $date+$days*86400;
foreach ($this->dates->where('code','=','O')->where_startstop($date,$date_end)->find_all() as $o)
while ($date<$date_end) {
// If we havent made the start date yet, we need to advance
if ($o->date_start > $date AND $o->date_stop > $date_end) {
$result[$date] = FALSE;
$date += 86400;
continue;
}
// Check that this record covers our current date
if ($o->date_stop < $date)
break;
$result[$date] = $o->open(date('w',$date)) ? TRUE : FALSE;
$date += 86400;
}
// If we broke out and our date $days hasnt ben evaluated, we are closed
while ($date<$date_end) {
$result[$date] = FALSE;
$date += 86400;
}
return $result;
}
/**
* Get/Set our Site Configuration from the DB
*

View File

@@ -0,0 +1,19 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Site Operating Dates
*
* @package Membership Database
* @category Models
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Site_Dates extends ORM {
// @todo: Code O (open) start/end dates cannot overlap with existing records - put in validation that it cannot be saved.
public function open($day) {
return $this->{'d_'.$day};
}
}
?>