From 30f6717c9f351149826f73759eea241fdd90a952 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 5 Sep 2014 15:13:25 +1000 Subject: [PATCH] Site Status and Room numbers implemented --- .../classes/Controller/TemplateDefault.php | 2 +- application/classes/Model/Account.php | 4 ++ .../classes/Model/Auth/UserDefault.php | 4 +- application/classes/Model/Room/Dates.php | 19 ++++++ application/classes/Model/Rooms.php | 59 +++++++++++++++++++ application/classes/Model/Setup.php | 35 +++++++++++ application/classes/Model/Site/Dates.php | 19 ++++++ application/classes/ORM.php | 15 +++++ application/classes/Site.php | 11 ++++ application/config/mainnav.php | 16 ----- 10 files changed, 166 insertions(+), 18 deletions(-) create mode 100644 application/classes/Model/Room/Dates.php create mode 100644 application/classes/Model/Rooms.php create mode 100644 application/classes/Model/Site/Dates.php delete mode 100644 application/config/mainnav.php diff --git a/application/classes/Controller/TemplateDefault.php b/application/classes/Controller/TemplateDefault.php index fa8bdc1..50a6050 100644 --- a/application/classes/Controller/TemplateDefault.php +++ b/application/classes/Controller/TemplateDefault.php @@ -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('
',array_values($e->errors('models')))); return FALSE; diff --git a/application/classes/Model/Account.php b/application/classes/Model/Account.php index 2bcbf6b..df7802a 100644 --- a/application/classes/Model/Account.php +++ b/application/classes/Model/Account.php @@ -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 diff --git a/application/classes/Model/Auth/UserDefault.php b/application/classes/Model/Auth/UserDefault.php index d3f4d06..c516961 100644 --- a/application/classes/Model/Auth/UserDefault.php +++ b/application/classes/Model/Auth/UserDefault.php @@ -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(); } ?> diff --git a/application/classes/Model/Room/Dates.php b/application/classes/Model/Room/Dates.php new file mode 100644 index 0000000..1ca688a --- /dev/null +++ b/application/classes/Model/Room/Dates.php @@ -0,0 +1,19 @@ +{'d_'.$day}; + } +} +?> diff --git a/application/classes/Model/Rooms.php b/application/classes/Model/Rooms.php new file mode 100644 index 0000000..d5516ce --- /dev/null +++ b/application/classes/Model/Rooms.php @@ -0,0 +1,59 @@ +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; + } +} +?> diff --git a/application/classes/Model/Setup.php b/application/classes/Model/Setup.php index bb73eaf..2eb5fa2 100644 --- a/application/classes/Model/Setup.php +++ b/application/classes/Model/Setup.php @@ -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 * diff --git a/application/classes/Model/Site/Dates.php b/application/classes/Model/Site/Dates.php new file mode 100644 index 0000000..e845f6d --- /dev/null +++ b/application/classes/Model/Site/Dates.php @@ -0,0 +1,19 @@ +{'d_'.$day}; + } +} +?> diff --git a/application/classes/ORM.php b/application/classes/ORM.php index 7420c1b..c3047e7 100644 --- a/application/classes/ORM.php +++ b/application/classes/ORM.php @@ -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'); + } } ?> diff --git a/application/classes/Site.php b/application/classes/Site.php index 5524c53..2f1780d 100644 --- a/application/classes/Site.php +++ b/application/classes/Site.php @@ -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 */ diff --git a/application/config/mainnav.php b/application/config/mainnav.php deleted file mode 100644 index 1a2cfcf..0000000 --- a/application/config/mainnav.php +++ /dev/null @@ -1,16 +0,0 @@ - array('icon'=>'icon-edit','url'=>URL::site('photo/duplicate')), -); -?>