Source of file MultiFormSession.php
Size: 2,393 Bytes - Last Modified: 2021-12-23T10:33:19+00:00
/var/www/docs.ssmods.com/process/src/src/Models/MultiFormSession.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 | <?php namespace SilverStripe\MultiForm\Models; use SilverStripe\ORM\DataObject; use SilverStripe\Security\Member; use SilverStripe\Security\Security; /** * Serializes one or more {@link MultiFormStep}s into * a database object. * * MultiFormSession also stores the current step, so that * the {@link MultiForm} and {@link MultiFormStep} classes * know what the current step is. * */ class MultiFormSession extends DataObject { private static $db = [ 'Hash' => 'Varchar(40)', // cryptographic hash identification to this session 'IsComplete' => 'Boolean' // flag to determine if this session is marked completed ]; private static $has_one = [ 'Submitter' => Member::class, 'CurrentStep' => MultiFormStep::class ]; private static $has_many = [ 'FormSteps' => MultiFormStep::class ]; private static $table_name = 'MultiFormSession'; /** * 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(); } /** * These actions are performed when write() is called on this object. */ public function onBeforeWrite() { // save submitter if a Member is logged in $currentMember = Security::getCurrentUser(); if (!$this->SubmitterID && $currentMember) { $this->SubmitterID = $currentMember->ID; } parent::onBeforeWrite(); } /** * These actions are performed when delete() is called on this object. */ public function onBeforeDelete() { // delete dependent form steps and relation $steps = $this->FormSteps(); if ($steps) { foreach ($steps as $step) { if ($step && $step->exists()) { $steps->remove($step); $step->delete(); $step->destroy(); } } } parent::onBeforeDelete(); } public function onAfterWrite() { parent::onAfterWrite(); // Create encrypted identification to the session instance if it doesn't exist if (!$this->Hash) { $this->Hash = sha1($this->ID . '-' . microtime()); $this->write(); } } } |