Commit 1b846441 authored by Phalkunz Ponlu's avatar Phalkunz Ponlu

Merge branch 'update-psr-2' into 'master'

Converted codebase to PSR-2



See merge request !11
parents cdb0ad7d 1bea47c9
......@@ -2,13 +2,12 @@
class EditableAutosuggestField extends EditableFormField
{
private static $singular_name = 'Auto-Suggest';
private static $plural_name = 'Auto-Suggests';
private static $db = array(
'SourceFile' => 'Varchar'
'SourceFile' => 'Varchar',
);
// removed slash before assets to suit for case of site URL not equals to base URL
......@@ -16,37 +15,37 @@ class EditableAutosuggestField extends EditableFormField
private static function get_json_directory()
{
return Director::baseFolder() . '/' . self::$json_source_files_folder;
return Director::baseFolder().'/'.self::$json_source_files_folder;
}
private static function get_json_files()
{
if(!file_exists(self::get_json_directory())) {
if (!file_exists(self::get_json_directory())) {
Filesystem::makeFolder(self::get_json_directory());
Filesystem::sync();
}
$files = scandir(self::get_json_directory());
$opts = [];
foreach($files as $val) {
if($val !== '.' && $val !== '..' && is_file(self::get_json_directory() . '/' . $val)) {
foreach ($files as $val) {
if ($val !== '.' && $val !== '..' && is_file(self::get_json_directory().'/'.$val)) {
$opts[$val] = $val;
}
}
return $opts;
}
public function getCMSFields()
{
$this->beforeUpdateCMSFields(function(FieldList $fields) {
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$dropdown = DropdownField::create('SourceFile', 'Source file', self::get_json_files());
// Display info text where to upload the source file to if there
// isn't one
if(count(self::get_json_files()) < 1) {
if (count(self::get_json_files()) < 1) {
$folderName = str_replace('/assets/', '', EditableAutosuggestField::$json_source_files_folder);
$dropdown->setRightTitle('Please upload a source JSON file under <strong>' . $folderName . '</strong> folder in <strong>Files</strong> section.');
$dropdown->setRightTitle('Please upload a source JSON file under <strong>'.$folderName.'</strong> folder in <strong>Files</strong> section.');
}
$fields->addFieldToTab('Root.Main', $dropdown);
......@@ -57,7 +56,7 @@ class EditableAutosuggestField extends EditableFormField
public function getFormField()
{
$field = AutoSuggestionsField::create($this->Name, $this->EscapedTitle, $this->SourceFile ,$this->Default)
$field = AutoSuggestionsField::create($this->Name, $this->EscapedTitle, $this->SourceFile, $this->Default)
->setFieldHolderTemplate('UserFormsField_holder')
->setTemplate('UserFormsField');
......@@ -65,5 +64,4 @@ class EditableAutosuggestField extends EditableFormField
return $field;
}
}
<?php
class EditableNameField extends EditableFormField {
private static $singular_name = 'Name Field';
class EditableNameField extends EditableFormField
{
private static $singular_name = 'Name Field';
private static $plural_name = 'Names';
private static $plural_name = 'Names';
private static $db = array(
"ShowMiddleName" => "Boolean",
"ValidationOption" => "Enum('Both, Either, None', 'Both')"
);
private static $db = array(
'ShowMiddleName' => 'Boolean',
'ValidationOption' => "Enum('Both, Either, None', 'Both')",
);
public function getCMSFields() {
public function getCMSFields()
{
$fields = parent::getCMSFields();
$validationOptions = singleton("EditableNameField")->dbObject('ValidationOption')->enumValues();
$validationOptions = singleton('EditableNameField')->dbObject('ValidationOption')->enumValues();
$fields->addFieldsToTab('Root.Main', CheckboxField::create('ShowMiddleName', 'Show Middle Name field'), 'Description');
$fields->addFieldsToTab('Root.Validation', OptionSetField::create('ValidationOption', 'Validation Options', $validationOptions, array_shift($validationOptions))
->setDescription('Note: The Middle Name field is always optional.'));
->setDescription('Note: The Middle Name field is always optional.'));
$fields->removeFieldFromTab('Root.Validation', 'Required');
$fields->removeFieldFromTab('Root.Validation', 'Required');
return $fields;
}
public function getFormField() {
public function getFormField()
{
$field = NameField::create($this->Name, $this->Title, array(
HeaderField::create('mainTitle', $this->Title, 5),
TextField::create($this->Name . '_First', 'First name', $this->Default)
TextField::create($this->Name.'_First', 'First name', $this->Default)
->setFieldHolderTemplate('UserFormsField_holder')
->setTemplate('UserFormsField'),
TextField::create($this->Name . '_Last', 'Last name', $this->Default)
TextField::create($this->Name.'_Last', 'Last name', $this->Default)
->setFieldHolderTemplate('UserFormsField_holder')
->setTemplate('UserFormsField')
->setRightTitle(Convert::raw2xml($this->RightTitle))
->setRightTitle(Convert::raw2xml($this->RightTitle)),
))
->setAttribute('data-show-middle-name', $this->ShowMiddleName)
->setAttribute('data-validation-option', $this->ValidationOption);
$this->doUpdateFormField($field);
$this->doUpdateFormField($field);
return $field;
}
return $field;
}
}
<?php
class PlaceHolderField extends EditableFormField {
class PlaceHolderField extends EditableFormField
{
private static $singular_name = 'Placeholder';
private static $plural_name = 'Placeholder';
private static $literal = true;
public function getFormField() {
public function getFormField()
{
$labelField = new HeaderField($this->Name, $this->EscapedTitle, $this->Level);
$labelField->setAttribute('data-show-on-load', true);
return $labelField;
}
}
\ No newline at end of file
}
<?php
class EditableFormFieldExtension extends DataExtension {
private static $db = array(
class EditableFormFieldExtension extends DataExtension
{
private static $db = array(
'ResponsiveTitle' => 'Varchar(255)',
'Description' => 'HTMLText',
'InitialVisibility' => 'Boolean(1)', // 'ShowOnLoad' replacement
'DisplayRuleAction' => 'Enum("Show, Hide")',
'DisplayRuleControlField' => 'Varchar(150)',
'DisplayRuleControlFieldValues' => 'Text',
'HelpText' => 'HTMLText'
);
'HelpText' => 'HTMLText',
);
public function updateCMSFields(FieldList $fields) {
public function updateCMSFields(FieldList $fields)
{
$fields->AddFieldsToTab('Root.Main', array(
HTMLEditorField::create('HelpText')
->setRows(15),
HTMLEditorField::create('Description', 'Question note')
->setRows(20)
->setRows(20),
));
// Responsive title field for dynamically piping data
......@@ -29,18 +32,18 @@ class EditableFormFieldExtension extends DataExtension {
'Default',
'Placeholder',
'ExtraClass',
'RightTitle'
'RightTitle',
));
$fields->removeFieldsFromTab('Root.DisplayRules', array(
'ShowOnLoad',
'DisplayRules'
'DisplayRules',
));
$radioFields = EditableFormField::get()
->filter(array(
'ParentID' => $this->owner->ParentID,
'Sort:lessThan' => $this->owner->Sort
'Sort:lessThan' => $this->owner->Sort,
))
->exclude('ID', $this->owner->ID)
->where(array('"ClassName" IN (?, ?)' => array('EditableRadioField', 'EditableCheckboxGroupField')));
......@@ -50,45 +53,44 @@ class EditableFormFieldExtension extends DataExtension {
DropdownField::create('DisplayRuleAction', 'This field will', $this->owner->dbObject('DisplayRuleAction')->enumValues())->setEmptyString(''),
DropdownField::create('DisplayRuleControlField', 'when field', $radioFields->map())->setEmptyString(''),
TextareaField::create('DisplayRuleControlFieldValues', 'equals to one of these values')
->setRightTitle('Values are case sensitive, separated by new lines. You can prefix each value by # character for readability.')
->setRightTitle('Values are case sensitive, separated by new lines. You can prefix each value by # character for readability.'),
));
}
public function beforeUpdateFormField($field)
{
if ($this->owner->Description) {
$field->setAttribute('data-description', $this->owner->Description);
}
}
}
public function beforeUpdateFormField($field) {
if($this->owner->Description) {
$field->setAttribute('data-description', $this->owner->Description);
}
}
public function afterUpdateFormField($field) {
$errorMessage = $this->owner->getErrorMessage()->HTML();
$field->setAttribute('data-msg-required', $errorMessage);
public function afterUpdateFormField($field)
{
$errorMessage = $this->owner->getErrorMessage()->HTML();
$field->setAttribute('data-msg-required', $errorMessage);
$field->setAttribute('data-show-on-load', $this->owner->InitialVisibility);
$field->setAttribute('data-responsive-label', $this->owner->ResponsiveTitle);
$field->setAttribute('data-help-text', $this->owner->dbObject('HelpText')->forTemplate());
if($this->owner->DisplayRuleAction && $this->owner->DisplayRuleControlField && $this->owner->DisplayRuleControlFieldValues) {
if ($this->owner->DisplayRuleAction && $this->owner->DisplayRuleControlField && $this->owner->DisplayRuleControlFieldValues) {
// Get dipslay rules
$displayRule = array();
$fields = EditableFormField::get()->filter('ID', $this->owner->DisplayRuleControlField);
$fieldName = null;
if($fields->count() > 0) {
if ($fields->count() > 0) {
$fieldName = $fields->First()->Name;
}
if($fieldName) {
if ($fieldName) {
$displayRule = [
'action' => $this->owner->DisplayRuleAction,
'controlField' => $fieldName,
'controlFieldValues' => $this->owner->DisplayRuleControlFieldValues
'controlFieldValues' => $this->owner->DisplayRuleControlFieldValues,
];
$field->setAttribute('data-display-rule', json_encode($displayRule));
}
}
}
}
}
<?php
class EditableFormStepExtension extends DataExtension
class EditableFormStepExtension extends DataExtension
{
public function updateCMSFields(FieldList $fields)
{
$fields->renameField('Description', 'Section introduction');
}
}
\ No newline at end of file
public function updateCMSFields(FieldList $fields)
{
$fields->renameField('Description', 'Section introduction');
}
}
<?php
class FormFieldDefinitionExtension extends DataExtension {
class FormFieldDefinitionExtension extends DataExtension
{
/**
* getFieldDefinition()
* getFieldDefinition().
*
* @TODO: Create another extension for dropdown and option set field
**/
public function getFieldDefinition() {
public function getFieldDefinition()
{
$label = trim(str_replace('<span class=\'required-identifier\'>(required)</span>', '', $this->owner->title));
$field = array(
......@@ -17,79 +19,78 @@ class FormFieldDefinitionExtension extends DataExtension {
);
// Replace the responsive label is we have one set.
if(!empty($this->owner->attributes['data-responsive-label'])) {
if (!empty($this->owner->attributes['data-responsive-label'])) {
$field['responsiveLabel'] = $this->owner->attributes['data-responsive-label'];
}
// Default values
if(!empty($this->owner->value)) {
if($this->owner instanceof NumericField) {
$field['default'] = (int)$this->owner->value;
} elseif($this->owner instanceof CheckboxField) {
$field['default'] = (bool)$this->owner->value;
if (!empty($this->owner->value)) {
if ($this->owner instanceof NumericField) {
$field['default'] = (int) $this->owner->value;
} elseif ($this->owner instanceof CheckboxField) {
$field['default'] = (bool) $this->owner->value;
} else {
$field['default'] = $this->owner->value;
}
} elseif(!empty($this->owner->defaultItems) && is_array($this->owner->defaultItems)) {
} elseif (!empty($this->owner->defaultItems) && is_array($this->owner->defaultItems)) {
$field['default'] = $this->owner->defaultItems;
}
if(isset($this->owner->attributes)) {
if (isset($this->owner->attributes)) {
// Required field validation
if(isset($this->owner->attributes['data-rule-required']) && $this->owner->attributes['data-rule-required']) {
if (isset($this->owner->attributes['data-rule-required']) && $this->owner->attributes['data-rule-required']) {
$field['mandatory'] = true;
}
if(!empty($this->owner->attributes['data-msg-required'])) {
if (!empty($this->owner->attributes['data-msg-required'])) {
$field['errorText'] = $this->owner->attributes['data-msg-required'];
}
if(!empty($this->owner->attributes['data-description'])) {
if (!empty($this->owner->attributes['data-description'])) {
$field['noteContent'] = $this->owner->attributes['data-description'];
}
// Numeric validation
if(!empty($this->owner->attributes['data-rule-min'])) {
$field['min'] = (int)$this->owner->attributes['data-rule-min'];
if (!empty($this->owner->attributes['data-rule-min'])) {
$field['min'] = (int) $this->owner->attributes['data-rule-min'];
}
if(!empty($this->owner->attributes['data-rule-max'])) {
$field['max'] = (int)$this->owner->attributes['data-rule-max'];
if (!empty($this->owner->attributes['data-rule-max'])) {
$field['max'] = (int) $this->owner->attributes['data-rule-max'];
}
// Field value length
if(!empty($this->owner->attributes['data-rule-minlength'])) {
$field['minlength'] = (int)$this->owner->attributes['data-rule-minlength'];
if (!empty($this->owner->attributes['data-rule-minlength'])) {
$field['minlength'] = (int) $this->owner->attributes['data-rule-minlength'];
}
if(!empty($this->owner->attributes['data-rule-maxlength'])) {
$field['maxlength'] = (int)$this->owner->attributes['data-rule-maxlength'];
if (!empty($this->owner->attributes['data-rule-maxlength'])) {
$field['maxlength'] = (int) $this->owner->attributes['data-rule-maxlength'];
}
// Show on laod
if(!empty($this->owner->attributes['data-show-on-load'])) {
$field['showOnLoad'] = (boolean)$this->owner->attributes['data-show-on-load'];
}
else {
if (!empty($this->owner->attributes['data-show-on-load'])) {
$field['showOnLoad'] = (boolean) $this->owner->attributes['data-show-on-load'];
} else {
$field['showOnLoad'] = false;
}
// Dispaly rules
if(!empty($this->owner->attributes['data-display-rule'])) {
if (!empty($this->owner->attributes['data-display-rule'])) {
$field['displayRule'] = json_decode($this->owner->attributes['data-display-rule']);
}
if(!empty($this->owner->attributes['data-help-text'])) {
if (!empty($this->owner->attributes['data-help-text'])) {
$field['helpText'] = $this->owner->attributes['data-help-text'];
}
}
if(!empty($this->owner->rows)) {
if (!empty($this->owner->rows)) {
$field['rows'] = $this->owner->rows;
}
// Fields with options
if($this->owner instanceof DropdownField && isset($this->owner->source)) {
if ($this->owner instanceof DropdownField && isset($this->owner->source)) {
$field['options'] = array();
foreach($this->owner->source as $value => $label) {
foreach ($this->owner->source as $value => $label) {
$field['options'][] = array(
'label' => $label,
'value' => $value,
......@@ -100,28 +101,28 @@ class FormFieldDefinitionExtension extends DataExtension {
return $field;
}
public function udfTypeToJsonType($type) {
public function udfTypeToJsonType($type)
{
$types = array(
'CheckboxField' => 'checkbox',
'CountryDropdownField' => 'dropdown',
'DropdownField' => 'dropdown',
'CheckboxField' => 'checkbox',
'CountryDropdownField' => 'dropdown',
'DropdownField' => 'dropdown',
'EditableDateField_FormField' => 'date',
'EmailField' => 'email',
'HeaderField' => 'placeholder',
'NumericField' => 'text-number',
'OptionsetField' => 'radio',
'TextField' => 'text',
'TextareaField' => 'textarea',
'EmailField' => 'email',
'HeaderField' => 'placeholder',
'NumericField' => 'text-number',
'OptionsetField' => 'radio',
'TextField' => 'text',
'TextareaField' => 'textarea',
'UserFormsCheckboxSetField' => 'checkbox-group',
'NameField' => 'name',
'AutoSuggestionsField' => 'autosuggest'
'NameField' => 'name',
'AutoSuggestionsField' => 'autosuggest',
);
if(array_key_exists($type, $types)) {
if (array_key_exists($type, $types)) {
return $types[$type];
} else {
return $type;
}
}
}
<?php
class SurveySiteConfigExtension extends DataExtension {
class SurveySiteConfigExtension extends DataExtension
{
private static $db = array(
'SurveyLegalObligations' => 'HTMLText',
'SurveyPrivacyAndConfidentiality' => 'HTMLText'
'SurveyPrivacyAndConfidentiality' => 'HTMLText',
);
public function updateCMSFields(FieldList $fields) {
$fields->addFieldsToTab('Root.Survey', array(
public function updateCMSFields(FieldList $fields)
{
$fields->addFieldsToTab('Root.Survey', array(
HTMLEditorField::create('SurveyLegalObligations')->setRows(5),
HTMLEditorField::create('SurveyPrivacyAndConfidentiality')->setRows(5),
));
}
}
}
<?php
class UserFormGroupedFieldsExtension extends DataExtension {
public function updateCMSFields(FieldList $fields) {
$fieldEditor = $this->getFieldEditorGrid();
class UserFormGroupedFieldsExtension extends DataExtension
{
public function updateCMSFields(FieldList $fields)
{
$fieldEditor = $this->getFieldEditorGrid();
// $fields->insertAfter(new Tab('FormFields', _t('UserFormFieldEditorExtension.FORMFIELDS', 'Form Fields')), 'Main');
$fields->addFieldToTab('Root.FormFields', $fieldEditor);
// $fields->insertAfter(new Tab('FormFields', _t('UserFormFieldEditorExtension.FORMFIELDS', 'Form Fields')), 'Main');
$fields->addFieldToTab('Root.FormFields', $fieldEditor);
return $fields;
}
/**
* Gets the field editor, for adding and removing EditableFormFields.
*
* @return GridField
*/
public function getFieldEditorGrid() {
Requirements::javascript(USERFORMS_DIR . '/javascript/FieldEditor.js');
return $fields;
}
/**
* Gets the field editor, for adding and removing EditableFormFields.
*
* @return GridField
*/
public function getFieldEditorGrid()
{
Requirements::javascript(USERFORMS_DIR.'/javascript/FieldEditor.js');
$fields = $this->owner->Fields();
$fields = $this->owner->Fields();
// $this->createInitialFormStep(true);
//
$editableColumns = new GridFieldEditableColumns();
$fieldClasses = singleton('EditableFormField')->getEditableFieldClasses();
$editableColumns->setDisplayFields(array(
'ClassName' => function($record, $column, $grid) use ($fieldClasses) {
if($record instanceof EditableFormField) {
return $record->getInlineClassnameField($column, $fieldClasses);
}
},
'Title' => function($record, $column, $grid) {
if($record instanceof EditableFormField) {
return $record->getInlineTitleField($column);
}
}
));
// if (Config::inst()->get('UserFormGroupedFieldsExtension', 'showAddGroup')) {
// $addFieldAction = new GridFieldAddNewMultiClass('buttons-before-right');
$addFieldAction = new GridFieldAddNewGroupedFields('buttons-before-right');
$config = GridFieldConfig::create()
->addComponent($addFieldAction);
// }
// $this->createInitialFormStep(true);
//
$editableColumns = new GridFieldEditableColumns();
$fieldClasses = singleton('EditableFormField')->getEditableFieldClasses();
$editableColumns->setDisplayFields(array(
'ClassName' => function ($record, $column, $grid) use ($fieldClasses) {
if ($record instanceof EditableFormField) {
return $record->getInlineClassnameField($column, $fieldClasses);
}
},
'Title' => function ($record, $column, $grid) {
if ($record instanceof EditableFormField) {
return $record->getInlineTitleField($column);
}
},
));
// if (Config::inst()->get('UserFormGroupedFieldsExtension', 'showAddGroup')) {
// $addFieldAction = new GridFieldAddNewMultiClass('buttons-before-right');
$addFieldAction = new GridFieldAddNewGroupedFields('buttons-before-right');
$config = GridFieldConfig::create()
->addComponent($addFieldAction);
// }
$config
->addComponents(
$editableColumns,
new GridFieldButtonRow(),
GridFieldAddClassesButton::create('EditableTextField')
->setButtonName(_t('UserFormFieldEditorExtension.ADD_FIELD', 'Add Field'))
->setButtonClass('ss-ui-action-constructive'),
GridFieldAddClassesButton::create('EditableFormStep')
->setButtonName(_t('UserFormFieldEditorExtension.ADD_PAGE_BREAK', 'Add Page Break')),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldToolbarHeader(),
new GridFieldOrderableRows('Sort'),
new GridFieldDetailForm()
);
$config
->addComponents(
$editableColumns,
new GridFieldButtonRow(),
GridFieldAddClassesButton::create('EditableTextField')
->setButtonName(_t('UserFormFieldEditorExtension.ADD_FIELD', 'Add Field'))
->setButtonClass('ss-ui-action-constructive'),
GridFieldAddClassesButton::create('EditableFormStep')
->setButtonName(_t('UserFormFieldEditorExtension.ADD_PAGE_BREAK', 'Add Page Break')),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldToolbarHeader(),
new GridFieldOrderableRows('Sort'),
new GridFieldDetailForm()
);