Completed
Pull Request — master (#518)
by Sam
34:41
created

UserDefinedForm::requireDefaultRecords()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 0
1
<?php
2
3
use SilverStripe\View\Requirements;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Requirements.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
use SilverStripe\Forms\LabelField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, LabelField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
5
use SilverStripe\Forms\CompositeField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, CompositeField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldConfig_RecordEditor.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use SilverStripe\Forms\GridField\GridField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use SilverStripe\ORM\DB;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, DB.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
use SilverStripe\Forms\GridField\GridFieldConfig;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldConfig.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldToolbarHeader.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
11
use SilverStripe\Forms\GridField\GridFieldSortableHeader;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldSortableHeader.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
12
use SilverStripe\Forms\GridField\GridFieldDataColumns;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldDataColumns.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
13
use SilverStripe\Forms\GridField\GridFieldEditButton;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldEditButton.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
14
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldDeleteAction.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
use SilverStripe\Forms\GridField\GridFieldPageCount;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldPageCount.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
16
use SilverStripe\Forms\GridField\GridFieldPaginator;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldPaginator.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
17
use SilverStripe\Forms\GridField\GridFieldDetailForm;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldDetailForm.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
18
use SilverStripe\Forms\GridField\GridFieldButtonRow;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldButtonRow.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
19
use SilverStripe\Forms\GridField\GridFieldExportButton;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldExportButton.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
20
use SilverStripe\Forms\GridField\GridFieldPrintButton;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, GridFieldPrintButton.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
21
use SilverStripe\Forms\CheckboxField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, CheckboxField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
22
use SilverStripe\Forms\LiteralField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, LiteralField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
23
use SilverStripe\ORM\ArrayList;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ArrayList.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
24
use SilverStripe\Forms\TextField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, TextField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
25
use SilverStripe\Forms\FieldList;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, FieldList.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
26
use SilverStripe\Core\Injector\Injector;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Injector.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
27
use SilverStripe\i18n\i18n;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, i18n.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
28
use SilverStripe\ORM\FieldType\DBField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, DBField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
29
use SilverStripe\Core\Object;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Object.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
30
use SilverStripe\Security\Member;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Member.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
31
use SilverStripe\Assets\Upload;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Upload.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
32
use SilverStripe\Assets\File;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, File.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
33
use SilverStripe\Control\Controller;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Controller.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
34
use SilverStripe\ORM\ValidationException;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ValidationException.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
35
use SilverStripe\Control\HTTP;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, HTTP.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
36
use SilverStripe\View\SSViewer;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, SSViewer.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
37
use SilverStripe\Control\Session;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Session.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
38
use SilverStripe\View\ArrayData;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ArrayData.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
39
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, HTMLEditorField.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
40
41
42
/**
43
 * @package userforms
44
 */
45
46
class UserDefinedForm extends Page
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
47
{
48
    
49
    /**
50
     * @var string
51
     */
52
    private static $icon = 'userforms/images/sitetree_icon.png';
0 ignored issues
show
Unused Code introduced by
The property $icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
53
54
    /**
55
     * @var string
56
     */
57
    private static $description = 'Adds a customizable form.';
0 ignored issues
show
Unused Code introduced by
The property $description is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
58
59
    /**
60
     * @var string Required Identifier
61
     */
62
    private static $required_identifier = null;
0 ignored issues
show
Unused Code introduced by
The property $required_identifier is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
63
64
    /**
65
     * @var string
66
     */
67
    private static $email_template_directory = 'userforms/templates/email/';
0 ignored issues
show
Unused Code introduced by
The property $email_template_directory is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
68
69
    /**
70
     * Should this module automatically upgrade on dev/build?
71
     *
72
     * @config
73
     * @var bool
74
     */
75
    private static $upgrade_on_build = true;
0 ignored issues
show
Unused Code introduced by
The property $upgrade_on_build is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
76
77
    /**
78
     * Built in extensions required by this page
79
     * @config
80
     * @var array
81
     */
82
    private static $extensions = array(
0 ignored issues
show
Unused Code introduced by
The property $extensions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
83
        'UserFormFieldEditorExtension'
84
    );
85
86
    /**
87
     * @var array Fields on the user defined form page.
88
     */
89
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
90
        "SubmitButtonText" => "Varchar",
91
        "ClearButtonText" => "Varchar",
92
        "OnCompleteMessage" => "HTMLText",
93
        "ShowClearButton" => "Boolean",
94
        'DisableSaveSubmissions' => 'Boolean',
95
        'EnableLiveValidation' => 'Boolean',
96
        'HideFieldLabels' => 'Boolean',
97
        'DisplayErrorMessagesAtTop' => 'Boolean',
98
        'DisableAuthenicatedFinishAction' => 'Boolean',
99
        'DisableCsrfSecurityToken' => 'Boolean'
100
    );
101
102
    /**
103
     * @var array Default values of variables when this page is created
104
     */
105
    private static $defaults = array(
0 ignored issues
show
Unused Code introduced by
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
106
        'Content' => '$UserDefinedForm',
107
        'DisableSaveSubmissions' => 0,
108
        'OnCompleteMessage' => '<p>Thanks, we\'ve received your submission.</p>'
109
    );
110
111
    /**
112
     * @var array
113
     */
114
    private static $has_many = array(
0 ignored issues
show
Unused Code introduced by
The property $has_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
115
        "Submissions" => "SubmittedForm",
116
        "EmailRecipients" => "UserDefinedForm_EmailRecipient"
117
    );
118
119
    /**
120
     * @var array
121
     * @config
122
     */
123
    private static $casting = array(
0 ignored issues
show
Unused Code introduced by
The property $casting is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
124
        'ErrorContainerID' => 'Text'
125
    );
126
127
    /**
128
     * Error container selector which matches the element for grouped messages
129
     *
130
     * @var string
131
     * @config
132
     */
133
    private static $error_container_id = 'error-container';
0 ignored issues
show
Unused Code introduced by
The property $error_container_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
134
135
    /**
136
     * The configuration used to determine whether a confirmation message is to
137
     * appear when navigating away from a partially completed form.
138
     *
139
     * @var boolean
140
     * @config
141
     */
142
    private static $enable_are_you_sure = true;
0 ignored issues
show
Unused Code introduced by
The property $enable_are_you_sure is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
143
144
    /**
145
     * @var bool
146
     * @config
147
     */
148
    private static $recipients_warning_enabled = false;
0 ignored issues
show
Unused Code introduced by
The property $recipients_warning_enabled is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
149
150
    /**
151
     * Temporary storage of field ids when the form is duplicated.
152
     * Example layout: array('EditableCheckbox3' => 'EditableCheckbox14')
153
     * @var array
154
     */
155
    protected $fieldsFromTo = array();
156
157
    /**
158
     * @return FieldList
159
     */
160
     public function getCMSFields()
161
     {
162
         Requirements::css(USERFORMS_DIR . '/css/UserForm_cms.css');
163
164
         $self = $this;
165
166
         $this->beforeUpdateCMSFields(function ($fields) use ($self) {
167
168
            // define tabs
169
            $fields->findOrMakeTab('Root.FormOptions', _t('UserDefinedForm.CONFIGURATION', 'Configuration'));
170
            $fields->findOrMakeTab('Root.Recipients', _t('UserDefinedForm.RECIPIENTS', 'Recipients'));
171
            $fields->findOrMakeTab('Root.Submissions', _t('UserDefinedForm.SUBMISSIONS', 'Submissions'));
172
173
            // text to show on complete
174
            $onCompleteFieldSet = new CompositeField(
175
                $label = new LabelField('OnCompleteMessageLabel', _t('UserDefinedForm.ONCOMPLETELABEL', 'Show on completion')),
176
                $editor = new HtmlEditorField('OnCompleteMessage', '', _t('UserDefinedForm.ONCOMPLETEMESSAGE', $self->OnCompleteMessage))
177
            );
178
179
            $onCompleteFieldSet->addExtraClass('field');
180
181
            $editor->setRows(3);
182
            $label->addExtraClass('left');
183
184
            // Define config for email recipients
185
            $emailRecipientsConfig = GridFieldConfig_RecordEditor::create(10);
186
            $emailRecipientsConfig->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldAddNewButton')
187
                ->setButtonName(
188
                    _t('UserDefinedForm.ADDEMAILRECIPIENT', 'Add Email Recipient')
189
                );
190
191
            // who do we email on submission
192
            $emailRecipients = new GridField(
193
                'EmailRecipients',
194
                _t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'),
195
                $self->EmailRecipients(),
196
                $emailRecipientsConfig
197
            );
198
            $emailRecipients
199
                ->getConfig()
200
                ->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDetailForm')
201
                ->setItemRequestClass('UserFormRecipientItemRequest');
202
203
            $fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet);
204
            $fields->addFieldToTab('Root.Recipients', $emailRecipients);
205
            $fields->addFieldsToTab('Root.FormOptions', $self->getFormOptions());
206
207
208
            // view the submissions
209
            $submissions = new GridField(
210
                'Submissions',
211
                _t('UserDefinedForm.SUBMISSIONS', 'Submissions'),
212
                 $self->Submissions()->sort('Created', 'DESC')
213
            );
214
215
            // make sure a numeric not a empty string is checked against this int column for SQL server
216
            $parentID = (!empty($self->ID)) ? (int) $self->ID : 0;
217
218
            // get a list of all field names and values used for print and export CSV views of the GridField below.
219
            $columnSQL = <<<SQL
220
SELECT "SubmittedFormField"."Name" as "Name", "SubmittedFormField"."Title" as "Title", COALESCE("EditableFormField"."Sort", 999) AS "Sort"
221
FROM "SubmittedFormField"
222
LEFT JOIN "SubmittedForm" ON "SubmittedForm"."ID" = "SubmittedFormField"."ParentID"
223
LEFT JOIN "EditableFormField" ON "EditableFormField"."Title" = "SubmittedFormField"."Title" AND "EditableFormField"."ParentID" = '$parentID'
224
WHERE "SubmittedForm"."ParentID" = '$parentID'
225
ORDER BY "Sort", "Title"
226
SQL;
227
            // Sanitise periods in title
228
            $columns = array();
229
            foreach (DB::query($columnSQL)->map() as $name => $title) {
230
                $columns[$name] = trim(strtr($title, '.', ' '));
231
            }
232
233
            $config = new GridFieldConfig();
234
            $config->addComponent(new GridFieldToolbarHeader());
235
            $config->addComponent($sort = new GridFieldSortableHeader());
236
            $config->addComponent($filter = new UserFormsGridFieldFilterHeader());
237
            $config->addComponent(new GridFieldDataColumns());
238
            $config->addComponent(new GridFieldEditButton());
239
            $config->addComponent(new GridFieldDeleteAction());
240
            $config->addComponent(new GridFieldPageCount('toolbar-header-right'));
241
            $config->addComponent($pagination = new GridFieldPaginator(25));
242
            $config->addComponent(new GridFieldDetailForm());
243
            $config->addComponent(new GridFieldButtonRow('after'));
244
            $config->addComponent($export = new GridFieldExportButton('buttons-after-left'));
245
            $config->addComponent($print = new GridFieldPrintButton('buttons-after-left'));
246
247
            /**
248
             * Support for {@link https://github.com/colymba/GridFieldBulkEditingTools}
249
             */
250
            if (class_exists('GridFieldBulkManager')) {
251
                $config->addComponent(new GridFieldBulkManager());
252
            }
253
254
            $sort->setThrowExceptionOnBadDataType(false);
255
            $filter->setThrowExceptionOnBadDataType(false);
256
            $pagination->setThrowExceptionOnBadDataType(false);
257
258
            // attach every column to the print view form
259
            $columns['Created'] = 'Created';
260
            $filter->setColumns($columns);
261
262
            // print configuration
263
264
            $print->setPrintHasHeader(true);
265
            $print->setPrintColumns($columns);
266
267
            // export configuration
268
            $export->setCsvHasHeader(true);
269
            $export->setExportColumns($columns);
270
271
            $submissions->setConfig($config);
272
            $fields->addFieldToTab('Root.Submissions', $submissions);
273
            $fields->addFieldToTab('Root.FormOptions', new CheckboxField('DisableSaveSubmissions', _t('UserDefinedForm.SAVESUBMISSIONS', 'Disable Saving Submissions to Server')));
274
275
        });
276
277
         $fields = parent::getCMSFields();
278
279
         if ($this->EmailRecipients()->Count() == 0 && static::config()->recipients_warning_enabled) {
280
             $fields->addFieldToTab("Root.Main", new LiteralField("EmailRecipientsWarning",
281
                "<p class=\"message warning\">" . _t("UserDefinedForm.NORECIPIENTS",
282
                "Warning: You have not configured any recipients. Form submissions may be missed.")
283
                . "</p>"), "Title");
284
         }
285
286
         return $fields;
287
     }
