From 281afc3f0dbb21aee44c262d72abeb4f5d57602d Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 24 Aug 2015 19:01:00 +0200 Subject: [PATCH] V1.1 --- CHANGELOG.txt | 1 + README.md | 7 +- classes/MaeEvent.php | 7 ++ config/autoload.php | 13 ++- config/config.php | 5 ++ dca/tl_mae_event_cat.php | 18 ++++- dca/tl_module.php | 11 +++ languages/de/modules.php | 8 +- languages/de/tl_mae_event_cat.php | 10 ++- languages/de/tl_module.php | 4 +- languages/en/modules.php | 8 +- languages/en/tl_mae_event_cat.php | 8 ++ languages/en/tl_module.php | 4 +- modules/ModuleFilter.php | 85 ++++++++++++++++++++ templates/modules/mod_mae_event_filter.html5 | 13 +++ 15 files changed, 192 insertions(+), 10 deletions(-) create mode 100644 modules/ModuleFilter.php create mode 100644 templates/modules/mod_mae_event_filter.html5 diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 40e421d..799bcdd 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,7 @@ mae_event_categories Changelog ============================== +Version 1.1.0 (2015-08-25) added filter module Version 1.0.3 (2015-06-02) hotfix model / namespace Version 1.0.1 (2015-06-01) added model class Version 1.0.0 stable (2015-04-08) Initial release. \ No newline at end of file diff --git a/README.md b/README.md index 5fbb6b2..ba7db42 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ mae_event_categories purpose ------- -if you have lots of events and using different calendars is not enough to organize your events, this plugin allows the definition of additional categories for filtering events in eventlist frontend modules +if you have lots of events and using different calendars is not enough to organize your events, this plugin allows the definition of additional categories for filtering events in eventlist frontend modules. +It also comes with an event filter module that alows visitors to chose sthe category to be displayed in the list. @@ -19,6 +20,8 @@ Eventlists without configured categories will work as if the plugin wasn't there If you delete a category, all references in tl_module and tl_calendar_events will be removed, too. There will be no warning, if the category is in use. You may filter events by category to see, if it is still assigned anywhere, before deleting (this may be improved in a later version). +The category filter module allows visitors to filter the displayed events by categories. + customized places within contao @@ -33,5 +36,7 @@ customized places within contao - Themes / Frontend modules: new field "Event categories" in frontend module eventlist (tl_module) +- new Event Category filter module + More info at: http://www.martin-eberhardt.com/mae_event_categories.html diff --git a/classes/MaeEvent.php b/classes/MaeEvent.php index 185587f..a9f3170 100644 --- a/classes/MaeEvent.php +++ b/classes/MaeEvent.php @@ -15,6 +15,7 @@ * Namespace */ namespace MaeEventCategories; +use Contao\Input; /** @@ -36,6 +37,12 @@ public function getAllEvents($arrEvents, $arrCalendars, $intStart, $intEnd, \Con if (!is_array($modCats)) { $modCats = array(); } + + $filterCat = Input::get('category'); + if(!empty($filterCat) && $filterCat != "all") { + $modCats = array($filterCat); + } + if (is_array($arrEvents) && count($arrEvents) > 0 && count($modCats) > 0) { foreach ($arrEvents as $day => $times) { foreach ($times as $time => $events) { diff --git a/config/autoload.php b/config/autoload.php index 847d9e5..1796380 100644 --- a/config/autoload.php +++ b/config/autoload.php @@ -1,10 +1,17 @@ 'system/modules/mae_event_categories/classes/MaeEvent.php', + 'MaeEventCategories\MaeEventCatModel' => 'system/modules/mae_event_categories/models/MaeEventCatModel.php', + 'MaeEventCategories\ModuleFilter' => 'system/modules/mae_event_categories/modules/ModuleFilter.php' +)); - // Models - 'MaeEventCategories\MaeEventCatModel' => 'system/modules/mae_event_categories/models/MaeEventCatModel.php' +/** + * Register the templates + */ +TemplateLoader::addFiles(array +( + 'mod_mae_event_filter' => 'system/modules/mae_event_categories/templates/modules' )); diff --git a/config/config.php b/config/config.php index b5e11ab..eeaea1e 100644 --- a/config/config.php +++ b/config/config.php @@ -26,3 +26,8 @@ * Add permissions */ $GLOBALS['TL_PERMISSIONS'][] = 'maeEventCat'; + +/** + * Front end modules + */ +$GLOBALS['FE_MOD']['events']['mae_event_filter'] = 'MaeEventCategories\ModuleFilter'; diff --git a/dca/tl_mae_event_cat.php b/dca/tl_mae_event_cat.php index 211f45e..0efb0a6 100644 --- a/dca/tl_mae_event_cat.php +++ b/dca/tl_mae_event_cat.php @@ -111,7 +111,7 @@ 'palettes' => array ( '__selector__' => array(''), - 'default' => '{title_legend},title;' + 'default' => '{title_legend},title;{layout_legend},cssId,cssClass' ), // Subpalettes @@ -139,6 +139,22 @@ 'inputType' => 'text', 'eval' => array('mandatory'=>true, 'maxlength'=>255), 'sql' => "varchar(255) NOT NULL default ''" + ), + 'cssId' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_mae_event_cat']['cssId'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('mandatory'=>false, 'maxlength'=>60, 'tl_class'=>'w50'), + 'sql' => "varchar(60) NOT NULL default ''" + ), + 'cssClass' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_mae_event_cat']['cssClass'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('mandatory'=>false, 'maxlength'=>255, 'tl_class'=>'w50'), + 'sql' => "varchar(255) NOT NULL default ''" ) ) ); diff --git a/dca/tl_module.php b/dca/tl_module.php index 98283aa..81a2d91 100644 --- a/dca/tl_module.php +++ b/dca/tl_module.php @@ -10,4 +10,15 @@ 'eval' => array('tl_class'=>'clr', 'multiple'=>true, 'fieldType'=>'checkbox', 'foreignTable'=>'tl_mae_event_cat', 'titleField'=>'title', 'searchField'=>'title'), 'sql' => "blob NULL" ); + +$GLOBALS['TL_DCA']['tl_module']['palettes']['mae_event_filter'] = '{title_legend},name,type;{mae_setup_legend},mae_event_list,headline;{event_cat_legend:hide},event_categories'; +$GLOBALS['TL_DCA']['tl_module']['fields']['mae_event_list'] = array( + 'label' => &$GLOBALS['TL_LANG']['tl_module']['mae_event_list'], + 'exclude' => true, + 'inputType' => 'select', + 'foreignKey' => 'tl_module.name', + 'eval' => array('chosen'=>true, 'tl_class'=>'w50','mandatory'=>false), + 'sql' => "int(10) unsigned NOT NULL default '0'", + 'relation' => array('type'=>'hasOne', 'load'=>'lazy') +); ?> \ No newline at end of file diff --git a/languages/de/modules.php b/languages/de/modules.php index e349035..0cd724d 100644 --- a/languages/de/modules.php +++ b/languages/de/modules.php @@ -14,4 +14,10 @@ /** * Back end modules */ -$GLOBALS['TL_LANG']['MOD']['MaeEventCat'] = array('Eventkategorien', 'Veranstaltungskategorien verwalten'); \ No newline at end of file +$GLOBALS['TL_LANG']['MOD']['MaeEventCat'] = array('Eventkategorien', 'Veranstaltungskategorien verwalten'); + +/** + * Front end modules + */ +$GLOBALS['TL_LANG']['FMD']['mae_event_filter']['0'] = "Event Kategoriefilter"; +$GLOBALS['TL_LANG']['FMD']['mae_event_filter']['1'] = "Filtert eine Eventliste nach Kategorien [mae_event_categories]."; \ No newline at end of file diff --git a/languages/de/tl_mae_event_cat.php b/languages/de/tl_mae_event_cat.php index e2e3414..776e96b 100644 --- a/languages/de/tl_mae_event_cat.php +++ b/languages/de/tl_mae_event_cat.php @@ -15,12 +15,15 @@ * Fields */ $GLOBALS['TL_LANG']['tl_mae_event_cat']['title'] = array('Name', 'Name der Kategorie'); +$GLOBALS['TL_LANG']['tl_mae_event_cat']['cssId'] = array('CSS ID', 'CSS Id für die Darstellung der Kategorie im Filtermodul'); +$GLOBALS['TL_LANG']['tl_mae_event_cat']['cssClass'] = array('CSS Klasse(n)', 'CSS Klassen für die Darstellung der Kategorie im Filtermodul (Leerzeichengetrennte Liste)'); /** * Legends */ $GLOBALS['TL_LANG']['tl_mae_event_cat']['title_legend'] = 'Bezeichnung'; +$GLOBALS['TL_LANG']['tl_mae_event_cat']['layout_legend'] = 'Darstellungsoptionen'; /** @@ -31,4 +34,9 @@ $GLOBALS['TL_LANG']['tl_mae_event_cat']['edit'] = array('Bearbeiten ', 'ID %s bearbeiten'); $GLOBALS['TL_LANG']['tl_mae_event_cat']['cut'] = array('Verschieben ', 'ID %s verschieben'); $GLOBALS['TL_LANG']['tl_mae_event_cat']['copy'] = array('Duplizieren ', 'ID %s duplizieren'); -$GLOBALS['TL_LANG']['tl_mae_event_cat']['delete'] = array('Löschen ', ' ID %s löschen'); \ No newline at end of file +$GLOBALS['TL_LANG']['tl_mae_event_cat']['delete'] = array('Löschen ', ' ID %s löschen'); + +/** + * Texts + */ +$GLOBALS['TL_LANG']['tl_mae_event_cat']['all'] = array('Alle anzeigen', 'Alle Kategorien anzeigen'); \ No newline at end of file diff --git a/languages/de/tl_module.php b/languages/de/tl_module.php index 917fb70..e2fea9c 100644 --- a/languages/de/tl_module.php +++ b/languages/de/tl_module.php @@ -1,3 +1,5 @@ wildcard = '### MODULE EVENT FILTER ###'; + $objTemplate->title = $this->headline; + $objTemplate->id = $this->id; + $objTemplate->link = $this->name; + $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; + + return $objTemplate->parse(); + } + + return parent::generate(); + } + + /** + * Compile the current element + */ + protected function compile() + { + $allowAllCats = false; + $selectedCat = Input::get('category'); + $this->Template->selectedCategory = empty($selectedCat) ? "all" : $selectedCat; + $this->Template->showAllHref = $this->addToUrl('category=all'); + + $items = array(); + $filterCats = empty($this->event_categories) ? array() : unserialize($this->event_categories); + if(count($filterCats) == 0) { + if($this->mae_event_list > 0) { + // take category list from event list, if configured + $objListCats = $this->Database->prepare("SELECT event_categories FROM tl_module WHERE id=?")->execute($this->mae_event_list); + if($objListCats->numRows == 1) { + $listCats = $objListCats->event_categories; + if(!empty($listCats)) { + $filterCats = unserialize($listCats); + } + } + } + if(count($filterCats) == 0) { + // take all categories, because there are no categories defined neither in filter, nore in event list + $allowAllCats = true; + } + } + + if(count($filterCats) > 0 || $allowAllCats) { + if($allowAllCats) { + $sqlSort = "SELECT * FROM tl_mae_event_cat ORDER BY title"; + } + else { + $sqlSort = "SELECT * FROM tl_mae_event_cat WHERE id IN (" . implode(",", $filterCats) . ") ORDER BY title"; + } + $objCats = $this->Database->execute($sqlSort); + while ($item = $objCats->fetchAssoc()) { + if($selectedCat == $item['id']) { + $item['cssClass'] = $item['cssClass'] . " active"; + } + if(!empty($item['cssClass'])) { + $item['cssClass'] = " " . trim($item['cssClass']); + } + if(empty($item['cssId'])) { + $item['cssId'] = "mae_cat_" . $item['id']; + } + $item['href'] = $this->addToUrl('category=' . $item['id']); + $items[] = $item; + } + } // if have categories + $this->Template->items = $items; + } +} diff --git a/templates/modules/mod_mae_event_filter.html5 b/templates/modules/mod_mae_event_filter.html5 new file mode 100644 index 0000000..6401cd8 --- /dev/null +++ b/templates/modules/mod_mae_event_filter.html5 @@ -0,0 +1,13 @@ +
+ headline)) {echo "<" . $this->hl . ">" . $this->headline . "hl . ">";} ?> + +
\ No newline at end of file