Source of file Job.php
Size: 9,352 Bytes - Last Modified: 2021-12-24T06:46:18+00:00
/var/www/docs.ssmods.com/process/src/src/Page/Job.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 | <?php namespace Dynamic\Jobs\Page; use Dynamic\Jobs\Model\JobCategory; use Dynamic\Jobs\Model\JobSection; use Dynamic\Jobs\Model\JobSubmission; use \Page; use SilverStripe\Control\Controller; use SilverStripe\Forms\DateField; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; use SilverStripe\Forms\GridField\GridFieldDeleteAction; use SilverStripe\Forms\ListboxField; use SilverStripe\Forms\TreeMultiselectField; use SilverStripe\ORM\Search\SearchContext; use SilverStripe\Security\Permission; use SilverStripe\Security\PermissionProvider; use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton; use Symbiote\GridFieldExtensions\GridFieldOrderableRows; /** * Class Job * @package Dynamic\Jobs\Model */ class Job extends Page implements PermissionProvider { /** * @var string */ private static $table_name = 'Dynamic_Job'; /** * @var array */ private static $db = [ 'PositionType' => "Enum(array('Full-time', 'Part-time', 'Freelance', 'Internship'))", 'PostDate' => 'Date', 'EndPostDate' => 'Date', ]; /** * @var array */ private static $has_many = [ 'Sections' => JobSection::class, 'Submissions' => JobSubmission::class, ]; /** * @var array */ private static $many_many = [ 'Categories' => JobCategory::class, ]; /** * @var array */ private static $many_many_extraFields = [ 'Categories' => [ 'Sort' => 'Int', ], ]; /** * @var array */ private static $searchable_fields = [ 'Title', 'Categories.ID' => [ 'title' => 'Category', ], 'PositionType' => [ 'title' => 'Type', ], ]; /** * @var string */ private static $default_parent = JobCollection::class; /** * @var bool */ private static $can_be_root = false; /** * @var bool */ private static $show_in_sitetree = false; /** * @var array */ private static $allowed_children = []; /** * @return SearchContext */ public function getCustomSearchContext() { $fields = $this->scaffoldSearchFields([ 'restrictFields' => [ 'Title', 'Categories.ID', 'PositionType', ], ]); $filters = $this->defaultSearchFilters(); return new SearchContext( $this->ClassName, $fields, $filters ); } /** * */ public function populateDefaults() { $this->PostDate = date('Y-m-d'); parent::populateDefaults(); } /** * @param bool $includerelations * @return array */ public function fieldLabels($includerelations = true) { $labels = parent::fieldLabels($includerelations); $labels['Title'] = _t(__CLASS__ . '.TitleLabel', 'Position Name'); $labels['Content'] = _t(__CLASS__ . '.ContentLabel', 'Introduction'); $labels['PositionType'] = _t(__CLASS__ . '.PositionTypeLabel', 'Position Type'); $labels['PostDate'] = _t(__CLASS__ . '.PostDateLabel', 'Post Start Date'); $labels['EndPostDate'] = _t(__CLASS__ . '.EndPostDateLabel', 'Post End Date'); $labels['Details'] = _t(__CLASS__ . '.DetailsTab', "Details"); $labels['Submissions'] = _t(__CLASS__ . '.SubmissionsTab', 'Submissions'); //$labels['Categories'] = _t(JobCategory::class . '.SlideType', 'Image or Video'); return $labels; } /** * @return FieldList */ public function getCMSFields() { $this->beforeUpdateCMSFields(function ($fields) { $fields->dataFieldByName('Content') ->setTitle($this->fieldLabel('Content')) ->setRows(10); $fields->addFieldsToTab('Root.' . $this->fieldLabel('Details'), [ DropdownField::create( 'PositionType', $this->fieldLabel('PositionType'), Job::singleton()->dbObject('PositionType')->enumValues() )->setEmptyString('--select--'), DateField::create('PostDate', $this->fieldLabel('PostDate')) ->setDescription(_t( __CLASS__ . '.PostDateDescription', 'Date position should appear on website' )), DateField::create('EndPostDate', $this->fieldLabel('EndPostDate')) ->setDescription(_t( __CLASS__ . '.EndPostDateDescription', 'Date position should be removed from website' )), ]); if ($this->ID) { // categories $categoriesField = ListboxField::create( 'Categories', _t(JobCategory::class . '.PLURALNAME', 'Categories'), JobCategory::get()->map() ); $fields->addFieldsToTab('Root.' . $this->fieldLabel('Details'), [ $categoriesField, ]); // sections $config = GridFieldConfig_RelationEditor::create(); $config ->addComponent(new GridFieldOrderableRows('Sort')) ->addComponent(new GridFieldDeleteAction(false)) ->removeComponentsByType(GridFieldAddExistingAutocompleter::class) ->removeComponentsByType(GridFieldDeleteAction::class); $sections = $this->Sections()->sort('Sort'); $sectionsField = GridField::create( 'Sections', _t(JobSection::class . '.PLURALNAME', 'Sections'), $sections, $config ) ->setDescription(_t( __CLASS__ . '.SectionsDescription', 'ex: Requirements, Education, Duties, etc.' )); $fields->addFieldsToTab('Root.Main', [ $sectionsField, ]); // submissions $config = GridFieldConfig_RelationEditor::create(); $config ->addComponent(new GridFieldDeleteAction(false)) ->removeComponentsByType(GridFieldAddExistingAutocompleter::class) ->removeComponentsByType(GridFieldDeleteAction::class); $submissions = $this->Submissions(); $submissionsField = GridField::create( 'Submissions', _t(JobSubmission::class . '.PLURALNAME', 'Submissions'), $submissions, $config ) ; $fields->addFieldsToTab('Root.' . $this->fieldLabel('Submissions'), [ $submissionsField, ]); } }); return parent::getCMSFields(); } /** * @return string */ public function getApplyButton() { $apply = Controller::join_links( $this->Link(), 'apply' ); return $apply; } /** * @return mixed */ public function getApplicationLink() { if ($this->parent()->Application()->ID != 0) { return $this->parent()->Application()->URL; } return false; } /** * @return mixed */ public function getCategoryList() { return $this->Categories()->sort('Sort'); } /** * @return bool */ public function getPrimaryCategory() { if ($this->Categories()->exists()) { return $this->Categories()->first(); } return false; } /** * @return array */ public function providePermissions() { return [ 'JOB_MANAGE' => [ 'name' => _t( __CLASS__ . '.JOB_MANAGE', 'Manage Jobs' ), 'category' => _t( __CLASS__ . '.JOB_MANAGE_CATEGORY', 'Jobs' ), 'help' => _t( __CLASS__ . '.JOB_MANAGE_HELP', 'Access to add, edit and delete Jobs' ), 'sort' => 400, ], ]; } /** * @param null $member * * @return bool|int */ public function canEdit($member = null) { return Permission::check('JOB_MANAGE', 'any', $member); } /** * @param null $member * * @return bool|int */ public function canDelete($member = null) { return Permission::check('JOB_MANAGE', 'any', $member); } /** * @param null $member * * @return bool|int */ public function canCreate($member = null, $context = []) { return Permission::check('JOB_MANAGE', 'any', $member); } } |