288
289
    /**
290
     * Allow overriding the EmailRecipients on a {@link DataExtension}
291
     * so you can customise who receives an email.
292
     * Converts the RelationList to an ArrayList so that manipulation
293
     * of the original source data isn't possible.
294
     *
295
     * @return ArrayList
296
     */
297
    public function FilteredEmailRecipients($data = null, $form = null)
298
    {
299
        $recipients = new ArrayList($this->EmailRecipients()->toArray());
300
301
        // Filter by rules
302
        $recipients = $recipients->filterByCallback(function ($recipient) use ($data, $form) {
303
            return $recipient->canSend($data, $form);
304
        });
305
306
        $this->extend('updateFilteredEmailRecipients', $recipients, $data, $form);
307
308
        return $recipients;
309
    }
310
311
    /**
312
     * Custom options for the form. You can extend the built in options by
313
     * using {@link updateFormOptions()}
314
     *
315
     * @return FieldList
316
     */
317
    public function getFormOptions()
318
    {
319
        $submit = ($this->SubmitButtonText) ? $this->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit');
320
        $clear = ($this->ClearButtonText) ? $this->ClearButtonText : _t('UserDefinedForm.CLEARBUTTON', 'Clear');
321
322
        $options = new FieldList(
323
            new TextField("SubmitButtonText", _t('UserDefinedForm.TEXTONSUBMIT', 'Text on submit button:'), $submit),
324
            new TextField("ClearButtonText", _t('UserDefinedForm.TEXTONCLEAR', 'Text on clear button:'), $clear),
325
            new CheckboxField("ShowClearButton", _t('UserDefinedForm.SHOWCLEARFORM', 'Show Clear Form Button'), $this->ShowClearButton),
326
            new CheckboxField("EnableLiveValidation", _t('UserDefinedForm.ENABLELIVEVALIDATION', 'Enable live validation')),
327
            new CheckboxField("HideFieldLabels", _t('UserDefinedForm.HIDEFIELDLABELS', 'Hide field labels')),
328
            new CheckboxField("DisplayErrorMessagesAtTop", _t('UserDefinedForm.DISPLAYERRORMESSAGESATTOP', 'Display error messages above the form?')),
329
            new CheckboxField('DisableCsrfSecurityToken', _t('UserDefinedForm.DISABLECSRFSECURITYTOKEN', 'Disable CSRF Token')),
330
            new CheckboxField('DisableAuthenicatedFinishAction', _t('UserDefinedForm.DISABLEAUTHENICATEDFINISHACTION', 'Disable Authentication on finish action'))
331
        );
332
333
        $this->extend('updateFormOptions', $options);
334
335
        return $options;
336
    }
