Passed
Push — master ( 97d2c5...5b541f )
by Jason
13:47
created

JobCollection::getLumberjackTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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 1
     */
82
    public function getCMSFields()
83 1
    {
84
        $this->beforeUpdateCMSFields(function ($fields) {
85 1
            $app = new UploadField('Application', 'Application Form');
86 1
            $app
87 1
                ->setDescription('optional - include application file to print and complete manually')
88
                ->setFolderName('Uploads/JobApplications')
89 1
                ->setIsMultiUpload(false)
90 1
                ->setAllowedFileCategories('document');
91 1
            $fields->addFieldToTab('Root.ApplicationFile', $app);
92 1
93 1
            $fields->addFieldsToTab('Root.Notifications', [
94
                EmailField::create('FromAddress', 'From Email'),
95
                EmailField::create('EmailRecipient', 'Recipient Email'),
96 1
                TextField::create('EmailSubject', 'Subject Line'),
97
                HTMLEditorField::create('Message', 'Message')
98
                    ->setRows(10)
99
                    ->setDescription('will display prior to application info.'),
100
            ]);
101
        });
102 2
103
        return parent::getCMSFields();
104 2
    }
105
106
    /**
107
     * @return ValidationResult
108
     */
109
    public function validate()
110
    {
111
        $result = parent::validate();
112
113
        // TODO - this bugs out and won't create the page if it is in
114
        /*
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...
115 2
        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 1
        }
122
        */
123 1
124 1
        return $result;
125 1
    }
126 1
127
    /**
128 1
     * @return DataList
129 1
     */
130
    public function getPostedJobs()
131
    {
132
        $jobs = Job::get()
133
            ->filter([
134
                'PostDate:LessThanOrEqual' => DBDatetime::now(),
135
                'EndPostDate:GreaterThanOrEqual' => DBDatetime::now(),
136
            ])
137
            ->sort('PostDate DESC');
138
        return $jobs;
139
    }
140
141
    /**
142
     * @return string
143
     */
144
    public function getLumberjackTitle()
145
    {
146
        return 'Jobs';
147
    }
148
}
149