Work on enrolment for Kinder
This commit is contained in:
63
application/classes/Controller/Enrol.php
Normal file
63
application/classes/Controller/Enrol.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* Membership Database Register
|
||||
*
|
||||
* @package Membership Database
|
||||
* @category Controllers/User
|
||||
* @author Deon George
|
||||
* @copyright (c) 2014 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Controller_Enrol extends Controller_TemplateDefault{
|
||||
protected $auth_required = FALSE;
|
||||
|
||||
public function action_index() {
|
||||
$sdo = $this->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('<br/>',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));
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user