diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/code/MultiFormObjectDecorator.php b/code/extensions/MultiFormObjectDecorator.php similarity index 100% rename from code/MultiFormObjectDecorator.php rename to code/extensions/MultiFormObjectDecorator.php diff --git a/code/MultiForm.php b/code/model/MultiForm.php similarity index 96% rename from code/MultiForm.php rename to code/model/MultiForm.php index 8ff1c75..720515b 100644 --- a/code/MultiForm.php +++ b/code/model/MultiForm.php @@ -7,8 +7,9 @@ * * CAUTION: If you're using controller permission control, * you have to allow the following methods: + * * - * static $allowed_actions = array('next','prev'); + * private static $allowed_actions = array('next','prev'); * * * @package multiform @@ -120,13 +121,7 @@ abstract class MultiForm extends Form { $validator = null; $applyValidation = true; - // Check if the $_REQUEST action that user clicked is an exempt one - // if the Config class is available, use that instead of get_static() which is deprecated in SS 3.x - if(class_exists('Config')) { - $actionNames = Config::inst()->get(get_class($this), 'actions_exempt_from_validation', Config::FIRST_SET); - } else { - $actionNames = Object::get_static(get_class($this),'actions_exempt_from_validation'); - } + $actionNames = static::$actions_exempt_from_validation; if( $actionNames ) { foreach( $actionNames as $exemptAction) { @@ -180,7 +175,7 @@ abstract class MultiForm extends Form { * @return MultiFormStep subclass */ public function getCurrentStep() { - $startStepClass = $this->stat('start_step'); + $startStepClass = static::$start_step; // Check if there was a start step defined on the subclass of MultiForm if(!isset($startStepClass)) user_error('MultiForm::init(): Please define a $startStep on ' . $this->class, E_USER_ERROR); @@ -498,7 +493,7 @@ abstract class MultiForm extends Form { $currentStep = $this->getCurrentStep(); if(is_array($data)) { foreach($data as $field => $value) { - if(in_array($field, $this->stat('ignored_fields'))) { + if(in_array($field, static::$ignored_fields)) { unset($data[$field]); } } @@ -557,7 +552,7 @@ abstract class MultiForm extends Form { public function getAllStepsLinear() { $stepsFound = (class_exists('ArrayList')) ? new ArrayList() : new DataObjectSet(); - $firstStep = DataObject::get_one($this->stat('start_step'), "\"SessionID\" = {$this->session->ID}"); + $firstStep = DataObject::get_one(static::$start_step, "\"SessionID\" = {$this->session->ID}"); $firstStep->LinkingMode = ($firstStep->ID == $this->getCurrentStep()->ID) ? 'current' : 'link'; $firstStep->setForm($this); $stepsFound->push($firstStep); diff --git a/code/MultiFormSession.php b/code/model/MultiFormSession.php similarity index 91% rename from code/MultiFormSession.php rename to code/model/MultiFormSession.php index 4c22b01..8c8d65b 100644 --- a/code/MultiFormSession.php +++ b/code/model/MultiFormSession.php @@ -1,68 +1,68 @@ - 'Varchar(40)', // cryptographic hash identification to this session - 'IsComplete' => 'Boolean' // flag to determine if this session is marked completed - ); - - static $has_one = array( - 'Submitter' => 'Member', - 'CurrentStep' => 'MultiFormStep' - ); - - static $has_many = array( - 'FormSteps' => 'MultiFormStep' - ); - - /** - * 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 = Member::currentUser(); - 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(); - } - -} + 'Varchar(40)', // cryptographic hash identification to this session + 'IsComplete' => 'Boolean' // flag to determine if this session is marked completed + ); + + private static $has_one = array( + 'Submitter' => 'Member', + 'CurrentStep' => 'MultiFormStep' + ); + + private static $has_many = array( + 'FormSteps' => 'MultiFormStep' + ); + + /** + * 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 = Member::currentUser(); + 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(); + } + +} diff --git a/code/MultiFormStep.php b/code/model/MultiFormStep.php similarity index 97% rename from code/MultiFormStep.php rename to code/model/MultiFormStep.php index 790680a..949ddd6 100644 --- a/code/MultiFormStep.php +++ b/code/model/MultiFormStep.php @@ -11,11 +11,11 @@ */ class MultiFormStep extends DataObject { - static $db = array( + private static $db = array( 'Data' => 'Text' // stores serialized maps with all session information ); - static $has_one = array( + private static $has_one = array( 'Session' => 'MultiFormSession' ); @@ -204,7 +204,7 @@ class MultiFormStep extends DataObject { * @return String Classname of a {@link MultiFormStep} subclass */ public function getNextStep() { - $nextSteps = $this->stat('next_steps'); + $nextSteps = static::$next_steps; // Check if next_steps have been implemented properly if not the final step if(!$this->isFinalStep()) { @@ -231,7 +231,8 @@ class MultiFormStep extends DataObject { */ public function getNextStepFromDatabase() { if($this->SessionID && is_numeric($this->SessionID)) { - $nextSteps = $this->stat('next_steps'); + $nextSteps = static::$next_steps; + if(is_string($nextSteps)) { return DataObject::get_one($nextSteps, "\"SessionID\" = {$this->SessionID}"); } elseif(is_array($nextSteps)) { @@ -248,7 +249,7 @@ class MultiFormStep extends DataObject { * @return string|array */ public function getNextSteps() { - return $this->stat('next_steps'); + return static::$next_steps; } /** @@ -336,7 +337,7 @@ class MultiFormStep extends DataObject { * @return boolean */ public function canGoBack() { - return $this->stat('can_go_back'); + return static::$can_go_back; } /** @@ -346,7 +347,7 @@ class MultiFormStep extends DataObject { * @return boolean */ public function isFinalStep() { - return $this->stat('is_final_step'); + return static::$is_final_step; } /** diff --git a/code/MultiFormPurgeTask.php b/code/tasks/MultiFormPurgeTask.php similarity index 100% rename from code/MultiFormPurgeTask.php rename to code/tasks/MultiFormPurgeTask.php diff --git a/tests/MultiFormTest.php b/tests/MultiFormTest.php index 4d2aebd..0fd3eed 100644 --- a/tests/MultiFormTest.php +++ b/tests/MultiFormTest.php @@ -99,7 +99,7 @@ class MultiFormTest_Form extends MultiForm implements TestOnly { public static $start_step = 'MultiFormTest_StepOne'; function getStartStep() { - return $this->stat('start_step'); + return self::$start_step; } }