dynamic /
silverstripe-jobs
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Dynamic\Jobs\Page; |
||||||
| 4 | |||||||
| 5 | use Dynamic\Jobs\Model\JobCategory; |
||||||
| 6 | use Dynamic\Jobs\Model\JobSection; |
||||||
| 7 | use Dynamic\Jobs\Model\JobSubmission; |
||||||
| 8 | use \Page; |
||||||
| 9 | use SilverStripe\Control\Controller; |
||||||
| 10 | use SilverStripe\Forms\DateField; |
||||||
| 11 | use SilverStripe\Forms\DropdownField; |
||||||
| 12 | use SilverStripe\Forms\FieldList; |
||||||
| 13 | use SilverStripe\Forms\GridField\GridField; |
||||||
| 14 | use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; |
||||||
| 15 | use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; |
||||||
| 16 | use SilverStripe\Forms\GridField\GridFieldDeleteAction; |
||||||
| 17 | use SilverStripe\Forms\ListboxField; |
||||||
| 18 | use SilverStripe\Forms\TreeMultiselectField; |
||||||
| 19 | use SilverStripe\ORM\Search\SearchContext; |
||||||
| 20 | use SilverStripe\Security\Permission; |
||||||
| 21 | use SilverStripe\Security\PermissionProvider; |
||||||
| 22 | use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton; |
||||||
| 23 | use Symbiote\GridFieldExtensions\GridFieldOrderableRows; |
||||||
| 24 | |||||||
| 25 | /** |
||||||
| 26 | * Class Job |
||||||
| 27 | * @package Dynamic\Jobs\Model |
||||||
| 28 | */ |
||||||
| 29 | class Job extends Page implements PermissionProvider |
||||||
| 30 | { |
||||||
| 31 | /** |
||||||
| 32 | * @var string |
||||||
| 33 | */ |
||||||
| 34 | private static $table_name = 'Dynamic_Job'; |
||||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||||
| 35 | |||||||
| 36 | /** |
||||||
| 37 | * @var array |
||||||
| 38 | */ |
||||||
| 39 | private static $db = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 40 | 'PositionType' => "Enum(array('Full-time', 'Part-time', 'Freelance', 'Internship'))", |
||||||
| 41 | 'PostDate' => 'Date', |
||||||
| 42 | 'EndPostDate' => 'Date', |
||||||
| 43 | ]; |
||||||
| 44 | |||||||
| 45 | /** |
||||||
| 46 | * @var array |
||||||
| 47 | */ |
||||||
| 48 | private static $has_many = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 49 | 'Sections' => JobSection::class, |
||||||
| 50 | 'Submissions' => JobSubmission::class, |
||||||
| 51 | ]; |
||||||
| 52 | |||||||
| 53 | /** |
||||||
| 54 | * @var array |
||||||
| 55 | */ |
||||||
| 56 | private static $many_many = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 57 | 'Categories' => JobCategory::class, |
||||||
| 58 | ]; |
||||||
| 59 | |||||||
| 60 | /** |
||||||
| 61 | * @var array |
||||||
| 62 | */ |
||||||
| 63 | private static $many_many_extraFields = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 64 | 'Categories' => [ |
||||||
| 65 | 'Sort' => 'Int', |
||||||
| 66 | ], |
||||||
| 67 | ]; |
||||||
| 68 | |||||||
| 69 | /** |
||||||
| 70 | * @var array |
||||||
| 71 | */ |
||||||
| 72 | private static $searchable_fields = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 73 | 'Title', |
||||||
| 74 | 'Categories.ID' => [ |
||||||
| 75 | 'title' => 'Category', |
||||||
| 76 | ], |
||||||
| 77 | 'PositionType' => [ |
||||||
| 78 | 'title' => 'Type', |
||||||
| 79 | ], |
||||||
| 80 | ]; |
||||||
| 81 | |||||||
| 82 | /** |
||||||
| 83 | * @var string |
||||||
| 84 | */ |
||||||
| 85 | private static $default_parent = JobCollection::class; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 86 | |||||||
| 87 | /** |
||||||
| 88 | * @var bool |
||||||
| 89 | */ |
||||||
| 90 | private static $can_be_root = false; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 91 | |||||||
| 92 | /** |
||||||
| 93 | * @var bool |
||||||
| 94 | */ |
||||||
| 95 | private static $show_in_sitetree = false; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 96 | |||||||
| 97 | /** |
||||||
| 98 | * @var array |
||||||
| 99 | */ |
||||||
| 100 | private static $allowed_children = []; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 101 | |||||||
| 102 | /** |
||||||
| 103 | * @return SearchContext |
||||||
| 104 | */ |
||||||
| 105 | public function getCustomSearchContext() |
||||||
| 106 | { |
||||||
| 107 | $fields = $this->scaffoldSearchFields([ |
||||||
| 108 | 'restrictFields' => [ |
||||||
| 109 | 'Title', |
||||||
| 110 | 'Categories.ID', |
||||||
| 111 | 'PositionType', |
||||||
| 112 | ], |
||||||
| 113 | ]); |
||||||
| 114 | |||||||
| 115 | $filters = $this->defaultSearchFilters(); |
||||||
| 116 | |||||||
| 117 | return new SearchContext( |
||||||
| 118 | $this->ClassName, |
||||||
| 119 | $fields, |
||||||
| 120 | $filters |
||||||
| 121 | ); |
||||||
| 122 | } |
||||||
| 123 | |||||||
| 124 | /** |
||||||
| 125 | * |
||||||
| 126 | */ |
||||||
| 127 | 14 | public function populateDefaults() |
|||||
| 128 | { |
||||||
| 129 | 14 | $this->PostDate = date('Y-m-d'); |
|||||
|
0 ignored issues
–
show
|
|||||||
| 130 | |||||||
| 131 | 14 | parent::populateDefaults(); |
|||||
| 132 | } |
||||||
| 133 | |||||||
| 134 | /** |
||||||
| 135 | * @param bool $includerelations |
||||||
| 136 | * @return array |
||||||
| 137 | */ |
||||||
| 138 | 1 | public function fieldLabels($includerelations = true) |
|||||
| 139 | { |
||||||
| 140 | 1 | $labels = parent::fieldLabels($includerelations); |
|||||
| 141 | |||||||
| 142 | 1 | $labels['Title'] = _t(__CLASS__ . '.TitleLabel', 'Position Name'); |
|||||
| 143 | 1 | $labels['Content'] = _t(__CLASS__ . '.ContentLabel', 'Introduction'); |
|||||
| 144 | 1 | $labels['PositionType'] = _t(__CLASS__ . '.PositionTypeLabel', 'Position Type'); |
|||||
| 145 | 1 | $labels['PostDate'] = _t(__CLASS__ . '.PostDateLabel', 'Post Start Date'); |
|||||
| 146 | 1 | $labels['EndPostDate'] = _t(__CLASS__ . '.EndPostDateLabel', 'Post End Date'); |
|||||
| 147 | 1 | $labels['Details'] = _t(__CLASS__ . '.DetailsTab', "Details"); |
|||||
| 148 | 1 | $labels['Submissions'] = _t(__CLASS__ . '.SubmissionsTab', 'Submissions'); |
|||||
| 149 | //$labels['Categories'] = _t(JobCategory::class . '.SlideType', 'Image or Video'); |
||||||
| 150 | |||||||
| 151 | 1 | return $labels; |
|||||
| 152 | } |
||||||
| 153 | |||||||
| 154 | /** |
||||||
| 155 | * @return FieldList |
||||||
| 156 | */ |
||||||
| 157 | public function getCMSFields() |
||||||
| 158 | { |
||||||
| 159 | 1 | $this->beforeUpdateCMSFields(function ($fields) { |
|||||
| 160 | 1 | $fields->dataFieldByName('Content') |
|||||
| 161 | 1 | ->setTitle($this->fieldLabel('Content')) |
|||||
| 162 | 1 | ->setRows(10); |
|||||
| 163 | |||||||
| 164 | 1 | $fields->addFieldsToTab('Root.' . $this->fieldLabel('Details'), [ |
|||||
| 165 | 1 | DropdownField::create( |
|||||
| 166 | 1 | 'PositionType', |
|||||
| 167 | 1 | $this->fieldLabel('PositionType'), |
|||||
| 168 | 1 | Job::singleton()->dbObject('PositionType')->enumValues() |
|||||
| 169 | 1 | )->setEmptyString('--select--'), |
|||||
| 170 | 1 | DateField::create('PostDate', $this->fieldLabel('PostDate')) |
|||||
| 171 | 1 | ->setDescription(_t( |
|||||
| 172 | 1 | __CLASS__ . '.PostDateDescription', |
|||||
| 173 | 1 | 'Date position should appear on website' |
|||||
| 174 | )), |
||||||
| 175 | 1 | DateField::create('EndPostDate', $this->fieldLabel('EndPostDate')) |
|||||
| 176 | 1 | ->setDescription(_t( |
|||||
| 177 | 1 | __CLASS__ . '.EndPostDateDescription', |
|||||
| 178 | 1 | 'Date position should be removed from website' |
|||||
| 179 | )), |
||||||
| 180 | ]); |
||||||
| 181 | |||||||
| 182 | 1 | if ($this->ID) { |
|||||
| 183 | // categories |
||||||
| 184 | 1 | $categoriesField = ListboxField::create( |
|||||
| 185 | 1 | 'Categories', |
|||||
| 186 | 1 | _t(JobCategory::class . '.PLURALNAME', 'Categories'), |
|||||
| 187 | 1 | JobCategory::get()->map() |
|||||
| 188 | ); |
||||||
| 189 | |||||||
| 190 | 1 | $fields->addFieldsToTab('Root.' . $this->fieldLabel('Details'), [ |
|||||
| 191 | 1 | $categoriesField, |
|||||
| 192 | ]); |
||||||
| 193 | |||||||
| 194 | // sections |
||||||
| 195 | 1 | $config = GridFieldConfig_RelationEditor::create(); |
|||||
| 196 | $config |
||||||
| 197 | 1 | ->addComponent(new GridFieldOrderableRows('Sort')) |
|||||
| 198 | 1 | ->addComponent(new GridFieldDeleteAction(false)) |
|||||
| 199 | 1 | ->removeComponentsByType(GridFieldAddExistingAutocompleter::class) |
|||||
| 200 | 1 | ->removeComponentsByType(GridFieldDeleteAction::class); |
|||||
| 201 | |||||||
| 202 | 1 | $sections = $this->Sections()->sort('Sort'); |
|||||
|
0 ignored issues
–
show
The method
Sections() does not exist on Dynamic\Jobs\Page\Job. 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
Loading history...
|
|||||||
| 203 | 1 | $sectionsField = GridField::create( |
|||||
| 204 | 1 | 'Sections', |
|||||
| 205 | 1 | _t(JobSection::class . '.PLURALNAME', 'Sections'), |
|||||
| 206 | 1 | $sections, |
|||||
| 207 | 1 | $config |
|||||
| 208 | ) |
||||||
| 209 | 1 | ->setDescription(_t( |
|||||
| 210 | 1 | __CLASS__ . '.SectionsDescription', |
|||||
| 211 | 1 | 'ex: Requirements, Education, Duties, etc.' |
|||||
| 212 | )); |
||||||
| 213 | |||||||
| 214 | 1 | $fields->addFieldsToTab('Root.Main', [ |
|||||
| 215 | 1 | $sectionsField, |
|||||
| 216 | ]); |
||||||
| 217 | |||||||
| 218 | // submissions |
||||||
| 219 | 1 | $config = GridFieldConfig_RelationEditor::create(); |
|||||
| 220 | $config |
||||||
| 221 | 1 | ->addComponent(new GridFieldDeleteAction(false)) |
|||||
| 222 | 1 | ->removeComponentsByType(GridFieldAddExistingAutocompleter::class) |
|||||
| 223 | 1 | ->removeComponentsByType(GridFieldDeleteAction::class); |
|||||
| 224 | |||||||
| 225 | 1 | $submissions = $this->Submissions(); |
|||||
|
0 ignored issues
–
show
The method
Submissions() does not exist on Dynamic\Jobs\Page\Job. 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
Loading history...
|
|||||||
| 226 | 1 | $submissionsField = GridField::create( |
|||||
| 227 | 1 | 'Submissions', |
|||||
| 228 | 1 | _t(JobSubmission::class . '.PLURALNAME', 'Submissions'), |
|||||
| 229 | 1 | $submissions, |
|||||
| 230 | 1 | $config |
|||||
| 231 | ) |
||||||
| 232 | ; |
||||||
| 233 | 1 | $fields->addFieldsToTab('Root.' . $this->fieldLabel('Submissions'), [ |
|||||
| 234 | 1 | $submissionsField, |
|||||
| 235 | ]); |
||||||
| 236 | } |
||||||
| 237 | 1 | }); |
|||||
| 238 | |||||||
| 239 | 1 | return parent::getCMSFields(); |
|||||
| 240 | } |
||||||
| 241 | |||||||
| 242 | /** |
||||||
| 243 | * @return string |
||||||
| 244 | */ |
||||||
| 245 | 1 | public function getApplyButton() |
|||||
| 246 | { |
||||||
| 247 | 1 | $apply = Controller::join_links( |
|||||
| 248 | 1 | $this->Link(), |
|||||
| 249 | 1 | 'apply' |
|||||
| 250 | ); |
||||||
| 251 | 1 | return $apply; |
|||||
| 252 | } |
||||||
| 253 | |||||||
| 254 | /** |
||||||
| 255 | * @return mixed |
||||||
| 256 | */ |
||||||
| 257 | 1 | public function getApplicationLink() |
|||||
| 258 | { |
||||||
| 259 | 1 | if ($this->parent()->Application()->ID != 0) { |
|||||
| 260 | return $this->parent()->Application()->URL; |
||||||
| 261 | } |
||||||
| 262 | 1 | return false; |
|||||
| 263 | } |
||||||
| 264 | |||||||
| 265 | /** |
||||||
| 266 | * @return mixed |
||||||
| 267 | */ |
||||||
| 268 | public function getCategoryList() |
||||||
| 269 | { |
||||||
| 270 | return $this->Categories()->sort('Sort'); |
||||||
|
0 ignored issues
–
show
The method
Categories() does not exist on Dynamic\Jobs\Page\Job. 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
Loading history...
|
|||||||
| 271 | } |
||||||
| 272 | |||||||
| 273 | /** |
||||||
| 274 | * @return bool |
||||||
| 275 | */ |
||||||
| 276 | public function getPrimaryCategory() |
||||||
| 277 | { |
||||||
| 278 | if ($this->Categories()->exists()) { |
||||||
| 279 | return $this->Categories()->first(); |
||||||
| 280 | } |
||||||
| 281 | return false; |
||||||
| 282 | } |
||||||
| 283 | |||||||
| 284 | /** |
||||||
| 285 | * @return array |
||||||
| 286 | */ |
||||||
| 287 | public function providePermissions() |
||||||
| 288 | { |
||||||
| 289 | return [ |
||||||
| 290 | 'JOB_MANAGE' => [ |
||||||
| 291 | 'name' => _t( |
||||||
| 292 | __CLASS__ . '.JOB_MANAGE', |
||||||
| 293 | 'Manage Jobs' |
||||||
| 294 | ), |
||||||
| 295 | 'category' => _t( |
||||||
| 296 | __CLASS__ . '.JOB_MANAGE_CATEGORY', |
||||||
| 297 | 'Jobs' |
||||||
| 298 | ), |
||||||
| 299 | 'help' => _t( |
||||||
| 300 | __CLASS__ . '.JOB_MANAGE_HELP', |
||||||
| 301 | 'Access to add, edit and delete Jobs' |
||||||
| 302 | ), |
||||||
| 303 | 'sort' => 400, |
||||||
| 304 | ], |
||||||
| 305 | ]; |
||||||
| 306 | } |
||||||
| 307 | |||||||
| 308 | /** |
||||||
| 309 | * @param null $member |
||||||
|
0 ignored issues
–
show
|
|||||||
| 310 | * |
||||||
| 311 | * @return bool|int |
||||||
| 312 | */ |
||||||
| 313 | 1 | public function canEdit($member = null) |
|||||
| 314 | { |
||||||
| 315 | 1 | return Permission::check('JOB_MANAGE', 'any', $member); |
|||||
| 316 | } |
||||||
| 317 | |||||||
| 318 | /** |
||||||
| 319 | * @param null $member |
||||||
|
0 ignored issues
–
show
|
|||||||
| 320 | * |
||||||
| 321 | * @return bool|int |
||||||
| 322 | */ |
||||||
| 323 | 1 | public function canDelete($member = null) |
|||||
| 324 | { |
||||||
| 325 | 1 | return Permission::check('JOB_MANAGE', 'any', $member); |
|||||
| 326 | } |
||||||
| 327 | |||||||
| 328 | /** |
||||||
| 329 | * @param null $member |
||||||
|
0 ignored issues
–
show
|
|||||||
| 330 | * |
||||||
| 331 | * @return bool|int |
||||||
| 332 | */ |
||||||
| 333 | 1 | public function canCreate($member = null, $context = []) |
|||||
| 334 | { |
||||||
| 335 | 1 | return Permission::check('JOB_MANAGE', 'any', $member); |
|||||
| 336 | } |
||||||
| 337 | } |
||||||
| 338 |