337
338
    /**
339
     * Get the HTML id of the error container displayed above the form.
340
     *
341
     * @return string
342
     */
343
    public function getErrorContainerID()
344
    {
345
        return $this->config()->error_container_id;
346
    }
347
348
    public function requireDefaultRecords()
349
    {
350
        parent::requireDefaultRecords();
351
352
        if (!$this->config()->upgrade_on_build) {
353
            return;
354
        }
355
356
        // Perform migrations
357
        Injector::inst()
358
            ->create('UserFormsUpgradeService')
359
            ->setQuiet(true)
360
            ->run();
361
362
        DB::alteration_message('Migrated userforms', 'changed');
363
    }
364
365
366
    /**
367
     * Validate formfields
368
     */
369
    public function getCMSValidator()
370
    {
371
        return new UserFormValidator();
372
    }
373
}
374
375
/**
376
 * Controller for the {@link UserDefinedForm} page type.
377
 *
378
 * @package userforms
379
 */
380
381
class UserDefinedForm_Controller extends Page_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
382
{
383
384
    private static $finished_anchor = '#uff';
0 ignored issues
show
Unused Code introduced by
The property $finished_anchor is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
385
386
    private static $allowed_actions = array(
0 ignored issues
show
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
387
        'index',
388
        'ping',
389
        'Form',
390
        'finished'
391
    );
392
393
    public function init()
394
    {
395
        parent::init();
396
397
        // load the jquery
398
        $lang = i18n::get_lang_from_locale(i18n::get_locale());
399
        Requirements::css(USERFORMS_DIR . '/css/UserForm.css');
400
        Requirements::javascript('http://code.jquery.com/jquery-1.7.2.min.js');
401
        Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery-validate/jquery.validate.min.js');
402
        Requirements::add_i18n_javascript(USERFORMS_DIR . '/javascript/lang');
403
        Requirements::javascript(USERFORMS_DIR . '/javascript/UserForm.js');
404
405
406 View Code Duplication
        if(file_exists(BASE_PATH . '/' . USERFORMS_DIR . "/thirdparty/jquery-validate/localization/messages_{$lang}.min.js")) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
407
            Requirements::javascript(
408
                USERFORMS_DIR . "/thirdparty/jquery-validate/localization/messages_{$lang}.min.js"
409
            );
410
        }
411 View Code Duplication
        if(file_exists(BASE_PATH . '/' . USERFORMS_DIR . "//thirdparty/jquery-validate/localization/methods_{$lang}.min.js")) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
412
            Requirements::javascript(
413
                USERFORMS_DIR . "/thirdparty/jquery-validate/localization/methods_{$lang}.min.js"
414
            );
415
        }
