Skip to content

Commit

Permalink
Converted to PSR-2
Browse files Browse the repository at this point in the history
  • Loading branch information
helpfulrobot committed Dec 17, 2015
1 parent 53e1fd4 commit 3616ed2
Show file tree
Hide file tree
Showing 33 changed files with 142 additions and 152 deletions.
4 changes: 2 additions & 2 deletions code/extensions/FlexiFormControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function FlexiForm($identifier = null)
$form_class = $flexi->stat('flexiform_form_class');
$form_name = Config::inst()->get($form_class, 'flexiform_post_action');
$form = new $form_class($this->owner, $form_name, $fields, $actions, $validator);
$form->addExtraClass(implode(' ',$flexi->stat('flexiform_form_extraclasses')));
$form->addExtraClass(implode(' ', $flexi->stat('flexiform_form_extraclasses')));

// identify the form in post
$form->setFormAction(
Expand Down Expand Up @@ -93,4 +93,4 @@ public function setFlexiFormObject($flexi)
{
return $this->flexiform_object = $flexi;
}
}
}
27 changes: 13 additions & 14 deletions code/extensions/FlexiFormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function updateCMSFields(FieldList $fields)
$fields->removeByName('FlexiFormConfigID');

if ($this->owner->exists()) {

$fields_tab = new Tab('Fields');
$settings_tab = new Tab('Settings');

Expand All @@ -80,7 +79,7 @@ public function updateCMSFields(FieldList $fields)
// hint allowed types to FlexiFormField search fields
singleton('FlexiFormField')->set_stat('allowed_types', $field_types);
$component = $config->getComponentByType('GridFieldAddExistingSearchButton');
$component->setSearchList(FlexiFormField::get()->filter('ClassName',array_keys($field_types)));
$component->setSearchList(FlexiFormField::get()->filter('ClassName', array_keys($field_types)));


$fields_tab->push(
Expand Down Expand Up @@ -137,13 +136,15 @@ public function getFlexiFormFrontEndFields()
return $fields;
}

public function getFlexiFormFrontEndFieldByID($id){
return $this->owner->FlexiFormFields()->filter('FlexiFormField.ID',$id)->first();
public function getFlexiFormFrontEndFieldByID($id)
{
return $this->owner->FlexiFormFields()->filter('FlexiFormField.ID', $id)->first();
}

// Templates
////////////
public function Form(){
public function Form()
{
return Controller::curr()->FlexiForm($this->FlexiFormID());
}
// Getters & Setters
Expand Down Expand Up @@ -194,7 +195,7 @@ public function getFlexiFormFieldTypes()
return $field_types;
}

public function setFlexiFormFieldTypes(Array $field_types)
public function setFlexiFormFieldTypes(array $field_types)
{
return $this->owner->set_stat('flexiform_field_types', $field_types);
}
Expand All @@ -204,7 +205,7 @@ public function getFlexiFormInitialFields()
return $this->owner->stat('flexiform_initial_fields');
}

public function setFlexiFormInitialFields(Array $field_definitions)
public function setFlexiFormInitialFields(array $field_definitions)
{
return $this->owner->set_stat('flexiform_initial_fields', $field_definitions);
}
Expand All @@ -223,7 +224,6 @@ public function setFlexiFormDefaultHandlerName($handler_name)
public function setFlexiFormConfigs($value)
{
if ($configs = Controller::curr()->getRequest()->requestVar('FlexiFormConfig')) {

$conf = $this->FlexiFormConf();

foreach ($configs as $property => $value) {
Expand All @@ -236,7 +236,7 @@ public function setFlexiFormConfigs($value)
}
$conf->write();

if($handler = $this->FlexiFormHandler()) {
if ($handler = $this->FlexiFormHandler()) {
$handler->onConfigUpdate($conf, $this->owner);
}
}
Expand All @@ -259,7 +259,8 @@ public function FlexiFormHandler()
return $this->FlexiFormConf('Handler');
}

public function FlexiFormSetting($setting){
public function FlexiFormSetting($setting)
{
return $this->FlexiFormConf("Setting.$setting");
}

Expand All @@ -268,7 +269,6 @@ public function validate(ValidationResult $result)
$names = array();
if ($result->valid()) {
foreach ($this->owner->FlexiFormFields() as $field) {

if (empty($field->Name)) {
$result->error("Field names cannot be blank. Encountered a blank {$field->Label()} field.");
break;
Expand Down Expand Up @@ -305,7 +305,6 @@ public function onAfterWrite()
// ensure valid config
//////////////////////
if (! $conf->exists()) {

if ($name = $this->getFlexiFormDefaultHandlerName()) {
if ($handler = FlexiFormHandler::get()->filter('HandlerName', $name)->first()) {
$conf->HandlerID = $handler->ID;
Expand All @@ -324,7 +323,7 @@ public function onAfterWrite()

if (!$this->FlexiFormConf('InitializedFields')) {
$definitions = $this->getFlexiFormInitialFields();
if(!empty($definitions)) {
if (!empty($definitions)) {
$fields = $this->owner->FlexiFormFields();
foreach ($definitions as $definition) {
if (! is_array($definition) || ! isset($definition['Name']) || ! isset($definition['Type'])) {
Expand Down Expand Up @@ -378,4 +377,4 @@ public function onBeforeDelete()
}
return parent::onBeforeDelete();
}
}
}
5 changes: 2 additions & 3 deletions code/forms/FlexiForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function setFlexiFormOrigin()
// @TODO can we use a mock the result of a mock request for a URL instead?
// ..Needed in case action requires URL params to display form.
$action = $this->controller->getAction();
if($action != $this->stat('flexiform_post_action')) {
if ($action != $this->stat('flexiform_post_action')) {
Session::set("FormInfo.{$this->FormName()}.flexi_origin", $action);
}
}
Expand Down Expand Up @@ -77,7 +77,6 @@ public function isSubmitted()
public function httpSubmission($request)
{
if ($this->isSubmitted() && ! $this->getSecurityToken()->checkRequest($request)) {

$this->sessionMessage(_t("FlexiForm.RESUBMISSION_MESSAGE", "Your submission was received."),
"warning");

Expand All @@ -86,4 +85,4 @@ public function httpSubmission($request)

return parent::httpSubmission($request);
}
}
}
4 changes: 1 addition & 3 deletions code/forms/gridfield/GridFieldConfig_FlexiForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public function __construct()
),
'DefaultValue' => array(
'title' => 'Default Value',
'callback' => function ($record, $column_name, $grid)
{
'callback' => function ($record, $column_name, $grid) {
return ($record->hasMethod('getDefaultValueFormField')) ? $record->getDefaultValueFormField(
'DefaultValue') : new TextField($column_name);
}
Expand All @@ -65,4 +64,3 @@ public function __construct()
FlexiFormUtil::include_requirements();
}
}

4 changes: 1 addition & 3 deletions code/forms/gridfield/GridFieldConfig_FlexiFormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public function __construct($allowed_types = array())
array(
'Selected' => array(
'title' => 'Selected',
'callback' => function ($record, $column_name, $grid)
{
'callback' => function ($record, $column_name, $grid) {
return new CheckboxField_Readonly($column_name);
}
),
Expand All @@ -60,4 +59,3 @@ public function __construct($allowed_types = array())
));
}
}

2 changes: 0 additions & 2 deletions code/forms/gridfield/GridFieldConfig_FlexiFormOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,5 @@ public function __construct()
// Sort Order
// ///////////
$this->addComponent(new GridFieldOrderableRows('SortOrder'));

}
}

9 changes: 4 additions & 5 deletions code/forms/gridfield/GridFieldConfig_FlexiFormSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function __construct($flexi)
$export->setExportColumns($this->getCSVColumns($flexi));
}

private function getCSVColumns($flexi) {

private function getCSVColumns($flexi)
{
$columns = array(
'SubmittedBy' => 'Submitted By',
'IPAddress' => 'IP Address',
Expand All @@ -36,16 +36,15 @@ private function getCSVColumns($flexi) {
$sql = new SQLQuery();
$sql->setFrom('FlexiFormSubmissionValue');
$sql->setSelect('"FlexiFormSubmissionValue"."Name"');
$sql->addLeftJoin('FlexiFormSubmission','"FlexiFormSubmissionValue"."SubmissionID" = "FlexiFormSubmission"."ID"');
$sql->addLeftJoin('FlexiFormSubmission', '"FlexiFormSubmissionValue"."SubmissionID" = "FlexiFormSubmission"."ID"');
$sql->addWhere('"FlexiFormSubmission"."FlexiFormID" = ' . $flexi->ID);
$sql->addWhere('"FlexiFormSubmission"."FlexiFormClass" = \'' . $flexi->class . '\'');
$sql->setDistinct(true);

foreach($sql->execute() as $row) {
foreach ($sql->execute() as $row) {
$columns['Values.' . $row['Name']] = $row['Name'];
}

return $columns;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ public function __construct()
),
'Value' => array(
'title' => 'Response Value',
'callback' => function ($record, $column_name, $grid)
{
return new ReadonlyField($column_name,'XXX','XXX');
'callback' => function ($record, $column_name, $grid) {
return new ReadonlyField($column_name, 'XXX', 'XXX');
}
)

));
}
}

4 changes: 2 additions & 2 deletions code/model/FlexiFormConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function relField($fieldName)
return parent::relField($fieldName);
}

public function updateHandlerSettings(Array $settings)
public function updateHandlerSettings(array $settings)
{
foreach ($settings as $component => $value) {
if ($setting = $this->relField("Setting.$component")) {
Expand Down Expand Up @@ -71,4 +71,4 @@ protected function onBeforeDelete()

return parent::onBeforeDelete();
}
}
}
12 changes: 6 additions & 6 deletions code/model/FlexiFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function getCMSFields()
$field->description = 'Shown in submissions. Should be short and without special characters.';


if($this->hasMethod('getDefaultValueFormField')) {
if ($this->hasMethod('getDefaultValueFormField')) {
$fields->replaceField('FieldDefaultValue', $this->getDefaultValueFormField());
}

Expand Down Expand Up @@ -117,10 +117,10 @@ public function scaffoldSearchFields($_params = null)
{
$fields = parent::scaffoldSearchFields($_params);

if($allowed_types = $this->stat('allowed_types')) {
$field = $fields->dataFieldByName('ClassName');
$field->setSource($allowed_types);
$field->setEmptyString('Select Type');
if ($allowed_types = $this->stat('allowed_types')) {
$field = $fields->dataFieldByName('ClassName');
$field->setSource($allowed_types);
$field->setEmptyString('Select Type');
}
return $fields;
}
Expand Down Expand Up @@ -198,7 +198,7 @@ public function getRequiredFieldDefinitions()
return $this->stat('required_field_definitions');
}

public function setRequiredFieldDefinitions(Array $required_field_definitions)
public function setRequiredFieldDefinitions(array $required_field_definitions)
{
return $this->set_stat('required_field_definitions', $required_field_definitions);
}
Expand Down
17 changes: 9 additions & 8 deletions code/model/FlexiFormFieldOption.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

class FlexiFormFieldOption extends DataObject {
class FlexiFormFieldOption extends DataObject
{

private static $db = array(
'Label' => 'Varchar',
Expand All @@ -17,22 +18,22 @@ class FlexiFormFieldOption extends DataObject {
);


public function validate() {
public function validate()
{
$result = parent::validate();

if($result->valid()) {
if(empty($this->Value)) {
if ($result->valid()) {
if (empty($this->Value)) {
$result->error('Option Values cannot be blank.');
}
}

return $result;
}

public function getLabel(){

public function getLabel()
{
$label = $this->getField('Label');
return (empty($label)) ? $this->Value : $label;
}

}
}
13 changes: 7 additions & 6 deletions code/model/FlexiFormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public function updateCMSFlexiTabs(TabSet $fields, TabSet $settings_tab, $flexi)

$form_settings = $flexi->FlexiFormConf('HandlerSettings');
foreach (Config::inst()->get($this->class, 'handler_settings', Config::INHERITED) as $component => $class) {

if (! $setting = $flexi->FlexiFormSetting($component)) {
$setting = new $class();
$setting->Setting = $component;
Expand Down Expand Up @@ -122,7 +121,7 @@ public function getFrontEndFormValidator($flexi)
* @param DataObject $flexi The object extended by FlexiFormExtension
* @return Boolean
*/
public function onSubmit(Array $data, FlexiForm $form, SS_HTTPRequest $request, DataObject $flexi)
public function onSubmit(array $data, FlexiForm $form, SS_HTTPRequest $request, DataObject $flexi)
{
return true;
}
Expand All @@ -138,7 +137,8 @@ public function onSubmit(Array $data, FlexiForm $form, SS_HTTPRequest $request,
* @param DataObject $flexi The object extended by FlexiFormExtension
*/
public function onSuccess(FlexiForm $form, DataObject $flexi)
{}
{
}

// Templates
////////////
Expand Down Expand Up @@ -170,7 +170,7 @@ public function getRequiredHandlerDefinitions()
return $this->lookup('required_handler_definitions');
}

public function setRequiredHandlerDefinitions(Array $definitions)
public function setRequiredHandlerDefinitions(array $definitions)
{
return $this->set_stat('required_handler_definitions', $definitions);
}
Expand All @@ -193,7 +193,8 @@ protected function getSettingFieldName($setting)
}

public function onConfigUpdate(FlexiFormConfig $config, DataObject $flexi)
{}
{
}

public function requireDefaultRecords()
{
Expand All @@ -212,4 +213,4 @@ public function onBeforeDelete()

return parent::onBeforeDelete();
}
}
}
3 changes: 1 addition & 2 deletions code/model/FlexiFormOptionField.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public function getCMSFields()
implode(', ', $this->Options()
->column('Label'))));
} else {

$config = new GridFieldConfig_FlexiFormOption();

$fields->addFieldToTab('Root.Main', new GridField('Options', 'Options', $this->Options(), $config));
Expand Down Expand Up @@ -75,4 +74,4 @@ public function getDefaultValueFormField($field_name = 'FieldDefaultValue')
$field->description = 'Optional. This value will be preselectd.';
return $field;
}
}
}
Loading

0 comments on commit 3616ed2

Please sign in to comment.