Completed
Push — master ( 5b541f...fb71d8 )
by Jason
03:08
created

JobSubmission::getEditLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\Jobs\Model;
4
5
use Dynamic\Jobs\Admin\JobAdmin;
6
use Dynamic\Jobs\Forms\SimpleHtmlEditorField;
7
use Dynamic\Jobs\Page\Job;
8
use SilverStripe\Assets\File;
9
use SilverStripe\Control\Controller;
10
use SilverStripe\Control\Director;
11
use SilverStripe\Forms\DateField;
12
use SilverStripe\Forms\EmailField;
13
use SilverStripe\Forms\FieldList;
14
use SilverStripe\Forms\FileField;
15
use SilverStripe\Forms\ReadonlyField;
16
use SilverStripe\Forms\RequiredFields;
17
use SilverStripe\Forms\TextField;
18
use SilverStripe\ORM\DataObject;
19
use SilverStripe\Security\Permission;
20
21
/**
22
 * Class JobSubmission
23
 * @package Dynamic\Jobs\Model
24
 */
25
class JobSubmission extends DataObject
26
{
27
    /**
28
     * @var string
29
     */
30
    private static $singular_name = 'Job Application';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
31
32
    /**
33
     * @var string
34
     */
35
    private static $plural_name = 'Job Applications';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
36
37
    /**
38
     * @var string
39
     */
40
    private static $description = 'Online job application allowing for a resume upload';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
41
42
    /**
43
     * @var string
44
     */
45
    private static $table_name = 'Dynamic_JobSubmission';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
46
47
    /**
48
     * @var array
49
     */
50
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
51
        'FirstName' => 'Varchar(255)',
52
        'LastName' => 'Varchar(255)',
53
        'Email' => 'Varchar(255)',
54
        'Phone' => 'Varchar(255)',
55
        'Available' => 'Date',
56
        'Content' => 'HTMLText',
57
    ];
58
59
    /**
60
     * @var array
61
     */
62
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
63
        'Job' => Job::class,
64
        'Resume' => File::class,
65
    ];
66
67
    /**
68
     * @var string
69
     */
70
    private static $default_sort = 'Created DESC';
0 ignored issues
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
71
72
    /**
73
     * @var array
74
     */
75
    private static $summary_fields = [
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
76
        'Name' => 'Applicant',
77
        'Job.Title' => 'Job',
78
        'Created.Nice' => 'Date',
79
    ];
80
81
    /**
82
     * @var array
83
     */
84
    private static $searchable_fields = [
0 ignored issues
show
introduced by
The private property $searchable_fields is not used, and could be removed.
Loading history...
85
        'FirstName' => [
86
            'title' => 'First',
87
        ],
88
        'LastName' => [
89
            'title' => 'Last',
90
        ],
91
        'Job.ID' => [
92
            'title' => 'Job',
93
        ],
94
        'Email' => [
95
            'title' => 'Email',
96
        ],
97
        'Phone' => [
98
            'title' => 'Phone',
99
        ],
100
        'Content' => [
101
            'title' => 'Cover Letter',
102
        ],
103
    ];
104
105
    /**
106
     * @return string
107
     */
108 2
    public function getName()
109
    {
110 2
        if ($this->FirstName) {
0 ignored issues
show
Bug Best Practice introduced by
The property FirstName does not exist on Dynamic\Jobs\Model\JobSubmission. Since you implemented __get, consider adding a @property annotation.
Loading history...
111 2
            return $this->FirstName . ' ' . $this->LastName;
0 ignored issues
show
Bug Best Practice introduced by
The property LastName does not exist on Dynamic\Jobs\Model\JobSubmission. Since you implemented __get, consider adding a @property annotation.
Loading history...
112
        } else {
113 1
            return 'No Name';
114
        }
115
    }
116
117
    /**
118
     * @return string
119
     */
120 1
    public function getTitle()
121
    {
122 1
        return $this->getName();
123
    }
124
125
    /**
126
     * @param null $params
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $params is correct as it would always require null to be passed?
Loading history...
127
     * @return FieldList
128
     */
129 4
    public function getFrontEndFields($params = null)
