Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
veronikaplenta committed Nov 19, 2024
1 parent 06cadaa commit 64b1633
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 3 deletions.
18 changes: 17 additions & 1 deletion contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
$GLOBALS['TL_DCA']['tl_module']['palettes']['__selector__'][] = 'plentaJobsBasicShowLocations';
$GLOBALS['TL_DCA']['tl_module']['palettes']['__selector__'][] = 'plentaJobsBasicShowButton';
$GLOBALS['TL_DCA']['tl_module']['palettes']['__selector__'][] = 'plentaJobsBasicShowSorting';
$GLOBALS['TL_DCA']['tl_module']['palettes']['__selector__'][] = 'plentaJobsBasicShowKeyword';

$GLOBALS['TL_DCA']['tl_module']['palettes']['plenta_jobs_basic_offer_list'] =
'{title_legend},name,type,headline;
Expand All @@ -36,7 +37,7 @@

$GLOBALS['TL_DCA']['tl_module']['palettes']['plenta_jobs_basic_filter'] =
'{title_legend},name,type;
{config_legend},plentaJobsBasicShowButton,plentaJobsBasicShowTypes,plentaJobsBasicShowLocations,plentaJobsBasicHideOffersWithoutTranslation;
{config_legend},plentaJobsBasicShowButton,plentaJobsBasicShowKeyword,plentaJobsBasicShowTypes,plentaJobsBasicShowLocations,plentaJobsBasicHideOffersWithoutTranslation;
{template_legend:hide},customTpl;
{redirect_legend},jumpTo;
{expert_legend:hide},cssID'
Expand All @@ -46,6 +47,7 @@
$GLOBALS['TL_DCA']['tl_module']['subpalettes']['plentaJobsBasicShowTypes'] = 'plentaJobsBasicTypesHeadline,plentaJobsBasicEmploymentTypes,plentaJobsBasicShowAllTypes,plentaJobsBasicShowQuantity';
$GLOBALS['TL_DCA']['tl_module']['subpalettes']['plentaJobsBasicShowLocations'] = 'plentaJobsBasicLocationsHeadline,plentaJobsBasicLocations,plentaJobsBasicShowAllLocations,plentaJobsBasicShowLocationQuantity,plentaJobsBasicDisableMultipleLocations';
$GLOBALS['TL_DCA']['tl_module']['subpalettes']['plentaJobsBasicShowSorting'] = 'plentaJobsBasicSortingFields';
$GLOBALS['TL_DCA']['tl_module']['subpalettes']['plentaJobsBasicShowKeyword'] = 'plentaJobsBasicKeywordHeadline';

$GLOBALS['TL_DCA']['tl_module']['fields']['plentaJobsBasicHeadlineTag'] = [
'exclude' => true,
Expand Down Expand Up @@ -262,3 +264,17 @@
'eval' => ['tl_class' => 'w50'],
'sql' => "varchar(255) NOT NULL default ''",
];

$GLOBALS['TL_DCA']['tl_module']['fields']['plentaJobsBasicShowKeyword'] = [
'exclude' => true,
'inputType' => 'checkbox',
'eval' => ['tl_class' => 'clr w50', 'submitOnChange' => true],
'sql' => "char(1) COLLATE ascii_bin NOT NULL default ''",
];

$GLOBALS['TL_DCA']['tl_module']['fields']['plentaJobsBasicKeywordHeadline'] = [
'exclude' => true,
'inputType' => 'text',
'eval' => ['allowHtml' => true, 'tl_class' => 'w50'],
'sql' => 'tinytext NULL',
];
12 changes: 12 additions & 0 deletions contao/languages/de/tl_module.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@
<trans-unit id="tl_module.plentaJobsBasicElementTpl.1">
<target>Bitte wählen Sie ein Template aus der Liste aus.</target>
</trans-unit>
<trans-unit id="tl_module.plentaJobsBasicShowKeyword.0">
<target>Volltextsuche hinzufügen</target>
</trans-unit>
<trans-unit id="tl_module.plentaJobsBasicShowKeyword.1">
<target>Soll eine Volltextsuche angezeigt werden?</target>
</trans-unit>
<trans-unit id="tl_module.plentaJobsBasicKeywordHeadline.0">
<target>Volltextsuche-Überschrift</target>
</trans-unit>
<trans-unit id="tl_module.plentaJobsBasicKeywordHeadline.1">
<target>Hier können Sie der Volltextsuche eine Überschrift hinzufügen.</target>
</trans-unit>
</body>
</file>
</xliff>
31 changes: 29 additions & 2 deletions src/Contao/Model/PlentaJobsBasicOfferModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Contao\PageModel;
use Contao\StringUtil;
use Contao\System;
use Plenta\ContaoJobsBasic\Events\JobOfferModelKeywordFieldsEvent;
use Plenta\ContaoJobsBasic\Events\Model\FindAllPublishedByTypesAndLocationEvent;

