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

@ -19,7 +19,7 @@ abstract class Controller_TemplateDefault extends lnApp_Controller_TemplateDefau
} catch (ORM_Validation_Exception $e) {
SystemMessage::factory()
->title('Record NOT updated')
->type('error')
->type('danger')
->body(join('<br/>',array_values($e->errors('models'))));
return FALSE;

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};
}
}
?>

View File

@ -175,5 +175,20 @@ abstract class ORM extends lnApp_ORM {
return $this->where($aid,'IN',$ao->RTM->customers($ao->RTM));
}
public function where_startstop($date,$date_end,$start='date_start',$stop='date_stop') {
if (array_key_exists('priority',$this->table_columns()))
$this->order_by('priority','ASC');
return $this
->where_open()
->where_open()->where($start,'<=',$date)->and_where($stop,'>=',$date)->where_close()
->or_where_open()->where($start,'<=',$date_end)->and_where($stop,'>=',$date_end)->where_close()
->or_where_open()->where($start,'is',NULL)->where_open()->where($stop,'is',NULL)->or_where($stop,'>=',$date)->where_close()->where_close()
->or_where_open()->where($stop,'is',NULL)->where_open()->where($start,'is',NULL)->or_where($start,'<=',$date_end)->where_close()->where_close()
->where_close()
->order_by($start,'ASC')
->order_by($stop,'ASC');
}
}
?>

View File

@ -10,6 +10,9 @@
* @license http://dev.leenooks.net/license.html
*/
class Site extends lnApp_Site {
private static $_weekstart = 'monday'; // @todo Move into setup table
private static $_weekend = 'sunday'; // @todo Move into setup table
/**
* Show a date using a site configured format
*/
@ -17,6 +20,14 @@ class Site extends lnApp_Site {
return (is_null($date) OR ! $date) ? '' : date(Company::instance()->date_format(),$date);
}
public static function DateEndOfWeek($date) {
return strtotime(self::$_weekend.' this week',$date);
}
public static function DateStartOfWeek($date) {
return strtotime(self::$_weekstart.' this week',$date);
}
/**
* Work out our site ID for multihosting
*/

View File

@ -1,16 +0,0 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Photo system default configurable items.
*
* @package Membership Database
* @category Configuration
* @author Deon George
* @copyright (c) 2014 Deon George
* @license http://dev.leenooks.net/license.html
*/
return array(
'Duplicates' => array('icon'=>'icon-edit','url'=>URL::site('photo/duplicate')),
);
?>