Passed
Push — master ( 05e846...9de07a )
by Jason
02:44
created

JobCollection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 110
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 14 1
A getPostedJobs() 0 9 1
A getCMSFields() 0 16 1
1
<?php
2
3
namespace Dynamic\Jobs\Page;
4
5
use SilverStripe\AssetAdmin\Forms\UploadField;
6
use SilverStripe\Assets\File;
7
use SilverStripe\Forms\EmailField;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
10
use SilverStripe\Forms\TextField;
11
use SilverStripe\Lumberjack\Model\Lumberjack;
12
use SilverStripe\ORM\DataList;
13
use SilverStripe\ORM\FieldType\DBDatetime;
14
use SilverStripe\ORM\ValidationResult;
15
16
/**
17
 * Class JobCollection
18
 * @package Dynamic\Jobs\Model
19
 */
20
class JobCollection extends \Page
21
{
22
    /**
23
     * @var string
24
     */
25
    private static $singular_name = "Job Collection";
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
26
27
    /**
28
     * @var string
29
     */
30
    private static $plural_name = "Job Collection";
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
31
32
    /**
33
     * @var string
34
     */
35
    private static $description = 'Display a list of available jobs';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
36
37
    /**
38
     * @var string
39
     */
40
    private static $table_name = 'Dynamic_JobCollection';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
41
42
    /**
43
     * @var array
44
     */
45
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
46
        'Message' => 'HTMLText',
47
        'FromAddress' => 'Varchar(255)',
48
        'EmailRecipient' => 'Varchar(255)',
49
        'EmailSubject' => 'Varchar(255)',
50
    ];
51
52
    /**
53
     * @var array
54
     */
55
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
56
        'Application' => File::class,
57
    ];
58
59
    /**
60
     * @var array
61
     */
62
    private static $extensions = [
0 ignored issues
show
introduced by
The private property $extensions is not used, and could be removed.
Loading history...
63
        Lumberjack::class,
64
    ];
65
66
    /**
67
     * @var string
68
     */
69
    private static $default_child = Job::class;
0 ignored issues
show
introduced by
The private property $default_child is not used, and could be removed.
Loading history...
70
71
    /**
72
     * @var array
73
     */
74
    private static $allowed_children = [
0 ignored issues
show
introduced by
The private property $allowed_children is not used, and could be removed.
Loading history...
75
        Job::class,
76
    ];
77
78
    /**
79
     * @return FieldList
80
     */
81 1
    public function getCMSFields()
82
    {
83 1
        $fields = parent::getCMSFields();
84
85 1
        $app = new UploadField('Application', 'Application Form');
86 1
        $app->allowedExtensions = ['pdf', 'PDF'];
87 1
        $fields->addFieldToTab('Root.ApplicationFile', $app);
88
89 1
        $fields->addFieldsToTab('Root.Configuration', [
90 1
            EmailField::create('FromAddress', 'Submission From Address'),
91 1
            EmailField::create('EmailRecipient', 'Submission Recipient'),
92 1
            TextField::create('EmailSubject', 'Submission Email Subject Line'),
93 1
            HTMLEditorField::create('Message', 'Submission Message'),
94
        ]);
95
96 1
        return $fields;
97
    }
98
99
    /**
100
     * @return ValidationResult
101
     */
102 2
    public function validate()
103
    {
104 2
        $result = parent::validate();
105
        // TODO - this bugs out and won't create the page if it is in
106
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
107
                if(!$this->EmailRecipient) {
108
                    $result->addError('Please enter Email Recipient before saving.');
109
                }
110
111
                if(!$this->EmailSubject) {
112
                    $result->addError('Please enter Email Subject before saving.');
113
                }
114
                */
115 2
        return $result;
116
    }
117
118
    /**
119
     * @return DataList
120
     */
121 1
    public function getPostedJobs()
122
    {
123 1
        $jobs = Job::get()
124 1
            ->filter([
125 1
                'PostDate:LessThanOrEqual' => DBDatetime::now(),
126 1
                'EndPostDate:GreaterThanOrEqual' => DBDatetime::now(),
127
            ])
128 1
            ->sort('PostDate DESC');
129 1
        return $jobs;
130
    }
131
}
132