FIX: Update class properties to use late static binding

This commit is contained in:
Will Rossiter 2013-05-25 19:04:59 +12:00
parent a0187dc133
commit 25f0c051ff
7 changed files with 84 additions and 87 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.DS_Store

View File

@ -7,8 +7,9 @@
* *
* CAUTION: If you're using controller permission control, * CAUTION: If you're using controller permission control,
* you have to allow the following methods: * you have to allow the following methods:
*
* <code> * <code>
* static $allowed_actions = array('next','prev'); * private static $allowed_actions = array('next','prev');
* </code> * </code>
* *
* @package multiform * @package multiform
@ -120,13 +121,7 @@ abstract class MultiForm extends Form {
$validator = null; $validator = null;
$applyValidation = true; $applyValidation = true;
// Check if the $_REQUEST action that user clicked is an exempt one $actionNames = static::$actions_exempt_from_validation;
// 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');
}
if( $actionNames ) { if( $actionNames ) {
foreach( $actionNames as $exemptAction) { foreach( $actionNames as $exemptAction) {
@ -180,7 +175,7 @@ abstract class MultiForm extends Form {
* @return MultiFormStep subclass * @return MultiFormStep subclass
*/ */
public function getCurrentStep() { 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 // 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); 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(); $currentStep = $this->getCurrentStep();
if(is_array($data)) { if(is_array($data)) {
foreach($data as $field => $value) { foreach($data as $field => $value) {
if(in_array($field, $this->stat('ignored_fields'))) { if(in_array($field, static::$ignored_fields)) {
unset($data[$field]); unset($data[$field]);
} }
} }
@ -557,7 +552,7 @@ abstract class MultiForm extends Form {
public function getAllStepsLinear() { public function getAllStepsLinear() {
$stepsFound = (class_exists('ArrayList')) ? new ArrayList() : new DataObjectSet(); $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->LinkingMode = ($firstStep->ID == $this->getCurrentStep()->ID) ? 'current' : 'link';
$firstStep->setForm($this); $firstStep->setForm($this);
$stepsFound->push($firstStep); $stepsFound->push($firstStep);

View File

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

View File

@ -11,11 +11,11 @@
*/ */
class MultiFormStep extends DataObject { class MultiFormStep extends DataObject {
static $db = array( private static $db = array(
'Data' => 'Text' // stores serialized maps with all session information 'Data' => 'Text' // stores serialized maps with all session information
); );
static $has_one = array( private static $has_one = array(
'Session' => 'MultiFormSession' 'Session' => 'MultiFormSession'
); );
@ -204,7 +204,7 @@ class MultiFormStep extends DataObject {
* @return String Classname of a {@link MultiFormStep} subclass * @return String Classname of a {@link MultiFormStep} subclass
*/ */
public function getNextStep() { 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 // Check if next_steps have been implemented properly if not the final step
if(!$this->isFinalStep()) { if(!$this->isFinalStep()) {
@ -231,7 +231,8 @@ class MultiFormStep extends DataObject {
*/ */
public function getNextStepFromDatabase() { public function getNextStepFromDatabase() {
if($this->SessionID && is_numeric($this->SessionID)) { if($this->SessionID && is_numeric($this->SessionID)) {
$nextSteps = $this->stat('next_steps'); $nextSteps = static::$next_steps;
if(is_string($nextSteps)) { if(is_string($nextSteps)) {
return DataObject::get_one($nextSteps, "\"SessionID\" = {$this->SessionID}"); return DataObject::get_one($nextSteps, "\"SessionID\" = {$this->SessionID}");
} elseif(is_array($nextSteps)) { } elseif(is_array($nextSteps)) {
@ -248,7 +249,7 @@ class MultiFormStep extends DataObject {
* @return string|array * @return string|array
*/ */
public function getNextSteps() { public function getNextSteps() {
return $this->stat('next_steps'); return static::$next_steps;
} }
/** /**
@ -336,7 +337,7 @@ class MultiFormStep extends DataObject {
* @return boolean * @return boolean
*/ */
public function canGoBack() { public function canGoBack() {
return $this->stat('can_go_back'); return static::$can_go_back;
} }
/** /**
@ -346,7 +347,7 @@ class MultiFormStep extends DataObject {
* @return boolean * @return boolean
*/ */
public function isFinalStep() { public function isFinalStep() {
return $this->stat('is_final_step'); return static::$is_final_step;
} }
/** /**

View File

@ -99,7 +99,7 @@ class MultiFormTest_Form extends MultiForm implements TestOnly {
public static $start_step = 'MultiFormTest_StepOne'; public static $start_step = 'MultiFormTest_StepOne';
function getStartStep() { function getStartStep() {
return $this->stat('start_step'); return self::$start_step;
} }
} }