416
        if ($this->HideFieldLabels) {
417
            Requirements::javascript(USERFORMS_DIR . '/thirdparty/Placeholders.js/Placeholders.min.js');
418
        }
419
420
        // Bind a confirmation message when navigating away from a partially completed form.
421
        $page = $this->data();
422
        if ($page::config()->enable_are_you_sure) {
423
            Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery.are-you-sure/jquery.are-you-sure.js');
424
        }
425
    }
426
427
    /**
428
     * Using $UserDefinedForm in the Content area of the page shows
429
     * where the form should be rendered into. If it does not exist
430
     * then default back to $Form.
431
     *
432
     * @return array
433
     */
434
    public function index()
435
    {
436
        if ($this->Content && $form = $this->Form()) {
437
            $hasLocation = stristr($this->Content, '$UserDefinedForm');
438
            if ($hasLocation) {
439
                $content = preg_replace('/(<p[^>]*>)?\\$UserDefinedForm(<\\/p>)?/i', $form->forTemplate(), $this->Content);
440
                return array(
441
                    'Content' => DBField::create_field('HTMLText', $content),
442
                    'Form' => ""
443
                );
444
            }
445
        }
446
447
        return array(
448
            'Content' => DBField::create_field('HTMLText', $this->Content),
449
            'Form' => $this->Form()
450
        );
451
    }
