Skip to content

Commit

Permalink
filter only future categories
Browse files Browse the repository at this point in the history
  • Loading branch information
marebe1602 committed Aug 3, 2016
1 parent aaaa691 commit 9b40fe4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mae_event_categories Changelog
==============================

Version 1.5.0 (2016-08-03) added 'only filter by categories, assigned to future events' to the event filter module
Version 1.4.0 RC1 (2016-04-29) added sortable cat filter list and filter url friendlieness
Version 1.3.0 (2016-01-08) added categories to calendar and eventmenu modules
Version 1.2.0 (2015-12-16) added default categories in user/group
Expand Down
9 changes: 8 additions & 1 deletion dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,12 @@
'eval' => array('maxlength'=>50, 'tl_class'=>'w50', 'rgxp'=>'alias'),
'sql' => "varchar(50) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_module']['palettes']['mae_event_filter'] = '{title_legend},name,type;{mae_setup_legend},mae_event_list,headline,mae_event_catname;{event_cat_legend:hide},event_categories';
$GLOBALS['TL_DCA']['tl_module']['fields']['mae_only_future_cat'] = array(
'label' => &$GLOBALS['TL_LANG']['tl_module']['mae_only_future_cat'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('tl_class'=>'clr'),
'sql' => "char(1) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_module']['palettes']['mae_event_filter'] = '{title_legend},name,type;{mae_setup_legend},mae_event_list,headline,mae_event_catname,mae_only_future_cat;{event_cat_legend:hide},event_categories';
?>
3 changes: 2 additions & 1 deletion languages/de/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
$GLOBALS['TL_LANG']['tl_module']['event_cat_legend'] = 'Eventkategorien';
$GLOBALS['TL_LANG']['tl_module']['mae_event_list'] = array('Eventliste', 'Das Eventlistenmodul, das gefiltert werden soll');
$GLOBALS['TL_LANG']['tl_module']['mae_setup_legend'] = 'Einstellungen';
$GLOBALS['TL_LANG']['tl_module']['mae_event_catname'] = array('Filter URL Parameter', 'Falls nichts angegeben wird, lautet der Filter-Parameter "category"');
$GLOBALS['TL_LANG']['tl_module']['mae_event_catname'] = array('Filter URL Parameter', 'Falls nichts angegeben wird, lautet der Filter-Parameter "category"');
$GLOBALS['TL_LANG']['tl_module']['mae_only_future_cat'] = array('Nur Kategorien aus zukünftigen Events auflisten', 'Sollen nur Kategorien im Filter aufgelistet werden, die mindestens einem zukünftigen Event zugewiesen sind');
3 changes: 2 additions & 1 deletion languages/en/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
$GLOBALS['TL_LANG']['tl_module']['event_cat_legend'] = 'Event categories';
$GLOBALS['TL_LANG']['tl_module']['mae_event_list'] = array('Event list', 'The event list module which has to be filtered');
$GLOBALS['TL_LANG']['tl_module']['mae_setup_legend'] = 'Setup';
$GLOBALS['TL_LANG']['tl_module']['mae_event_catname'] = array('Filter URL Parameter', 'if nothing specified, it will be "category"');
$GLOBALS['TL_LANG']['tl_module']['mae_event_catname'] = array('Filter URL Parameter', 'if nothing specified, it will be "category"');
$GLOBALS['TL_LANG']['tl_module']['mae_only_future_cat'] = array('List categories of future events, only', 'Should only categories be listed in the filter, which are assigned to at least one event in the future');
39 changes: 36 additions & 3 deletions modules/ModuleFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ public function generate()
*/
protected function compile()
{
$allowAllCats = false;
$paramName = empty($this->mae_event_catname) ? "category" : $this->mae_event_catname;
$selectedCat = Input::get($paramName);
$allowAllCats = false;
$paramName = empty($this->mae_event_catname) ? "category" : $this->mae_event_catname;
$selectedCat = Input::get($paramName);
$onlyFutureCats = $this->mae_only_future_cat == '1';
$futureCats = array();

$this->Template->selectedCategory = empty($selectedCat) ? "all" : $selectedCat;
$this->Template->showAllHref = $this->addToUrl($paramName . '=all');

Expand All @@ -57,6 +60,9 @@ protected function compile()
$allowAllCats = true;
}
}
if($onlyFutureCats) {
$futureCats = $this->getFutureCategories();
}

$item_ar = array();
if(count($filterCats) > 0 || $allowAllCats) {
Expand All @@ -76,6 +82,9 @@ protected function compile()
}
}
foreach ($item_ar as $item) {
if($onlyFutureCats && !in_array($item['id'], $futureCats)) {
continue;
}
if($selectedCat == $item['id'] || $selectedCat == $item['alias']) {
$item['cssClass'] = $item['cssClass'] . " active";
}
Expand All @@ -91,4 +100,28 @@ protected function compile()
} // if have categories
$this->Template->items = $items;
}

/**
* get all categories, assigned to published events in the future
* @return array an array of category ids
*/
protected function getFutureCategories()
{
$result = array();
$now = time();
$sqlCat = "SELECT categories FROM tl_calendar_events WHERE published='1' AND (startTime >= " . $now . " OR endTime >= " . $now . ")";
$objCat = $this->Database->execute($sqlCat);
while ($cat = $objCat->fetchAssoc()) {
$eventCats = $cat['categories'];
if(!empty($eventCats)) {
$eventCats = deserialize($eventCats, true);
foreach ($eventCats as $eventCatId) {
if(!in_array($eventCatId, $result)) {
$result[] = (int)$eventCatId;
}
}
}
}
return $result;
}
}

0 comments on commit 9b40fe4

Please sign in to comment.