Index: trunk/core/kernel/db/dblist.php =================================================================== diff -u -N -r6751 -r7391 --- trunk/core/kernel/db/dblist.php (.../dblist.php) (revision 6751) +++ trunk/core/kernel/db/dblist.php (.../dblist.php) (revision 7391) @@ -141,13 +141,13 @@ parent::kDBBase(); $this->OrderFields = Array(); - + $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->PerPage = -1; } @@ -165,21 +165,21 @@ 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 * @@ -228,11 +228,11 @@ function clearFilters() { $filters = $this->getFilterStructure(); - + foreach ($filters as $filter_params) { $filter =& $this->$filter_params['type']; $filter[ $filter_params['class'] ]->clearFilters(); - } + } } /** @@ -251,9 +251,11 @@ $all_sql = $this->GetSelectSQL(true,false); $sql = $this->getCountSQL($all_sql); + $this->Counted = true; + if( $this->GetGroupClause() ) { - $this->RecordsCount = count( $this->Conn->GetCol($sql) ); + $this->RecordsCount = count( $this->Conn->GetCol($sql) ); } else { @@ -276,8 +278,6 @@ { $this->NoFilterCount = (int)$this->Conn->GetOne($sql); } - - $this->Counted = true; } function getCountSQL($sql) @@ -379,6 +379,18 @@ return $this->Totals[$field.'_'.$total_function]; } + function GetFormattedTotal($field, $total_function) + { + $val = $this->getTotal($field, $total_function); + $options = $this->GetFieldOptions($field); + $res = $val; + if (isset($options['formatter'])) { + $formatter =& $this->Application->recallObject($options['formatter']); + $res = $formatter->Format($val, $field, $this ); + } + return $res; + } + /** * Builds full select query except for LIMIT clause * @@ -415,6 +427,7 @@ $fields = $this->getCalculatedFields($aggregated); if (is_array($fields) && count($fields) > 0) { foreach ($fields as $field_name => $field_expression) { + $clause = preg_replace('/(\\(+)[(,` ]*'.$field_name.'[` ]{1}/', '\1 '.$field_expression.' ', $clause); $clause = preg_replace('/[,` ]{1}'.$field_name.'[` ]{1}/', ' '.$field_expression.' ', $clause); } } @@ -442,7 +455,7 @@ $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 @@ -626,9 +639,32 @@ function GetDBField($name) { $row =& $this->getCurrentRecord(); + return $row[$name]; } + /** + * Returns ID of currently processed record + * + * @return int + * @access public + */ + function GetID() + { + return $this->Queried ? $this->GetDBField($this->IDField) : null; + } + + /** + * Allows kDBTagProcessor.SectionTitle to detect if it's editing or new item creation + * + * @return bool + */ + function IsNewItem() + { + // no such thing as NewItem for lists :) + return false; + } + function HasField($name) { $row =& $this->getCurrentRecord(); @@ -783,6 +819,8 @@ $parent_object =& $this->Application->recallObject($parent_prefix.'.'.$special); $parent_id = $parent_object->GetDBField($parent_table_key); + if (!$parent_id) return ; + $this->addFilter('parent_filter', '`'.$this->TableName.'`.`'.$foreign_key_field.'` = '.$parent_id); // only for list in this case } }