452
453
    /**
454
     * Keep the session alive for the user.
455
     *
456
     * @return int
457
     */
458
    public function ping()
459
    {
460
        return 1;
461
    }
462
463
    /**
464
     * Get the form for the page. Form can be modified by calling {@link updateForm()}
465
     * on a UserDefinedForm extension.
466
     *
467
     * @return Forms
468
     */
469
    public function Form()
470
    {
471
        $form = UserForm::create($this);
472
        $this->generateConditionalJavascript();
473
        return $form;
474
    }
475
476
    /**
477
     * Generate the javascript for the conditional field show / hiding logic.
478
     *
479
     * @return void
480
     */
481
    public function generateConditionalJavascript()
482
    {
483
        $default = "";
484
        $rules = "";
485
486
        $watch = array();
487
        $watchLoad = array();
488
489
        if ($this->Fields()) {
490
            foreach ($this->Fields() as $field) {
491
                $holderSelector = $field->getSelectorHolder();
492
493
                // Is this Field Show by Default
494
                if (!$field->ShowOnLoad) {
495
                    $default .= "{$holderSelector}.hide().trigger('userform.field.hide');\n";
496
                }
497
498
                // Check for field dependencies / default
499
                foreach ($field->EffectiveDisplayRules() as $rule) {
500
501
                    // Get the field which is effected
502
                    $formFieldWatch = EditableFormField::get()->byId($rule->ConditionFieldID);
503
504
                    // Skip deleted fields
505
                    if (!$formFieldWatch) {
506
                        continue;
507
                    }
508
509
                    $fieldToWatch = $formFieldWatch->getSelectorField($rule);
510
                    $fieldToWatchOnLoad = $formFieldWatch->getSelectorField($rule, true);
511
512
                    // show or hide?
513
                    $view = ($rule->Display == 'Hide') ? 'hide' : 'show';
514
                    $opposite = ($view == "show") ? "hide" : "show";
515
516
                    // what action do we need to keep track of. Something nicer here maybe?
517
                    // @todo encapulsation
518
                    $action = "change";
519
520
                    if ($formFieldWatch instanceof EditableTextField) {
521
                        $action = "keyup";
522
                    }
523
524
                    // is this field a special option field
525
                    $checkboxField = false;
526
                    $radioField = false;
527
528
                    if (in_array($formFieldWatch->ClassName, array('EditableCheckboxGroupField', 'EditableCheckbox'))) {
529
                        $action = "click";
530
                        $checkboxField = true;
531
                    } elseif ($formFieldWatch->ClassName == "EditableRadioField") {
532
                        $radioField = true;
533
                    }
534
535
                    // and what should we evaluate
536
                    switch ($rule->ConditionOption) {
537
                        case 'IsNotBlank':
538
                            $expression = ($checkboxField || $radioField) ? '$(this).is(":checked")' :'$(this).val() != ""';
539
540
                            break;
541
                        case 'IsBlank':
542
                            $expression = ($checkboxField || $radioField) ? '!($(this).is(":checked"))' : '$(this).val() == ""';
543
544
                            break;
545 View Code Duplication
                        case 'HasValue':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
546
                            if ($checkboxField) {
547
                                $expression = '$(this).prop("checked")';
548
                            } elseif ($radioField) {
549
                                // We cannot simply get the value of the radio group, we need to find the checked option first.
550
                                $expression = '$(this).parents(".field, .control-group").find("input:checked").val()=="'. $rule->FieldValue .'"';
551
                            } else {
552
                                $expression = '$(this).val() == "'. $rule->FieldValue .'"';
553
                            }
554
555
                            break;
556
                        case 'ValueLessThan':
557
                            $expression = '$(this).val() < parseFloat("'. $rule->FieldValue .'")';
558
559
                            break;
560
                        case 'ValueLessThanEqual':
561
                            $expression = '$(this).val() <= parseFloat("'. $rule->FieldValue .'")';
562
563
                            break;
564
                        case 'ValueGreaterThan':
565
                            $expression = '$(this).val() > parseFloat("'. $rule->FieldValue .'")';
566
567
                            break;
568
                        case 'ValueGreaterThanEqual':
569
                            $expression = '$(this).val() >= parseFloat("'. $rule->FieldValue .'")';
570
571
                            break;
572 View Code Duplication
                        default: // ==HasNotValue
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
573
                            if ($checkboxField) {
574
                                $expression = '!$(this).prop("checked")';
575
                            } elseif ($radioField) {
576
                                // We cannot simply get the value of the radio group, we need to find the checked option first.
577
                                $expression = '$(this).parents(".field, .control-group").find("input:checked").val()!="'. $rule->FieldValue .'"';
578
                            } else {
579
                                $expression = '$(this).val() != "'. $rule->FieldValue .'"';
580
                            }
581
582
                            break;
583
                    }
584
585
                    if (!isset($watch[$fieldToWatch])) {
586
                        $watch[$fieldToWatch] = array();
587
                    }
588
589
                    $watch[$fieldToWatch][] = array(
590
                        'expression' => $expression,
591
                        'holder_selector' => $holderSelector,
592
                        'view' => $view,
593
                        'opposite' => $opposite,
594
                        'action' => $action
595
                    );
596
597
                    $watchLoad[$fieldToWatchOnLoad] = true;
598
                }
599
            }
600
        }
601
602
        if ($watch) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $watch of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
603
            foreach ($watch as $key => $values) {
604
                $logic = array();
605
                $actions = array();
606
607
                foreach ($values as $rule) {
608
                    // Assign action
609
                    $actions[$rule['action']] = $rule['action'];
610
611
                    // Assign behaviour
612
                    $expression = $rule['expression'];
613
                    $holder = $rule['holder_selector'];
614
                    $view = $rule['view']; // hide or show
615
                    $opposite = $rule['opposite'];
616
                    // Generated javascript for triggering visibility
617
                    $logic[] = <<<"EOS"
618
if({$expression}) {
619
	{$holder}
620
		.{$view}()
621
		.trigger('userform.field.{$view}');
622
} else {
623
	{$holder}
624
		.{$opposite}()
625
		.trigger('userform.field.{$opposite}');
626
}
627
EOS;
628
                }
629
630
                $logic = implode("\n", $logic);
631
                $rules .= $key.".each(function() {\n
632
	$(this).data('userformConditions', function() {\n
633
		$logic\n
634
	}); \n
635
});\n";
636
                foreach ($actions as $action) {
637
                    $rules .= $key.".$action(function() {
638
	$(this).data('userformConditions').call(this);\n
639
});\n";
640
                }
