Index: trunk/core/kernel/db/dblist.php =================================================================== diff -u -N -r6428 -r6751 --- trunk/core/kernel/db/dblist.php (.../dblist.php) (revision 6428) +++ trunk/core/kernel/db/dblist.php (.../dblist.php) (revision 6751) @@ -1,29 +1,5 @@ OrderFields = Array(); - $this->WhereFilter[FLT_SYSTEM] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_AND); - $this->WhereFilter[FLT_NORMAL] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_OR); + + $filters = $this->getFilterStructure(); + + foreach ($filters as $filter_params) { + $filter =& $this->$filter_params['type']; + $filter[ $filter_params['class'] ] =& $this->Application->makeClass('kMultipleFilter', $filter_params['join_using']); + } - $this->WhereFilter[FLT_SEARCH] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_OR); - $this->WhereFilter[FLT_VIEW] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_AND); - - $this->HavingFilter[FLT_SYSTEM] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_AND); - $this->HavingFilter[FLT_NORMAL] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_OR); - - $this->HavingFilter[FLT_SEARCH] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_OR); - $this->HavingFilter[FLT_VIEW] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_AND); - - $this->AggregateFilter[FLT_SYSTEM] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_AND); - $this->AggregateFilter[FLT_NORMAL] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_OR); - $this->AggregateFilter[FLT_VIEW] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_AND); - $this->PerPage = -1; } /** + * Returns information about all possible filter types + * + * @return Array + */ + function getFilterStructure() + { + $filters = Array ( + Array ('type' => 'WhereFilter', 'class' => FLT_SYSTEM, 'join_using' => FLT_TYPE_AND), + Array ('type' => 'WhereFilter', 'class' => FLT_NORMAL, 'join_using' => FLT_TYPE_OR), + Array ('type' => 'WhereFilter', 'class' => FLT_SEARCH, 'join_using' => FLT_TYPE_OR), + Array ('type' => 'WhereFilter', 'class' => FLT_VIEW, 'join_using' => FLT_TYPE_AND), + Array ('type' => 'WhereFilter', 'class' => FLT_CUSTOM, 'join_using' => FLT_TYPE_AND), + + Array ('type' => 'HavingFilter', 'class' => FLT_SYSTEM, 'join_using' => FLT_TYPE_AND), + Array ('type' => 'HavingFilter', 'class' => FLT_NORMAL, 'join_using' => FLT_TYPE_OR), + Array ('type' => 'HavingFilter', 'class' => FLT_SEARCH, 'join_using' => FLT_TYPE_OR), + Array ('type' => 'HavingFilter', 'class' => FLT_VIEW, 'join_using' => FLT_TYPE_AND), + Array ('type' => 'HavingFilter', 'class' => FLT_CUSTOM, 'join_using' => FLT_TYPE_AND), + + Array ('type' => 'AggregateFilter', 'class' => FLT_SYSTEM, 'join_using' => FLT_TYPE_AND), + Array ('type' => 'AggregateFilter', 'class' => FLT_NORMAL, 'join_using' => FLT_TYPE_OR), + Array ('type' => 'AggregateFilter', 'class' => FLT_VIEW, 'join_using' => FLT_TYPE_AND), + ); + + return $filters; + } + + /** * Adds new or replaces old filter with same name * * @param string $name filter name (for internal use) * @param string $clause where/having clause part (no OR/AND allowed) * @param int $filter_type is filter having filter or where filter - * @param int $filter_scope filter subtype: FLT_NORMAL,FLT_SYSTEM,FLT_SEARCH,FLT_VIEW + * @param int $filter_scope filter subtype: FLT_NORMAL,FLT_SYSTEM,FLT_SEARCH,FLT_VIEW,FLT_CUSTOM * @access public */ function addFilter($name, $clause, $filter_type = WHERE_FILTER, $filter_scope = FLT_SYSTEM) @@ -210,7 +206,7 @@ * * @param string $name filter name (for internal use) * @param int $filter_type is filter having filter or where filter - * @param int $filter_scope filter subtype: FLT_NORMAL,FLT_SYSTEM,FLT_SEARCH,FLT_VIEW + * @param int $filter_scope filter subtype: FLT_NORMAL,FLT_SYSTEM,FLT_SEARCH,FLT_VIEW,FLT_CUSTOM * @access public */ function removeFilter($name, $filter_type = WHERE_FILTER, $filter_scope = FLT_SYSTEM) @@ -228,32 +224,15 @@ /** * Clear list filters * - * @param bool $user clear user filters - * @param bool $system clear system filters */ - function clearFilters($user=true,$system=true,$search=true,$view=true) + function clearFilters() { - if ($system) { - $this->WhereFilter[FLT_SYSTEM]->clearFilters(); - $this->HavingFilter[FLT_SYSTEM]->clearFilters(); - $this->AggregateFilter[FLT_SYSTEM]->clearFilters(); - } - - if ($user) { - $this->WhereFilter[FLT_NORMAL]->clearFilters(); - $this->HavingFilter[FLT_NORMAL]->clearFilters(); - $this->AggregateFilter[FLT_NORMAL]->clearFilters(); - } - - if ($search) { - $this->WhereFilter[FLT_SEARCH]->clearFilters(); - $this->HavingFilter[FLT_SEARCH]->clearFilters(); - } - - if ($view) { - $this->WhereFilter[FLT_VIEW]->clearFilters(); - $this->HavingFilter[FLT_VIEW]->clearFilters(); - } + $filters = $this->getFilterStructure(); + + foreach ($filters as $filter_params) { + $filter =& $this->$filter_params['type']; + $filter[ $filter_params['class'] ]->clearFilters(); + } } /** @@ -458,12 +437,20 @@ if (!$system_filters_only) { $where->addFilter('view_where', $this->WhereFilter[FLT_VIEW] ); $search_w = $this->WhereFilter[FLT_SEARCH]->getSQL(); - if( $search_w || $for_counting ) // move search_having to search_where in case search_where isset or we are counting - { + if ($search_w || $for_counting) { // move search_having to search_where in case search_where isset or we are counting $search_h = $this->extractCalculatedFields( $this->HavingFilter[FLT_SEARCH]->getSQL() ); $search_w = ($search_w && $search_h) ? $search_w.' OR '.$search_h : $search_w.$search_h; $where->addFilter('search_where', $search_w ); } + + // CUSTOM + $search_w = $this->WhereFilter[FLT_CUSTOM]->getSQL(); + if ($search_w || $for_counting) { // move search_having to search_where in case search_where isset or we are counting + $search_h = $this->extractCalculatedFields( $this->HavingFilter[FLT_CUSTOM]->getSQL() ); + $search_w = ($search_w && $search_h) ? $search_w.' AND '.$search_h : $search_w.$search_h; + $where->addFilter('custom_where', $search_w ); + } + // CUSTOM } if( $for_counting ) // add system_having and view_having to where @@ -523,6 +510,7 @@ if (!$system_filters_only) { $having->addFilter('view_having', $this->HavingFilter[FLT_VIEW] ); + $having->addFilter('custom_having', $this->HavingFilter[FLT_CUSTOM] ); $search_w = $this->WhereFilter[FLT_SEARCH]->getSQL(); if (!$search_w) { $having->addFilter('search_having', $this->HavingFilter[FLT_SEARCH] );