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 $table_name = 'Dynamic_JobSubmission'; |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
31 | |||||
32 | /** |
||||
33 | * @var array |
||||
34 | */ |
||||
35 | private static $db = [ |
||||
0 ignored issues
–
show
|
|||||
36 | 'FirstName' => 'Varchar(255)', |
||||
37 | 'LastName' => 'Varchar(255)', |
||||
38 | 'Email' => 'Varchar(255)', |
||||
39 | 'Phone' => 'Varchar(255)', |
||||
40 | 'Available' => 'Date', |
||||
41 | 'Content' => 'HTMLText', |
||||
42 | ]; |
||||
43 | |||||
44 | /** |
||||
45 | * @var array |
||||
46 | */ |
||||
47 | private static $has_one = [ |
||||
0 ignored issues
–
show
|
|||||
48 | 'Job' => Job::class, |
||||
49 | 'Resume' => File::class, |
||||
50 | ]; |
||||
51 | |||||
52 | /** |
||||
53 | * @var string |
||||
54 | */ |
||||
55 | private static $default_sort = 'Created DESC'; |
||||
0 ignored issues
–
show
|
|||||
56 | |||||
57 | /** |
||||
58 | * @var array |
||||
59 | */ |
||||
60 | private static $summary_fields = [ |
||||
0 ignored issues
–
show
|
|||||
61 | 'Name', |
||||
62 | 'Job.Title', |
||||
63 | 'Created.Nice', |
||||
64 | ]; |
||||
65 | |||||
66 | /** |
||||
67 | * @var array |
||||
68 | */ |
||||
69 | private static $searchable_fields = [ |
||||
0 ignored issues
–
show
|
|||||
70 | 'FirstName', |
||||
71 | 'LastName', |
||||
72 | 'Job.ID', |
||||
73 | 'Email', |
||||
74 | 'Phone', |
||||
75 | 'Content', |
||||
76 | ]; |
||||
77 | |||||
78 | /** |
||||
79 | * @param bool $includerelations |
||||
80 | * @return array |
||||
81 | */ |
||||
82 | 1 | public function fieldLabels($includerelations = true) |
|||
83 | { |
||||
84 | 1 | $labels = parent::fieldLabels($includerelations); |
|||
85 | |||||
86 | 1 | $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Applicant'); |
|||
87 | 1 | $labels['Job.Title'] = _t(__CLASS__ . '.JobLabel', 'Job'); |
|||
88 | 1 | $labels['Job.ID'] = _t(__CLASS__ . '.JobLabel', 'Job'); |
|||
89 | 1 | $labels['Created'] = _t(__CLASS__ . '.CreatedLabel', 'Application Date'); |
|||
90 | 1 | $labels['Created.Nice'] = _t(__CLASS__ . '.CreatedLabel', 'Application Date'); |
|||
91 | 1 | $labels['FirstName'] = _t(__CLASS__ . '.FirstNameLabel', 'First'); |
|||
92 | 1 | $labels['LastName'] = _t(__CLASS__ . '.LastNameLabel', 'Last'); |
|||
93 | 1 | $labels['Email'] = _t(__CLASS__ . '.EmailLabel', 'Email'); |
|||
94 | 1 | $labels['Phone'] = _t(__CLASS__ . '.PhoneLabel', 'Phone'); |
|||
95 | 1 | $labels['Available'] = _t(__CLASS__ . '.AvailableLabel', 'Date Available'); |
|||
96 | 1 | $labels['Resume'] = _t(__CLASS__ . '.ResumeLabel', 'Resume'); |
|||
97 | 1 | $labels['Content'] = _t(__CLASS__ . '.ContentLabel', 'Cover Letter'); |
|||
98 | |||||
99 | 1 | return $labels; |
|||
100 | } |
||||
101 | |||||
102 | /** |
||||
103 | * @return string |
||||
104 | */ |
||||
105 | 2 | public function getName() |
|||
106 | { |
||||
107 | 2 | if ($this->FirstName) { |
|||
0 ignored issues
–
show
The property
FirstName does not exist on Dynamic\Jobs\Model\JobSubmission . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||
108 | 2 | return $this->FirstName . ' ' . $this->LastName; |
|||
0 ignored issues
–
show
The property
LastName does not exist on Dynamic\Jobs\Model\JobSubmission . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||
109 | } else { |
||||
110 | 1 | return 'No Name'; |
|||
111 | } |
||||
112 | } |
||||
113 | |||||
114 | /** |
||||
115 | * @return string |
||||
116 | */ |
||||
117 | 1 | public function getTitle() |
|||
118 | { |
||||
119 | 1 | return $this->getName(); |
|||
120 | } |
||||
121 | |||||
122 | /** |
||||
123 | * @param null $params |
||||
0 ignored issues
–
show
|
|||||
124 | * @return FieldList |
||||
125 | */ |
||||
126 | 4 | public function getFrontEndFields($params = null) |
|||
127 | { |
||||
128 | // Resume Upload |
||||
129 | 4 | $ResumeField = FileField::create('Resume')->setTitle('Resume'); |
|||
130 | 4 | $ResumeField->getValidator()->setAllowedExtensions([ |
|||
131 | 4 | 'pdf', |
|||
132 | 'doc', |
||||
133 | 'docx', |
||||
134 | ]); |
||||
135 | 4 | $ResumeField->setFolderName('Uploads/Resumes'); |
|||
136 | 4 | $ResumeField->setRelationAutoSetting(false); |
|||
137 | 4 | $ResumeField->setAttribute('required', true); |
|||
138 | |||||
139 | 4 | $fields = FieldList::create( |
|||
140 | 4 | TextField::create('FirstName', 'First Name') |
|||
141 | 4 | ->setAttribute('required', true), |
|||
142 | 4 | TextField::create('LastName', 'Last Name') |
|||
143 | 4 | ->setAttribute('required', true), |
|||
144 | 4 | EmailField::create('Email') |
|||
145 | 4 | ->setAttribute('required', true), |
|||
146 | 4 | TextField::create('Phone') |
|||
147 | 4 | ->setAttribute('required', true), |
|||
148 | 4 | DateField::create('Available', 'Date Available'), |
|||
149 | 4 | $ResumeField, |
|||
150 | 4 | SimpleHtmlEditorField::create('Content', 'Cover Letter') |
|||
151 | ); |
||||
152 | |||||
153 | 4 | $this->extend('updateFrontEndFields', $fields); |
|||
154 | |||||
155 | 4 | return $fields; |
|||
156 | } |
||||
157 | |||||
158 | /** |
||||
159 | * @return RequiredFields |
||||
160 | */ |
||||
161 | 1 | public function getRequiredFields() |
|||
162 | { |
||||
163 | 1 | return new RequiredFields([ |
|||
164 | 1 | 'FirstName', |
|||
165 | 'LastName', |
||||
166 | 'Email', |
||||
167 | 'Phone', |
||||
168 | 'Resume', |
||||
169 | ]); |
||||
170 | } |
||||
171 | |||||
172 | /** |
||||
173 | * @return FieldList |
||||
174 | */ |
||||
175 | 1 | public function getCMSFields() |
|||
176 | { |
||||
177 | 1 | $fields = parent::getCMSFields(); |
|||
178 | |||||
179 | 1 | $fields->removeByName([ |
|||
180 | 1 | 'JobID', |
|||
181 | ]); |
||||
182 | |||||
183 | 1 | $fields->insertBefore( |
|||
184 | 1 | ReadonlyField::create('JobTitle', $this->fieldLabel('Job.Title'), $this->Job()->getTitle()), |
|||
0 ignored issues
–
show
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
![]() |
|||||
185 | 1 | 'Content' |
|||
0 ignored issues
–
show
'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
![]() |
|||||
186 | ); |
||||
187 | |||||
188 | 1 | $fields->insertBefore( |
|||
189 | 1 | ReadonlyField::create( |
|||
190 | 1 | 'Created', |
|||
191 | 1 | $this->fieldLabel('Created'), |
|||
192 | 1 | $this->dbObject('Created')->FormatFromSettings() |
|||
193 | ), |
||||
194 | 1 | 'Content' |
|||
195 | ); |
||||
196 | |||||
197 | 1 | $resume = $fields->dataFieldByName('Resume') |
|||
198 | 1 | ->setFolderName('Uploads/Resumes'); |
|||
199 | 1 | $fields->insertBefore($resume, 'Content'); |
|||
200 | |||||
201 | 1 | return $fields; |
|||
202 | } |
||||
203 | |||||
204 | 1 | public function getEditLink() |
|||
205 | { |
||||
206 | 1 | $link = Controller::join_links( |
|||
207 | 1 | Director::absoluteBaseURL(), |
|||
208 | 1 | singleton(JobAdmin::class)->Link(), |
|||
209 | 'Dynamic-Jobs-Model-JobSubmission/EditForm/field/Dynamic-Jobs-Model-JobSubmission/item/' . |
||||
210 | 1 | $this->ID . '/edit' |
|||
211 | ); |
||||
212 | |||||
213 | 1 | return $link; |
|||
214 | } |
||||
215 | |||||
216 | /** |
||||
217 | * @param null $member |
||||
0 ignored issues
–
show
|
|||||
218 | * |
||||
219 | * @return bool|int |
||||
220 | */ |
||||
221 | 1 | public function canEdit($member = null) |
|||
222 | { |
||||
223 | 1 | return Permission::check('JOB_MANAGE', 'any', $member); |
|||
224 | } |
||||
225 | |||||
226 | /** |
||||
227 | * @param null $member |
||||
0 ignored issues
–
show
|
|||||
228 | * |
||||
229 | * @return bool|int |
||||
230 | */ |
||||
231 | 1 | public function canDelete($member = null) |
|||
232 | { |
||||
233 | 1 | return Permission::check('JOB_MANAGE', 'any', $member); |
|||
234 | } |
||||
235 | |||||
236 | /** |
||||
237 | * @param null $member |
||||
0 ignored issues
–
show
|
|||||
238 | * |
||||
239 | * @return bool|int |
||||
240 | */ |
||||
241 | 1 | public function canCreate($member = null, $contect = []) |
|||
242 | { |
||||
243 | 1 | return Permission::check('JOB_MANAGE', 'any', $member); |
|||
244 | } |
||||
245 | |||||
246 | /** |
||||
247 | * @param null $member |
||||
0 ignored issues
–
show
|
|||||
248 | * |
||||
249 | * @return bool |
||||
250 | */ |
||||
251 | 9 | public function canView($member = null) |
|||
252 | { |
||||
253 | 9 | return Permission::check('JOB_MANAGE', 'any', $member); |
|||
254 | } |
||||
255 | } |
||||
256 |