Skip to content

Commit

Permalink
Merge pull request #4 from fritzmg/sitemap
Browse files Browse the repository at this point in the history
Implement sitemap
  • Loading branch information
Stefanmelz authored Feb 4, 2022
2 parents f92128a + e776b8f commit b4a58b6
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 11 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}
],
"require": {
"php": ">=5.4",
"contao/core-bundle": "^4.4.8"
},
"extra": {
Expand Down
96 changes: 96 additions & 0 deletions src/EventListener/GetSearchablePagesListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace Slashworks\ContaoSimpleJobManagerBundle\EventListener;

use Contao\ContentModel;
use Contao\Date;
use Contao\ModuleModel;
use Contao\PageModel;
use Contao\StringUtil;
use Slashworks\ContaoSimpleJobManagerBundle\Models\Jobs;

class GetSearchablePagesListener
{
/**
* @param array $pages
* @param int|null $rootId
* @param bool $isSitemap
* @param string $language
*
* @return array
*/
public function __invoke($pages, $rootId = null, $isSitemap = false, $language = null)
{
// Load all job list modules
$modules = ModuleModel::findByType('job-list');

if (null === $modules) {
return $pages;
}

$detailPageIds = [];

foreach ($modules as $module) {
// Check if the module has a detail page defined
if (empty($module->jumpTo)) {
continue;
}

// Find all content elements integrating this module
$time = Date::floorToMinute();
$elements = ContentModel::findBy([
"invisible='' AND (start='' OR start<='$time') AND (stop='' OR stop>'$time')",
"type = 'module'",
"ptable = 'tl_article'",
'module = ?',
], [$module->id]);

if (null === $elements) {
continue;
}

// Check if we already processed this detail page
if (\in_array((int) $module->jumpTo, $detailPageIds, true)) {
continue;
}

$detailPageIds[] = (int) $module->jumpTo;
$page = PageModel::findPublishedById((int) $module->jumpTo);

if (null === $page) {
continue;
}

// Check if indexing is disabled
if ('noindex,nofollow' === $page->robots) {
continue;
}

$page->loadDetails();

// Check if page belongs to current root
if (null !== $rootId && (int) $rootId !== (int) $page->rootId) {
continue;
}

// Load all jobs for this list
$organisations = StringUtil::deserialize($module->organisation, true);

if (empty($organisations)) {
continue;
}

$jobs = Jobs::findBy(['pid IN(' . implode(',', array_map('intval', $organisations)) . ')'], []);

if (null === $jobs) {
continue;
}

foreach ($jobs as $job) {
$pages[] = $page->getAbsoluteUrl('/'.$job->alias);
}
}

return $pages;
}
}
19 changes: 9 additions & 10 deletions src/Module/JobList.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
namespace Slashworks\ContaoSimpleJobManagerBundle\Module;

use Contao\Controller;
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\Date;
use Contao\FilesModel;
use Contao\Image\PictureConfiguration;
use Contao\Input;
use Contao\Module;
use Contao\PageModel;
use Contao\StringUtil;
use Slashworks\ContaoSimpleJobManagerBundle\Models\Jobs;

/**
Expand Down Expand Up @@ -54,15 +50,18 @@ protected function compile()

$aOptions = array
(
'order' => 'pid',$this->jobsorting . ' ' . $this->sortorder,
'order' => 'pid, '.$this->jobsorting . ' ' . $this->sortorder,
);

if (!$bExpiredJobs) {
$aOptions['column'][] = ' validthrough >= ' . $dTime;
$aOptions['column'][] = 'validthrough >= ' . $dTime;
}

$aJobsByOrganisation = array();
$oOrganisations = \Slashworks\ContaoSimpleJobManagerBundle\Models\Organisation::findAll();
$organisations = StringUtil::deserialize($this->organisation, true);

if (!empty($organisations)) {
$aOptions['column'][] = 'pid IN(' . implode(',', array_map('intval', $organisations)) . ')';
}

$oJobs = Jobs::findAll($aOptions);

Expand All @@ -74,7 +73,7 @@ protected function compile()

// generate URL
$oPage = PageModel::findBy('id', $this->jumpTo);
$oJob->jobJumpTo = Controller::generateFrontendUrl($oPage->row(), '/job/' . $oJob->alias);
$oJob->jobJumpTo = Controller::generateFrontendUrl($oPage->row(), '/' . $oJob->alias);
$oJob->organisation = $oJob->getRelated('pid');

}
Expand Down
8 changes: 7 additions & 1 deletion src/Module/JobReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Contao\Controller;
use Contao\CoreBundle\Exception\PageNotFoundException;
use Contao\CoreBundle\Exception\RedirectResponseException;
use Contao\Date;
use Contao\FilesModel;
use Contao\Input;
Expand Down Expand Up @@ -49,9 +50,14 @@ protected function compile()
{
Controller::loadLanguageFile('tl_sjm_jobs');

// Redirect to new URL without /job
if (!empty($GLOBALS['objPage']) && null !== Input::get('job')) {
throw new RedirectResponseException($GLOBALS['objPage']->getAbsoluteUrl('/'.Input::get('job')));
}

$aOptions = array
(
'alias' => \Input::get('job')
'alias' => Input::get('auto_item')
);

$oJob = \Slashworks\ContaoSimpleJobManagerBundle\Models\Jobs::findOneBy('alias', $aOptions['alias']);
Expand Down
7 changes: 7 additions & 0 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Slashworks\ContaoSimpleJobManagerBundle\EventListener\GetSearchablePagesListener;

/**
* Backend modules
*/
Expand Down Expand Up @@ -31,3 +33,8 @@


$GLOBALS['sjm']['jobsorting']['options'] = array('dateposted','validthrough','title','jobnumber','business');

/**
* Register Hooks
*/
$GLOBALS['TL_HOOKS']['getSearchablePages'][] = [GetSearchablePagesListener::class, '__invoke'];

0 comments on commit b4a58b6

Please sign in to comment.