This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
memberdb/application/classes/Controller/Enrol.php
2016-08-31 02:13:05 +10:00

64 lines
1.8 KiB
PHP

<?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));
}
}
?>