silverstripe-multiform/code/MultiFormSession.php

67 lines
1.6 KiB
PHP
Raw Normal View History

2008-04-18 00:03:51 +02:00
<?php
/**
* Serializes one or more {@link MultiFormStep}s into
* a database object.
*
2008-04-22 13:03:03 +02:00
* MultiFormSession also stores the current step, so that
* the {@link MultiForm} and {@link MultiFormStep} classes
* know what the current step is.
*
2008-04-18 00:03:51 +02:00
* @package multiform
*/
class MultiFormSession extends DataObject {
static $db = array(
'Hash' => 'Varchar(40)', // cryptographic hash identification to this session
'IsComplete' => 'Boolean' // flag to determine if this session is marked completed
2008-04-18 00:03:51 +02:00
);
static $has_one = array(
'Submitter' => 'Member',
'CurrentStep' => 'MultiFormStep'
2008-04-18 00:03:51 +02:00
);
static $has_many = array(
'FormSteps' => 'MultiFormStep'
2008-04-18 00:03:51 +02:00
);
/**
* Mark this session as completed.
*
* This sets the flag "IsComplete" to true,
* and writes the session back.
*/
public function markCompleted() {
$this->IsComplete = 1;
$this->write();
}
2008-04-22 13:03:03 +02:00
/**
* These actions are performed when write() is called on this object.
*/
2008-04-18 00:03:51 +02:00
public function onBeforeWrite() {
// save submitter if a Member is logged in
$currentMember = Member::currentMember();
if(!$this->SubmitterID && $currentMember) $this->SubmitterID = $currentMember->ID;
parent::onBeforeWrite();
}
2008-04-22 13:03:03 +02:00
/**
* These actions are performed when delete() is called on this object.
*/
2008-04-18 00:03:51 +02:00
public function onBeforeDelete() {
// delete dependent form steps and relation
2008-04-18 00:03:51 +02:00
$steps = $this->FormSteps();
if($steps) foreach($steps as $step) {
$steps->remove($step); // @TODO not sure if this is required (does delete() remove the relation too?)
2008-04-18 00:03:51 +02:00
$step->delete();
}
parent::onBeforeDelete();
2008-04-18 00:03:51 +02:00
}
2008-04-18 00:03:51 +02:00
}
?>