From c82b8b127d923d843c07434942b59f9629c0694a Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 31 Aug 2016 02:13:05 +1000 Subject: [PATCH] Work on enrolment for Kinder --- .htaccess | 2 +- application/bootstrap.php | 33 ++++++-- .../classes/Controller/Admin/Site/Date.php | 77 +++++++++++++++++++ application/classes/Controller/Enrol.php | 63 +++++++++++++++ application/classes/Model/Child.php | 4 +- application/classes/Model/Rooms.php | 9 +++ application/classes/Model/Site/Dates.php | 62 ++++++++++++++- application/classes/URL.php | 2 +- application/views/enrol/child.php | 44 +++++++++++ application/views/enrol/selectyear.php | 8 ++ .../views/site/date/admin/add_edit.php | 15 ++++ application/views/site/date/list.php | 14 ++++ includes/kohana | 2 +- modules/lnapp | 2 +- modules/lnauth | 2 +- 15 files changed, 324 insertions(+), 15 deletions(-) create mode 100644 application/classes/Controller/Admin/Site/Date.php create mode 100644 application/classes/Controller/Enrol.php create mode 100644 application/views/enrol/child.php create mode 100644 application/views/enrol/selectyear.php create mode 100644 application/views/site/date/admin/add_edit.php create mode 100644 application/views/site/date/list.php diff --git a/.htaccess b/.htaccess index 8ed192d..c8dada9 100644 --- a/.htaccess +++ b/.htaccess @@ -2,7 +2,7 @@ RewriteEngine On # Installation directory -RewriteBase /memberdb +RewriteBase / # Protect hidden files from being viewed diff --git a/application/bootstrap.php b/application/bootstrap.php index ef50819..0404d43 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -1,9 +1,6 @@ Kohana::$environment === Kohana::PRODUCTION ? '/memberdb' : '/memberdb', + 'base_url' => '/', 'caching' => Kohana::$environment === Kohana::PRODUCTION, 'profile' => Kohana::$environment !== Kohana::PRODUCTION, 'index_file' => FALSE, @@ -133,12 +143,21 @@ Kohana::modules(array( 'khemail' => SMDPATH.'khemail', // Email module for Kohana 3 PHP Framework // 'minion' => SMDPATH.'minion', // CLI Tasks 'orm' => SMDPATH.'orm', // Object Relationship Mapping - // 'pagination' => SMDPATH.'pagination', // Kohana Pagination module for Kohana 3 PHP Framework + 'pagination' => SMDPATH.'pagination', // Kohana Pagination module for Kohana 3 PHP Framework // 'unittest' => SMDPATH.'unittest', // Unit testing // 'userguide' => SMDPATH.'userguide', // User guide and API documentation // 'xml' => SMDPATH.'xml', // XML module for Kohana 3 PHP Framework )); +/** + * Cookie Salt + * @see http://kohanaframework.org/3.3/guide/kohana/cookies + * + * If you have not defined a cookie salt in your Cookie class then + * uncomment the line below and define a preferrably long salt. + */ +// Cookie::$salt = NULL; + /** * Load our modules defined in the DB */ @@ -168,7 +187,7 @@ Route::set('default/media', 'media(/)', array('file' => '.+')) */ Route::set('default', '((/(/)))', array('id'=>'[a-zA-Z0-9_.:-]+')) ->defaults(array( - 'controller' => 'welcome', + 'controller' => 'login', 'action' => 'index', )); diff --git a/application/classes/Controller/Admin/Site/Date.php b/application/classes/Controller/Admin/Site/Date.php new file mode 100644 index 0000000..92b1473 --- /dev/null +++ b/application/classes/Controller/Admin/Site/Date.php @@ -0,0 +1,77 @@ +TRUE, + 'edit'=>TRUE, + 'list'=>TRUE, + ); + + protected $icon = 'fa fa-calendar'; + + /** + * Add a new site dates + */ + public function action_add() { + Block::factory() + ->type('form-horizontal') + ->title('New Site Date') + ->title_icon($this->icon) + ->body($this->add_edit()); + } + + private function add_edit($id=NULL,$output='') { + $o = ORM::factory('Site_Dates',$id); + + if ($this->request->post() AND $o->values($this->request->post())->changed()) { + // Some validation + if ($o->code == 'S') { + $o->date_stop = NULL; + $o->date_start = strtotime(date('Y',$o->date_start).'-01-01'); + $o->date_stop = strtotime(date('Y',$o->date_start).'-12-31'); + } + + if (! $this->save($o)) + $o->reload(); + } + + $this->meta->title = $o->loaded() ? sprintf('Site Date: %s',$o->id) : 'New Site Date'; + + return View::factory('site/date/admin/add_edit') + ->set('o',$o); + } + + /** + * Edit a Module Configuration + */ + public function action_edit() { + Block::factory() + ->type('form-horizontal') + ->title('Update Site Date') + ->title_icon($this->icon) + ->body($this->add_edit($this->request->param('id'))); + } + + /** + * List site dates + */ + public function action_list() { + $this->meta->title = 'A|List Site Dates'; + + Block::factory() + ->title('Site Dates') + ->title_icon($this->icon) + ->body(View::factory('site/date/list')->set('o',ORM::factory('Site_Dates')->find_all())); + } +} +?> diff --git a/application/classes/Controller/Enrol.php b/application/classes/Controller/Enrol.php new file mode 100644 index 0000000..b8d4047 --- /dev/null +++ b/application/classes/Controller/Enrol.php @@ -0,0 +1,63 @@ +request->post('year') ? ORM::factory('Site_Dates',$this->request->post('year')) : ORM::factory('Site_Dates')->where_year($this->request->param('id')); + if (! $sdo->loaded()) { + Block::factory() + ->type('form-horizontal') + ->title('Choose year of enrolment') + ->title_icon('fa fa-calendar') + ->body(View::factory('enrol/selectyear')); + + return; + } + + $ao = ORM::factory('Account'); + $co = ORM::factory('Child'); + + $this->meta->title = 'Enrol'; + + if ($this->request->post('account') AND $this->request->post('child') AND $this->request->post('room.id')) { + $ao->values($this->request->post('account')); + $co->values($this->request->post('child')); + $ro = ORM::factory('Rooms',$this->request->post('room.id')); + + // First we need to make an account + try { + if ($ao->save() AND $co->save()) { + $co->account_id = $ao; + $co->status = 'PEND'; + $co->save(); + + $co->add('rooms',$ro); + } + + } catch (ORM_Validation_Exception $e) { + SystemMessage::factory() + ->title('Record NOT created') + ->type('danger') + ->body(join('
',array_values($e->errors('register')))); + + } + } + + Block::factory() + ->type('form-horizontal') + ->title('Register enrolment for: '.$sdo->year()) + ->title_icon('fa fa-university') + ->body(View::factory('enrol/child')->set('ao',$ao)->set('co',$co)->set('room_id',$this->request->post('room.id'))->set('year',$sdo->id)); + } +} +?> diff --git a/application/classes/Model/Child.php b/application/classes/Model/Child.php index 4a47887..1efc8aa 100644 --- a/application/classes/Model/Child.php +++ b/application/classes/Model/Child.php @@ -16,7 +16,7 @@ class Model_Child extends ORM { protected $_max_return = '12-31'; // Date to leave the center when max date reached, eg: Jan 1 protected $_has_many = array( - 'room'=>array('model'=>'Room_Children','foreign_key'=>'child_id','far_key'=>'id'), + 'rooms'=>array('through'=>'room_children'), ); public function filters() { @@ -38,7 +38,7 @@ class Model_Child extends ORM { ); protected $_sub_items_load = array( - 'room'=>array('date_start','date_stop'), + 'rooms'=>array('date_start','date_stop'), ); private function _dob() { diff --git a/application/classes/Model/Rooms.php b/application/classes/Model/Rooms.php index ed6b1a1..af17def 100644 --- a/application/classes/Model/Rooms.php +++ b/application/classes/Model/Rooms.php @@ -132,5 +132,14 @@ class Model_Rooms extends ORM { return $result; } + + /** + * Rooms marked with the internal flag are the actual rooms that children are assigned in + * but cannot have an enrolment application for (there may be multiple rooms for the program). + * Thus a non "internal" room should be used for enrolments for the program. + */ + public function where_external() { + return $this->where_open()->where('internal','is',NULL)->or_where('internal','=',0)->where_close(); + } } ?> diff --git a/application/classes/Model/Site/Dates.php b/application/classes/Model/Site/Dates.php index e845f6d..40b1b18 100644 --- a/application/classes/Model/Site/Dates.php +++ b/application/classes/Model/Site/Dates.php @@ -8,12 +8,72 @@ * @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. + protected $_created_column = NULL; + protected $_updated_column = NULL; + protected $_display_filters = array( + 'date_start'=>array( + array('Site::date',array(':value')), + ), + 'date_stop'=>array( + array('Site::date',array(':value')), + ), + ); + + /** + * List our codes + * CODE: + * + O (open) - site is open for business (start/end cannot overlap) + * + S (school year) - this is a year for school terms @see mdb_term_dates (only year is used from start) + * @todo: Code O (open) start/end dates cannot overlap with existing records - put in validation that it cannot be saved. + */ + public function codes() { + return [ + 'O'=>'Open', + 'S'=>'School Year', + ]; + } + + /** + * Return if this day is open + */ public function open($day) { return $this->{'d_'.$day}; } + + public function where_year($year) { + $id = 0; + foreach ($this->list_years() as $k => $v) + if ($v == $year) { + $id = $k; + break; + } + + // If we get hear, we didnt find the years + return ORM::factory('Site_Dates',$id ? $id : NULL); + } + + /** + * Return the year this record peratins to + * @note: Only valid for School Years (code S) + */ + public function year() { + if ($this->code != 'S') + throw HTTP_Exception::factory(501,'Invalid call to :method, code [:code] is incorrect',[':method'=>__METHOD__,':code'=>$this->code]); + + return $this->date_start ? date('Y',$this->date_start) : NULL; + } + + public function list_years() { + $result = array(); + + foreach (ORM::factory('Site_Dates')->where('code','=','S')->where('date_stop','>',time())->find_all()->as_array() as $sdo) + $result[$sdo->id] = $sdo->year(); + + return $result; + } } ?> diff --git a/application/classes/URL.php b/application/classes/URL.php index af1c08c..c6d6a67 100644 --- a/application/classes/URL.php +++ b/application/classes/URL.php @@ -35,7 +35,7 @@ class URL extends lnApp_URL { case 'user': $result[$k] = array('name'=>Auth::instance()->get_user()->name(),'icon'=>'fa-user'); break; - default: $result[$k] = array('name'=>$k,'icon'=>'fa-question-sign'); + default: $result[$k] = array('name'=>$k,'icon'=>'fa-question'); } return $result; diff --git a/application/views/enrol/child.php b/application/views/enrol/child.php new file mode 100644 index 0000000..6cda4a8 --- /dev/null +++ b/application/views/enrol/child.php @@ -0,0 +1,44 @@ +
+ +set('data',['field'=>'room[id]','value'=>ORM::factory('Rooms')->where_external()->list_select(),'default'=>$room_id,'text'=>'Program','class'=>'col-md-4']); +?> +
+ Child Details + +set('data',['field'=>'child[first_name]','value'=>$co->first_name,'text'=>'First Name','class'=>'col-md-5']); + echo View::factory('field/text')->set('data',['field'=>'child[family_name]','value'=>$co->family_name,'text'=>'Last Name','class'=>'col-md-5']); + echo View::factory('field/date')->set('data',['field'=>'child[dob]','value'=>$co->dob ? $co->dob : time(),'text'=>'Date of Birth','enddate'=>'new Date()']); +?> + +
+ +
+ Parent Details + +set('data',['field'=>'account[first_name]','value'=>$ao->first_name,'text'=>'First Name','class'=>'col-md-5']); + echo View::factory('field/text')->set('data',['field'=>'account[last_name]','value'=>$ao->last_name,'text'=>'Last Name','class'=>'col-md-5']); + echo View::factory('field/text')->set('data',['field'=>'account[email]','value'=>$ao->email,'text'=>'Email','class'=>'col-md-5']); + echo View::factory('field/text')->set('data',['field'=>'account[address1]','value'=>$ao->address1,'text'=>'Address','class'=>'col-md-5']); + echo View::factory('field/text')->set('data',['field'=>'account[address2]','value'=>$ao->address2,'text'=>'Address','class'=>'col-md-5']); + echo View::factory('field/text')->set('data',['field'=>'account[city]','value'=>$ao->city,'text'=>'City','class'=>'col-md-5']); + echo View::factory('field/text')->set('data',['field'=>'account[state]','value'=>$ao->state ? $ao->state : 'Vic','text'=>'State','class'=>'col-md-1']); + echo View::factory('field/text')->set('data',['field'=>'account[zip]','value'=>$ao->zip,'text'=>'Post Code','class'=>'col-md-1']); +?> + + + + +
+ + +
+

