MINOR codestyle to improve readibility

This commit is contained in:
Peter Thaleikis 2015-11-25 00:08:14 +13:00
parent d2780c4b7e
commit d239c294af
3 changed files with 30 additions and 28 deletions

View File

@ -127,8 +127,8 @@ abstract class MultiForm extends Form {
$actionNames = static::$actions_exempt_from_validation; $actionNames = static::$actions_exempt_from_validation;
if( $actionNames ) { if($actionNames) {
foreach( $actionNames as $exemptAction) { foreach ($actionNames as $exemptAction) {
if(!empty($_REQUEST[$exemptAction])) { if(!empty($_REQUEST[$exemptAction])) {
$applyValidation = false; $applyValidation = false;
break; break;
@ -182,7 +182,10 @@ abstract class MultiForm extends Form {
$startStepClass = static::$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 $start_step on ' . $this->class, E_USER_ERROR); if(!isset($startStepClass)) user_error(
'MultiForm::init(): Please define a $start_step on ' . $this->class,
E_USER_ERROR
);
// Determine whether we use the current step, or create one if it doesn't exist // Determine whether we use the current step, or create one if it doesn't exist
$currentStep = null; $currentStep = null;
@ -295,10 +298,10 @@ abstract class MultiForm extends Form {
* If you want a full chain of steps regardless if they've already been saved * If you want a full chain of steps regardless if they've already been saved
* to the database, use {@link getAllStepsLinear()}. * to the database, use {@link getAllStepsLinear()}.
* *
* @param String $filter SQL WHERE statement * @param string $filter SQL WHERE statement
* @return DataObjectSet|boolean A set of MultiFormStep subclasses * @return DataObjectSet|boolean A set of MultiFormStep subclasses
*/ */
function getSavedSteps($filter = null) { public function getSavedSteps($filter = null) {
$filter .= ($filter) ? ' AND ' : ''; $filter .= ($filter) ? ' AND ' : '';
$filter .= sprintf("\"SessionID\" = '%s'", $this->session->ID); $filter .= sprintf("\"SessionID\" = '%s'", $this->session->ID);
return DataObject::get('MultiFormStep', $filter); return DataObject::get('MultiFormStep', $filter);
@ -312,7 +315,7 @@ abstract class MultiForm extends Form {
* @param string $className Classname of a {@link MultiFormStep} subclass * @param string $className Classname of a {@link MultiFormStep} subclass
* @return MultiFormStep * @return MultiFormStep
*/ */
function getSavedStepByClass($className) { public function getSavedStepByClass($className) {
return DataObject::get_one( return DataObject::get_one(
'MultiFormStep', 'MultiFormStep',
sprintf("\"SessionID\" = '%s' AND \"ClassName\" = '%s'", sprintf("\"SessionID\" = '%s' AND \"ClassName\" = '%s'",
@ -341,7 +344,7 @@ abstract class MultiForm extends Form {
* @param $currentStep Subclass of MultiFormStep * @param $currentStep Subclass of MultiFormStep
* @return FieldList of FormAction objects * @return FieldList of FormAction objects
*/ */
function actionsFor($step) { public function actionsFor($step) {
// Create default multi step actions (next, prev), and merge with extra actions, if any // Create default multi step actions (next, prev), and merge with extra actions, if any
$actions = (class_exists('FieldList')) ? new FieldList() : new FieldSet(); $actions = (class_exists('FieldList')) ? new FieldList() : new FieldSet();
@ -379,7 +382,7 @@ abstract class MultiForm extends Form {
* *
* @return SSViewer object to render the template with * @return SSViewer object to render the template with
*/ */
function forTemplate() { public function forTemplate() {
$return = $this->renderWith(array( $return = $this->renderWith(array(
$this->getCurrentStep()->class, $this->getCurrentStep()->class,
'MultiFormStep', 'MultiFormStep',
@ -416,7 +419,6 @@ abstract class MultiForm extends Form {
$this->controller->redirectBack(); $this->controller->redirectBack();
return false; return false;
} }
} }
/** /**
@ -531,7 +533,7 @@ abstract class MultiForm extends Form {
* *
* @return string * @return string
*/ */
function FormAction() { public function FormAction() {
$action = parent::FormAction(); $action = parent::FormAction();
$action .= (strpos($action, '?')) ? '&' : '?'; $action .= (strpos($action, '?')) ? '&' : '?';
$action .= "MultiFormSessionID={$this->session->Hash}"; $action .= "MultiFormSessionID={$this->session->Hash}";
@ -643,6 +645,7 @@ abstract class MultiForm extends Form {
*/ */
public function getCompletedStepCount() { public function getCompletedStepCount() {
$steps = DataObject::get('MultiFormStep', "\"SessionID\" = {$this->session->ID} && \"Data\" IS NOT NULL"); $steps = DataObject::get('MultiFormStep', "\"SessionID\" = {$this->session->ID} && \"Data\" IS NOT NULL");
return $steps ? $steps->Count() : 0; return $steps ? $steps->Count() : 0;
} }
@ -663,7 +666,6 @@ abstract class MultiForm extends Form {
* @return float * @return float
*/ */
public function getCompletedPercent() { public function getCompletedPercent() {
return (float)$this->getCompletedStepCount() * 100 / $this->getTotalStepCount(); return (float) $this->getCompletedStepCount() * 100 / $this->getTotalStepCount();
} }
} }

View File

@ -208,7 +208,7 @@ class MultiFormStep extends DataObject {
/** /**
* Returns the first value of $next_step * Returns the first value of $next_step
* *
* @return String Classname of a {@link MultiFormStep} subclass * @return string Classname of a {@link MultiFormStep} subclass
*/ */
public function getNextStep() { public function getNextStep() {
$nextSteps = static::$next_steps; $nextSteps = static::$next_steps;
@ -265,7 +265,7 @@ class MultiFormStep extends DataObject {
* To determine if there is a previous step, we check the database to see if there's * To determine if there is a previous step, we check the database to see if there's
* a previous step for this multi form session ID. * a previous step for this multi form session ID.
* *
* @return String Classname of a {@link MultiFormStep} subclass * @return string Classname of a {@link MultiFormStep} subclass
*/ */
public function getPreviousStep() { public function getPreviousStep() {
$steps = DataObject::get('MultiFormStep', "\"SessionID\" = {$this->SessionID}", '"LastEdited" DESC'); $steps = DataObject::get('MultiFormStep', "\"SessionID\" = {$this->SessionID}", '"LastEdited" DESC');

View File

@ -23,24 +23,24 @@ class MultiFormTest extends FunctionalTest {
protected $controller; protected $controller;
function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->controller = new MultiFormTest_Controller(); $this->controller = new MultiFormTest_Controller();
$this->form = $this->controller->Form(); $this->form = $this->controller->Form();
} }
function testInitialisingForm() { public function testInitialisingForm() {
$this->assertTrue(is_numeric($this->form->getCurrentStep()->ID) && ($this->form->getCurrentStep()->ID > 0)); $this->assertTrue(is_numeric($this->form->getCurrentStep()->ID) && ($this->form->getCurrentStep()->ID > 0));
$this->assertTrue(is_numeric($this->form->getSession()->ID) && ($this->form->getSession()->ID > 0)); $this->assertTrue(is_numeric($this->form->getSession()->ID) && ($this->form->getSession()->ID > 0));
$this->assertEquals('MultiFormTest_StepOne', $this->form->getStartStep()); $this->assertEquals('MultiFormTest_StepOne', $this->form->getStartStep());
} }
function testSessionGeneration() { public function testSessionGeneration() {
$this->assertTrue($this->form->session->ID > 0); $this->assertTrue($this->form->session->ID > 0);
} }
function testMemberLogging() { public function testMemberLogging() {
// Grab any user to fake being logged in as, and ensure that after a session is written it has // Grab any user to fake being logged in as, and ensure that after a session is written it has
// that user as the submitter. // that user as the submitter.
$userId = Member::get_one("Member")->ID; $userId = Member::get_one("Member")->ID;
@ -52,27 +52,27 @@ class MultiFormTest extends FunctionalTest {
$this->assertEquals($userId, $session->SubmitterID); $this->assertEquals($userId, $session->SubmitterID);
} }
function testSecondStep() { public function testSecondStep() {
$this->assertEquals('MultiFormTest_StepTwo', $this->form->getCurrentStep()->getNextStep()); $this->assertEquals('MultiFormTest_StepTwo', $this->form->getCurrentStep()->getNextStep());
} }
function testParentForm() { public function testParentForm() {
$currentStep = $this->form->getCurrentStep(); $currentStep = $this->form->getCurrentStep();
$this->assertEquals($currentStep->getForm()->class, $this->form->class); $this->assertEquals($currentStep->getForm()->class, $this->form->class);
} }
function testTotalStepCount() { public function testTotalStepCount() {
$this->assertEquals(3, $this->form->getAllStepsLinear()->Count()); $this->assertEquals(3, $this->form->getAllStepsLinear()->Count());
} }
function testCompletedSession() { public function testCompletedSession() {
$this->form->setCurrentSessionHash($this->form->session->Hash); $this->form->setCurrentSessionHash($this->form->session->Hash);
$this->assertInstanceOf('MultiFormSession', $this->form->getCurrentSession()); $this->assertInstanceOf('MultiFormSession', $this->form->getCurrentSession());
$this->form->session->markCompleted(); $this->form->session->markCompleted();
$this->assertNull($this->form->getCurrentSession()); $this->assertNull($this->form->getCurrentSession());
} }
function testIncorrectSessionIdentifier() { public function testIncorrectSessionIdentifier() {
$this->form->setCurrentSessionHash('sdfsdf3432325325sfsdfdf'); // made up! $this->form->setCurrentSessionHash('sdfsdf3432325325sfsdfdf'); // made up!
// A new session is generated, even though we made up the identifier // A new session is generated, even though we made up the identifier
@ -87,7 +87,7 @@ class MultiFormTest extends FunctionalTest {
*/ */
class MultiFormTest_Controller extends Controller implements TestOnly { class MultiFormTest_Controller extends Controller implements TestOnly {
function Link() { public function Link() {
return 'MultiFormTest_Controller'; return 'MultiFormTest_Controller';
} }
@ -106,7 +106,7 @@ class MultiFormTest_Form extends MultiForm implements TestOnly {
public static $start_step = 'MultiFormTest_StepOne'; public static $start_step = 'MultiFormTest_StepOne';
function getStartStep() { public function getStartStep() {
return self::$start_step; return self::$start_step;
} }
@ -120,7 +120,7 @@ class MultiFormTest_StepOne extends MultiFormStep implements TestOnly {
public static $next_steps = 'MultiFormTest_StepTwo'; public static $next_steps = 'MultiFormTest_StepTwo';
function getFields() { public function getFields() {
$class = (class_exists('FieldList')) ? 'FieldList' : 'FieldSet'; $class = (class_exists('FieldList')) ? 'FieldList' : 'FieldSet';
return new $class( return new $class(
new TextField('FirstName', 'First name'), new TextField('FirstName', 'First name'),
@ -138,7 +138,7 @@ class MultiFormTest_StepTwo extends MultiFormStep implements TestOnly {
public static $next_steps = 'MultiFormTest_StepThree'; public static $next_steps = 'MultiFormTest_StepThree';
function getFields() { public function getFields() {
$class = (class_exists('FieldList')) ? 'FieldList' : 'FieldSet'; $class = (class_exists('FieldList')) ? 'FieldList' : 'FieldSet';
return new $class( return new $class(
new TextareaField('Comments', 'Tell us a bit about yourself...') new TextareaField('Comments', 'Tell us a bit about yourself...')
@ -154,7 +154,7 @@ class MultiFormTest_StepThree extends MultiFormStep implements TestOnly {
public static $is_final_step = true; public static $is_final_step = true;
function getFields() { public function getFields() {
$class = (class_exists('FieldList')) ? 'FieldList' : 'FieldSet'; $class = (class_exists('FieldList')) ? 'FieldList' : 'FieldSet';
return new $class( return new $class(
new TextField('Test', 'Anything else you\'d like to tell us?') new TextField('Test', 'Anything else you\'d like to tell us?')