silverstripe-multiform/code/MultiFormSession.php

95 lines
2.3 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(
'Data' => 'Text', // stores serialized maps with all session information
'Hash' => 'Varchar(40)' // cryptographic hash identification to this session
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
);
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
$steps = $this->FormSteps();
if($steps) foreach($steps as $step) {
$step->delete();
}
}
/**
2008-04-22 13:03:03 +02:00
* Get all the temporary objects, and set them as temporary, writing
* them back to the database.
2008-04-18 00:03:51 +02:00
*/
public function markTemporaryDataObjectsFinished() {
$temporaryObjects = $this->getTemporaryDataObjects();
if($temporaryObjects) foreach($temporaryObjects as $obj) {
$obj->MultiFormIsTemporary = 0;
$obj->write();
}
}
/**
2008-04-22 13:03:03 +02:00
* Get all classes that implement the MultiFormObjectDecorator,
* find the records for each and merge them together into a
* DataObjectSet.
2008-04-18 00:03:51 +02:00
*
* @return DataObjectSet
*/
public function getTemporaryDataObjects() {
$implementors = Object::get_implementors_for_extension('MultiFormObjectDecorator');
$objs = new DataObjectSet();
if($implementors) foreach($implementors as $implementorClass) {
$objs->merge(
DataObject::get($implementorClass, "MultiFormSessionID = {$this->ID}")
);
}
return $objs;
}
/**
* Remove all related data, either serialized
* in $Data property, or in related stored
* DataObjects.
*
* @return boolean
*/
public function purgeStoredData() {
die('MultiFormSession->purgeStoredData(): Not implemented yet');
}
}
?>