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,
* you have to allow the following methods:
*
* <code>
* static $allowed_actions = array('next','prev');
* private static $allowed_actions = array('next','prev');
* </code>
*
* @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);

View File

@ -1,68 +1,68 @@
<?php
/**
* 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.
*
* @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
);
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();
}
}
<?php
/**
* 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.
*
* @package multiform
*/
class MultiFormSession extends DataObject {
private static $db = array(
'Hash' => '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();
}
}

View File

@ -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;
}
/**

View File

@ -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;
}
}