Skip to content

Commit

Permalink
V1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin committed Aug 24, 2015
1 parent 57f216f commit 281afc3
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 10 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.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.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.



Expand All @@ -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
Expand All @@ -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
7 changes: 7 additions & 0 deletions classes/MaeEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Namespace
*/
namespace MaeEventCategories;
use Contao\Input;


/**
Expand All @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions config/autoload.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<?php
ClassLoader::addNamespace(array('MaeEventCategories'));
ClassLoader::addNamespace('MaeEventCategories');

ClassLoader::addClasses(array
(
'MaeEventCategories\MaeEvent' => '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'
));
5 changes: 5 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@
* Add permissions
*/
$GLOBALS['TL_PERMISSIONS'][] = 'maeEventCat';

/**
* Front end modules
*/
$GLOBALS['FE_MOD']['events']['mae_event_filter'] = 'MaeEventCategories\ModuleFilter';
18 changes: 17 additions & 1 deletion dca/tl_mae_event_cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
'palettes' => array
(
'__selector__' => array(''),
'default' => '{title_legend},title;'
'default' => '{title_legend},title;{layout_legend},cssId,cssClass'
),

// Subpalettes
Expand Down Expand Up @@ -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 ''"
)
)
);
Expand Down
11 changes: 11 additions & 0 deletions dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
?>
8 changes: 7 additions & 1 deletion languages/de/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
/**
* Back end modules
*/
$GLOBALS['TL_LANG']['MOD']['MaeEventCat'] = array('Eventkategorien', 'Veranstaltungskategorien verwalten');
$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].";
10 changes: 9 additions & 1 deletion languages/de/tl_mae_event_cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';


/**
Expand All @@ -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');
$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');
4 changes: 3 additions & 1 deletion languages/de/tl_module.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php
$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']['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';
8 changes: 7 additions & 1 deletion languages/en/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
/**
* Back end modules
*/
$GLOBALS['TL_LANG']['MOD']['MaeEventCat'] = array('Event categories', 'manage event categories');
$GLOBALS['TL_LANG']['MOD']['MaeEventCat'] = array('Event categories', 'manage event categories');

/**
* Front end modules
*/
$GLOBALS['TL_LANG']['FMD']['mae_event_filter']['0'] = "Event Category filter";
$GLOBALS['TL_LANG']['FMD']['mae_event_filter']['1'] = "filters an event list by categories [mae_event_categories].";
8 changes: 8 additions & 0 deletions languages/en/tl_mae_event_cat.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
* Fields
*/
$GLOBALS['TL_LANG']['tl_mae_event_cat']['title'] = array('Name', 'category name');
$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)');


/**
* Legends
*/
$GLOBALS['TL_LANG']['tl_mae_event_cat']['title_legend'] = 'Description';
$GLOBALS['TL_LANG']['tl_mae_event_cat']['layout_legend'] = 'Layout';


/**
Expand All @@ -32,3 +35,8 @@
$GLOBALS['TL_LANG']['tl_mae_event_cat']['cut'] = array('move ', 'move ID %s');
$GLOBALS['TL_LANG']['tl_mae_event_cat']['copy'] = array('duplicate ', 'duplicate ID %s');
$GLOBALS['TL_LANG']['tl_mae_event_cat']['delete'] = array('delete ', 'delete ID %s');

/**
* Texts
*/
$GLOBALS['TL_LANG']['tl_mae_event_cat']['all'] = array('Show all', 'Display all event categories');
4 changes: 3 additions & 1 deletion languages/en/tl_module.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php
$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']['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';
85 changes: 85 additions & 0 deletions modules/ModuleFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace MaeEventCategories;
use Contao\Database;
use Contao\Input;


class ModuleFilter extends \Module
{
/**
* Template
* @var string
*/
protected $strTemplate = 'mod_mae_event_filter';

public function generate()
{
if (TL_MODE == 'BE') {
$objTemplate = new \BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### MODULE EVENT FILTER ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;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;
}
}
13 changes: 13 additions & 0 deletions templates/modules/mod_mae_event_filter.html5
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="mod_mae_event_filter block">
<?php if(!empty($this->headline)) {echo "<" . $this->hl . ">" . $this->headline . "</" . $this->hl . ">";} ?>
<ul>
<li class="category all<?php echo ($this->selectedCategory == "all" ? " active" : ""); ?>">
<a href="<?php echo $this->showAllHref; ?>" title="{{label::tl_mae_event_cat:all:1}}">{{label::tl_mae_event_cat:all:0}}</a>
</li>
<?php foreach ($this->items as $item) { ?>
<li id="<?php echo $item['cssId']; ?>" class="category<?php echo $item['cssClass']; ?>">
<a href="<?php echo $item['href']; ?>" title="<?php echo $item['title']; ?>"><?php echo $item['title']; ?></a>
</li>
<?php } // each $item ?>
</ul>
</div>

0 comments on commit 281afc3

Please sign in to comment.