diff --git a/application/classes/Controller/Child.php b/application/classes/Controller/Child.php new file mode 100644 index 0000000..0e01cdf --- /dev/null +++ b/application/classes/Controller/Child.php @@ -0,0 +1,3 @@ +TRUE, + 'ajaxlist'=>FALSE, + 'list'=>TRUE, + ); + + /** + * Edit a Module Configuration + */ + public function action_add() { + Block::factory() + ->type('form-horizontal') + ->title('Add/Edit Record') + ->title_icon('fa-wrench') + ->body($this->add_edit()); + } + + public function action_ajaxlist() { + $result = array(); + + if ($this->request->query('query')) + $result = Arr::merge($result,ORM::factory('Account')->list_autocomplete($this->request->query('query'),'id','id',array('%s: %s'=>array('id','name(TRUE)')))); + + $this->response->headers('Content-Type','application/json'); + $this->response->body(json_encode(array_values($result))); + } + /** + * Edit a Module Configuration + */ + public function action_list() { + $output = __METHOD__; + + Block::factory() + ->title('List Families') + ->body($output); + } + + private function add_edit($id=NULL) { + $co = ORM::factory('Child',$id); + + if ($this->request->post() AND $co->values($this->request->post())->changed() AND (! $this->save($co))) + $co->reload()->values($this->request->post()); + + // If there are no room records, we'll create a waitlist one that can be completed. + if (! $co->subitems()) + $co->subitem_add($co->room->values(array('child_id'=>$co->id,'code'=>'W'))); + + Style::factory() + ->type('file') + ->data('media/theme/bootstrap/css/bootstrap.datepicker.css'); + + Script::factory() + ->type('file') + ->data('media/theme/bootstrap/js/bootstrap.datepicker.js'); + + return View::factory('child/user/add_edit') + ->set('o',$co) + ->set('so',Company::instance()->so()); + + } +} +?> diff --git a/application/classes/Controller/Director/Welcome.php b/application/classes/Controller/Director/Welcome.php index a069ac3..a4951e5 100644 --- a/application/classes/Controller/Director/Welcome.php +++ b/application/classes/Controller/Director/Welcome.php @@ -20,92 +20,34 @@ class Controller_Director_Welcome extends Controller_Welcome { public function action_index() { $output = ''; - $date = Site::DateStartOfWeek(time()); + $t = strtotime($this->request->query('date')); + if (! $t) + $t = time(); + $so = Company::instance()->so(); + $date = Site::DateStartOfWeek($t); $days = 7; - $open_dates = $so->open_dates($date,$days); - $output .= ''; + $output .= ''; + $output .= View::factory('room/availability') + ->set('date',$date) + ->set('days',$days) + ->set('open_dates',$so->open_dates($date,$days)) + ->set('total_places',$so->total_places($date,$days)) + ->set('r',$so->rooms->find_all()) + ->set('uri',$this->request->uri()); + $output .= ''; - $output .= ''; - $output .= ''; - foreach (array_keys($open_dates) as $day) - $output .= sprintf('',Site::date($day),date('D',$day)); - $output .= ''; + Style::factory() + ->type('file') + ->data('media/theme/bootstrap/css/bootstrap.datepicker.css'); - $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
 
'; + Script::factory() + ->type('file') + ->data('media/theme/bootstrap/js/bootstrap.datepicker.js'); Block::factory() - ->title(sprintf('Site Availability for %s',Site::date($date))) + ->title(sprintf('Availability for %s',Site::date($date))) ->title_icon('icon-cog') ->body($output); } diff --git a/application/classes/Controller/Family.php b/application/classes/Controller/Family.php deleted file mode 100644 index c2bd26e..0000000 --- a/application/classes/Controller/Family.php +++ /dev/null @@ -1,3 +0,0 @@ -TRUE, + 'edit'=>TRUE, + ); + + public function action_add() { + Block::factory() + ->type('form-horizontal') + ->title('Add/Edit Record') + ->title_icon('fa-wrench') + ->body($this->add_edit()); + } + + public function action_edit() { + Block::factory() + ->type('form-horizontal') + ->title('Add/Edit Record') + ->title_icon('fa-wrench') + ->body($this->add_edit($this->request->param('id'))); + } + + private function add_edit($id=NULL) { + $co = ORM::factory('Child',$id); + + if ($this->request->post()) { + $co->values($this->request->post()); + $co->account_id = (string)$this->ao; + + if ($co->changed() AND (! $this->save($co))) + $co->reload()->values($this->request->post()); + } + + // If there are no room records, we'll create a waitlist one that can be completed. + if (! $co->subitems()) + $co->subitem_add($co->room->values(array('child_id'=>$co->id,'code'=>'W'))); + + Style::factory() + ->type('file') + ->data('media/theme/bootstrap/css/bootstrap.datepicker.css'); + + Script::factory() + ->type('file') + ->data('media/theme/bootstrap/js/bootstrap.datepicker.js'); + + // Set our maximum date, that children can stay + Script::factory() + ->type('stdin') + ->data(' + $(document).ready(function() { + $("#date_stop").datepicker({ + endDate: new Date('.($co->date_enrol_max()*1000).') + }); + }) + '); + + return View::factory('child/user/add_edit') + ->set('o',$co) + ->set('so',Company::instance()->so()); + } +} +?> diff --git a/application/classes/Controller/User/Welcome.php b/application/classes/Controller/User/Welcome.php new file mode 100644 index 0000000..c33191c --- /dev/null +++ b/application/classes/Controller/User/Welcome.php @@ -0,0 +1,49 @@ +TRUE, + ); + + public function action_index() { + $output = ''; + + if (! $this->ao->list_children()->count()) + $output .= 'You have no currently registered children, would you like to '.HTML::anchor(URL::link('user','child/add'),'Register').' a child?'; + else + $output = Table::factory() + ->data($this->ao->list_children()) + ->columns(array( + 'id'=>'ID', + 'first_name'=>'First Name', + 'family_name'=>'Family Name', + 'dob'=>'DOB', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('user','child/edit/')), + )); + + Block::factory() + ->title(sprintf('Membership details for : %s',$this->ao->name())) + ->title_icon('icon-info-sign') + ->span(9) + ->body($output); + + Block::factory() + ->title('Quick Shortcuts') + ->title_icon('icon-bookmark') + ->span(3) + ->body(View::factory('welcome/user/shortcuts')); + } +} +?> diff --git a/application/classes/Controller/Welcome.php b/application/classes/Controller/Welcome.php index 11c00f1..23b53fa 100644 --- a/application/classes/Controller/Welcome.php +++ b/application/classes/Controller/Welcome.php @@ -3,7 +3,7 @@ /** * Main home page for un-authenticated users * - * @package lnApp + * @package Membership Database * @category Controllers * @author Deon George * @copyright (c) 2009-2013 Deon George diff --git a/application/classes/Model/Account.php b/application/classes/Model/Account.php new file mode 100644 index 0000000..43b1616 --- /dev/null +++ b/application/classes/Model/Account.php @@ -0,0 +1,24 @@ +array('far_key'=>'id'), + 'email_log'=>array('far_key'=>'id'), + 'group'=>array('through'=>'account_group'), + ); + + public function list_children() { + return $this->child->find_all(); + } +} +?> diff --git a/application/classes/Model/Child.php b/application/classes/Model/Child.php index 0e3d300..15dc3d8 100644 --- a/application/classes/Model/Child.php +++ b/application/classes/Model/Child.php @@ -1,7 +1,7 @@ array('model'=>'Room_Children','foreign_key'=>'child_id','far_key'=>'id'), + ); + + public function filters() { + return Arr::merge(parent::filters(),array( + 'dob'=>array(array('strtotime', array(':value'))), + )); + } + + protected $_display_filters = array( + 'dob'=>array( + array('Site::Date',array(':value')), + ), + ); + + protected $_sub_items_load = array( + 'room'=>'date_start,date_stop', + ); + + private function _dob() { + $x = new DateTime(); + + return $x->setTimestamp($this->dob); + } + + public function age($asat=NULL,$format='%Yy%Mm') { + if (is_null($asat)) + $asat = time(); + + $dob = $this->_dob(); + + $today = new DateTime(); + $today->setTimestamp($asat); + + return $format == '%w' ? sprintf('%02dw',$dob->diff($today)->days/7) : $dob->diff($today)->format($format); + } + + public function date_enrol_min() { + $dob = $this->_dob(); + $dob->add(new DateInterval('P'.$this->_start)); + + return $format ? $result->format(Kohana::$config->load('config')->date_format) : $result->format('U'); + } + + public function date_enrol_max($format=FALSE) { + $dob = $this->_dob(); + $dob->add(new DateInterval('P'.$this->_max)); + + $last = new DateTime(sprintf('%s-%s',$dob->format('Y'),$this->_max_date)); + $x = $dob->diff($last); + + $result = new DateTime(sprintf('%s-%s',$dob->format('Y')+($x->invert ? 1 : 0),$this->_max_return)); + + return $format ? $result->format(Company::instance()->date_format()) : $result->format('U'); + } + + public function save(Validation $validation=NULL) { + $changed = $this->changed(); + + parent::save($validation); + + // Insert into waitlist + $rco = ORM::factory('Room_Children',array('child_id'=>$this,'code'=>$_POST['room']['code'])); + + $rco->values($_POST['room']); + $rco->child_id = (string)$this; + + foreach ($_POST['room']['R'] as $k => $v) { + if (! $v OR isset($_POST['room']['d_'.$k])) + continue; + + $rco->{'d_'.$k} = NULL; + } + + if ($rco->changed() AND (! $rco->save())) + $rco->reload()->values($_POST['room']); + + return $this->reload(); + } } ?> diff --git a/application/classes/Model/Room/Children.php b/application/classes/Model/Room/Children.php index f81b702..ebd5776 100644 --- a/application/classes/Model/Room/Children.php +++ b/application/classes/Model/Room/Children.php @@ -14,6 +14,30 @@ class Model_Room_Children extends ORM { 'child'=>array(), ); + public function filters() { + return Arr::merge(parent::filters(),array( + 'date_start'=>array(array('strtotime', array(':value'))), + 'date_stop'=>array(array('strtotime', array(':value'))), + )); + } + + public function rules() { + $x = parent::rules(); + + unset($x['id']); + + return $x; + } + + protected $_display_filters = array( + 'date_start'=>array( + array('Site::Date',array(':value')), + ), + 'date_stop'=>array( + array('Site::Date',array(':value')), + ), + ); + // @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/Room/Dates.php b/application/classes/Model/Room/Dates.php index 1ca688a..872f837 100644 --- a/application/classes/Model/Room/Dates.php +++ b/application/classes/Model/Room/Dates.php @@ -13,7 +13,7 @@ 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}; + return $this->{'d_'.$day} ? $this->{'d_'.$day} : 0; } } ?> diff --git a/application/classes/Model/Rooms.php b/application/classes/Model/Rooms.php index b60ef91..59e2564 100644 --- a/application/classes/Model/Rooms.php +++ b/application/classes/Model/Rooms.php @@ -28,24 +28,19 @@ class Model_Rooms extends ORM { $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 (($o->date_start <= $x AND (is_null($o->date_stop) OR $o->date_stop >= $x)) + OR ($o->date_stop >= $x AND (is_null($o->date_start) OR $o->date_start <= $x)) + OR (is_null($o->date_start) AND is_null($o->date_start))) { - if (! isset($result[$x]) OR ! $result[$x]) - $result[$x] = 0; + $result[$x] = $o->avail(date('w',$x)); $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]) OR ! $result[$x]) + $result[$x] = 0; - $result[$x] = $o->avail(date('w',$x)); $x += 86400; } } @@ -66,6 +61,10 @@ class Model_Rooms extends ORM { $result = array(); $x = $date; + // We need to set this, so that unassigned room records are found. + if (! $this->loaded()) + $this->site_id = Company::instance()->site(); + $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) { @@ -75,8 +74,7 @@ class Model_Rooms extends ORM { // 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))) { + OR ((is_null($o->date_start) OR $o->date_start > $x) AND $o->date_stop > $date_end)) { if (! isset($result[$x]) OR ! $result[$x]) $result[$x] = array(); diff --git a/application/classes/Model/Setup.php b/application/classes/Model/Setup.php index 2eb5fa2..0972e22 100644 --- a/application/classes/Model/Setup.php +++ b/application/classes/Model/Setup.php @@ -97,11 +97,23 @@ class Model_Setup extends ORM { return $result; } - public function open_dates($date,$days=0) { + public function open_days() { + $result = array(); + + //@todo this needs to change to node have any dates, since the current date may be closed, or a public holiday + foreach ($this->open_dates(Site::DateStartOfWeek(time()),7) as $date => $open) + $result[date('w',$date)] = $open; + + ksort($result); + + return $result; + } + + public function open_dates($date,$days=0,$code='O') { $result = array(); $date_end = $date+$days*86400; - foreach ($this->dates->where('code','=','O')->where_startstop($date,$date_end)->find_all() as $o) + foreach ($this->dates->where('code','=',$code)->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) { @@ -146,5 +158,20 @@ class Model_Setup extends ORM { return $this; } + + public function total_places($date_start,$days=0) { + $result = array(); + + foreach ($this->rooms->find_all() as $ro) { + foreach ($ro->availability_dates($date_start,$days) as $date => $total) { + if (! isset($result[$date])) + $result[$date] = 0; + + $result[$date] += $total; + } + } + + return $result; + } } ?> diff --git a/application/classes/StaticList/Room/Children.php b/application/classes/StaticList/Room/Children.php new file mode 100644 index 0000000..98ed707 --- /dev/null +++ b/application/classes/StaticList/Room/Children.php @@ -0,0 +1,23 @@ +_('Waitlist'), + ); + } + + public static function get($value) { + return self::factory()->_get($value); + } +} +?> diff --git a/application/views/child/user/add_edit.php b/application/views/child/user/add_edit.php new file mode 100644 index 0000000..56b32f3 --- /dev/null +++ b/application/views/child/user/add_edit.php @@ -0,0 +1,80 @@ +
+ Register Child + +
+ +
+
+ display('first_name'),array('class'=>'form-control','placeholder'=>'First Name','required','nocg'=>TRUE)); ?> +
+
+ display('family_name'),array('class'=>'form-control','placeholder'=>'Family Name','required','nocg'=>TRUE)); ?> +
+
+
+ +
+ +
+
+ display('dob'),array('class'=>'form-control','placeholder'=>'DOB','required','nocg'=>TRUE,'readonly')); ?> + +
+
+
+ Age: age(); ?>
+
+
+ +
+ +
+ + + + + open_days() as $d => $open) : ?> + + + + + + + + + subitems() as $rco) : ?> + + child_id); ?> + code); ?> + + open_days() as $d => $open) : ?> + + + + + + + +
 Start DateEnd Date
