mirror of
https://github.com/silverstripe/silverstripe-multiform
synced 2024-10-22 11:05:49 +02:00
FIX ran linter and removed php tags from README
This commit is contained in:
parent
b9c4929fd5
commit
43cc780627
177
README.md
177
README.md
@ -83,7 +83,7 @@ Using [Composer](https://getcomposer.org/), you can install multiform into your
|
||||
SilverStripe site using this command (while in the directory where your site is
|
||||
currently located)
|
||||
|
||||
composer require "silverstripe/multiform:*"
|
||||
`composer require "silverstripe/multiform:*"`
|
||||
|
||||
### 2. Create subclass of MultiForm
|
||||
|
||||
@ -91,13 +91,11 @@ First of all, we need to create a new subclass of *MultiForm*.
|
||||
|
||||
For the above example, our multi-form will be called *SurveyForm*
|
||||
|
||||
:::php
|
||||
<?php
|
||||
|
||||
class SurveyForm extends MultiForm {
|
||||
|
||||
}
|
||||
```php
|
||||
class SurveyForm extends MultiForm {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Set up first step
|
||||
|
||||
@ -111,27 +109,23 @@ form.
|
||||
So, for example, if we were going to have a first step which collects the
|
||||
personal details of the form user, then we might have this class:
|
||||
|
||||
:::php
|
||||
<?php
|
||||
|
||||
class SurveyFormPersonalDetailsStep extends MultiFormStep {
|
||||
|
||||
}
|
||||
```php
|
||||
class SurveyFormPersonalDetailsStep extends MultiFormStep {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
Now that we've got our first step of the form defined, we need to go back to our
|
||||
subclass of MultiForm, SurveyForm, and tell it that SurveyFormPersonalDetailsStep
|
||||
is the first step.
|
||||
|
||||
:::php
|
||||
<?php
|
||||
|
||||
class SurveyForm extends MultiForm {
|
||||
```php
|
||||
class SurveyForm extends MultiForm {
|
||||
|
||||
public static $start_step = 'SurveyFormPersonalDetailsStep';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### 4. Define next step, and final step
|
||||
|
||||
@ -144,10 +138,8 @@ order to use flow control in our system.
|
||||
To let the step know what step is next in the process, we do the same as setting
|
||||
the `$start_step` variable *SurveyForm*, but we call it `$next_steps`.
|
||||
|
||||
:::php
|
||||
<?php
|
||||
|
||||
class SurveyFormPersonalDetailsStep extends MultiFormStep {
|
||||
```php
|
||||
class SurveyFormPersonalDetailsStep extends MultiFormStep {
|
||||
|
||||
public static $next_steps = 'SurveyFormOrganisationDetailsStep';
|
||||
|
||||
@ -158,8 +150,8 @@ the `$start_step` variable *SurveyForm*, but we call it `$next_steps`.
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
At the very least, each step also has to have a `getFields()` method returning
|
||||
a *FieldSet* with some form field objects. These are the fields that the form
|
||||
@ -172,15 +164,13 @@ this is the final step.
|
||||
So, if we assume that the last step in our process is
|
||||
SurveyFormOrganisationDetailsStep, then we can do something like this:
|
||||
|
||||
:::php
|
||||
<?php
|
||||
|
||||
class SurveyFormOrganisationDetailsStep extends MultiFormStep {
|
||||
```php
|
||||
class SurveyFormOrganisationDetailsStep extends MultiFormStep {
|
||||
|
||||
public static $is_final_step = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### 5. Run database integrity check
|
||||
|
||||
@ -197,18 +187,16 @@ that the form can be rendered into a given template.
|
||||
So, if we want to render our multi-form as `$SurveyForm` in the *Page.ss*
|
||||
template, we need to create a SurveyForm method (function) on the controller:
|
||||
|
||||
:::php
|
||||
<?php
|
||||
```php
|
||||
class Page extends SiteTree {
|
||||
|
||||
class Page extends SiteTree {
|
||||
// ...
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
}
|
||||
class Page_Controller extends ContentController {
|
||||
|
||||
class Page_Controller extends ContentController {
|
||||
|
||||
// ...
|
||||
// ...
|
||||
|
||||
//
|
||||
private static $allowed_actions = array(
|
||||
@ -227,10 +215,10 @@ template, we need to create a SurveyForm method (function) on the controller:
|
||||
);
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
}
|
||||
// ...
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
The `SurveyForm()` function will create a new instance our subclass of
|
||||
MultiForm, which in this example, is *SurveyForm*. This in turn will then set
|
||||
@ -242,8 +230,8 @@ like.
|
||||
|
||||
Your template should look something like this, to render the form in:
|
||||
|
||||
:::html
|
||||
<div id="content">
|
||||
```html
|
||||
<div id="content">
|
||||
<% if $Content %>
|
||||
$Content
|
||||
<% end_if %>
|
||||
@ -255,8 +243,8 @@ Your template should look something like this, to render the form in:
|
||||
<% if $Form %>
|
||||
$Form
|
||||
<% end_if %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
```
|
||||
|
||||
In this case, the above template example is a *sub-template* inside the *Layout*
|
||||
directory for the templates. Note that we have also included `$Form`, so
|
||||
@ -281,11 +269,11 @@ To include these with our instance of multiform, we just need to add an
|
||||
|
||||
For example:
|
||||
|
||||
:::html
|
||||
<% with $SurveyForm %>
|
||||
```html
|
||||
<% with $SurveyForm %>
|
||||
<% include MultiFormProgressList %>
|
||||
<% end_with %>
|
||||
|
||||
<% end_with %>
|
||||
```
|
||||
|
||||
This means the included template is rendered within the scope of the
|
||||
SurveyForm instance returned, instead of the top level controller context.
|
||||
@ -293,8 +281,8 @@ This gives us the data to show the progression of the steps.
|
||||
|
||||
Putting it together, we might have something looking like this:
|
||||
|
||||
:::html
|
||||
<div id="content">
|
||||
```html
|
||||
<div id="content">
|
||||
<% if $Content %>
|
||||
$Content
|
||||
<% end_if %>
|
||||
@ -309,8 +297,8 @@ Putting it together, we might have something looking like this:
|
||||
<% if $Form %>
|
||||
$Form
|
||||
<% end_if %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
```
|
||||
|
||||
Feel free to play around with the progress indicators. If you need something
|
||||
specific to your project, just create a new "Include" template inside your own
|
||||
@ -343,11 +331,9 @@ based on the submission value of another step. There are two methods supporting
|
||||
|
||||
Here is an example of how to populate the email address from step 1 in step2 :
|
||||
|
||||
:::php
|
||||
<?php
|
||||
|
||||
class Step1 extends MultiFormStep
|
||||
{
|
||||
```php
|
||||
class Step1 extends MultiFormStep
|
||||
{
|
||||
public static $next_steps = 'Step2';
|
||||
|
||||
public function getFields() {
|
||||
@ -355,10 +341,10 @@ Here is an example of how to populate the email address from step 1 in step2 :
|
||||
new EmailField('Email', 'Your email')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Step2 extends MultiFormStep
|
||||
{
|
||||
class Step2 extends MultiFormStep
|
||||
{
|
||||
public static $next_steps = 'Step3';
|
||||
|
||||
public function getFields() {
|
||||
@ -372,8 +358,8 @@ Here is an example of how to populate the email address from step 1 in step2 :
|
||||
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### 8. Finishing it up
|
||||
|
||||
@ -389,10 +375,8 @@ So, we must write some code on our subclass of *MultiForm*, overloading
|
||||
|
||||
Here is an example of what we could do here:
|
||||
|
||||
:::php
|
||||
<?php
|
||||
|
||||
class SurveyForm extends MultiForm {
|
||||
```php
|
||||
class SurveyForm extends MultiForm {
|
||||
|
||||
public static $start_step = 'SurveyFormPersonalDetailsStep';
|
||||
|
||||
@ -437,8 +421,8 @@ Here is an example of what we could do here:
|
||||
|
||||
$this->controller->redirect($this->controller->Link() . 'finished');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
#### 9. Organisation data model
|
||||
|
||||
@ -449,17 +433,14 @@ groups in SilverStripe) so we need to create it:
|
||||
This example has been chosen as a separate DataObject but you may wish to change
|
||||
the code and add the data to the Member class instead.
|
||||
|
||||
:::php
|
||||
<?php
|
||||
|
||||
class Organisation extends DataObject {
|
||||
```php
|
||||
class Organisation extends DataObject {
|
||||
|
||||
private static $db = array(
|
||||
// Add your Organisation fields here
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
#### Warning
|
||||
|
||||
If you're dealing with sensitive data, it's best to delete the session and step
|
||||
@ -468,9 +449,9 @@ data immediately after the form is successfully submitted.
|
||||
You can delete it by calling this method on the finish() for your MultiForm
|
||||
subclass:
|
||||
|
||||
:::php
|
||||
$this->session->delete();
|
||||
|
||||
```php
|
||||
$this->session->delete();
|
||||
```
|
||||
|
||||
This will also go through each of it's steps and delete them as well.
|
||||
|
||||
@ -517,10 +498,10 @@ be something different based on a user's choice of input during the step, you
|
||||
can override getNextStep() on any given step to manually override what the next
|
||||
step should be. An example:
|
||||
|
||||
:::php
|
||||
class MyStep extends MultiFormStep
|
||||
```php
|
||||
class MyStep extends MultiFormStep
|
||||
|
||||
// ...
|
||||
// ...
|
||||
|
||||
public function getNextStep() {
|
||||
$data = $this->loadData();
|
||||
@ -531,10 +512,10 @@ step should be. An example:
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
}
|
||||
// ...
|
||||
|
||||
}
|
||||
```
|
||||
### Validation
|
||||
|
||||
To define validation on a step-by-step basis, please define getValidator() and
|
||||
@ -543,8 +524,8 @@ validation see [:form](http://doc.silverstripe.org/form-validation).
|
||||
|
||||
e.g.
|
||||
|
||||
:::php
|
||||
class MyStep extends MultiFormStep {
|
||||
```php
|
||||
class MyStep extends MultiFormStep {
|
||||
|
||||
...
|
||||
|
||||
@ -557,8 +538,8 @@ e.g.
|
||||
|
||||
...
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### finish()
|
||||
|
||||
@ -573,10 +554,8 @@ won't be saved.
|
||||
|
||||
For example:
|
||||
|
||||
:::php
|
||||
<?php
|
||||
|
||||
class SurveyForm extends MultiForm {
|
||||
```php
|
||||
class SurveyForm extends MultiForm {
|
||||
|
||||
public static $start_step = 'SurveyFormPersonalDetailsStep';
|
||||
|
||||
@ -594,8 +573,8 @@ For example:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
The above is a sample bit of code that simply fetches all the steps in the
|
||||
database that were saved. Further refinement could include getting steps only
|
||||
@ -613,9 +592,9 @@ idea to immediately delete this data after the user has submitted.
|
||||
This can be easily achieved by adding the following line at the end of your
|
||||
`finish()` method on your MultiForm subclass.
|
||||
|
||||
:::php
|
||||
$this->session->delete();
|
||||
|
||||
```php
|
||||
$this->session->delete();
|
||||
```
|
||||
|
||||
### Expiring old session data
|
||||
|
||||
|
@ -1,2 +1 @@
|
||||
<?php
|
||||
|
||||
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('ar_SA', $lang) && is_array($lang['ar_SA'])) {
|
||||
if (array_key_exists('ar_SA', $lang) && is_array($lang['ar_SA'])) {
|
||||
$lang['ar_SA'] = array_merge($lang['en_US'], $lang['ar_SA']);
|
||||
} else {
|
||||
$lang['ar_SA'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['ar_SA']['MultiFormSession']['singular_name'] = '(لايوجد)';
|
||||
$lang['ar_SA']['MultiFormStep']['db_Data'] = 'بيانات';
|
||||
$lang['ar_SA']['MultiFormStep']['plural_name'] = '(لايوجد)';
|
||||
$lang['ar_SA']['MultiFormStep']['singular_name'] = '(لايوجد)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('bg_BG', $lang) && is_array($lang['bg_BG'])) {
|
||||
if (array_key_exists('bg_BG', $lang) && is_array($lang['bg_BG'])) {
|
||||
$lang['bg_BG'] = array_merge($lang['en_US'], $lang['bg_BG']);
|
||||
} else {
|
||||
$lang['bg_BG'] = $lang['en_US'];
|
||||
@ -23,5 +23,3 @@ $lang['bg_BG']['MultiFormSession']['plural_name'] = '(никакви)';
|
||||
$lang['bg_BG']['MultiFormSession']['singular_name'] = '(никакво)';
|
||||
$lang['bg_BG']['MultiFormStep']['plural_name'] = '(никакви)';
|
||||
$lang['bg_BG']['MultiFormStep']['singular_name'] = '(никакво)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('bs_BA', $lang) && is_array($lang['bs_BA'])) {
|
||||
if (array_key_exists('bs_BA', $lang) && is_array($lang['bs_BA'])) {
|
||||
$lang['bs_BA'] = array_merge($lang['en_US'], $lang['bs_BA']);
|
||||
} else {
|
||||
$lang['bs_BA'] = $lang['en_US'];
|
||||
@ -24,5 +24,3 @@ $lang['bs_BA']['MultiFormSession']['singular_name'] = '(ništa)';
|
||||
$lang['bs_BA']['MultiFormStep']['db_Data'] = 'Podaci';
|
||||
$lang['bs_BA']['MultiFormStep']['plural_name'] = '(ništa)';
|
||||
$lang['bs_BA']['MultiFormStep']['singular_name'] = '(ništa)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('cs_CZ', $lang) && is_array($lang['cs_CZ'])) {
|
||||
if (array_key_exists('cs_CZ', $lang) && is_array($lang['cs_CZ'])) {
|
||||
$lang['cs_CZ'] = array_merge($lang['en_US'], $lang['cs_CZ']);
|
||||
} else {
|
||||
$lang['cs_CZ'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['cs_CZ']['MultiFormSession']['singular_name'] = '(žádný)';
|
||||
$lang['cs_CZ']['MultiFormStep']['db_Data'] = 'Data';
|
||||
$lang['cs_CZ']['MultiFormStep']['plural_name'] = '(žádný)';
|
||||
$lang['cs_CZ']['MultiFormStep']['singular_name'] = '(žádný)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('da_DK', $lang) && is_array($lang['da_DK'])) {
|
||||
if (array_key_exists('da_DK', $lang) && is_array($lang['da_DK'])) {
|
||||
$lang['da_DK'] = array_merge($lang['en_US'], $lang['da_DK']);
|
||||
} else {
|
||||
$lang['da_DK'] = $lang['en_US'];
|
||||
@ -24,5 +24,3 @@ $lang['da_DK']['MultiFormSession']['singular_name'] = '(ingen)';
|
||||
$lang['da_DK']['MultiFormStep']['db_Data'] = 'Data';
|
||||
$lang['da_DK']['MultiFormStep']['plural_name'] = '(ingen)';
|
||||
$lang['da_DK']['MultiFormStep']['singular_name'] = '(none)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('de_DE', $lang) && is_array($lang['de_DE'])) {
|
||||
if (array_key_exists('de_DE', $lang) && is_array($lang['de_DE'])) {
|
||||
$lang['de_DE'] = array_merge($lang['en_US'], $lang['de_DE']);
|
||||
} else {
|
||||
$lang['de_DE'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['de_DE']['MultiFormSession']['singular_name'] = 'Multi-Formular';
|
||||
$lang['de_DE']['MultiFormStep']['db_Data'] = 'Daten';
|
||||
$lang['de_DE']['MultiFormStep']['plural_name'] = 'Multi-Formular-Schritte';
|
||||
$lang['de_DE']['MultiFormStep']['singular_name'] = 'Multi-Formular-Schritt';
|
||||
|
||||
?>
|
@ -25,5 +25,3 @@ $lang['en_US']['MultiFormStep']['SINGULARNAME'] = array(
|
||||
50,
|
||||
'Singular name of the object, used in dropdowns and to generally identify a single object in the interface'
|
||||
);
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('eo_XX', $lang) && is_array($lang['eo_XX'])) {
|
||||
if (array_key_exists('eo_XX', $lang) && is_array($lang['eo_XX'])) {
|
||||
$lang['eo_XX'] = array_merge($lang['en_US'], $lang['eo_XX']);
|
||||
} else {
|
||||
$lang['eo_XX'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['eo_XX']['MultiFormSession']['singular_name'] = '(neniu)';
|
||||
$lang['eo_XX']['MultiFormStep']['db_Data'] = 'Datumoj';
|
||||
$lang['eo_XX']['MultiFormStep']['plural_name'] = '(neniu)';
|
||||
$lang['eo_XX']['MultiFormStep']['singular_name'] = '(neniu)';
|
||||
|
||||
?>
|
@ -10,11 +10,8 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('es_', $lang) && is_array($lang['es_'])) {
|
||||
if (array_key_exists('es_', $lang) && is_array($lang['es_'])) {
|
||||
$lang['es_'] = array_merge($lang['en_US'], $lang['es_']);
|
||||
} else {
|
||||
$lang['es_'] = $lang['en_US'];
|
||||
}
|
||||
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('es_AR', $lang) && is_array($lang['es_AR'])) {
|
||||
if (array_key_exists('es_AR', $lang) && is_array($lang['es_AR'])) {
|
||||
$lang['es_AR'] = array_merge($lang['en_US'], $lang['es_AR']);
|
||||
} else {
|
||||
$lang['es_AR'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['es_AR']['MultiFormSession']['singular_name'] = '(ninguno)';
|
||||
$lang['es_AR']['MultiFormStep']['db_Data'] = 'Datos';
|
||||
$lang['es_AR']['MultiFormStep']['plural_name'] = '(ninguno)';
|
||||
$lang['es_AR']['MultiFormStep']['singular_name'] = '(ninguno)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('es_MX', $lang) && is_array($lang['es_MX'])) {
|
||||
if (array_key_exists('es_MX', $lang) && is_array($lang['es_MX'])) {
|
||||
$lang['es_MX'] = array_merge($lang['en_US'], $lang['es_MX']);
|
||||
} else {
|
||||
$lang['es_MX'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['es_MX']['MultiFormSession']['singular_name'] = '(ningún)';
|
||||
$lang['es_MX']['MultiFormStep']['db_Data'] = 'Datos';
|
||||
$lang['es_MX']['MultiFormStep']['plural_name'] = '(ningunos)';
|
||||
$lang['es_MX']['MultiFormStep']['singular_name'] = '(ningún)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('et_EE', $lang) && is_array($lang['et_EE'])) {
|
||||
if (array_key_exists('et_EE', $lang) && is_array($lang['et_EE'])) {
|
||||
$lang['et_EE'] = array_merge($lang['en_US'], $lang['et_EE']);
|
||||
} else {
|
||||
$lang['et_EE'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['et_EE']['MultiFormSession']['singular_name'] = '(none)';
|
||||
$lang['et_EE']['MultiFormStep']['db_Data'] = 'Andmed';
|
||||
$lang['et_EE']['MultiFormStep']['plural_name'] = '(none)';
|
||||
$lang['et_EE']['MultiFormStep']['singular_name'] = '(none)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('fr_FR', $lang) && is_array($lang['fr_FR'])) {
|
||||
if (array_key_exists('fr_FR', $lang) && is_array($lang['fr_FR'])) {
|
||||
$lang['fr_FR'] = array_merge($lang['en_US'], $lang['fr_FR']);
|
||||
} else {
|
||||
$lang['fr_FR'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['fr_FR']['MultiFormSession']['singular_name'] = '(aucun)';
|
||||
$lang['fr_FR']['MultiFormStep']['db_Data'] = 'Data';
|
||||
$lang['fr_FR']['MultiFormStep']['plural_name'] = '(aucun)';
|
||||
$lang['fr_FR']['MultiFormStep']['singular_name'] = '(aucun)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('id_ID', $lang) && is_array($lang['id_ID'])) {
|
||||
if (array_key_exists('id_ID', $lang) && is_array($lang['id_ID'])) {
|
||||
$lang['id_ID'] = array_merge($lang['en_US'], $lang['id_ID']);
|
||||
} else {
|
||||
$lang['id_ID'] = $lang['en_US'];
|
||||
@ -26,5 +26,3 @@ $lang['id_ID']['MultiFormSession']['singular_name'] = '(tidak ada)';
|
||||
$lang['id_ID']['MultiFormStep']['db_Data'] = 'Data';
|
||||
$lang['id_ID']['MultiFormStep']['plural_name'] = '(tidak ada)';
|
||||
$lang['id_ID']['MultiFormStep']['singular_name'] = '(tidak ada)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('is_IS', $lang) && is_array($lang['is_IS'])) {
|
||||
if (array_key_exists('is_IS', $lang) && is_array($lang['is_IS'])) {
|
||||
$lang['is_IS'] = array_merge($lang['en_US'], $lang['is_IS']);
|
||||
} else {
|
||||
$lang['is_IS'] = $lang['en_US'];
|
||||
@ -21,5 +21,3 @@ $lang['is_IS']['MultiFormSession']['singular_name'] = '(ekkert)';
|
||||
$lang['is_IS']['MultiFormStep']['db_Data'] = 'Gögn';
|
||||
$lang['is_IS']['MultiFormStep']['plural_name'] = '(ekkert)';
|
||||
$lang['is_IS']['MultiFormStep']['singular_name'] = '(ekkert)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('it_IT', $lang) && is_array($lang['it_IT'])) {
|
||||
if (array_key_exists('it_IT', $lang) && is_array($lang['it_IT'])) {
|
||||
$lang['it_IT'] = array_merge($lang['en_US'], $lang['it_IT']);
|
||||
} else {
|
||||
$lang['it_IT'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['it_IT']['MultiFormSession']['singular_name'] = '(nessuno)';
|
||||
$lang['it_IT']['MultiFormStep']['db_Data'] = 'Dati';
|
||||
$lang['it_IT']['MultiFormStep']['plural_name'] = '(nessuno)';
|
||||
$lang['it_IT']['MultiFormStep']['singular_name'] = '(nessuno)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('ja_JP', $lang) && is_array($lang['ja_JP'])) {
|
||||
if (array_key_exists('ja_JP', $lang) && is_array($lang['ja_JP'])) {
|
||||
$lang['ja_JP'] = array_merge($lang['en_US'], $lang['ja_JP']);
|
||||
} else {
|
||||
$lang['ja_JP'] = $lang['en_US'];
|
||||
@ -21,5 +21,3 @@ $lang['ja_JP']['MultiForm']['NEXT'] = '次へ';
|
||||
$lang['ja_JP']['MultiForm']['SUBMIT'] = '送信';
|
||||
$lang['ja_JP']['MultiFormSession']['db_Hash'] = 'ハッシュ';
|
||||
$lang['ja_JP']['MultiFormStep']['db_Data'] = 'データ';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('ms_MY', $lang) && is_array($lang['ms_MY'])) {
|
||||
if (array_key_exists('ms_MY', $lang) && is_array($lang['ms_MY'])) {
|
||||
$lang['ms_MY'] = array_merge($lang['en_US'], $lang['ms_MY']);
|
||||
} else {
|
||||
$lang['ms_MY'] = $lang['en_US'];
|
||||
@ -24,5 +24,3 @@ $lang['ms_MY']['MultiFormSession']['singular_name'] = '(tiada)';
|
||||
$lang['ms_MY']['MultiFormStep']['db_Data'] = 'Data';
|
||||
$lang['ms_MY']['MultiFormStep']['plural_name'] = '(tiada)';
|
||||
$lang['ms_MY']['MultiFormStep']['singular_name'] = '(tiada)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('nb_NO', $lang) && is_array($lang['nb_NO'])) {
|
||||
if (array_key_exists('nb_NO', $lang) && is_array($lang['nb_NO'])) {
|
||||
$lang['nb_NO'] = array_merge($lang['en_US'], $lang['nb_NO']);
|
||||
} else {
|
||||
$lang['nb_NO'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['nb_NO']['MultiFormSession']['singular_name'] = '(ingen)';
|
||||
$lang['nb_NO']['MultiFormStep']['db_Data'] = 'Data';
|
||||
$lang['nb_NO']['MultiFormStep']['plural_name'] = '(ingen)';
|
||||
$lang['nb_NO']['MultiFormStep']['singular_name'] = '(ingen)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('nl_NL', $lang) && is_array($lang['nl_NL'])) {
|
||||
if (array_key_exists('nl_NL', $lang) && is_array($lang['nl_NL'])) {
|
||||
$lang['nl_NL'] = array_merge($lang['en_US'], $lang['nl_NL']);
|
||||
} else {
|
||||
$lang['nl_NL'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['nl_NL']['MultiFormSession']['singular_name'] = '(geen)';
|
||||
$lang['nl_NL']['MultiFormStep']['db_Data'] = 'Data';
|
||||
$lang['nl_NL']['MultiFormStep']['plural_name'] = '(geen)';
|
||||
$lang['nl_NL']['MultiFormStep']['singular_name'] = '(geen)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('pl_PL', $lang) && is_array($lang['pl_PL'])) {
|
||||
if (array_key_exists('pl_PL', $lang) && is_array($lang['pl_PL'])) {
|
||||
$lang['pl_PL'] = array_merge($lang['en_US'], $lang['pl_PL']);
|
||||
} else {
|
||||
$lang['pl_PL'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['pl_PL']['MultiFormSession']['singular_name'] = '(brak)';
|
||||
$lang['pl_PL']['MultiFormStep']['db_Data'] = 'Dane';
|
||||
$lang['pl_PL']['MultiFormStep']['plural_name'] = '(brak)';
|
||||
$lang['pl_PL']['MultiFormStep']['singular_name'] = '(brak)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('pt_PT', $lang) && is_array($lang['pt_PT'])) {
|
||||
if (array_key_exists('pt_PT', $lang) && is_array($lang['pt_PT'])) {
|
||||
$lang['pt_PT'] = array_merge($lang['en_US'], $lang['pt_PT']);
|
||||
} else {
|
||||
$lang['pt_PT'] = $lang['en_US'];
|
||||
@ -23,5 +23,3 @@ $lang['pt_PT']['MultiFormSession']['singular_name'] = '(nenhum)';
|
||||
$lang['pt_PT']['MultiFormStep']['db_Data'] = 'Dados';
|
||||
$lang['pt_PT']['MultiFormStep']['plural_name'] = '(nenhum)';
|
||||
$lang['pt_PT']['MultiFormStep']['singular_name'] = '(nenhum)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('sr_RS', $lang) && is_array($lang['sr_RS'])) {
|
||||
if (array_key_exists('sr_RS', $lang) && is_array($lang['sr_RS'])) {
|
||||
$lang['sr_RS'] = array_merge($lang['en_US'], $lang['sr_RS']);
|
||||
} else {
|
||||
$lang['sr_RS'] = $lang['en_US'];
|
||||
@ -22,5 +22,3 @@ $lang['sr_RS']['MultiFormSession']['singular_name'] = '(без)';
|
||||
$lang['sr_RS']['MultiFormStep']['db_Data'] = 'Подаци';
|
||||
$lang['sr_RS']['MultiFormStep']['plural_name'] = '(без)';
|
||||
$lang['sr_RS']['MultiFormStep']['singular_name'] = '(без)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('sv_SE', $lang) && is_array($lang['sv_SE'])) {
|
||||
if (array_key_exists('sv_SE', $lang) && is_array($lang['sv_SE'])) {
|
||||
$lang['sv_SE'] = array_merge($lang['en_US'], $lang['sv_SE']);
|
||||
} else {
|
||||
$lang['sv_SE'] = $lang['en_US'];
|
||||
@ -24,5 +24,3 @@ $lang['sv_SE']['MultiFormSession']['plural_name'] = '(ingen)';
|
||||
$lang['sv_SE']['MultiFormStep']['db_Data'] = 'Data';
|
||||
$lang['sv_SE']['MultiFormStep']['plural_name'] = '(inga)';
|
||||
$lang['sv_SE']['MultiFormStep']['singular_name'] = '(ingen)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('tr_TR', $lang) && is_array($lang['tr_TR'])) {
|
||||
if (array_key_exists('tr_TR', $lang) && is_array($lang['tr_TR'])) {
|
||||
$lang['tr_TR'] = array_merge($lang['en_US'], $lang['tr_TR']);
|
||||
} else {
|
||||
$lang['tr_TR'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['tr_TR']['MultiFormSession']['singular_name'] = '(hiçbiri)';
|
||||
$lang['tr_TR']['MultiFormStep']['db_Data'] = 'Veri';
|
||||
$lang['tr_TR']['MultiFormStep']['plural_name'] = '(hiçbiri)';
|
||||
$lang['tr_TR']['MultiFormStep']['singular_name'] = '(hiçbiri)';
|
||||
|
||||
?>
|
@ -10,7 +10,7 @@ i18n::include_locale_file('modules: multiform', 'en_US');
|
||||
|
||||
global $lang;
|
||||
|
||||
if(array_key_exists('zh_CN', $lang) && is_array($lang['zh_CN'])) {
|
||||
if (array_key_exists('zh_CN', $lang) && is_array($lang['zh_CN'])) {
|
||||
$lang['zh_CN'] = array_merge($lang['en_US'], $lang['zh_CN']);
|
||||
} else {
|
||||
$lang['zh_CN'] = $lang['en_US'];
|
||||
@ -27,5 +27,3 @@ $lang['zh_CN']['MultiFormSession']['singular_name'] = '单名称';
|
||||
$lang['zh_CN']['MultiFormStep']['db_Data'] = '数据';
|
||||
$lang['zh_CN']['MultiFormStep']['plural_name'] = '多名称';
|
||||
$lang['zh_CN']['MultiFormStep']['singular_name'] = '单名称';
|
||||
|
||||
?>
|
@ -14,7 +14,8 @@
|
||||
*
|
||||
* @package multiform
|
||||
*/
|
||||
class MultiFormObjectDecorator extends DataExtension {
|
||||
class MultiFormObjectDecorator extends DataExtension
|
||||
{
|
||||
|
||||
private static $db = array(
|
||||
'MultiFormIsTemporary' => 'Boolean',
|
||||
@ -28,16 +29,16 @@ class MultiFormObjectDecorator extends DataExtension {
|
||||
* Augment any queries to MultiFormObjectDecorator and only
|
||||
* return anything that isn't considered temporary.
|
||||
*/
|
||||
public function augmentSQL(SQLQuery &$query) {
|
||||
public function augmentSQL(SQLQuery &$query)
|
||||
{
|
||||
$where = $query->getWhere();
|
||||
if(!$where && !$this->wantsTemporary($query)) {
|
||||
if (!$where && !$this->wantsTemporary($query)) {
|
||||
$from = array_values($query->getFrom());
|
||||
$query->addWhere("{$from[0]}.\"MultiFormIsTemporary\" = '0'");
|
||||
return;
|
||||
}
|
||||
|
||||
if(
|
||||
strpos($where[0], ".`ID` = ") === false
|
||||
if (strpos($where[0], ".`ID` = ") === false
|
||||
&& strpos($where[0], ".ID = ") === false
|
||||
&& strpos($where[0], "ID = ") !== 0
|
||||
&& !$this->wantsTemporary($query)
|
||||
@ -55,11 +56,12 @@ class MultiFormObjectDecorator extends DataExtension {
|
||||
* @param SQLQuery $query
|
||||
* @return boolean
|
||||
*/
|
||||
protected function wantsTemporary($query) {
|
||||
foreach($query->getWhere() as $whereClause) {
|
||||
protected function wantsTemporary($query)
|
||||
{
|
||||
foreach ($query->getWhere() as $whereClause) {
|
||||
$from = array_values($query->getFrom());
|
||||
// SQLQuery will automatically add double quotes and single quotes to values, so check against that.
|
||||
if($whereClause == "{$from[0]}.\"MultiFormIsTemporary\" = '1'") {
|
||||
if ($whereClause == "{$from[0]}.\"MultiFormIsTemporary\" = '1'") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,8 @@
|
||||
*
|
||||
* @package multiform
|
||||
*/
|
||||
abstract class MultiForm extends Form {
|
||||
abstract class MultiForm extends Form
|
||||
{
|
||||
|
||||
/**
|
||||
* A session object stored in the database, to identify and store
|
||||
@ -100,7 +101,8 @@ abstract class MultiForm extends Form {
|
||||
* @param Controller instance $controller Controller this form is created on
|
||||
* @param string $name The form name, typically the same as the method name
|
||||
*/
|
||||
public function __construct($controller, $name) {
|
||||
public function __construct($controller, $name)
|
||||
{
|
||||
// First set the controller and name manually so they are available for
|
||||
// field construction.
|
||||
$this->controller = $controller;
|
||||
@ -131,9 +133,9 @@ abstract class MultiForm extends Form {
|
||||
|
||||
$actionNames = static::$actions_exempt_from_validation;
|
||||
|
||||
if($actionNames) {
|
||||
if ($actionNames) {
|
||||
foreach ($actionNames as $exemptAction) {
|
||||
if(!empty($_REQUEST[$exemptAction])) {
|
||||
if (!empty($_REQUEST[$exemptAction])) {
|
||||
$applyValidation = false;
|
||||
break;
|
||||
}
|
||||
@ -141,8 +143,8 @@ abstract class MultiForm extends Form {
|
||||
}
|
||||
|
||||
// Apply validation if the current step requires validation (is not exempt)
|
||||
if($applyValidation) {
|
||||
if($currentStep->getValidator()) {
|
||||
if ($applyValidation) {
|
||||
if ($currentStep->getValidator()) {
|
||||
$validator = $currentStep->getValidator();
|
||||
}
|
||||
}
|
||||
@ -157,7 +159,7 @@ abstract class MultiForm extends Form {
|
||||
|
||||
// If there is saved data for the current step, we load it into the form it here
|
||||
//(CAUTION: loadData() MUST unserialize first!)
|
||||
if($data = $currentStep->loadData()) {
|
||||
if ($data = $currentStep->loadData()) {
|
||||
$this->loadDataFrom($data);
|
||||
}
|
||||
|
||||
@ -172,7 +174,8 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @return Controller this MultiForm was instanciated on.
|
||||
*/
|
||||
public function getController() {
|
||||
public function getController()
|
||||
{
|
||||
return $this->controller;
|
||||
}
|
||||
|
||||
@ -181,7 +184,8 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getGetVar() {
|
||||
public function getGetVar()
|
||||
{
|
||||
return $this->config()->get_var;
|
||||
}
|
||||
|
||||
@ -195,19 +199,22 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @return MultiFormStep subclass
|
||||
*/
|
||||
public function getCurrentStep() {
|
||||
public function getCurrentStep()
|
||||
{
|
||||
$startStepClass = static::$start_step;
|
||||
|
||||
// Check if there was a start step defined on the subclass of MultiForm
|
||||
if(!isset($startStepClass)) 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
|
||||
$currentStep = null;
|
||||
$StepID = $this->controller->request->getVar('StepID');
|
||||
if(isset($StepID)) {
|
||||
if (isset($StepID)) {
|
||||
$currentStep = DataObject::get_one(
|
||||
'MultiFormStep',
|
||||
array(
|
||||
@ -215,12 +222,12 @@ abstract class MultiForm extends Form {
|
||||
'ID' => $StepID
|
||||
)
|
||||
);
|
||||
} elseif($this->session->CurrentStepID) {
|
||||
} elseif ($this->session->CurrentStepID) {
|
||||
$currentStep = $this->session->CurrentStep();
|
||||
}
|
||||
|
||||
// Always fall back to creating a new step (in case the session or request data is invalid)
|
||||
if(!$currentStep || !$currentStep->ID) {
|
||||
if (!$currentStep || !$currentStep->ID) {
|
||||
$currentStep = Object::create($startStepClass);
|
||||
$currentStep->SessionID = $this->session->ID;
|
||||
$currentStep->write();
|
||||
@ -229,7 +236,9 @@ abstract class MultiForm extends Form {
|
||||
$this->session->flushCache();
|
||||
}
|
||||
|
||||
if($currentStep) $currentStep->setForm($this);
|
||||
if ($currentStep) {
|
||||
$currentStep->setForm($this);
|
||||
}
|
||||
|
||||
return $currentStep;
|
||||
}
|
||||
@ -240,7 +249,8 @@ abstract class MultiForm extends Form {
|
||||
* @param MultiFormStep $step A subclass of MultiFormStep
|
||||
* @return boolean The return value of write()
|
||||
*/
|
||||
protected function setCurrentStep($step) {
|
||||
protected function setCurrentStep($step)
|
||||
{
|
||||
$this->session->CurrentStepID = $step->ID;
|
||||
$step->setForm($this);
|
||||
|
||||
@ -252,7 +262,8 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @return MultiFormSession
|
||||
*/
|
||||
public function getSession() {
|
||||
public function getSession()
|
||||
{
|
||||
return $this->session;
|
||||
}
|
||||
|
||||
@ -268,16 +279,17 @@ abstract class MultiForm extends Form {
|
||||
* @TODO Not sure if we should bake the session stuff directly into MultiForm.
|
||||
* Perhaps it would be best dealt with on a separate class?
|
||||
*/
|
||||
protected function setSession() {
|
||||
protected function setSession()
|
||||
{
|
||||
$this->session = $this->getCurrentSession();
|
||||
|
||||
// If there was no session found, create a new one instead
|
||||
if(!$this->session) {
|
||||
if (!$this->session) {
|
||||
$this->session = new MultiFormSession();
|
||||
}
|
||||
|
||||
// Create encrypted identification to the session instance if it doesn't exist
|
||||
if(!$this->session->Hash) {
|
||||
if (!$this->session->Hash) {
|
||||
$this->session->Hash = sha1($this->session->ID . '-' . microtime());
|
||||
$this->session->write();
|
||||
}
|
||||
@ -289,7 +301,8 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @param string $hash Encrypted identification to session
|
||||
*/
|
||||
public function setCurrentSessionHash($hash) {
|
||||
public function setCurrentSessionHash($hash)
|
||||
{
|
||||
$this->currentSessionHash = $hash;
|
||||
$this->setSession();
|
||||
}
|
||||
@ -298,11 +311,12 @@ abstract class MultiForm extends Form {
|
||||
* Return the currently used {@link MultiFormSession}
|
||||
* @return MultiFormSession|boolean FALSE
|
||||
*/
|
||||
public function getCurrentSession() {
|
||||
if(!$this->currentSessionHash) {
|
||||
public function getCurrentSession()
|
||||
{
|
||||
if (!$this->currentSessionHash) {
|
||||
$this->currentSessionHash = $this->controller->request->getVar($this->config()->get_var);
|
||||
|
||||
if(!$this->currentSessionHash) {
|
||||
if (!$this->currentSessionHash) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -324,7 +338,8 @@ abstract class MultiForm extends Form {
|
||||
* @param string $filter SQL WHERE statement
|
||||
* @return DataObjectSet|boolean A set of MultiFormStep subclasses
|
||||
*/
|
||||
public function getSavedSteps($filter = null) {
|
||||
public function getSavedSteps($filter = null)
|
||||
{
|
||||
$filter .= ($filter) ? ' AND ' : '';
|
||||
$filter .= sprintf("\"SessionID\" = '%s'", $this->session->ID);
|
||||
return DataObject::get('MultiFormStep', $filter);
|
||||
@ -338,10 +353,12 @@ abstract class MultiForm extends Form {
|
||||
* @param string $className Classname of a {@link MultiFormStep} subclass
|
||||
* @return MultiFormStep
|
||||
*/
|
||||
public function getSavedStepByClass($className) {
|
||||
public function getSavedStepByClass($className)
|
||||
{
|
||||
return DataObject::get_one(
|
||||
'MultiFormStep',
|
||||
sprintf("\"SessionID\" = '%s' AND \"ClassName\" = '%s'",
|
||||
sprintf(
|
||||
"\"SessionID\" = '%s' AND \"ClassName\" = '%s'",
|
||||
$this->session->ID,
|
||||
Convert::raw2sql($className)
|
||||
)
|
||||
@ -367,22 +384,23 @@ abstract class MultiForm extends Form {
|
||||
* @param $currentStep Subclass of MultiFormStep
|
||||
* @return FieldList of FormAction objects
|
||||
*/
|
||||
public function actionsFor($step) {
|
||||
public function actionsFor($step)
|
||||
{
|
||||
// Create default multi step actions (next, prev), and merge with extra actions, if any
|
||||
$actions = (class_exists('FieldList')) ? new FieldList() : new FieldSet();
|
||||
|
||||
// If the form is at final step, create a submit button to perform final actions
|
||||
// The last step doesn't have a next button, so add that action to any step that isn't the final one
|
||||
if($step->isFinalStep()) {
|
||||
if ($step->isFinalStep()) {
|
||||
$actions->push(new FormAction('finish', $step->getSubmitText()));
|
||||
} else {
|
||||
$actions->push(new FormAction('next', $step->getNextText()));
|
||||
}
|
||||
|
||||
// If there is a previous step defined, add the back button
|
||||
if($step->getPreviousStep() && $step->canGoBack()) {
|
||||
if ($step->getPreviousStep() && $step->canGoBack()) {
|
||||
// If there is a next step, insert the action before the next action
|
||||
if($step->getNextStep()) {
|
||||
if ($step->getNextStep()) {
|
||||
$actions->insertBefore($prev = new FormAction('prev', $step->getPrevText()), 'action_next');
|
||||
// Assume that this is the last step, insert the action before the finish action
|
||||
} else {
|
||||
@ -407,7 +425,8 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @return SSViewer object to render the template with
|
||||
*/
|
||||
public function forTemplate() {
|
||||
public function forTemplate()
|
||||
{
|
||||
$return = $this->renderWith(array(
|
||||
$this->getCurrentStep()->class,
|
||||
'MultiFormStep',
|
||||
@ -430,16 +449,17 @@ abstract class MultiForm extends Form {
|
||||
* @param array $data The request data returned from the form
|
||||
* @param object $form The form that the action was called on
|
||||
*/
|
||||
public function finish($data, $form) {
|
||||
public function finish($data, $form)
|
||||
{
|
||||
// Save the form data for the current step
|
||||
$this->save($data);
|
||||
|
||||
if(!$this->getCurrentStep()->isFinalStep()) {
|
||||
if (!$this->getCurrentStep()->isFinalStep()) {
|
||||
$this->controller->redirectBack();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$this->getCurrentStep()->validateStep($data, $form)) {
|
||||
if (!$this->getCurrentStep()->validateStep($data, $form)) {
|
||||
Session::set("FormInfo.{$form->FormName()}.data", $form->getData());
|
||||
$this->controller->redirectBack();
|
||||
return false;
|
||||
@ -457,14 +477,15 @@ abstract class MultiForm extends Form {
|
||||
* @param array $data The request data returned from the form
|
||||
* @param object $form The form that the action was called on
|
||||
*/
|
||||
public function next($data, $form) {
|
||||
public function next($data, $form)
|
||||
{
|
||||
// Save the form data for the current step
|
||||
$this->save($form->getData());
|
||||
|
||||
// Get the next step class
|
||||
$nextStepClass = $this->getCurrentStep()->getNextStep();
|
||||
|
||||
if(!$nextStepClass) {
|
||||
if (!$nextStepClass) {
|
||||
$this->controller->redirectBack();
|
||||
return false;
|
||||
}
|
||||
@ -472,7 +493,7 @@ abstract class MultiForm extends Form {
|
||||
// Perform custom step validation (use MultiFormStep->getValidator() for
|
||||
// built-in functionality). The data needs to be manually saved on error
|
||||
// so the form is re-populated.
|
||||
if(!$this->getCurrentStep()->validateStep($data, $form)) {
|
||||
if (!$this->getCurrentStep()->validateStep($data, $form)) {
|
||||
Session::set("FormInfo.{$form->FormName()}.data", $form->getData());
|
||||
$this->controller->redirectBack();
|
||||
return false;
|
||||
@ -482,7 +503,7 @@ abstract class MultiForm extends Form {
|
||||
$this->resetValidation();
|
||||
|
||||
// Determine whether we can use a step already in the DB, or have to create a new one
|
||||
if(!$nextStep = DataObject::get_one($nextStepClass, "\"SessionID\" = {$this->session->ID}")) {
|
||||
if (!$nextStep = DataObject::get_one($nextStepClass, "\"SessionID\" = {$this->session->ID}")) {
|
||||
$nextStep = Object::create($nextStepClass);
|
||||
$nextStep->SessionID = $this->session->ID;
|
||||
$nextStep->write();
|
||||
@ -505,14 +526,15 @@ abstract class MultiForm extends Form {
|
||||
* @param array $data The request data returned from the form
|
||||
* @param object $form The form that the action was called on
|
||||
*/
|
||||
public function prev($data, $form) {
|
||||
public function prev($data, $form)
|
||||
{
|
||||
// Save the form data for the current step
|
||||
$this->save($form->getData());
|
||||
|
||||
// Get the previous step class
|
||||
$prevStepClass = $this->getCurrentStep()->getPreviousStep();
|
||||
|
||||
if(!$prevStepClass && !$this->getCurrentStep()->canGoBack()) {
|
||||
if (!$prevStepClass && !$this->getCurrentStep()->canGoBack()) {
|
||||
$this->controller->redirectBack();
|
||||
return false;
|
||||
}
|
||||
@ -536,11 +558,12 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @param array $data An array of data to save
|
||||
*/
|
||||
protected function save($data) {
|
||||
protected function save($data)
|
||||
{
|
||||
$currentStep = $this->getCurrentStep();
|
||||
if(is_array($data)) {
|
||||
foreach($data as $field => $value) {
|
||||
if(in_array($field, static::$ignored_fields)) {
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $field => $value) {
|
||||
if (in_array($field, static::$ignored_fields)) {
|
||||
unset($data[$field]);
|
||||
}
|
||||
}
|
||||
@ -558,7 +581,8 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function FormAction() {
|
||||
public function FormAction()
|
||||
{
|
||||
$action = parent::FormAction();
|
||||
$action .= (strpos($action, '?')) ? '&' : '?';
|
||||
$action .= "{$this->config()->get_var}={$this->session->Hash}";
|
||||
@ -573,7 +597,8 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDisplayLink() {
|
||||
public function getDisplayLink()
|
||||
{
|
||||
return $this->displayLink ? $this->displayLink : Controller::curr()->Link();
|
||||
}
|
||||
|
||||
@ -585,7 +610,8 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @param string $link
|
||||
*/
|
||||
public function setDisplayLink($link) {
|
||||
public function setDisplayLink($link)
|
||||
{
|
||||
$this->displayLink = $link;
|
||||
}
|
||||
|
||||
@ -596,7 +622,8 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @return DataObjectSet of MultiFormStep instances
|
||||
*/
|
||||
public function getAllStepsLinear() {
|
||||
public function getAllStepsLinear()
|
||||
{
|
||||
$stepsFound = (class_exists('ArrayList')) ? new ArrayList() : new DataObjectSet();
|
||||
|
||||
$firstStep = DataObject::get_one(static::$start_step, "\"SessionID\" = {$this->session->ID}");
|
||||
@ -628,25 +655,30 @@ abstract class MultiForm extends Form {
|
||||
* @param $stepsFound $stepsFound DataObjectSet reference, the steps found to call back on
|
||||
* @return DataObjectSet of MultiFormStep instances
|
||||
*/
|
||||
protected function getAllStepsRecursive($step, &$stepsFound) {
|
||||
protected function getAllStepsRecursive($step, &$stepsFound)
|
||||
{
|
||||
// Find the next step to the current step, the final step has no next step
|
||||
if(!$step->isFinalStep()) {
|
||||
if($step->getNextStep()) {
|
||||
if (!$step->isFinalStep()) {
|
||||
if ($step->getNextStep()) {
|
||||
// Is this step in the DB? If it is, we use that
|
||||
$nextStep = $step->getNextStepFromDatabase();
|
||||
if(!$nextStep) {
|
||||
if (!$nextStep) {
|
||||
// If it's not in the DB, we use a singleton instance of it instead -
|
||||
// - this step hasn't been accessed yet
|
||||
$nextStep = singleton($step->getNextStep());
|
||||
}
|
||||
|
||||
// once the current steps has been found we won't add the completed class anymore.
|
||||
if ($nextStep->ID == $this->getCurrentStep()->ID) $this->currentStepHasBeenFound = true;
|
||||
if ($nextStep->ID == $this->getCurrentStep()->ID) {
|
||||
$this->currentStepHasBeenFound = true;
|
||||
}
|
||||
|
||||
$nextStep->LinkingMode = ($nextStep->ID == $this->getCurrentStep()->ID) ? 'current' : 'link';
|
||||
|
||||
// add the completed class
|
||||
if (!$this->currentStepHasBeenFound) $nextStep->addExtraClass('completed');
|
||||
if (!$this->currentStepHasBeenFound) {
|
||||
$nextStep->addExtraClass('completed');
|
||||
}
|
||||
|
||||
$nextStep->setForm($this);
|
||||
|
||||
@ -671,7 +703,8 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCompletedStepCount() {
|
||||
public function getCompletedStepCount()
|
||||
{
|
||||
$steps = DataObject::get('MultiFormStep', "\"SessionID\" = {$this->session->ID} && \"Data\" IS NOT NULL");
|
||||
|
||||
return $steps ? $steps->Count() : 0;
|
||||
@ -684,7 +717,8 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalStepCount() {
|
||||
public function getTotalStepCount()
|
||||
{
|
||||
return $this->getAllStepsLinear() ? $this->getAllStepsLinear()->Count() : 0;
|
||||
}
|
||||
|
||||
@ -693,7 +727,8 @@ abstract class MultiForm extends Form {
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getCompletedPercent() {
|
||||
public function getCompletedPercent()
|
||||
{
|
||||
return (float) $this->getCompletedStepCount() * 100 / $this->getTotalStepCount();
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,8 @@
|
||||
*
|
||||
* @package multiform
|
||||
*/
|
||||
class MultiFormSession extends DataObject {
|
||||
class MultiFormSession extends DataObject
|
||||
{
|
||||
|
||||
private static $db = array(
|
||||
'Hash' => 'Varchar(40)', // cryptographic hash identification to this session
|
||||
@ -32,7 +33,8 @@ class MultiFormSession extends DataObject {
|
||||
* This sets the flag "IsComplete" to true,
|
||||
* and writes the session back.
|
||||
*/
|
||||
public function markCompleted() {
|
||||
public function markCompleted()
|
||||
{
|
||||
$this->IsComplete = 1;
|
||||
$this->write();
|
||||
}
|
||||
@ -40,10 +42,13 @@ class MultiFormSession extends DataObject {
|
||||
/**
|
||||
* 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
|
||||
$currentMember = Member::currentUser();
|
||||
if(!$this->SubmitterID && $currentMember) $this->SubmitterID = $currentMember->ID;
|
||||
if (!$this->SubmitterID && $currentMember) {
|
||||
$this->SubmitterID = $currentMember->ID;
|
||||
}
|
||||
|
||||
parent::onBeforeWrite();
|
||||
}
|
||||
@ -51,18 +56,20 @@ class MultiFormSession extends DataObject {
|
||||
/**
|
||||
* These actions are performed when delete() is called on this object.
|
||||
*/
|
||||
public function onBeforeDelete() {
|
||||
public function onBeforeDelete()
|
||||
{
|
||||
// delete dependent form steps and relation
|
||||
$steps = $this->FormSteps();
|
||||
if($steps) foreach($steps as $step) {
|
||||
if($step && $step->exists()) {
|
||||
if ($steps) {
|
||||
foreach ($steps as $step) {
|
||||
if ($step && $step->exists()) {
|
||||
$steps->remove($step);
|
||||
$step->delete();
|
||||
$step->destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parent::onBeforeDelete();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,8 @@
|
||||
*
|
||||
* @package multiform
|
||||
*/
|
||||
class MultiFormStep extends DataObject {
|
||||
class MultiFormStep extends DataObject
|
||||
{
|
||||
|
||||
private static $db = array(
|
||||
'Data' => 'Text' // stores serialized maps with all session information
|
||||
@ -95,7 +96,8 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getFields() {
|
||||
public function getFields()
|
||||
{
|
||||
user_error('Please implement getFields on your MultiFormStep subclass', E_USER_ERROR);
|
||||
}
|
||||
|
||||
@ -108,7 +110,8 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getExtraActions() {
|
||||
public function getExtraActions()
|
||||
{
|
||||
return (class_exists('FieldList')) ? new FieldList() : new FieldSet();
|
||||
}
|
||||
|
||||
@ -118,7 +121,8 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return Validator
|
||||
*/
|
||||
public function getValidator() {
|
||||
public function getValidator()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -127,7 +131,8 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return string Title of this step
|
||||
*/
|
||||
public function getTitle() {
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title ? $this->title : $this->class;
|
||||
}
|
||||
|
||||
@ -139,7 +144,8 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return string Relative URL to this step
|
||||
*/
|
||||
public function Link() {
|
||||
public function Link()
|
||||
{
|
||||
$form = $this->form;
|
||||
return Controller::join_links($form->getDisplayLink(), "?{$form->config()->get_var}={$this->Session()->Hash}");
|
||||
}
|
||||
@ -156,7 +162,8 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function loadData() {
|
||||
public function loadData()
|
||||
{
|
||||
return ($this->Data && is_string($this->Data)) ? unserialize($this->Data) : array();
|
||||
}
|
||||
|
||||
@ -168,7 +175,8 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @param array $data The processed data from save() on {@link MultiForm}
|
||||
*/
|
||||
public function saveData($data) {
|
||||
public function saveData($data)
|
||||
{
|
||||
$this->Data = serialize($data);
|
||||
$this->write();
|
||||
}
|
||||
@ -184,7 +192,8 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @param DataObject $obj
|
||||
*/
|
||||
public function saveInto($obj) {
|
||||
public function saveInto($obj)
|
||||
{
|
||||
$form = new Form(
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
@ -209,7 +218,8 @@ class MultiFormStep extends DataObject {
|
||||
* @param Form $form
|
||||
* @return boolean Validation success
|
||||
*/
|
||||
public function validateStep($data, $form) {
|
||||
public function validateStep($data, $form)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -218,17 +228,20 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return string Classname of a {@link MultiFormStep} subclass
|
||||
*/
|
||||
public function getNextStep() {
|
||||
public function getNextStep()
|
||||
{
|
||||
$nextSteps = static::$next_steps;
|
||||
|
||||
// Check if next_steps have been implemented properly if not the final step
|
||||
if(!$this->isFinalStep()) {
|
||||
if(!isset($nextSteps)) user_error('MultiFormStep->getNextStep(): Please define at least one $next_steps on ' . $this->class, E_USER_ERROR);
|
||||
if (!$this->isFinalStep()) {
|
||||
if (!isset($nextSteps)) {
|
||||
user_error('MultiFormStep->getNextStep(): Please define at least one $next_steps on ' . $this->class, E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if(is_string($nextSteps)) {
|
||||
if (is_string($nextSteps)) {
|
||||
return $nextSteps;
|
||||
} elseif(is_array($nextSteps) && count($nextSteps)) {
|
||||
} elseif (is_array($nextSteps) && count($nextSteps)) {
|
||||
// custom flow control goes here
|
||||
return $nextSteps[0];
|
||||
} else {
|
||||
@ -244,13 +257,14 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return MultiFormStep|boolean
|
||||
*/
|
||||
public function getNextStepFromDatabase() {
|
||||
if($this->SessionID && is_numeric($this->SessionID)) {
|
||||
public function getNextStepFromDatabase()
|
||||
{
|
||||
if ($this->SessionID && is_numeric($this->SessionID)) {
|
||||
$nextSteps = static::$next_steps;
|
||||
|
||||
if(is_string($nextSteps)) {
|
||||
if (is_string($nextSteps)) {
|
||||
return DataObject::get_one($nextSteps, "\"SessionID\" = {$this->SessionID}");
|
||||
} elseif(is_array($nextSteps)) {
|
||||
} elseif (is_array($nextSteps)) {
|
||||
return DataObject::get_one($nextSteps[0], "\"SessionID\" = {$this->SessionID}");
|
||||
} else {
|
||||
return false;
|
||||
@ -263,7 +277,8 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function getNextSteps() {
|
||||
public function getNextSteps()
|
||||
{
|
||||
return static::$next_steps;
|
||||
}
|
||||
|
||||
@ -275,14 +290,15 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return string Classname of a {@link MultiFormStep} subclass
|
||||
*/
|
||||
public function getPreviousStep() {
|
||||
public function getPreviousStep()
|
||||
{
|
||||
$steps = DataObject::get('MultiFormStep', "\"SessionID\" = {$this->SessionID}", '"LastEdited" DESC');
|
||||
if($steps) {
|
||||
foreach($steps as $step) {
|
||||
if ($steps) {
|
||||
foreach ($steps as $step) {
|
||||
$step->setForm($this->form);
|
||||
|
||||
if($step->getNextStep()) {
|
||||
if($step->getNextStep() == $this->class) {
|
||||
if ($step->getNextStep()) {
|
||||
if ($step->getNextStep() == $this->class) {
|
||||
return $step->class;
|
||||
}
|
||||
}
|
||||
@ -297,8 +313,9 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return MultiFormStep subclass
|
||||
*/
|
||||
public function getPreviousStepFromDatabase() {
|
||||
if($prevStepClass = $this->getPreviousStep()) {
|
||||
public function getPreviousStepFromDatabase()
|
||||
{
|
||||
if ($prevStepClass = $this->getPreviousStep()) {
|
||||
return DataObject::get_one($prevStepClass, "\"SessionID\" = {$this->SessionID}");
|
||||
}
|
||||
}
|
||||
@ -307,7 +324,8 @@ class MultiFormStep extends DataObject {
|
||||
* Get the text to the use on the button to the previous step.
|
||||
* @return string
|
||||
*/
|
||||
public function getPrevText() {
|
||||
public function getPrevText()
|
||||
{
|
||||
return _t('MultiForm.BACK', 'Back');
|
||||
}
|
||||
|
||||
@ -315,7 +333,8 @@ class MultiFormStep extends DataObject {
|
||||
* Get the text to use on the button to the next step.
|
||||
* @return string
|
||||
*/
|
||||
public function getNextText() {
|
||||
public function getNextText()
|
||||
{
|
||||
return _t('MultiForm.NEXT', 'Next');
|
||||
}
|
||||
|
||||
@ -323,7 +342,8 @@ class MultiFormStep extends DataObject {
|
||||
* Get the text to use on the button to submit the form.
|
||||
* @return string
|
||||
*/
|
||||
public function getSubmitText() {
|
||||
public function getSubmitText()
|
||||
{
|
||||
return _t('MultiForm.SUBMIT', 'Submit');
|
||||
}
|
||||
|
||||
@ -332,14 +352,16 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @param MultiForm subclass $form
|
||||
*/
|
||||
public function setForm($form) {
|
||||
public function setForm($form)
|
||||
{
|
||||
$this->form = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Form
|
||||
*/
|
||||
public function getForm() {
|
||||
public function getForm()
|
||||
{
|
||||
return $this->form;
|
||||
}
|
||||
|
||||
@ -353,7 +375,8 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canGoBack() {
|
||||
public function canGoBack()
|
||||
{
|
||||
return static::$can_go_back;
|
||||
}
|
||||
|
||||
@ -363,7 +386,8 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isFinalStep() {
|
||||
public function isFinalStep()
|
||||
{
|
||||
return static::$is_final_step;
|
||||
}
|
||||
|
||||
@ -375,7 +399,8 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isCurrentStep() {
|
||||
public function isCurrentStep()
|
||||
{
|
||||
return ($this->class == $this->Session()->CurrentStep()->class) ? true : false;
|
||||
}
|
||||
|
||||
@ -385,10 +410,11 @@ class MultiFormStep extends DataObject {
|
||||
* @param string $class A string containing a classname or several class names delimited by a space.
|
||||
* @return MultiFormStep
|
||||
*/
|
||||
public function addExtraClass($class) {
|
||||
public function addExtraClass($class)
|
||||
{
|
||||
// split at white space
|
||||
$classes = preg_split('/\s+/', $class);
|
||||
foreach($classes as $class) {
|
||||
foreach ($classes as $class) {
|
||||
// add classes one by one
|
||||
$this->extraClasses[$class] = $class;
|
||||
}
|
||||
@ -401,7 +427,8 @@ class MultiFormStep extends DataObject {
|
||||
* @param string $class
|
||||
* @return MultiFormStep
|
||||
*/
|
||||
public function removeExtraClass($class) {
|
||||
public function removeExtraClass($class)
|
||||
{
|
||||
// split at white space
|
||||
$classes = preg_split('/\s+/', $class);
|
||||
foreach ($classes as $class) {
|
||||
@ -414,7 +441,8 @@ class MultiFormStep extends DataObject {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getExtraClasses() {
|
||||
public function getExtraClasses()
|
||||
{
|
||||
return join(' ', array_keys($this->extraClasses));
|
||||
}
|
||||
|
||||
@ -426,21 +454,22 @@ class MultiFormStep extends DataObject {
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValueFromOtherStep($fromStep, $key) {
|
||||
public function getValueFromOtherStep($fromStep, $key)
|
||||
{
|
||||
// load the steps in the cache, if this one doesn't exist
|
||||
if (!array_key_exists('steps_' . $fromStep, $this->step_data_cache)) {
|
||||
$steps = MultiFormStep::get()->filter('SessionID', $this->form->session->ID);
|
||||
|
||||
if($steps) {
|
||||
foreach($steps as $step) {
|
||||
if ($steps) {
|
||||
foreach ($steps as $step) {
|
||||
$this->step_data_cache['steps_' . $step->ClassName] = $step->loadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check both as PHP isn't recursive
|
||||
if(isset($this->step_data_cache['steps_' . $fromStep])) {
|
||||
if(isset($this->step_data_cache['steps_' . $fromStep][$key])) {
|
||||
if (isset($this->step_data_cache['steps_' . $fromStep])) {
|
||||
if (isset($this->step_data_cache['steps_' . $fromStep][$key])) {
|
||||
return $this->step_data_cache['steps_' . $fromStep][$key];
|
||||
}
|
||||
}
|
||||
@ -456,9 +485,12 @@ class MultiFormStep extends DataObject {
|
||||
* @param string $fieldName
|
||||
* @param string $fieldNameTarget (optional)
|
||||
*/
|
||||
public function copyValueFromOtherStep(FieldList $fields, $formStep, $fieldName, $fieldNameTarget = null) {
|
||||
public function copyValueFromOtherStep(FieldList $fields, $formStep, $fieldName, $fieldNameTarget = null)
|
||||
{
|
||||
// if a target field isn't defined use the same fieldname
|
||||
if (!$fieldNameTarget) $fieldNameTarget = $fieldName;
|
||||
if (!$fieldNameTarget) {
|
||||
$fieldNameTarget = $fieldName;
|
||||
}
|
||||
|
||||
$fields->fieldByName($fieldNameTarget)->setValue($this->getValueFromOtherStep($formStep, $fieldName));
|
||||
}
|
||||
|
@ -12,7 +12,8 @@
|
||||
*
|
||||
* @package multiform
|
||||
*/
|
||||
class MultiFormPurgeTask extends BuildTask {
|
||||
class MultiFormPurgeTask extends BuildTask
|
||||
{
|
||||
|
||||
/**
|
||||
* Days after which sessions expire and
|
||||
@ -29,13 +30,16 @@ class MultiFormPurgeTask extends BuildTask {
|
||||
* are older than the days specified in $session_expiry_days
|
||||
* and delete them.
|
||||
*/
|
||||
public function run($request) {
|
||||
public function run($request)
|
||||
{
|
||||
$sessions = $this->getExpiredSessions();
|
||||
$delCount = 0;
|
||||
if($sessions) foreach($sessions as $session) {
|
||||
if ($sessions) {
|
||||
foreach ($sessions as $session) {
|
||||
$session->delete();
|
||||
$delCount++;
|
||||
}
|
||||
}
|
||||
echo $delCount . ' session records deleted that were older than ' . self::$session_expiry_days . ' days.';
|
||||
}
|
||||
|
||||
@ -45,11 +49,11 @@ class MultiFormPurgeTask extends BuildTask {
|
||||
*
|
||||
* @return DataObjectSet
|
||||
*/
|
||||
protected function getExpiredSessions() {
|
||||
protected function getExpiredSessions()
|
||||
{
|
||||
return DataObject::get(
|
||||
'MultiFormSession',
|
||||
"DATEDIFF(NOW(), \"MultiFormSession\".\"Created\") > " . self::$session_expiry_days
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
class MultiFormObjectDecoratorTest extends SapphireTest {
|
||||
class MultiFormObjectDecoratorTest extends SapphireTest
|
||||
{
|
||||
|
||||
protected static $fixture_file = 'MultiFormObjectDecoratorTest.yml';
|
||||
|
||||
@ -11,7 +12,8 @@ class MultiFormObjectDecoratorTest extends SapphireTest {
|
||||
'MultiFormObjectDecorator_DataObject'
|
||||
);
|
||||
|
||||
public function testTemporaryDataFilteredQuery() {
|
||||
public function testTemporaryDataFilteredQuery()
|
||||
{
|
||||
$records = MultiFormObjectDecorator_DataObject::get()
|
||||
->map('Name')
|
||||
->toArray();
|
||||
@ -19,10 +21,10 @@ class MultiFormObjectDecoratorTest extends SapphireTest {
|
||||
$this->assertContains('Test 1', $records);
|
||||
$this->assertContains('Test 2', $records);
|
||||
$this->assertNotContains('Test 3', $records);
|
||||
|
||||
}
|
||||
|
||||
public function testTemporaryDataQuery() {
|
||||
public function testTemporaryDataQuery()
|
||||
{
|
||||
$records = MultiFormObjectDecorator_DataObject::get()
|
||||
->filter(array('MultiFormIsTemporary' => 1))
|
||||
->map('Name')
|
||||
@ -32,13 +34,12 @@ class MultiFormObjectDecoratorTest extends SapphireTest {
|
||||
$this->assertNotContains('Test 2', $records);
|
||||
$this->assertContains('Test 3', $records);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MultiFormObjectDecorator_DataObject extends DataObject {
|
||||
class MultiFormObjectDecorator_DataObject extends DataObject
|
||||
{
|
||||
|
||||
private static $db = array(
|
||||
'Name' => 'Varchar'
|
||||
);
|
||||
|
||||
}
|
||||
|
@ -17,30 +17,35 @@
|
||||
* @package multiform
|
||||
* @subpackage tests
|
||||
*/
|
||||
class MultiFormTest extends FunctionalTest {
|
||||
class MultiFormTest extends FunctionalTest
|
||||
{
|
||||
|
||||
public static $fixture_file = 'multiform/tests/MultiFormTest.yml';
|
||||
|
||||
protected $controller;
|
||||
|
||||
public function setUp() {
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new MultiFormTest_Controller();
|
||||
$this->form = $this->controller->Form();
|
||||
}
|
||||
|
||||
public function testInitialisingForm() {
|
||||
public function testInitialisingForm()
|
||||
{
|
||||
$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->assertEquals('MultiFormTest_StepOne', $this->form->getStartStep());
|
||||
}
|
||||
|
||||
public function testSessionGeneration() {
|
||||
public function testSessionGeneration()
|
||||
{
|
||||
$this->assertTrue($this->form->session->ID > 0);
|
||||
}
|
||||
|
||||
public function testMemberLogging() {
|
||||
public function testMemberLogging()
|
||||
{
|
||||
// Grab any user to fake being logged in as, and ensure that after a session is written it has
|
||||
// that user as the submitter.
|
||||
$userId = Member::get_one("Member")->ID;
|
||||
@ -52,34 +57,40 @@ class MultiFormTest extends FunctionalTest {
|
||||
$this->assertEquals($userId, $session->SubmitterID);
|
||||
}
|
||||
|
||||
public function testSecondStep() {
|
||||
public function testSecondStep()
|
||||
{
|
||||
$this->assertEquals('MultiFormTest_StepTwo', $this->form->getCurrentStep()->getNextStep());
|
||||
}
|
||||
|
||||
public function testParentForm() {
|
||||
public function testParentForm()
|
||||
{
|
||||
$currentStep = $this->form->getCurrentStep();
|
||||
$this->assertEquals($currentStep->getForm()->class, $this->form->class);
|
||||
}
|
||||
|
||||
public function testTotalStepCount() {
|
||||
public function testTotalStepCount()
|
||||
{
|
||||
$this->assertEquals(3, $this->form->getAllStepsLinear()->Count());
|
||||
}
|
||||
|
||||
public function testCompletedSession() {
|
||||
public function testCompletedSession()
|
||||
{
|
||||
$this->form->setCurrentSessionHash($this->form->session->Hash);
|
||||
$this->assertInstanceOf('MultiFormSession', $this->form->getCurrentSession());
|
||||
$this->form->session->markCompleted();
|
||||
$this->assertNull($this->form->getCurrentSession());
|
||||
}
|
||||
|
||||
public function testIncorrectSessionIdentifier() {
|
||||
public function testIncorrectSessionIdentifier()
|
||||
{
|
||||
$this->form->setCurrentSessionHash('sdfsdf3432325325sfsdfdf'); // made up!
|
||||
|
||||
// A new session is generated, even though we made up the identifier
|
||||
$this->assertInstanceOf('MultiFormSession', $this->form->session);
|
||||
}
|
||||
|
||||
function testCustomGetVar() {
|
||||
function testCustomGetVar()
|
||||
{
|
||||
Config::nest();
|
||||
Config::inst()->update('MultiForm', 'get_var', 'SuperSessionID');
|
||||
|
||||
@ -91,21 +102,23 @@ class MultiFormTest extends FunctionalTest {
|
||||
session ID parameter");
|
||||
|
||||
Config::unnest();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package multiform
|
||||
* @subpackage tests
|
||||
*/
|
||||
class MultiFormTest_Controller extends Controller implements TestOnly {
|
||||
class MultiFormTest_Controller extends Controller implements TestOnly
|
||||
{
|
||||
|
||||
public function Link() {
|
||||
public function Link()
|
||||
{
|
||||
return 'MultiFormTest_Controller';
|
||||
}
|
||||
|
||||
public function Form($request = null) {
|
||||
public function Form($request = null)
|
||||
{
|
||||
$form = new MultiFormTest_Form($this, 'Form');
|
||||
$form->setHTMLID('MultiFormTest_Form');
|
||||
return $form;
|
||||
@ -116,25 +129,28 @@ class MultiFormTest_Controller extends Controller implements TestOnly {
|
||||
* @package multiform
|
||||
* @subpackage tests
|
||||
*/
|
||||
class MultiFormTest_Form extends MultiForm implements TestOnly {
|
||||
class MultiFormTest_Form extends MultiForm implements TestOnly
|
||||
{
|
||||
|
||||
public static $start_step = 'MultiFormTest_StepOne';
|
||||
|
||||
public function getStartStep() {
|
||||
public function getStartStep()
|
||||
{
|
||||
return self::$start_step;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package multiform
|
||||
* @subpackage tests
|
||||
*/
|
||||
class MultiFormTest_StepOne extends MultiFormStep implements TestOnly {
|
||||
class MultiFormTest_StepOne extends MultiFormStep implements TestOnly
|
||||
{
|
||||
|
||||
public static $next_steps = 'MultiFormTest_StepTwo';
|
||||
|
||||
public function getFields() {
|
||||
public function getFields()
|
||||
{
|
||||
$class = (class_exists('FieldList')) ? 'FieldList' : 'FieldSet';
|
||||
return new $class(
|
||||
new TextField('FirstName', 'First name'),
|
||||
@ -148,11 +164,13 @@ class MultiFormTest_StepOne extends MultiFormStep implements TestOnly {
|
||||
* @package multiform
|
||||
* @subpackage tests
|
||||
*/
|
||||
class MultiFormTest_StepTwo extends MultiFormStep implements TestOnly {
|
||||
class MultiFormTest_StepTwo extends MultiFormStep implements TestOnly
|
||||
{
|
||||
|
||||
public static $next_steps = 'MultiFormTest_StepThree';
|
||||
|
||||
public function getFields() {
|
||||
public function getFields()
|
||||
{
|
||||
$class = (class_exists('FieldList')) ? 'FieldList' : 'FieldSet';
|
||||
return new $class(
|
||||
new TextareaField('Comments', 'Tell us a bit about yourself...')
|
||||
@ -164,15 +182,16 @@ class MultiFormTest_StepTwo extends MultiFormStep implements TestOnly {
|
||||
* @package multiform
|
||||
* @subpackage tests
|
||||
*/
|
||||
class MultiFormTest_StepThree extends MultiFormStep implements TestOnly {
|
||||
class MultiFormTest_StepThree extends MultiFormStep implements TestOnly
|
||||
{
|
||||
|
||||
public static $is_final_step = true;
|
||||
|
||||
public function getFields() {
|
||||
public function getFields()
|
||||
{
|
||||
$class = (class_exists('FieldList')) ? 'FieldList' : 'FieldSet';
|
||||
return new $class(
|
||||
new TextField('Test', 'Anything else you\'d like to tell us?')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user