Source of file JobAdderJobBoardPageController.php
Size: 13,394 Bytes - Last Modified: 2022-01-13T10:01:37+00:00
/var/www/docs.ssmods.com/process/src/src/Pages/JobAdderJobBoardPageController.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553 | <?php namespace BiffBangPow\JobAdderJobBoard\Pages; use BiffBangPow\JobAdderJobBoard\DataObjects\JobAd; use BiffBangPow\JobAdderJobBoard\DataObjects\JobCategory; use BiffBangPow\JobAdderJobBoard\DataObjects\JobCountry; use BiffBangPow\JobAdderJobBoard\DataObjects\JobCurrency; use BiffBangPow\JobAdderJobBoard\DataObjects\JobLocation; use BiffBangPow\JobAdderJobBoard\DataObjects\JobSalaryFrequency; use BiffBangPow\JobAdderJobBoard\DataObjects\JobWorkType; use PageController; use SilverStripe\Control\HTTPRequest; use SilverStripe\ORM\DataList; use SilverStripe\ORM\PaginatedList; class JobAdderJobBoardPageController extends PageController { const SEARCH = 's'; const COUNTRY = 'co'; const LOCATION = 'lo'; const CATEGORY = 'ca'; const SUB_CATEGORY = 'sca'; const CURRENCY = 'cu'; const SALARY_MIN = 'smin'; const SALARY_MAX = 'smax'; const SALARY_PER = 'sper'; const WORK_TYPE = 'wt'; public $filters = []; public $anyFilters = []; /** * @var array */ private static $allowed_actions = [ 'job', 'apply', ]; /** * @return PaginatedList * @throws \Exception */ public function Results() { $dataList = JobAd::get(); $this->filters = [ 'ExpiresAt:GreaterThanOrEqual' => date('Y-m-d'), ]; $this->anyFilters = []; /** @var HTTPRequest $request */ $request = $this->getRequest(); $search = $request->getVar(self::SEARCH); if ($this->isParameterSet($search)) { $this->filters['Title:PartialMatch'] = $search; } $countryID = $request->getVar(self::COUNTRY); if ($this->isParameterSet($countryID)) { $this->filters['Country.ID'] = $countryID; } $locationID = $request->getVar(self::LOCATION); if ($this->isParameterSet($locationID)) { $this->filters['Location.ID'] = $locationID; } $categoryID = $request->getVar(self::CATEGORY); if ($this->isParameterSet($categoryID)) { $this->filters['Category.ID'] = $categoryID; } $subCategoryID = $request->getVar(self::SUB_CATEGORY); if ($this->isParameterSet($subCategoryID)) { $this->filters['SubCategory.ID'] = $subCategoryID; } $salaryMin = $request->getVar(self::SALARY_MIN); if ($this->isParameterSet($salaryMin)) { $this->filters['SalaryRateLow:GreaterThanOrEqual'] = $salaryMin; } $salaryMax = $request->getVar(self::SALARY_MAX); if ($this->isParameterSet($salaryMax)) { $this->filters['SalaryRateHigh:LessThanOrEqual'] = $salaryMax; } $currencyID = $request->getVar(self::CURRENCY); if ($this->isParameterSet($currencyID)) { $this->filters['Currency.ID'] = $currencyID; } $salaryRatePer = $request->getVar(self::SALARY_PER); if ($this->isParameterSet($salaryRatePer)) { $this->filters['SalaryFrequency.ID'] = $salaryRatePer; } $workTypeID = $request->getVar(self::WORK_TYPE); if ($this->isParameterSet($workTypeID)) { $this->filters['WorkType.ID'] = $workTypeID; } $this->extend('updateResults', $request, $this->filters, $this->anyFilters); $dataList = $dataList->filter($this->filters); if (count($this->anyFilters) > 0) { $dataList = $dataList->filterAny($this->anyFilters); } $dataList = $dataList->sort('PostedAt', 'DESC'); $paginatedList = new PaginatedList($dataList, $request); $paginatedList->setPageLength($this->JobsPerPage); return $paginatedList; } /** * @param HTTPRequest $request * @return array * @throws \Exception */ public function index(HTTPRequest $request) { return [ 'Results' => $this->Results(), ]; } /** * @param HTTPRequest $request * @return array * @throws \Exception */ public function job(HTTPRequest $request) { $jobAd = JobAd::get()->filter(['Slug' => $request->param('ID')])->first(); if(!$jobAd) { return $this->httpError(404,'That job ad could not be found'); } return [ 'JobAd' => $jobAd ]; } /** * @param HTTPRequest $request * @return array * @throws \Exception */ public function apply(HTTPRequest $request) { $jobAd = JobAd::get()->filter(['Slug' => $request->param('ID')])->first(); if(!$jobAd) { return $this->httpError(404,'That job ad could not be found'); } return [ 'JobAd' => $jobAd ]; } /** * @return bool */ public function getSearch() { $search = $this->getRequest()->getVar(self::SEARCH); return $search; } /** * @return DataList */ public function getCountries() { return JobCountry::get(); } /** * @return string */ public function getCountryParam() { return self::COUNTRY; } /** * @param int $countryId * @return bool */ public function IsSelectedCountry(int $countryId) { $countryIds = $this->getRequest()->getVar(self::COUNTRY); if (!is_null($countryIds)) { if (is_array($countryIds)) { return in_array($countryId, $countryIds); } else { return ((int)$countryIds === (int)$countryId); } } return false; } /** * @return bool */ public function IsSelectedCountries() { $countryIds = $this->getRequest()->getVar(self::COUNTRY); return (!is_null($countryIds)); } /** * @return string */ public function getLocationParam() { return self::LOCATION; } /** * @return DataList */ public function getLocations() { return JobLocation::get(); } /** * @param int $locationId * @return bool */ public function IsSelectedLocation(int $locationId) { $locationIds = $this->getRequest()->getVar(self::LOCATION); if (!is_null($locationIds)) { if (is_array($locationIds)) { return in_array($locationId, $locationIds); } else { return ((int)$locationIds === (int)$locationId); } } return false; } /** * @return bool */ public function IsSelectedLocations() { $locationIds = $this->getRequest()->getVar(self::LOCATION); return (!is_null($locationIds)); } /** * @param $countryId * @return bool */ public function IsSelectedLocationsInCountry($countryId) { $locationsIds = $this->getRequest()->getVar(self::LOCATION); if (is_array($locationsIds)) { /** @var JobCountry $country */ $country = JobCountry::get()->filter(['ID' => $countryId])->first(); $locationIdsFromCountry = $country->Locations()->map()->toArray(); $commonIds = array_intersect(array_keys($locationIdsFromCountry), $locationsIds); return (count($commonIds) > 0); } return false; } /** * @return DataList */ public function getCategories() { return JobCategory::get(); } /** * @return string */ public function getCategoryParam() { return self::CATEGORY; } /** * @param int $categoryId * @return bool */ public function IsSelectedCategory(int $categoryId) { $categoryIds = $this->getRequest()->getVar(self::CATEGORY); if (!is_null($categoryIds)) { if (is_array($categoryIds)) { return in_array($categoryId, $categoryIds); } else { return ((int)$categoryIds === (int)$categoryId); } } return false; } /** * @return bool */ public function IsSelectedCategories() { $categoryIds = $this->getRequest()->getVar(self::CATEGORY); return (!is_null($categoryIds)); } /** * @return string */ public function getSubCategoryParam() { return self::SUB_CATEGORY; } /** * @param int $subCategoryId * @return bool */ public function IsSelectedSubCategory(int $subCategoryId) { $subCategoryIds = $this->getRequest()->getVar(self::SUB_CATEGORY); if (!is_null($subCategoryIds)) { if (is_array($subCategoryIds)) { return in_array($subCategoryId, $subCategoryIds); } else { return ((int)$subCategoryIds === (int)$subCategoryId); } } return false; } /** * @return bool */ public function IsSelectedSubCategories() { $subCategoryIds = $this->getRequest()->getVar(self::SUB_CATEGORY); return (!is_null($subCategoryIds)); } /** * @param $categoryId * @return bool */ public function IsSelectedSubCategoriesInCategory($categoryId) { $subCategoryIds = $this->getRequest()->getVar(self::SUB_CATEGORY); if (is_array($subCategoryIds)) { /** @var JobCategory $category */ $category = JobCategory::get()->filter(['ID' => $categoryId])->first(); $subCategoryIdsFromCategory = $category->SubCategories()->map()->toArray(); $commonIds = array_intersect(array_keys($subCategoryIdsFromCategory), $subCategoryIds); return (count($commonIds) > 0); } return false; } /** * @return DataList */ public function getWorkTypes() { return JobWorkType::get(); } /** * @return string */ public function getWorkTypeParam() { return self::WORK_TYPE; } /** * @param int $workType * @return bool */ public function IsSelectedWorkType(int $workType) { $workTypeIds = $this->getRequest()->getVar(self::WORK_TYPE); if (!is_null($workTypeIds)) { if (is_array($workTypeIds)) { return in_array($workType, $workTypeIds); } else { return ((int)$workTypeIds === (int)$workType); } } return false; } /** * @return bool */ public function IsSelectedWorkTypes() { $workTypeIds = $this->getRequest()->getVar(self::WORK_TYPE); return (!is_null($workTypeIds)); } /** * @return DataList */ public function getCurrencies() { return JobCurrency::get(); } /** * @return string */ public function getCurrencyParam() { return self::CURRENCY; } /** * @param string $currency * @return bool */ public function IsSelectedCurrency(string $currency) { $currencyId = $this->getRequest()->getVar(self::CURRENCY); return ($currencyId === $currency); } /** * @return DataList */ public function getSalaryFrequencies() { return JobSalaryFrequency::get(); } /** * @return string */ public function getSalaryFrequencyParam() { return self::SALARY_PER; } /** * @param string $salaryFrequency * @return bool */ public function IsSelectedSalaryFrequency(string $salaryFrequency) { $salaryFrequencyId = $this->getRequest()->getVar(self::SALARY_PER); return ($salaryFrequencyId === $salaryFrequency); } /** * @return bool */ public function getSalaryMinimum() { $salaryMinimum = $this->getRequest()->getVar(self::SALARY_MIN); return $salaryMinimum; } /** * @return bool */ public function getSalaryMaximum() { $salaryMax = $this->getRequest()->getVar(self::SALARY_MAX); return $salaryMax; } /** * @return bool */ public function getSalaryPer() { $salaryPer = $this->getRequest()->getVar(self::SALARY_PER); return $salaryPer; } /** * @return bool */ public function IsSelectedSalaryFields() { $currencyId = $this->getRequest()->getVar(self::CURRENCY); if ($currencyId !== null && $currencyId !== 'All') { return true; } $salaryMin = $this->getRequest()->getVar(self::SALARY_MIN); if ($salaryMin !== null && $salaryMin !== '') { return true; } $salaryMax = $this->getRequest()->getVar(self::SALARY_MAX); if ($salaryMax !== null && $salaryMax !== '') { return true; } $salaryPer = $this->getRequest()->getVar(self::SALARY_PER); if ($salaryPer !== null && $salaryPer !== 'Any') { return true; } return false; } /** * @param $parameter * @return bool */ public function isParameterSet($parameter) { return (!is_null($parameter) && $parameter !== 0 && $parameter !== '0' && $parameter !== '' && $parameter !== 'Any' && $parameter !== 'All'); } } |