I'm trying to use a single category type in my component with 2 filters (admin side) using this category but I'm wondering if one is cancelling the other because neither filter works.
So in the view.html file for my multiple listing, I have these filters
JHtmlSidebar::addFilter(
JText::_("COM_MYCOMPONENT_TITLE_FIRST_MEAL"), 'filter_first_meal',
JHtml::_('select.options',
JHtml::_('category.options', 'com_mycomponent
.meals'), "value", "text", $this->state->get('filter.first_meal'))
);
JHtmlSidebar::addFilter(
JText::_("COM_MYCOMPONENT
_TITLE_LAST_MEAL"), 'filter_last_meal',
JHtml::_('select.options',
JHtml::_('category.options', 'com_mycomponent.meals'), "value", "text", $this->state->get('filter.last_meal'))
);
Then in the model, within the populateState I have the following:
// Filtering first_meal
$this->setState('filter.first_meal', $app->getUserStateFromRequest($this->context.'.filter.first_meal', 'filter_first_meal', '', 'string'));
// Filtering last_meal
$this->setState('filter.last_meal', $app->getUserStateFromRequest($this->context.'.filter.last_meal', 'filter_last_meal', '', 'string'));
Then in the getListQuery I have the following:
// Filtering first_meal
$filter_first_meal = $this->state->get("filter.first_meal");
if ($filter_first_meal !== null && !empty($filter_first_meal)) {
$query->where("a.`first_meal` = '".$db->escape($filter_first_meal)."'");
}
// Filtering last_meal
$filter_last_meal = $this->state->get("filter.last_meal");
if ($filter_last_meal !== null && !empty($filter_last_meal)) {
$query->where("a.`last_meal` = '".$db->escape($filter_last_meal)."'");
}
This is the same code that works perfectly when only one filtered field is being used. It seems painful if I have to duplicate the category to have one for first meal and another for the last meal when the content is Breakfast, Lunch and Dinner for both.
Any advice appreciated. Cheers.
Glenn