Thank you for your enrolment. An enrolment application of $10 will be invoiced to the email address you have included above.

+

This fee must be paid within 2 days for your application to be accepted. Paying this fee via the method in the email will also confirm that your email address is correct.

+

We send all correspondence via email, so if you change your email, or dont recieve the enrolment application invoice via email, please contact us.

+

This application will be automatically deleted in 2 days if your payment has not been received. + + +

diff --git a/application/views/enrol/selectyear.php b/application/views/enrol/selectyear.php new file mode 100644 index 0000000..61c46ca --- /dev/null +++ b/application/views/enrol/selectyear.php @@ -0,0 +1,8 @@ +
+ +set('data',['field'=>'year','value'=>ORM::factory('Site_Dates')->list_years(),'default'=>date('Y',time()),'text'=>'Year','class'=>'col-md-4']); +?> + + +
diff --git a/application/views/site/date/admin/add_edit.php b/application/views/site/date/admin/add_edit.php new file mode 100644 index 0000000..60bb17d --- /dev/null +++ b/application/views/site/date/admin/add_edit.php @@ -0,0 +1,15 @@ +
+ +
+ Configure New Date Parameters + +set('data',['field'=>'code','value'=>Arr::Merge([''=>''],$o->codes()),'text'=>'Code','default'=>$o->code,'class'=>'col-md-4']); + echo View::factory('field/date')->set('data',['field'=>'date_start','value'=>$o->date_start ? $o->date_start : time(),'text'=>'Date Start']); + echo View::factory('field/date')->set('data',['field'=>'date_stop','value'=>$o->date_stop ? $o->date_stop : time(),'text'=>'Date Stop']); +?> + +
+ + +
diff --git a/application/views/site/date/list.php b/application/views/site/date/list.php new file mode 100644 index 0000000..ce7acc3 --- /dev/null +++ b/application/views/site/date/list.php @@ -0,0 +1,14 @@ + +page_items(50) + ->data($o) + ->columns(array( + 'id'=>'ID', + 'code'=>'Code', + 'date_start'=>'Date Start', + 'date_stop'=>'Date End', + )) + ->prepend(array( + 'id'=>array('url'=>URL::link('admin','site_date/edit/')), + )); +?> diff --git a/includes/kohana b/includes/kohana index e04ac7d..898371c 160000 --- a/includes/kohana +++ b/includes/kohana @@ -1 +1 @@ -Subproject commit e04ac7d0978213f406f2a8a8e5f389af1a9620b9 +Subproject commit 898371c849356932afe44d00f29f881430792c46 diff --git a/modules/lnapp b/modules/lnapp index 69c8052..f5bc5df 160000 --- a/modules/lnapp +++ b/modules/lnapp @@ -1 +1 @@ -Subproject commit 69c8052b53a2686e2a6893611a68cdcdde6c8659 +Subproject commit f5bc5dfa296a1517ebdb29b2dd0f81b09f136b6a diff --git a/modules/lnauth b/modules/lnauth index 932252b..ceb8159 160000 --- a/modules/lnauth +++ b/modules/lnauth @@ -1 +1 @@ -Subproject commit 932252b620b5dc4f7f714ae6974d228417830f8a +Subproject commit ceb8159826a20dc11e4df61e036dfa9a2d2e3d73