641
            }
642
        }
643
644
        if ($watchLoad) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $watchLoad of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
645
            foreach ($watchLoad as $key => $value) {
646
                $rules .= $key.".each(function() {
647
	$(this).data('userformConditions').call(this);\n
648
});\n";
649
            }
650
        }
651
652
        // Only add customScript if $default or $rules is defined
653
        if ($default  || $rules) {
654
            Requirements::customScript(<<<JS
655
				(function($) {
656
					$(document).ready(function() {
657
						$default
658
659
						$rules
660
					})
661
				})(jQuery);
662
JS
663
, 'UserFormsConditional');
664
        }
665
    }
666
667
    /**
668
     * Process the form that is submitted through the site
669
     *
670
     * {@see UserForm::validate()} for validation step prior to processing
671
     *
672
     * @param array $data
673
     * @param Form $form
674
     *
675
     * @return Redirection
676
     */
677
    public function process($data, $form)
0 ignored issues
show
Coding Style introduced by
process uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
678
    {
679
        $submittedForm = Object::create('SubmittedForm');
680
        $submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0;
681
        $submittedForm->ParentID = $this->ID;
682
683
        // if saving is not disabled save now to generate the ID
684
        if (!$this->DisableSaveSubmissions) {
685
            $submittedForm->write();
686
        }
687
688
        $attachments = array();
689
        $submittedFields = new ArrayList();
690
691
        foreach ($this->Fields() as $field) {
692
            if (!$field->showInReports()) {
693
                continue;
694
            }
695
696
            $submittedField = $field->getSubmittedFormField();
697
            $submittedField->ParentID = $submittedForm->ID;
698
            $submittedField->Name = $field->Name;
699
            $submittedField->Title = $field->getField('Title');
700
701
            // save the value from the data
702
            if ($field->hasMethod('getValueFromData')) {
703
                $submittedField->Value = $field->getValueFromData($data);
704
            } else {
705
                if (isset($data[$field->Name])) {
706
                    $submittedField->Value = $data[$field->Name];
707
                }
708
            }
709
710
            if (!empty($data[$field->Name])) {
711
                if (in_array("EditableFileField", $field->getClassAncestry())) {
712
                    if (isset($_FILES[$field->Name])) {
713
                        $foldername = $field->getFormField()->getFolderName();
714
715
                        // create the file from post data
716
                        $upload = new Upload();
717
                        $file = new File();
718
                        $file->ShowInSearch = 0;
719
                        try {
720
                            $upload->loadIntoFile($_FILES[$field->Name], $file, $foldername);
721
                        } catch (ValidationException $e) {
0 ignored issues
show
Bug introduced by
The class SilverStripe\ORM\ValidationException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
722
                            $validationResult = $e->getResult();
723
                            $form->addErrorMessage($field->Name, $validationResult->message(), 'bad');
724
                            Controller::curr()->redirectBack();
725
                            return;
726
                        }
727
728
                        // write file to form field
729
                        $submittedField->UploadedFileID = $file->ID;
730
731
                        // attach a file only if lower than 1MB
732
                        if ($file->getAbsoluteSize() < 1024*1024*1) {
733
                            $attachments[] = $file;
734
                        }
735
                    }
736
                }
737
            }
738
739
            $submittedField->extend('onPopulationFromField', $field);
740
741
            if (!$this->DisableSaveSubmissions) {
742
                $submittedField->write();
743
            }
744
745
            $submittedFields->push($submittedField);
746
        }
747
748
        $emailData = array(
749
            "Sender" => Member::currentUser(),
750
            "Fields" => $submittedFields
751
        );
752
753
        $this->extend('updateEmailData', $emailData, $attachments);
754
755
        // email users on submit.
756
        if ($recipients = $this->FilteredEmailRecipients($data, $form)) {
757
            foreach ($recipients as $recipient) {
758
                $email = new UserFormRecipientEmail($submittedFields);
759
                $mergeFields = $this->getMergeFieldsMap($emailData['Fields']);
760
    
761
                if ($attachments) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $attachments of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
762
                    foreach ($attachments as $file) {
763
                        if ($file->ID != 0) {
764
                            $email->attachFile(
765
                                $file->Filename,
766
                                $file->Filename,
767
                                HTTP::get_mime_type($file->Filename)
768
                            );
769
                        }
770
                    }
771
                }
772
                
773
                $parsedBody = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields);
774
775
                if (!$recipient->SendPlain && $recipient->emailTemplateExists()) {
776
                    $email->setTemplate($recipient->EmailTemplate);
777
                }
778
779
                $email->populateTemplate($recipient);
780
                $email->populateTemplate($emailData);
781
                $email->setFrom($recipient->EmailFrom);
782
                $email->setBody($parsedBody);
783
                $email->setTo($recipient->EmailAddress);
784
                $email->setSubject($recipient->EmailSubject);
785
786
                if ($recipient->EmailReplyTo) {
787
                    $email->setReplyTo($recipient->EmailReplyTo);
788
                }
789
790
                // check to see if they are a dynamic reply to. eg based on a email field a user selected
791 View Code Duplication
                if ($recipient->SendEmailFromField()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
792
                    $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name);
793
794
                    if ($submittedFormField && is_string($submittedFormField->Value)) {
795
                        $email->setReplyTo($submittedFormField->Value);
796
                    }
797
                }
