Skip to content

Commit

Permalink
Merge pull request #25 from oveleon/feature/search
Browse files Browse the repository at this point in the history
Implement search functionality
  • Loading branch information
zoglo authored Jul 10, 2024
2 parents 9297ac3 + e693b26 commit b59158f
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 54 deletions.
22 changes: 19 additions & 3 deletions contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@

use Contao\Controller;
use Contao\System;
use Oveleon\ContaoMemberExtensionBundle\EventListener\DataContainer\MemberFieldsOptionsListener;

System::loadLanguageFile('tl_member_settings');

// Add palettes to tl_module
$GLOBALS['TL_DCA']['tl_module']['palettes']['avatar'] = '{title_legend},name,headline,type;{source_legend},imgSize;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
$GLOBALS['TL_DCA']['tl_module']['palettes']['deleteAvatar'] = '{title_legend},name,headline,type;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
$GLOBALS['TL_DCA']['tl_module']['palettes']['memberList'] = '{title_legend},name,headline,type;{config_legend},ext_order,ext_orderField,numberOfItems,perPage,ext_groups,memberFields,imgSize,ext_activateFilter,ext_parseDetails,ext_memberAlias;{redirect_legend},jumpTo;{template_legend:hide},customTpl,memberListTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
$GLOBALS['TL_DCA']['tl_module']['palettes']['memberList'] = '{title_legend},name,headline,type;{config_legend},ext_order,ext_orderField,numberOfItems,perPage,ext_groups,memberFields,imgSize,ext_parseDetails,ext_memberAlias;{filter_search_legend:hide},ext_where,ext_activateFilter;{redirect_legend},jumpTo;{template_legend:hide},customTpl,memberListTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';
$GLOBALS['TL_DCA']['tl_module']['palettes']['memberReader'] = '{title_legend},name,headline,type;{config_legend},ext_groups,memberFields,imgSize,ext_parseDetails,overviewPage,customLabel;{template_legend:hide},customTpl,memberReaderTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID';

$GLOBALS['TL_DCA']['tl_module']['palettes']['__selector__'][] = 'ext_activateFilter';
$GLOBALS['TL_DCA']['tl_module']['subpalettes']['ext_activateFilter'] = 'ext_selectFilter';

$GLOBALS['TL_DCA']['tl_module']['fields']['memberListTpl'] = [
'exclude' => true,
'inputType' => 'select',
Expand Down Expand Up @@ -87,9 +89,23 @@
'relation' => ['type' => 'hasMany', 'load' => 'lazy']
];

$GLOBALS['TL_DCA']['tl_module']['fields']['ext_where'] = [
'exclude' => true,
'inputType' => 'select',
'eval' => ['tl_class' => 'w50', 'includeBlankOption' => true, 'chosen' => true],
'sql' => "varchar(32) NOT NULL default ''"
];

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

$GLOBALS['TL_DCA']['tl_module']['fields']['ext_selectFilter'] = [
'exclude' => true,
'inputType' => 'select',
'eval' => ['tl_class' => 'w50', 'includeBlankOption' => true, 'chosen' => true],
'sql' => "varchar(32) NOT NULL default ''"
];
37 changes: 29 additions & 8 deletions contao/languages/de/tl_module.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" ?><xliff version="1.1">
<file datatype="php" original="contao/languages/en/tl_module.php" source-language="en" target-language="de">
<body>
<trans-unit id="tl_module.filter_search_legend">
<source>Filter / Search</source>
<target>Filterung / Suche</target>
</trans-unit>
<trans-unit id="tl_module.ext_order.0">
<source>Sort order</source>
<target>Sortierreihenfolge</target>
Expand Down Expand Up @@ -33,14 +37,6 @@
<source>Here you can select the member fields to be displayed.</source>
<target>Hier können Sie die auszugebenden Mitgliederfelder auswählen.</target>
</trans-unit>
<trans-unit id="tl_module.ext_activateFilter.0">
<source>Activate filters</source>
<target>Filter aktivieren</target>
</trans-unit>
<trans-unit id="tl_module.ext_activateFilter.1">
<source>Adds filtering. Only works with checkbox fields with the eval flag 'feFilterable'.</source>
<target>Fügt eine Filterung hinzu. Funktioniert nur mit Checkbox-Feldern mit dem eval-flag 'feFilterable'.</target>
</trans-unit>
<trans-unit id="tl_module.ext_parseDetails.0">
<source>Parse details</source>
<target>Details umwandeln</target>
Expand All @@ -58,6 +54,31 @@
<target>Verwendet den Mitgliedsalias für die Detailseite.</target>
</trans-unit>

<trans-unit id="tl_module.ext_where.0">
<source>Search field</source>
<target>Suchfeld</target>
</trans-unit>
<trans-unit id="tl_module.ext_where.1">
<source>Activates search. Here you can select the field that you want to be searchable.</source>
<target>Aktiviert die Suche. Hier können Sie das Feld auswählen, welches durchsuchbar sein soll.</target>
</trans-unit>
<trans-unit id="tl_module.ext_activateFilter.0">
<source>Activate filters</source>
<target>Filter aktivieren</target>
</trans-unit>
<trans-unit id="tl_module.ext_activateFilter.1">
<source>Adds filtering. Only works with checkbox fields with the eval flag 'feFilterable'.</source>
<target>Fügt eine Filterung hinzu. Funktioniert nur mit Checkbox-Feldern mit dem eval-flag 'feFilterable'.</target>
</trans-unit>
<trans-unit id="tl_module.ext_selectFilter.0">
<source>Select filter</source>
<target>Select-Filter</target>
</trans-unit>
<trans-unit id="tl_module.ext_selectFilter.1">
<source>Here you can select a field that provides an options filter in the frontend.</source>
<target>Hier können Sie ein Feld auswählen, welches einen Optionen-Filter im Frontend zur Verfügung stellt.</target>
</trans-unit>

