Skip to content

Commit

Permalink
added sortable cat filter list and filter url friendlieness
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin committed Apr 29, 2016
1 parent 643b9dc commit a1ff56f
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 27 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
mae_event_categories Changelog
==============================

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
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.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
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.
33 changes: 26 additions & 7 deletions classes/MaeEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,36 @@ class MaeEvent extends \Frontend

public function getAllEvents($arrEvents, $arrCalendars, $intStart, $intEnd, \Contao\Module $objModule)
{
// FIXME it's possible to filter a list for categories, it doesn't allow by its configuration
$result = array();
$modCats = unserialize($objModule->event_categories);
$modCats = deserialize($objModule->event_categories, true);
$hasCatCfg = is_array($modCats) && count($modCats) > 0;

if (!is_array($modCats)) {
$modCats = array();
$filterParam_ar = array('category');
$objFilterMod = Database::getInstance()->prepare("SELECT mae_event_catname FROM tl_module WHERE mae_event_catname != '' AND type='mae_event_filter' AND mae_event_list=?")->execute($objModule->id);
while($objFilterMod->fetchAssoc()) {
$filterParam_ar[] = $objFilterMod->mae_event_catname;
}

$filterCat = Input::get('category');
if(!empty($filterCat) && $filterCat != "all") {
$modCats = array($filterCat);
}
foreach ($filterParam_ar as $paramName) {
$filterCat = Input::get($paramName);
if(!empty($filterCat) && $filterCat != "all") {
if(!is_numeric($filterCat)) {
$objCat = Database::getInstance()->prepare("SELECT id FROM tl_mae_event_cat WHERE alias=?")->execute($filterCat);
if($objCat->numRows == 1) {
$filterCat = $objCat->id;
}
}
if($hasCatCfg) {
$modCats = array($filterCat);
$hasCatCfg = false;
}
else {
$modCats[] = $filterCat;
}
} // have filter value
} // each possible category url parameter


if (is_array($arrEvents) && count($arrEvents) > 0 && count($modCats) > 0) {
foreach ($arrEvents as $day => $times) {
Expand Down
16 changes: 13 additions & 3 deletions dca/tl_mae_event_cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
(
'keys' => array
(
'id' => 'primary'
'id' => 'primary',
'alias' => 'index'
)
),
'backlink' => 'do=calendar',
Expand Down Expand Up @@ -111,7 +112,7 @@
'palettes' => array
(
'__selector__' => array(''),
'default' => '{title_legend},title;{layout_legend},cssId,cssClass'
'default' => '{title_legend},title,alias;{layout_legend},cssId,cssClass'
),

// Subpalettes
Expand All @@ -137,9 +138,18 @@
'exclude' => false,
'search' => true,
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'maxlength'=>255),
'eval' => array('mandatory'=>true, 'maxlength'=>255, 'tl_class'=>'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'alias' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_mae_event_cat']['alias'],
'exclude' => false,
'search' => true,
'inputType' => 'text',
'eval' => array('mandatory'=>false, 'maxlength'=>50, 'rgxp'=>'alias', 'tl_class'=>'w50', 'unique'=>true),
'sql' => "varchar(50) NOT NULL default ''"
),
'cssId' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_mae_event_cat']['cssId'],
Expand Down
9 changes: 8 additions & 1 deletion dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
'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,
Expand All @@ -23,4 +22,12 @@
'sql' => "int(10) unsigned NOT NULL default '0'",
'relation' => array('type'=>'hasOne', 'load'=>'lazy')
);
$GLOBALS['TL_DCA']['tl_module']['fields']['mae_event_catname'] = array(
'label' => &$GLOBALS['TL_LANG']['tl_module']['mae_event_catname'],
'exclude' => true,
'inputType' => 'text',
'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';
?>
3 changes: 2 additions & 1 deletion languages/de/tl_mae_event_cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
/**
* Fields
*/
$GLOBALS['TL_LANG']['tl_mae_event_cat']['title'] = array('Name', 'Name der Kategorie');
$GLOBALS['TL_LANG']['tl_mae_event_cat']['title'] = array('Name', 'Name der Kategorie (Wird im Frontend angezeigt)');
$GLOBALS['TL_LANG']['tl_mae_event_cat']['alias'] = array('Alias', 'Wird im Listen-Filtermodul zur Ersetzung der ID in der URL verwendet');
$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)');

Expand Down
3 changes: 2 additions & 1 deletion languages/de/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
$GLOBALS['TL_LANG']['tl_module']['event_categories'] = array('Eventkategorien', 'Eine oder mehrere Kategorien auswählen, die in der Liste angezeigt werden sollen, ansonsten werden alle angezeigt.');
$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_setup_legend'] = 'Einstellungen';
$GLOBALS['TL_LANG']['tl_module']['mae_event_catname'] = array('Filter URL Parameter', 'Falls nichts angegeben wird, lautet der Filter-Parameter "category"');
3 changes: 2 additions & 1 deletion languages/en/tl_mae_event_cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
/**
* Fields
*/
$GLOBALS['TL_LANG']['tl_mae_event_cat']['title'] = array('Name', 'category name');
$GLOBALS['TL_LANG']['tl_mae_event_cat']['title'] = array('Name', 'category name, which is displayed in frontend');
$GLOBALS['TL_LANG']['tl_mae_event_cat']['alias'] = array('Alias', 'The list-filter module uses this to replace the id within the url');
$GLOBALS['TL_LANG']['tl_mae_event_cat']['cssId'] = array('CSS ID', 'CSS Id for the filter module');
$GLOBALS['TL_LANG']['tl_mae_event_cat']['cssClass'] = array('CSS Class(es)', 'CSS classes for the filter module (space separated list)');

Expand Down
3 changes: 2 additions & 1 deletion languages/en/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
$GLOBALS['TL_LANG']['tl_module']['event_categories'] = array('Event categories', 'Select one or more categories to be displayed in the list.');
$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_setup_legend'] = 'Setup';
$GLOBALS['TL_LANG']['tl_module']['mae_event_catname'] = array('Filter URL Parameter', 'if nothing specified, it will be "category"');
23 changes: 16 additions & 7 deletions modules/ModuleFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public function generate()
protected function compile()
{
$allowAllCats = false;
$selectedCat = Input::get('category');
$paramName = empty($this->mae_event_catname) ? "category" : $this->mae_event_catname;
$selectedCat = Input::get($paramName);
$this->Template->selectedCategory = empty($selectedCat) ? "all" : $selectedCat;
$this->Template->showAllHref = $this->addToUrl('category=all');
$this->Template->showAllHref = $this->addToUrl($paramName . '=all');

$items = array();
$filterCats = empty($this->event_categories) ? array() : unserialize($this->event_categories);
if(count($filterCats) == 0) {
if($this->mae_event_list > 0) {
Expand All @@ -58,15 +58,24 @@ protected function compile()
}
}

$item_ar = array();
if(count($filterCats) > 0 || $allowAllCats) {
if($allowAllCats) {
$sqlSort = "SELECT * FROM tl_mae_event_cat ORDER BY title";
$objCats = $this->Database->execute($sqlSort);
while ($item = $objCats->fetchAssoc()) {
$item_ar[] = $item;
}
}
else {
$sqlSort = "SELECT * FROM tl_mae_event_cat WHERE id IN (" . implode(",", $filterCats) . ") ORDER BY title";
foreach ($filterCats as $catId) {
$objItem = $this->Database->prepare("SELECT * FROM tl_mae_event_cat WHERE id=?")->execute($catId);
if($objItem->numRows == 1) {
$item_ar[] = $objItem->fetchAssoc();
}
}
}
$objCats = $this->Database->execute($sqlSort);
while ($item = $objCats->fetchAssoc()) {
foreach ($item_ar as $item) {
if($selectedCat == $item['id']) {
$item['cssClass'] = $item['cssClass'] . " active";
}
Expand All @@ -76,7 +85,7 @@ protected function compile()
if(empty($item['cssId'])) {
$item['cssId'] = "mae_cat_" . $item['id'];
}
$item['href'] = $this->addToUrl('category=' . $item['id']);
$item['href'] = $this->addToUrl($paramName . '=' . (empty($item['alias']) ? $item['id'] : $item['alias']));
$items[] = $item;
}
} // if have categories
Expand Down

0 comments on commit a1ff56f

Please sign in to comment.