798
                // check to see if they are a dynamic reciever eg based on a dropdown field a user selected
799 View Code Duplication
                if ($recipient->SendEmailToField()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
800
                    $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
801
802
                    if ($submittedFormField && is_string($submittedFormField->Value)) {
803
                        $email->setTo($submittedFormField->Value);
804
                    }
805
                }
806
807
                // check to see if there is a dynamic subject
808 View Code Duplication
                if ($recipient->SendEmailSubjectField()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
809
                    $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailSubjectField()->Name);
810
811
                    if ($submittedFormField && trim($submittedFormField->Value)) {
812
                        $email->setSubject($submittedFormField->Value);
813
                    }
814
                }
815
816
                $this->extend('updateEmail', $email, $recipient, $emailData);
817
818
                if ($recipient->SendPlain) {
819
                    $body = strip_tags($recipient->getEmailBodyContent()) . "\n";
820
                    if (isset($emailData['Fields']) && !$recipient->HideFormData) {
821
                        foreach ($emailData['Fields'] as $Field) {
822
                            $body .= $Field->Title .': '. $Field->Value ." \n";
823
                        }
824
                    }
825
826
                    $email->setBody($body);
827
                    $email->sendPlain();
828
                } else {
829
                    $email->send();
830
                }
831
            }