code); ?> + day($d) ? TRUE : FALSE,array('nocg'=>TRUE,$open ? '': 'disabled')); ?> + day($d)); ?> + +
+ date_start ? $rco->display('date_start') : Site::Date(time()),array('class'=>'form-control','placeholder'=>'Start','required','nocg'=>TRUE,'readonly')); ?> + +
+
+ date_stop ? $rco->display('date_stop') : $o->date_enrol_max(TRUE),array('class'=>'form-control','placeholder'=>'End','required','nocg'=>TRUE,'readonly')); ?> + +
+
+
+
+
+ +
+
+ + +
+
diff --git a/application/views/module/method/admin/add.php b/application/views/module/method/admin/add.php deleted file mode 100644 index f4508cd..0000000 --- a/application/views/module/method/admin/add.php +++ /dev/null @@ -1,16 +0,0 @@ -
-
- Add Method - - 'Method','disabled','class'=>'col-sm-5')); ?> - 'Description','placeholder'=>'Method Description','class'=>'col-sm-7')); ?> - 'Menu Title','placeholder'=>'Menu Title','class'=>'col-sm-7')); ?> -
- -
-
- - -
-
-
diff --git a/application/views/module/method/admin/edit.php b/application/views/module/method/admin/edit.php deleted file mode 100644 index 510d172..0000000 --- a/application/views/module/method/admin/edit.php +++ /dev/null @@ -1,42 +0,0 @@ -
-
- Method Details - - notes,array('label'=>'Description','placeholder'=>'Method Description','xclass'=>'col-md-5')); ?> - menu_display,array('label'=>'Menu Title','placeholder'=>'Menu Title','xclass'=>'col-md-5')); ?> - -
-
- -
-
- Method Security - - - - - - - - - - - find_all() as $go) : ?> - - - - - - - - -
MethodNotesGroup ActiveMethod Enable
id,TRUE),$go->display('name')); ?>display('notes'); ?>display('active'); ?>id,$o->has('group',$go)); ?>
-
- -
-
- - -
-
-
diff --git a/application/views/room/availability.php b/application/views/room/availability.php new file mode 100644 index 0000000..38fa098 --- /dev/null +++ b/application/views/room/availability.php @@ -0,0 +1,140 @@ +
+ Room Summary next Days + +
+ +
+
+ 'caldate','class'=>'form-control','required','nocg'=>TRUE,'readonly','onchange'=>'submit()')); ?> + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + child_list_date($date,$days,'W')) as $x) : ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + child_list_date($date,$days)) as $x) : ?> + + + + + + + + + + + child_list_date($date,$days,'a')) as $x) : ?> + + + + + + + + + + + child_list_date($date,$days,'C')) as $x) : ?> + + + + + + + + + + + + + child_list_date($date,$days,'W')) as $x) : ?> + + + + + + + + + + + room_availablity($date,$days)) as $x) : ?> + + + + + + +
 >'); ?>