<trans-unit id="tl_module.memberListTpl.0">
<source>List template</source>
<target>Listen-Template</target>
Expand Down
28 changes: 22 additions & 6 deletions contao/languages/en/tl_module.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" ?><xliff version="1.1">
<file datatype="php" original="contao/languages/en/tl_module.php" source-language="en">
<body>
<trans-unit id="tl_module.filter_search_legend">
<source>Filter / Search</source>
</trans-unit>
<trans-unit id="tl_module.ext_order.0">
<source>Sort order</source>
</trans-unit>
Expand All @@ -25,12 +28,6 @@
<trans-unit id="tl_module.memberFields.1">
<source>Here you can select the member fields to be displayed.</source>
</trans-unit>
<trans-unit id="tl_module.ext_activateFilter.0">
<source>Activate filters</source>
</trans-unit>
<trans-unit id="tl_module.ext_activateFilter.1">
<source>Adds filtering. Only works with checkbox fields with the eval flag 'feFilterable'.</source>
</trans-unit>
<trans-unit id="tl_module.ext_parseDetails.0">
<source>Parse details</source>
</trans-unit>
Expand All @@ -44,6 +41,25 @@
<source>Uses the member alias for the detail page.</source>
</trans-unit>

<trans-unit id="tl_module.ext_where.0">
<source>Search field</source>
</trans-unit>
<trans-unit id="tl_module.ext_where.1">
<source>Activates search. Here you can select the field that you want to be searchable.</source>
</trans-unit>
<trans-unit id="tl_module.ext_activateFilter.0">
<source>Activate filters</source>
</trans-unit>
<trans-unit id="tl_module.ext_activateFilter.1">
<source>Adds filtering. Only works with checkbox fields with the eval flag 'feFilterable'.</source>
</trans-unit>
<trans-unit id="tl_module.ext_selectFilter.0">
<source>Select filter</source>
</trans-unit>
<trans-unit id="tl_module.ext_selectFilter.1">
<source>Here you can select a field that provides an options filter in the frontend.</source>
</trans-unit>

<trans-unit id="tl_module.memberListTpl.0">
<source>List template</source>
</trans-unit>
Expand Down
25 changes: 25 additions & 0 deletions contao/templates/block/memberExtension_searchFilter.html5
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<form method="GET">
<div class="formbody">
<?php if ($this->selectField): ?>
<div class="widget widget-select">
<label for="ctrl_select-filter"><?= $this->trans('tl_member.' . $this->selectField . '.0') ?></label>
<select name="select_filter" id="ctrl_select-filter" class="select">
<?php foreach ($this->selectOptions as $option): ?>
<option value="<?= $option ?>"<?=($option === $this->selected)?' selected':''?>>
<?= !!$option ? $this->trans('country' === $this->selectField ? 'CNT.' . $option : 'tl_member' .$option . '1') : '-' ?>
</option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
<?php if ($this->searchField): ?>
<div class="widget widget-text">
<label for="ctrl_search"><?= $this->trans('tl_member.' . $this->searchField . '.0') ?></label>
<input type="text" name="search_string" id="ctrl_search" class="text" value="<?= $this->searchString ?>">
</div>
<?php endif; ?>
<div class="widget widget-submit">
<button type="submit" class="submit"><?= $this->trans('MSC.search') ?></button>
</div>
</div>
</form>
13 changes: 13 additions & 0 deletions contao/templates/modules/mod_memberList.html5
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

<?php $this->block('content'); ?>

<?php if ($this->ext_where || $this->selectFilterable): ?>
<div class="member-list-search-filter">
<?php $this->insert('memberExtension_searchFilter', [
'selectField' => $this->ext_selectFilter ?? '',
'selectOptions' => $this->selectOptions ?? [],
'selected' => $this->selectedOption ?? '',
'searchField' => $this->ext_where ?? '',
'searchString' => $this->searchString ?? '',
'requestToken' => $this->requestToken
]) ?>
</div>
<?php endif; ?>

<?php if (!empty($this->filters)): ?>
<div class="member-list-filter">
<?php $this->insert('memberExtension_filter', [
Expand Down
16 changes: 10 additions & 6 deletions src/Controller/FrontendModule/MemberExtensionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ abstract class MemberExtensionController extends AbstractFrontendModuleControlle

protected function parseMemberTemplate(MemberModel|Model $objMember, FrontendTemplate $objTemplate, ModuleModel $model): string
{
System::loadLanguageFile('default');
System::loadLanguageFile('tl_member');
System::loadLanguageFile('countries');
System::loadLanguageFile('languages');

$this->model = $model;

$arrFields = [];
Expand Down Expand Up @@ -96,9 +91,18 @@ protected function parseMemberTemplate(MemberModel|Model $objMember, FrontendTem

$returnFields = [];

$skipEmptyValues = System::getContainer()->getParameter('contao_member_extension.skip_empty_values');

foreach ($this->memberFields as $value)
{
$returnFields[$value] = $arrFields[$value] ?? '';
$val = $arrFields[$value] ?? '';

if ($skipEmptyValues && !$val)
{
continue;
}

$returnFields[$value] = $val;
}

$labels = array_keys($returnFields);
Expand Down
Loading

0 comments on commit b59158f

Please sign in to comment.