2010-03-10 21:20:44 +01:00
|
|
|
<?php
|
|
|
|
|
2022-10-19 01:00:04 +02:00
|
|
|
use SilverStripe\Control\HTTPResponse;
|
2016-07-01 04:37:50 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2016-07-20 00:34:52 +02:00
|
|
|
use SilverStripe\Security\Member;
|
2016-09-07 07:10:55 +02:00
|
|
|
use SilverStripe\Forms\TextField;
|
|
|
|
use SilverStripe\Forms\FieldList;
|
2022-10-19 01:00:04 +02:00
|
|
|
use SilverStripe\Forms\Form;
|
2016-07-01 04:37:50 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
class Page2MultiForm extends MultiForm
|
|
|
|
{
|
2016-07-20 00:34:52 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public static $start_step = 'Page2PersonalDetailsFormStep';
|
2016-07-20 00:34:52 +02:00
|
|
|
|
2022-10-19 01:00:04 +02:00
|
|
|
public function finish(array $data, Form $form): HTTPResponse
|
2015-12-17 21:20:49 +01:00
|
|
|
{
|
|
|
|
parent::finish($data, $form);
|
|
|
|
$steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}");
|
|
|
|
if ($steps) {
|
|
|
|
foreach ($steps as $step) {
|
2017-05-18 07:11:01 +02:00
|
|
|
if ($step->ClassName == 'Page2PersonalDetailsFormStep') {
|
2015-12-17 21:20:49 +01:00
|
|
|
$member = new Member();
|
|
|
|
$data = $step->loadData();
|
|
|
|
if ($data) {
|
|
|
|
$member->update($data);
|
|
|
|
$member->write();
|
|
|
|
}
|
|
|
|
}
|
2010-03-10 21:20:44 +01:00
|
|
|
|
2017-05-18 07:11:01 +02:00
|
|
|
if ($step->ClassName == 'Page2OrganisationDetailsFormStep') {
|
2015-12-17 21:20:49 +01:00
|
|
|
$organisation = new Organisation();
|
|
|
|
$data = $step->loadData();
|
|
|
|
if ($data) {
|
|
|
|
$organisation->update($data);
|
|
|
|
if ($member && $member->ID) {
|
|
|
|
$organisation->MemberID = $member->ID;
|
|
|
|
}
|
|
|
|
$organisation->write();
|
|
|
|
}
|
|
|
|
}
|
2010-03-10 21:20:44 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
// Debug::show($step->loadData()); // Shows the step data (unserialized by loadData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$controller = $this->getController();
|
2022-10-19 01:00:04 +02:00
|
|
|
return $controller->redirect($controller->Link() . 'finished');
|
2015-12-17 21:20:49 +01:00
|
|
|
}
|
|
|
|
}
|
2010-03-10 21:20:44 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
class Page2PersonalDetailsFormStep extends MultiFormStep
|
|
|
|
{
|
2016-07-20 00:34:52 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public static $next_steps = 'Page2OrganisationDetailsFormStep';
|
2016-07-20 00:34:52 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public function getFields()
|
|
|
|
{
|
|
|
|
return new FieldList(
|
|
|
|
new TextField('FirstName', 'First name'),
|
|
|
|
new TextField('Surname', 'Surname')
|
|
|
|
);
|
|
|
|
}
|
2010-03-10 21:20:44 +01:00
|
|
|
}
|
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
class Page2OrganisationDetailsFormStep extends MultiFormStep
|
|
|
|
{
|
2016-07-20 00:34:52 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public static $is_final_step = true;
|
2010-03-10 21:20:44 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public function getFields()
|
|
|
|
{
|
|
|
|
return new FieldList(
|
|
|
|
new TextField('OrganisationName', 'Organisation Name')
|
|
|
|
);
|
|
|
|
}
|
2010-03-10 21:20:44 +01:00
|
|
|
}
|