From ef16492de22642323b57fe09ed08157383f8a159 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 5 Sep 2014 22:19:22 +1000 Subject: [PATCH] Dashboard functional --- .../classes/Controller/Director/Welcome.php | 114 ++++++++++++++++++ application/classes/Model/Child.php | 14 +++ application/classes/Model/Room/Children.php | 22 ++++ application/classes/Model/Rooms.php | 83 ++++++++++++- application/classes/ORM.php | 11 -- application/config/database.php | 2 +- 6 files changed, 231 insertions(+), 15 deletions(-) create mode 100644 application/classes/Controller/Director/Welcome.php create mode 100644 application/classes/Model/Child.php create mode 100644 application/classes/Model/Room/Children.php diff --git a/application/classes/Controller/Director/Welcome.php b/application/classes/Controller/Director/Welcome.php new file mode 100644 index 0000000..9341d10 --- /dev/null +++ b/application/classes/Controller/Director/Welcome.php @@ -0,0 +1,114 @@ +TRUE, + ); + + /** + * Edit a Module Configuration + */ + public function action_index() { + $output = ''; + + $date = Site::DateStartOfWeek(time()); + $so = Company::instance()->so(); + $days = 7; + + $open_dates = $so->open_dates($date,$days); + $output .= ''; + + $output .= ''; + $output .= ''; + foreach (array_keys($open_dates) as $day) + $output .= sprintf('',Site::date($day),date('D',$day)); + $output .= ''; + + $output .= ''; + $output .= ''; + foreach (array_keys($open_dates) as $day) + $output .= sprintf('',StaticList_YesNo::factory()->get(isset($open_dates[$day]) ? $open_dates[$day] : FALSE,TRUE)); + $output .= ''; + + $output .= ''; + $output .= ''; + foreach (array_keys($open_dates) as $day) + $output .= sprintf('','-'); + $output .= ''; + + foreach ($so->rooms->find_all() as $ro) { + $output .= sprintf('',$ro->display('name'),$days); + + // Capacity + $output .= ''; + $output .= ''; + $output .= ''; + $output .= sprintf('',join(''; + + // Permanent + $output .= ''; + $output .= ''; + $output .= ''; + foreach (array_values($ro->child_list_date($date,$days)) as $x) + $output .= sprintf('',count($x)); + $output .= ''; + + // Permanent + $output .= ''; + $output .= ''; + $output .= ''; + foreach (array_values($ro->child_list_date($date,$days,'a')) as $x) + $output .= sprintf('',count($x)); + $output .= ''; + + // Casual + $output .= ''; + $output .= ''; + $output .= ''; + foreach (array_values($ro->child_list_date($date,$days,'C')) as $x) + $output .= sprintf('',count($x)); + $output .= ''; + + // Spacer + $output .= sprintf('',$days+2); + + // Waitlist + $output .= ''; + $output .= ''; + $output .= ''; + foreach (array_values($ro->child_list_date($date,$days,'W')) as $x) + $output .= sprintf('',count($x)); + $output .= ''; + + // Availablity + $output .= ''; + $output .= ''; + $output .= ''; + foreach (array_values($ro->room_availablity($date,$days)) as $x) + $output .= sprintf('',$x); + $output .= ''; + + // Spacer + $output .= sprintf('',$days+2); + } + + $output .= '
 %s (%s)
Open%s
Total%s
%s 
 Capacity%s',array_values($ro->availability_dates($date,$days)))); + $output .= '
 Permanent%s
 Absent%s
 Casual%s
 
 Waitlist%s
 Availability%s
 
'; + + Block::factory() + ->title(sprintf('Site Availability for %s',Site::date($date))) + ->title_icon('icon-cog') + ->span(10) + ->body($output); + } +} +?> diff --git a/application/classes/Model/Child.php b/application/classes/Model/Child.php new file mode 100644 index 0000000..0e3d300 --- /dev/null +++ b/application/classes/Model/Child.php @@ -0,0 +1,14 @@ + diff --git a/application/classes/Model/Room/Children.php b/application/classes/Model/Room/Children.php new file mode 100644 index 0000000..f81b702 --- /dev/null +++ b/application/classes/Model/Room/Children.php @@ -0,0 +1,22 @@ +array(), + ); + + // @todo: Code A (availble) start/end dates cannot overlap with existing records - put in validation that it cannot be saved. + public function day($day) { + return $this->{'d_'.$day}; + } +} +?> diff --git a/application/classes/Model/Rooms.php b/application/classes/Model/Rooms.php index d5516ce..b60ef91 100644 --- a/application/classes/Model/Rooms.php +++ b/application/classes/Model/Rooms.php @@ -10,16 +10,21 @@ * @license http://dev.leenooks.net/license.html */ class Model_Rooms extends ORM { + protected $_belongs_to = array( + 'site'=>array('model'=>'Setup'), + ); protected $_has_many = array( 'dates'=>array('model'=>'Room_Dates','far_key'=>'id','foreign_key'=>'room_id'), + 'children'=>array('model'=>'Room_Children','far_key'=>'id','foreign_key'=>'room_id'), ); - public function room_dates(Model_Setup $so,$date,$days=0) { + public function availability_dates($date,$days=0,$code='A') { $result = array(); + $x = $date; $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) { + $open_dates = $this->site->open_dates($date,$days); + foreach ($this->dates->where('code','=',$code)->where_startstop($date,$date_end)->find_all() as $o) { $x = $date; while ($x<$date_end) { @@ -55,5 +60,77 @@ class Model_Rooms extends ORM { return $result; } + + // 'P' - Permanent + public function child_list_date($date,$days,$code='P') { + $result = array(); + $x = $date; + + $date_end = $date+$days*86400; + $open_dates = $this->site->open_dates($date,$days); + foreach ($this->children->where('code','=',$code)->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] = array(); + + $x += 86400; + continue; + } + + // Check that this record covers our current date + if ($o->date_stop < $x AND ! is_null($o->date_stop)) + break; + + if (! isset($result[$x])) + $result[$x] = array(); + + if ($o->day(date('w',$x))) + array_push($result[$x],$o->child); + + $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] = array(); + + $x += 86400; + } + + return $result; + } + + public function room_availablity($date,$days) { + // We start with our availablity + $result = $this->availability_dates($date,$days); + + // Less Permanents + foreach ($this->child_list_date($date,$days) as $k => $v) + $result[$k] -= count($v); + + // Add Absent + foreach ($this->child_list_date($date,$days,'a') as $k => $v) + $result[$k] += count($v); + + // Less Casuals + foreach ($this->child_list_date($date,$days,'C') as $k => $v) + $result[$k] -= count($v); + + // Less Waitlist + foreach ($this->child_list_date($date,$days,'W') as $k => $v) + $result[$k] -= count($v); + + return $result; + } } ?> diff --git a/application/classes/ORM.php b/application/classes/ORM.php index c3047e7..917b09f 100644 --- a/application/classes/ORM.php +++ b/application/classes/ORM.php @@ -41,17 +41,6 @@ abstract class ORM extends lnApp_ORM { if (! in_array($this->_table_name,ORM::$no_site_id_tables)) $this->where($this->_object_name.'.site_id','=',Company::instance()->site()); - // Ensure we Cache our queries - $caching = FALSE; - foreach ($this->_db_pending as $method) - if ($method['name'] == 'cached') { - $caching = TRUE; - break; - } - - if (! $caching) - $this->cached(Kohana::$config->load('cache.orm.'.$this->_table_name)); - return parent::_build($type); } diff --git a/application/config/database.php b/application/config/database.php index a781657..feeb115 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -26,6 +26,6 @@ return array ), 'table_prefix' => 'mdb_', 'charset' => 'utf8', - 'caching' => FALSE, + 'caching' => TRUE, ), );