832
        }
833
834
        $submittedForm->extend('updateAfterProcess');
835
836
        Session::clear("FormInfo.{$form->FormName()}.errors");
837
        Session::clear("FormInfo.{$form->FormName()}.data");
838
839
        $referrer = (isset($data['Referrer'])) ? '?referrer=' . urlencode($data['Referrer']) : "";
840
841
        // set a session variable from the security ID to stop people accessing
842
        // the finished method directly.
843
        if (!$this->DisableAuthenicatedFinishAction) {
844
            if (isset($data['SecurityID'])) {
845
                Session::set('FormProcessed', $data['SecurityID']);
846
            } else {
847
                // if the form has had tokens disabled we still need to set FormProcessed
848
                // to allow us to get through the finshed method
849
                if (!$this->Form()->getSecurityToken()->isEnabled()) {
850
                    $randNum = rand(1, 1000);
851
                    $randHash = md5($randNum);
852
                    Session::set('FormProcessed', $randHash);
853
                    Session::set('FormProcessedNum', $randNum);
854
                }
855
            }
856
        }
857
858
        if (!$this->DisableSaveSubmissions) {
859
            Session::set('userformssubmission'. $this->ID, $submittedForm->ID);
860
        }
861
862
        return $this->redirect($this->Link('finished') . $referrer . $this->config()->finished_anchor);
863
    }
864
865
    /**
866
     * Allows the use of field values in email body.
867
     *
868
     * @param ArrayList fields
869
     * @return ArrayData
870
     */
871
    private function getMergeFieldsMap($fields = array())
872
    {
873
        $data = new ArrayData(array());
874
875
        foreach ($fields as $field) {
876
            $data->setField($field->Name, DBField::create_field('Text', $field->Value));
877
        }
878
879
        return $data;
880
    }
881
882
    /**
883
     * This action handles rendering the "finished" message, which is
884
     * customizable by editing the ReceivedFormSubmission template.
885
     *
886
     * @return ViewableData
887
     */
888
    public function finished()
0 ignored issues
show
Coding Style introduced by
finished uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
889
    {
890
        $submission = Session::get('userformssubmission'. $this->ID);
891
892
        if ($submission) {
893
            $submission = SubmittedForm::get()->byId($submission);
894
        }
895
896
        $referrer = isset($_GET['referrer']) ? urldecode($_GET['referrer']) : null;
897
898
        if (!$this->DisableAuthenicatedFinishAction) {
899
            $formProcessed = Session::get('FormProcessed');
900
901
            if (!isset($formProcessed)) {
902
                return $this->redirect($this->Link() . $referrer);
903
            } else {
904
                $securityID = Session::get('SecurityID');
905
                // make sure the session matches the SecurityID and is not left over from another form
906
                if ($formProcessed != $securityID) {
907
                    // they may have disabled tokens on the form
908
                    $securityID = md5(Session::get('FormProcessedNum'));
909
                    if ($formProcessed != $securityID) {
910
                        return $this->redirect($this->Link() . $referrer);
911
                    }
912
                }
913
            }
914
915
            Session::clear('FormProcessed');
916
        }
917
918
        return $this->customise(array(
919
            'Content' => $this->customise(array(
920
                'Submission' => $submission,
921
                'Link' => $referrer
922
            ))->renderWith('ReceivedFormSubmission'),
923
            'Form' => '',
924
        ));
925
    }
926
}
927