class PlentaJobsBasicOfferModel extends Model
Expand Down Expand Up @@ -224,8 +225,8 @@ protected static function buildSearchQuery(array &$columns, array &$arrOptions,
$columns[] = '('.implode(' OR ', $criteria).')';
}

$requestStack = System::getContainer()->get('request_stack');
if ($onlyTranslated) {
$requestStack = System::getContainer()->get('request_stack');
$language = $requestStack->getCurrentRequest()->getLocale();
$page = PageModel::findBy(['type = ?', 'language = ?', '(dns = ? OR dns = ?)'], ['root', $language, '', $requestStack->getCurrentRequest()->getHost()]);
if ($page && !$page->fallback) {
Expand All @@ -235,6 +236,33 @@ protected static function buildSearchQuery(array &$columns, array &$arrOptions,
}
}

$dispatcher = System::getContainer()->get('event_dispatcher');

if ($applyFilterRequests && $keyword = $requestStack->getCurrentRequest()->get('keyword')) {
$fields = ['title', 'description', 'translations'];

$fieldEvent = new JobOfferModelKeywordFieldsEvent($fields);
$dispatcher->dispatch($fieldEvent, $fieldEvent::NAME);
$fields = $fieldEvent->getFields();

$keywords = array_filter(StringUtil::trimsplit(' ', $keyword));

if (!empty($keywords)) {
$criteria = [];

foreach ($fields as $searchField) {
foreach ($keywords as $keyword) {
$criteria[] = $searchField.' LIKE ?';
$values[] = '%'.$keyword.'%';
}
}

if (!empty($criteria)) {
$columns[] = '('.implode(' OR ', $criteria).')';
}
}
}

$sortingFields = [];
Controller::loadDataContainer('tl_plenta_jobs_basic_offer');
foreach ($GLOBALS['TL_DCA']['tl_plenta_jobs_basic_offer']['fields'] as $name => $field) {
Expand All @@ -254,7 +282,6 @@ protected static function buildSearchQuery(array &$columns, array &$arrOptions,
$arrOptions = [];
}

$dispatcher = System::getContainer()->get('event_dispatcher');
$findAllPublishedByTypesAndLocationEvent = new FindAllPublishedByTypesAndLocationEvent();
$findAllPublishedByTypesAndLocationEvent
->setColumns($columns)
Expand Down
25 changes: 25 additions & 0 deletions src/Events/JobOfferModelKeywordFieldsEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Plenta\ContaoJobsBasic\Events;

use Symfony\Contracts\EventDispatcher\Event;

class JobOfferModelKeywordFieldsEvent extends Event
{
public const NAME = 'plenta_jobs_basic.job_offer.model.keyword_fields';

public function __construct(protected array $fields)
{
}

public function getFields(): array
{
return $this->fields;
}

public function setFields(array $fields): JobOfferModelKeywordFieldsEvent
{
$this->fields = $fields;
return $this;
}
}
15 changes: 15 additions & 0 deletions src/Form/Type/JobOfferFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\OptionsResolver\OptionsResolver;
Expand All @@ -36,6 +37,20 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
{
/** @var ModuleModel $model */
$model = $options['fmd'];
if ($model->plentaJobsBasicShowKeyword) {
$builder->add('keywordHeadline', HtmlType::class, [
'html' => $this->getHeadlineHtml($model->plentaJobsBasicKeywordHeadline, 'keyword'),
'priority' => 110,
]);
$builder->add('keyword', TextType::class, [
'label' => false,
'required' => false,
'row_attr' => [
'class' => 'widget-text',
],
'priority' => 109,
]);
}
if ($model->plentaJobsBasicShowTypes) {
$builder->add('typesHeadline', HtmlType::class, [
'html' => $this->getHeadlineHtml($model->plentaJobsBasicTypesHeadline, 'jobTypes'),
Expand Down

0 comments on commit 64b1633

Please sign in to comment.