130
    {
131
        // Resume Upload
132 4
        $ResumeField = FileField::create('Resume')->setTitle('Resume');
133 4
        $ResumeField->getValidator()->setAllowedExtensions([
134 4
            'pdf',
135
            'doc',
136
            'docx',
137
        ]);
138 4
        $ResumeField->setFolderName('Uploads/Resumes');
139 4
        $ResumeField->setRelationAutoSetting(false);
140 4
        $ResumeField->setAttribute('required', true);
141
142 4
        $fields = FieldList::create(
143 4
            TextField::create('FirstName', 'First Name')
144 4
                ->setAttribute('required', true),
145 4
            TextField::create('LastName', 'Last Name')
146 4
                ->setAttribute('required', true),
147 4
            EmailField::create('Email')
148 4
                ->setAttribute('required', true),
149 4
            TextField::create('Phone')
150 4
                ->setAttribute('required', true),
151 4
            DateField::create('Available', 'Date Available'),
152 4
            $ResumeField,
153 4
            SimpleHtmlEditorField::create('Content', 'Cover Letter')
154
        );
155
156 4
        $this->extend('updateFrontEndFields', $fields);
157
158 4
        return $fields;
159
    }
160
161
    /**
162
     * @return RequiredFields
163
     */
164 1
    public function getRequiredFields()
165
    {
166 1
        return new RequiredFields([
167 1
            'FirstName',
168
            'LastName',
169
            'Email',
170
            'Phone',
171
            'Resume',
172
        ]);
173
    }
174
175
    /**
176
     * @return FieldList
177
     */
178 1
    public function getCMSFields()
179
    {
180 1
        $fields = parent::getCMSFields();
181
182 1
        $fields->removeByName([
183 1
            'JobID',
184
        ]);
185
186 1
        $fields->insertBefore(
187 1
            ReadonlyField::create('JobTitle', 'Job', $this->Job()->getTitle()),
0 ignored issues
show
Bug introduced by
The method Job() does not exist on Dynamic\Jobs\Model\JobSubmission. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

187
            ReadonlyField::create('JobTitle', 'Job', $this->/** @scrutinizer ignore-call */ Job()->getTitle()),
Loading history...
188 1
            'Content'
0 ignored issues
show
Bug introduced by
'Content' of type string is incompatible with the type SilverStripe\Forms\FormField expected by parameter $item of SilverStripe\Forms\FieldList::insertBefore(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

188
            /** @scrutinizer ignore-type */ 'Content'
Loading history...
189
        );
190
191 1
        $fields->insertBefore(
192 1
            ReadonlyField::create('Created', 'Application Date', $this->dbObject('Created')->FormatFromSettings()),
193 1
            'Content'
194
        );
195
196 1
        $resume = $fields->dataFieldByName('Resume')
197 1
            ->setFolderName('Uploads/Resumes');
198 1
        $fields->insertBefore($resume, 'Content');
199
200 1
        return $fields;
201
    }
202
203 1
    public function getEditLink()
204
    {
205 1
        $link = Controller::join_links(
206 1
            Director::absoluteBaseURL(),
207 1
            singleton(JobAdmin::class)->Link(),
208
            'Dynamic-Jobs-Model-JobSubmission/EditForm/field/Dynamic-Jobs-Model-JobSubmission/item/' .
209 1
                $this->ID . '/edit'
210
        );
211
212 1
        return $link;
213
    }
214
215
    /**
216
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
217
     *
218
     * @return bool|int
219
     */
220 1
    public function canEdit($member = null)
221
    {
222 1
        return Permission::check('Job_EDIT', 'any', $member);
223
    }
224
225
    /**
226
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
227
     *
228
     * @return bool|int
229
     */
230 1
    public function canDelete($member = null)
231
    {
232 1
        return Permission::check('Job_DELETE', 'any', $member);
233
    }
234
235
    /**
236
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
237
     *
238
     * @return bool|int
239
     */
240 1
    public function canCreate($member = null, $contect = [])
241
    {
242 1
        return Permission::check('Job_CREATE', 'any', $member);
243
    }
244
245
    /**
246
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
247
     *
248
     * @return bool
249
     */
250 9
    public function canView($member = null)
251
    {
252 9
        return true;
253
    }
254
}
255