Open get(isset($open_dates[$day]) ? $open_dates[$day] : FALSE,TRUE); ?> 
Total  
New Applications  
 
display('name'); ?> 
 Capacity ',array_values($ro->availability_dates($date,$days))); ?> 
 Permanent  
 Absent  
 Casual  
 
 Waitlist  
 Availability  
+
diff --git a/application/views/welcome/user/shortcuts.php b/application/views/welcome/user/shortcuts.php new file mode 100644 index 0000000..d299138 --- /dev/null +++ b/application/views/welcome/user/shortcuts.php @@ -0,0 +1,3 @@ +
+ Register Child +
diff --git a/modules/lnapp b/modules/lnapp index f679bf9..db7f5f8 160000 --- a/modules/lnapp +++ b/modules/lnapp @@ -1 +1 @@ -Subproject commit f679bf9c06e17f7fe69dc34c0227d91ef30b56b0 +Subproject commit db7f5f8d55fb2d467d7e70df5f7bd15b7a21efbc diff --git a/modules/lnauth b/modules/lnauth index d034b84..082e280 160000 --- a/modules/lnauth +++ b/modules/lnauth @@ -1 +1 @@ -Subproject commit d034b846a6212e8ce8b8a6815b61f91988867b26 +Subproject commit 082e280fb657ad2377b070b2979cfd118766aa67