/** * Build the filter query for the given element. * Can be overwritten in plugin - e.g. see checkbox element which checks for partial matches * * @param string $key element name in format `tablename`.`elementname` * @param string $condition =/like etc. * @param string $value search string - already quoted if specified in filter array options * @param string $originalValue original filter value without quotes or %'s applied * @param string $type filter type advanced/normal/prefilter/search/querystring/searchall * @param string $evalFilter evaled * * @return string sql query part e,g, "key = value" */ public function getFilterQuery($key, $condition, $value, $originalValue, $type = 'normal', $evalFilter = '0') { $params = $this->getParams(); $element = $this->getElement(); if ($type === 'prefilter' || $type === 'menuPrefilter') { switch ($condition) { case 'earlierthisyear': throw new UnexpectedValueException('The birthday element can not deal with "Earlier This Year" prefilters'); break; case 'laterthisyear': throw new UnexpectedValueException('The birthday element can not deal with "Later This Year" prefilters'); break; case 'today': $search = array(date('Y'), date('n'), date('j')); return $this->_dayMonthYearFilterQuery($key, $search); break; case 'yesterday': $today = new DateTime(); $today->sub(new DateInterval('P1D')); $search = array('', $today->format('n'), $today->format('j')); return $this->_dayMonthYearFilterQuery($key, $search); break; case 'tomorrow': $today = new DateTime(); $today->add(new DateInterval('P1D')); $search = array('', $today->format('n'), $today->format('j')); return $this->_dayMonthYearFilterQuery($key, $search); case 'thismonth': $search = array('', date('n'), ''); return $this->_dayMonthYearFilterQuery($key, $search); break; case 'lastmonth': $today = new DateTime(); $today->sub(new DateInterval('P1M')); $search = array('', $today->format('n'), ''); return $this->_dayMonthYearFilterQuery($key, $search); case 'nextmonth': $today = new DateTime(); $today->add(new DateInterval('P1M')); $search = array('', $today->format('n'), ''); return $this->_dayMonthYearFilterQuery($key, $search); case 'birthday': $search = array('', date('n'), date('j')); return $this->_dayMonthYearFilterQuery($key, $search); break; } } if ($element->filter_type === 'dropdown' && $params->get('list_filter_layout', 'individual') === 'day_mont_year') { return $this->_dayMonthYearFilterQuery($key, $originalValue); } else { $ft = $this->getParams()->get('list_date_format', 'd.m.Y'); if ($ft === 'd m') { $value = explode('-', $originalValue); array_shift($value); $value = implode('-', $value); $query = 'DATE_FORMAT(' . $key . ', \'%m-%d\') = ' . $this->_db->q($value); return $query; } $query = parent::getFilterQuery($key, $condition, $value, $originalValue, $type, $evalFilter); return $query; } }