JobCollection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 42
dl 0
loc 126
ccs 28
cts 28
cp 1
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPostedJobs() 0 9 1
A validate() 0 16 1
A getCMSFields() 0 22 1
A getLumberjackTitle() 0 3 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\HeaderField;
10
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
11
use SilverStripe\Forms\TextField;
12
use SilverStripe\Lumberjack\Model\Lumberjack;
13
use SilverStripe\ORM\DataList;
14
use SilverStripe\ORM\FieldType\DBDatetime;
15
use SilverStripe\ORM\ValidationResult;
16
17
/**
18
 * Class JobCollection
19
 * @package Dynamic\Jobs\Model
20
 */
21
class JobCollection extends \Page
22
{
23
    /**
24
     * @var string
25
     */
26
    private static $singular_name = "Job Holder";
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
27
28
    /**
29
     * @var string
30
     */
31
    private static $plural_name = "Job Holders";
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
32
33
    /**
34
     * @var string
35
     */
36
    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...
37
38
    /**
39
     * @var string
40
     */
41
    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...
42
43
    /**
44
     * @var array
45
     */
46
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
47
        'Message' => 'HTMLText',
48
        'FromAddress' => 'Varchar(255)',
49
        'EmailRecipient' => 'Varchar(255)',
50
        'EmailSubject' => 'Varchar(255)',
51
    ];
52
53
    /**
54
     * @var array
55
     */
56
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
57
        'Application' => File::class,
58
    ];
59
60
    /**
61
     * @var array
62
     */
63
    private static $extensions = [
0 ignored issues
show
introduced by
The private property $extensions is not used, and could be removed.
Loading history...
64
        Lumberjack::class,
65
    ];
66
67
    /**
68
     * @var string
69
     */
70
    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...
71
72
    /**
73
     * @var array
74
     */
75
    private static $allowed_children = [
0 ignored issues
show
introduced by
The private property $allowed_children is not used, and could be removed.
Loading history...
76
        Job::class,
77
    ];
78
79
    /**
80
     * @return FieldList
81
     */
82
    public function getCMSFields()
83
    {
84 1
        $this->beforeUpdateCMSFields(function ($fields) {
85 1
            $app = new UploadField('Application', 'Application Form');
86
            $app
87 1
                ->setDescription('optional - include application file to print and complete manually')
88 1
                ->setFolderName('Uploads/JobApplications')
89 1
                ->setIsMultiUpload(false)
90 1
                ->setAllowedFileCategories('document');
91 1
            $fields->addFieldToTab('Root.ApplicationFile', $app);
92
93 1
            $fields->addFieldsToTab('Root.Notifications', [
94 1
                EmailField::create('FromAddress', 'From Email'),
95 1
                EmailField::create('EmailRecipient', 'Recipient Email'),
96 1
                TextField::create('EmailSubject', 'Subject Line'),
97 1
                HTMLEditorField::create('Message', 'Message')
98 1
                    ->setRows(10)
99 1
                    ->setDescription('will display after a successful application submission.'),
100
            ]);
101 1
        });
102
103 1
        return parent::getCMSFields();
104
    }
105
106
    /**
107
     * @return ValidationResult
108
     */
109 2
    public function validate()
110
    {
111 2
        $result = parent::validate();
112
113
        // TODO - this bugs out and won't create the page if it is in
114
        /*
115
        if(!$this->EmailRecipient) {
116
            $result->addError('Please enter Email Recipient before saving.');
117
        }
118
119
        if(!$this->EmailSubject) {
120
            $result->addError('Please enter Email Subject before saving.');
121
        }
122
        */
123
124 2
        return $result;
125
    }
126
127
    /**
128
     * @return DataList
129
     */
130 1
    public function getPostedJobs()
131
    {
132 1
        $jobs = Job::get()
133 1
            ->filter([
134 1
                'PostDate:LessThanOrEqual' => DBDatetime::now(),
135 1
                'EndPostDate:GreaterThanOrEqual' => DBDatetime::now(),
136
            ])
137 1
            ->sort('PostDate DESC');
138 1
        return $jobs;
139
    }
140
141
    /**
142
     * @return string
143
     */
144 1
    public function getLumberjackTitle()
145
    {
146 1
        return 'Jobs';
147
    }
148
}
149