Index: branches/5.2.x/core/kernel/db/dblist.php =================================================================== diff -u -N -r14092 -r14095 --- branches/5.2.x/core/kernel/db/dblist.php (.../dblist.php) (revision 14092) +++ branches/5.2.x/core/kernel/db/dblist.php (.../dblist.php) (revision 14095) @@ -1,6 +1,6 @@ null, FLT_NORMAL => null, FLT_SEARCH => null, FLT_VIEW => null); + protected $AggregateFilter = Array (); /** - * Holds list HAVING filter object + * List of "GROUP BY" fields * - * @var kMultipleFilter - * @access private + * @var Array + * @access protected */ - var $HavingFilter = Array (FLT_SYSTEM => null, FLT_NORMAL => null, FLT_SEARCH => null, FLT_VIEW => null); + protected $GroupByFields = Array (); - var $AggregateFilter = Array (FLT_SYSTEM => null, FLT_NORMAL => null); + /** + * Remembers if list was queried + * + * @var bool + * @access protected + */ + protected $Queried = false; - var $GroupByFields = Array (); + /** + * Remembers if list was counted + * + * @var bool + * @access protected + */ + protected $Counted = false; - var $Queried = false; - - var $Counted = false; - - var $TotalsCalculated = false; - /** * Name of the grid, used to display the list * @@ -157,25 +238,27 @@ * Identifies this list as main on the page, that allows to react on "page", "per_page" and "sort_by" parameters from url * * @var bool + * @access protected */ - var $mainList = false; + protected $mainList = false; /** * Creates kDBList * * @return kDBList + * @access public */ - function kDBList() + public function __construct() { - parent::kDBBase(); + parent::__construct(); $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']); + $filter[ $filter_params['class'] ] =& $this->Application->makeClass('kMultipleFilter', Array ($filter_params['join_using'])); } $this->PerPage = -1; @@ -190,25 +273,26 @@ * Returns information about all possible filter types * * @return Array + * @access protected */ - function getFilterStructure() + protected 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' => 'WhereFilter', 'class' => kDBList::FLT_SYSTEM, 'join_using' => kDBList::FLT_TYPE_AND), + Array ('type' => 'WhereFilter', 'class' => kDBList::FLT_NORMAL, 'join_using' => kDBList::FLT_TYPE_OR), + Array ('type' => 'WhereFilter', 'class' => kDBList::FLT_SEARCH, 'join_using' => kDBList::FLT_TYPE_OR), + Array ('type' => 'WhereFilter', 'class' => kDBList::FLT_VIEW, 'join_using' => kDBList::FLT_TYPE_AND), + Array ('type' => 'WhereFilter', 'class' => kDBList::FLT_CUSTOM, 'join_using' => kDBList::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' => 'HavingFilter', 'class' => kDBList::FLT_SYSTEM, 'join_using' => kDBList::FLT_TYPE_AND), + Array ('type' => 'HavingFilter', 'class' => kDBList::FLT_NORMAL, 'join_using' => kDBList::FLT_TYPE_OR), + Array ('type' => 'HavingFilter', 'class' => kDBList::FLT_SEARCH, 'join_using' => kDBList::FLT_TYPE_OR), + Array ('type' => 'HavingFilter', 'class' => kDBList::FLT_VIEW, 'join_using' => kDBList::FLT_TYPE_AND), + Array ('type' => 'HavingFilter', 'class' => kDBList::FLT_CUSTOM, 'join_using' => kDBList::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), + Array ('type' => 'AggregateFilter', 'class' => kDBList::FLT_SYSTEM, 'join_using' => kDBList::FLT_TYPE_AND), + Array ('type' => 'AggregateFilter', 'class' => kDBList::FLT_NORMAL, 'join_using' => kDBList::FLT_TYPE_OR), + Array ('type' => 'AggregateFilter', 'class' => kDBList::FLT_VIEW, 'join_using' => kDBList::FLT_TYPE_AND), ); return $filters; @@ -223,11 +307,11 @@ * @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) + public function addFilter($name, $clause, $filter_type = kDBList::WHERE_FILTER, $filter_scope = kDBList::FLT_SYSTEM) { - $filter_source = Array( WHERE_FILTER => 'WhereFilter', - HAVING_FILTER => 'HavingFilter', - AGGREGATE_FILTER => 'AggregateFilter'); + $filter_source = Array( kDBList::WHERE_FILTER => 'WhereFilter', + kDBList::HAVING_FILTER => 'HavingFilter', + kDBList::AGGREGATE_FILTER => 'AggregateFilter'); $filter_name = $filter_source[$filter_type]; $filter =& $this->$filter_name; @@ -243,11 +327,11 @@ * @param int $filter_scope filter subtype: FLT_NORMAL,FLT_SYSTEM,FLT_SEARCH,FLT_VIEW,FLT_CUSTOM * @access public */ - function getFilter($name, $filter_type = WHERE_FILTER, $filter_scope = FLT_SYSTEM) + public function getFilter($name, $filter_type = kDBList::WHERE_FILTER, $filter_scope = kDBList::FLT_SYSTEM) { - $filter_source = Array( WHERE_FILTER => 'WhereFilter', - HAVING_FILTER => 'HavingFilter', - AGGREGATE_FILTER => 'AggregateFilter'); + $filter_source = Array( kDBList::WHERE_FILTER => 'WhereFilter', + kDBList::HAVING_FILTER => 'HavingFilter', + kDBList::AGGREGATE_FILTER => 'AggregateFilter'); $filter_name = $filter_source[$filter_type]; $filter =& $this->$filter_name; @@ -263,11 +347,11 @@ * @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) + public function removeFilter($name, $filter_type = kDBList::WHERE_FILTER, $filter_scope = kDBList::FLT_SYSTEM) { - $filter_source = Array( WHERE_FILTER => 'WhereFilter', - HAVING_FILTER => 'HavingFilter', - AGGREGATE_FILTER => 'AggregateFilter'); + $filter_source = Array( kDBList::WHERE_FILTER => 'WhereFilter', + kDBList::HAVING_FILTER => 'HavingFilter', + kDBList::AGGREGATE_FILTER => 'AggregateFilter'); $filter_name = $filter_source[$filter_type]; $filter =& $this->$filter_name; @@ -276,10 +360,11 @@ } /** - * Clear list filters + * Clear all filters * + * @access public */ - function clearFilters() + public function clearFilters() { $filters = $this->getFilterStructure(); @@ -296,11 +381,9 @@ * Special care should be applied when working with lists based on grouped queries, all aggregate function fields * like SUM(), AVERAGE() etc. should be added to CountedSQL by using {@link kDBList::SetCountedSQL()} * - * @access public - * @param string - * @return void + * @access protected */ - function CountRecs() + protected function CountRecs() { $all_sql = $this->GetSelectSQL(true,false); $sql = $this->getCountSQL($all_sql); @@ -334,23 +417,41 @@ } } - function GetNoFilterCount() + /** + * Returns record count in list with/without user filters applied + * + * @param bool $with_filters + * @return int + * @access public + */ + public function GetRecordsCount($with_filters = true) { if (!$this->Counted) { $this->CountRecs(); } - return $this->NoFilterCount; + + return $with_filters ? $this->RecordsCount : $this->NoFilterCount; } - function GetRecordsCount() + /** + * Returns record count, that were actually selected + * + * @return int + * @access public + */ + public function GetSelectedCount() { - if (!$this->Counted) { - $this->CountRecs(); - } - return $this->RecordsCount; + return $this->SelectedCount; } - function getCountSQL($sql) + /** + * Transforms given query into count query (DISTINCT is also processed) + * + * @param string $sql + * @return string + * @access public + */ + public function getCountSQL($sql) { if ( preg_match("/DISTINCT(.*?)FROM(?!_)/is",$sql,$regs ) ) { @@ -367,11 +468,10 @@ * * All the sorting, pagination, filtration of the list should be set prior to calling Query(). * + * @param bool $force force re-query, when already queried * @access public - * @param string - * @return void */ - function Query($force=false) + public function Query($force=false) { if (!$force && $this->Queried) return true; $q = $this->GetSelectSQL(); @@ -412,15 +512,21 @@ * Adds one more record to list virtually and updates all counters * * @param Array $record + * @access public */ - function addRecord($record) + public function addRecord($record) { $this->Records[] = $record; $this->SelectedCount++; $this->RecordsCount++; } - function CalculateTotals() + /** + * Calculates totals based on config + * + * @access protected + */ + protected function CalculateTotals() { $fields = Array(); $this->Totals = Array(); @@ -453,7 +559,9 @@ } } - if(!$fields) return false; + if (!$fields) { + return ; + } $sql = $this->GetSelectSQL(true, false); $fields = implode(', ', $fields); @@ -480,7 +588,15 @@ $this->TotalsCalculated = true; } - function getTotal($field, $total_function) + /** + * Returns previously calculated total (not formatted) + * + * @param string $field + * @param string $total_function + * @return float + * @access public + */ + public function getTotal($field, $total_function) { if (!$this->TotalsCalculated) { $this->CalculateTotals(); @@ -514,6 +630,14 @@ return false; } + /** + * Returns previously calculated total (formatted) + * + * @param string $field + * @param string $total_function + * @return float + * @access public + */ function GetFormattedTotal($field, $total_function) { $val = $this->getTotal($field, $total_function); @@ -527,12 +651,14 @@ } /** - * Builds full select query except for LIMIT clause - * - * @access public - * @return string - */ - function GetSelectSQL($for_counting=false,$system_filters_only=false) + * Builds full select query except for LIMIT clause + * + * @param bool $for_counting + * @param bool $system_filters_only + * @return string + * @access public + */ + public function GetSelectSQL($for_counting=false,$system_filters_only=false) { $q = parent::GetSelectSQL($this->SelectClause); $q = !$for_counting ? $this->addCalculatedFields($q, 0) : str_replace('%2$s', '', $q); @@ -551,13 +677,14 @@ } /** - * Enter description here... + * Replaces all calculated field occurences with their associated expressions * * @param string $clause where clause to extract calculated fields from * @param int $aggregated 0 - having + aggregated, 1 - having only, 2 - aggregated only * @return string + * @access private */ - function extractCalculatedFields($clause, $aggregated = 1) + private function extractCalculatedFields($clause, $aggregated = 1) { $fields = $this->getCalculatedFields($aggregated); if (is_array($fields) && count($fields) > 0) { @@ -570,31 +697,32 @@ } /** - * Returns WHERE clause of the query - * - * @access public - * @param bool $for_counting merge where filters with having filters + replace field names for having fields with their values - * @return string - */ - function GetWhereClause($for_counting=false,$system_filters_only=false) + * Returns WHERE clause of the query + * + * @param bool $for_counting merge where filters with having filters + replace field names for having fields with their values + * @param bool $system_filters_only + * @return string + * @access private + */ + private function GetWhereClause($for_counting=false,$system_filters_only=false) { $where =& $this->Application->makeClass('kMultipleFilter'); - $where->addFilter('system_where', $this->WhereFilter[FLT_SYSTEM] ); + $where->addFilter('system_where', $this->WhereFilter[kDBList::FLT_SYSTEM] ); if (!$system_filters_only) { - $where->addFilter('view_where', $this->WhereFilter[FLT_VIEW] ); - $search_w = $this->WhereFilter[FLT_SEARCH]->getSQL(); + $where->addFilter('view_where', $this->WhereFilter[kDBList::FLT_VIEW] ); + $search_w = $this->WhereFilter[kDBList::FLT_SEARCH]->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_SEARCH]->getSQL() ); + $search_h = $this->extractCalculatedFields( $this->HavingFilter[kDBList::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(); + $search_w = $this->WhereFilter[kDBList::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_h = $this->extractCalculatedFields( $this->HavingFilter[kDBList::FLT_CUSTOM]->getSQL() ); $search_w = ($search_w && $search_h) ? $search_w.' AND '.$search_h : $search_w.$search_h; $where->addFilter('custom_where', $search_w ); } @@ -603,65 +731,49 @@ if( $for_counting ) // add system_having and view_having to where { - $where->addFilter('system_having', $this->extractCalculatedFields($this->HavingFilter[FLT_SYSTEM]->getSQL()) ); - if (!$system_filters_only) $where->addFilter('view_having', $this->extractCalculatedFields( $this->HavingFilter[FLT_VIEW]->getSQL() ) ); + $where->addFilter('system_having', $this->extractCalculatedFields($this->HavingFilter[kDBList::FLT_SYSTEM]->getSQL()) ); + if (!$system_filters_only) $where->addFilter('view_having', $this->extractCalculatedFields( $this->HavingFilter[kDBList::FLT_VIEW]->getSQL() ) ); } return $where->getSQL(); } /** - * Depricated method - * - * @param string $clause - * @todo REMOVE - */ - function SetWhereClause($clause) - { - if ($this->Application->isDebugMode()) { - global $debugger; - $debugger->appendTrace(); - } - - trigger_error('Depricated method kDBList->SetWhereClause. Use kDBList->addFilter instead.', defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_NOTICE); - } - - /** * Returns HAVING clause of the query * * @param bool $for_counting don't return having filter in case if this is counting sql * @param bool $system_filters_only return only system having filters * @param int $aggregated 0 - aggregated and having, 1 - having only, 2 - aggregated only * @return string - * @access public + * @access private */ - function GetHavingClause($for_counting=false, $system_filters_only=false, $aggregated = 0) + private function GetHavingClause($for_counting=false, $system_filters_only=false, $aggregated = 0) { if ($for_counting) { $aggregate_filter =& $this->Application->makeClass('kMultipleFilter'); - $aggregate_filter->addFilter('aggregate_system', $this->AggregateFilter[FLT_SYSTEM]); + $aggregate_filter->addFilter('aggregate_system', $this->AggregateFilter[kDBList::FLT_SYSTEM]); if (!$system_filters_only) { - $aggregate_filter->addFilter('aggregate_view', $this->AggregateFilter[FLT_VIEW]); + $aggregate_filter->addFilter('aggregate_view', $this->AggregateFilter[kDBList::FLT_VIEW]); } return $this->extractCalculatedFields($aggregate_filter->getSQL(), 2); } $having =& $this->Application->makeClass('kMultipleFilter'); - $having->addFilter('system_having', $this->HavingFilter[FLT_SYSTEM] ); + $having->addFilter('system_having', $this->HavingFilter[kDBList::FLT_SYSTEM] ); if ($aggregated == 0) { if (!$system_filters_only) { - $having->addFilter('view_aggregated', $this->AggregateFilter[FLT_VIEW] ); + $having->addFilter('view_aggregated', $this->AggregateFilter[kDBList::FLT_VIEW] ); } - $having->addFilter('system_aggregated', $this->AggregateFilter[FLT_SYSTEM]); + $having->addFilter('system_aggregated', $this->AggregateFilter[kDBList::FLT_SYSTEM]); } 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(); + $having->addFilter('view_having', $this->HavingFilter[kDBList::FLT_VIEW] ); + $having->addFilter('custom_having', $this->HavingFilter[kDBList::FLT_CUSTOM] ); + $search_w = $this->WhereFilter[kDBList::FLT_SEARCH]->getSQL(); if (!$search_w) { - $having->addFilter('search_having', $this->HavingFilter[FLT_SEARCH] ); + $having->addFilter('search_having', $this->HavingFilter[kDBList::FLT_SEARCH] ); } } @@ -671,34 +783,45 @@ /** * Returns GROUP BY clause of the query * - * @access public * @return string + * @access protected */ - function GetGroupClause() + protected function GetGroupClause() { return $this->GroupByFields ? implode(',', $this->GroupByFields) : ''; } - function AddGroupByField($field) + /** + * Adds new group by field + * + * @param string $field + * @access public + */ + public function AddGroupByField($field) { $this->GroupByFields[$field] = $field; } - function RemoveGroupByField($field) + /** + * Removes group by field added before + * + * @param string $field + * @access public + */ + public function RemoveGroupByField($field) { unset($this->GroupByFields[$field]); } /** * Adds order field to ORDER BY clause * - * @access public * @param string $field Field name * @param string $direction Direction of ordering (asc|desc) * @param bool $is_expression this is expression, that should not be escapted by "`" symbols - * @return void + * @access public */ - function AddOrderField($field, $direction = 'asc', $is_expression = false) + public function AddOrderField($field, $direction = 'asc', $is_expression = false) { // original multilanguage field - convert to current lang field $formatter = isset($this->Fields[$field]['formatter']) ? $this->Fields[$field]['formatter'] : false; @@ -737,9 +860,8 @@ * Removes all order fields * * @access public - * @return void */ - function ClearOrderFields() + public function ClearOrderFields() { $this->OrderFields = Array(); } @@ -749,10 +871,10 @@ * * The method builds order by clause by iterating {@link kDBList::OrderFields} array and concatenating it. * - * @access public * @return string + * @access private */ - function GetOrderClause() + private function GetOrderClause() { $ret = ''; foreach ($this->OrderFields as $field) { @@ -771,7 +893,15 @@ return $ret; } - function GetOrderField($pos = NULL, $no_default = false) + /** + * Returns order field name in given position + * + * @param int $pos + * @param bool $no_default + * @return string + * @access public + */ + public function GetOrderField($pos = NULL, $no_default = false) { if ( !(isset($this->OrderFields[$pos]) && $this->OrderFields[$pos]) && !$no_default ) { $pos = 0; @@ -792,7 +922,15 @@ return ''; } - function GetOrderDirection($pos = NULL, $no_default = false) + /** + * Returns order field direction in given position + * + * @param int $pos + * @param bool $no_default + * @return string + * @access public + */ + public function GetOrderDirection($pos = NULL, $no_default = false) { if ( !(isset($this->OrderFields[$pos]) && $this->OrderFields[$pos]) && !$no_default ) { $pos = 0; @@ -802,18 +940,41 @@ } /** + * Returns ID of currently processed record + * + * @return int + * @access public + */ + 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 + * @access public + */ + public function IsNewItem() + { + // no such thing as NewItem for lists :) + return false; + } + + /** * Return unformatted field value * * @param string $name * @return string * @access public */ - function GetDBField($name) + public function GetDBField($name) { $row =& $this->getCurrentRecord(); if (defined('DEBUG_MODE') && DEBUG_MODE && $this->Queried && !array_key_exists($name, $row)) { - if ($this->Application->isDebugMode()) { + if ( $this->Application->isDebugMode() ) { $this->Application->Debugger->appendTrace(); } @@ -826,119 +987,111 @@ } /** - * Returns ID of currently processed record + * Checks if requested field is present after database query * - * @return int + * @param string $name + * @return bool * @access public */ - function GetID() + public function HasField($name) { - return $this->Queried ? $this->GetDBField($this->IDField) : null; + $row =& $this->getCurrentRecord(); + return isset($row[$name]); } /** - * Allows kDBTagProcessor.SectionTitle to detect if it's editing or new item creation + * Returns current record fields * - * @return bool + * @return Array + * @access public */ - function IsNewItem() + public function GetFieldValues() { - // no such thing as NewItem for lists :) - return false; - } + $record =& $this->getCurrentRecord(); - function HasField($name) - { - $row =& $this->getCurrentRecord(); - return isset($row[$name]); + return $record; } - function GetFieldValues() - { - return $this->getCurrentRecord(); - } - /** * Returns current record from list * * @param int $offset Offset relative to current record index * @return Array + * @access public */ - function &getCurrentRecord($offset = 0) + public function &getCurrentRecord($offset = 0) { $record_index = $this->CurrentIndex + $offset; if ($record_index >=0 && $record_index < $this->SelectedCount) { return $this->Records[$record_index]; } - return false; + $false = false; + return $false; } /** * Goes to record with given index * * @param int $index + * @access public */ - function GoIndex($index) + public function GoIndex($index) { $this->CurrentIndex = $index; } /** - * Description + * Goes to first record * * @access public - * @param string - * @return void */ - function GoFirst() + public function GoFirst() { $this->CurrentIndex = 0; } /** - * Description + * Goes to next record * * @access public - * @return void */ - function GoNext() + public function GoNext() { $this->CurrentIndex++; } /** - * Description + * Goes to previous record * * @access public - * @return void */ - function GoPrev() + public function GoPrev() { - if ($this->CurrentIndex>0) + if ($this->CurrentIndex>0) { $this->CurrentIndex--; + } } /** - * Description + * Checks if there is no end of list * - * @access public * @return bool + * @access public */ - function EOL() + public function EOL() { return ($this->CurrentIndex >= $this->SelectedCount); } /** - * Description + * Returns total page count based on list per-page * - * @access public * @param string - * @return void + * @access public */ - function GetTotalPages() + public function GetTotalPages() { if (!$this->Counted) $this->CountRecs(); if ($this->PerPage == -1) return 1; @@ -950,28 +1103,37 @@ /** * Sets number of records to query per page * - * @access public * @param int $per_page Number of records to display per page - * @return void + * @access public */ - function SetPerPage($per_page) + public function SetPerPage($per_page) { $this->PerPage = $per_page; } - function GetPerPage() + /** + * Returns records per page count + * + * @param bool $in_fact + * @return int + * @access public + */ + public function GetPerPage($in_fact = false) { + if ($in_fact) { + return $this->PerPage; + } + return $this->PerPage == -1 ? $this->RecordsCount : $this->PerPage; } /** - * Description + * Sets current page in list * - * @access public * @param int $page - * @return void + * @access public */ - function SetPage($page) + public function SetPage($page) { if ($this->PerPage == -1) { $this->Page = 1; @@ -989,15 +1151,46 @@ } /** - * Sets current item field value - * (doesn't apply formatting) + * Returns current list page + * + * @return int + * @access public + */ + public function GetPage() + { + return $this->Page; + } + + /** + * Sets list query offset + * + * @param int $offset + * @access public + */ + public function SetOffset($offset) + { + $this->Offset = $offset; + } + + /** + * Gets list query offset + * + * @return int + * @access public + */ + public function GetOffset() + { + return $this->Offset; + } + + /** + * Sets current item field value (doesn't apply formatting) * - * @access public * @param string $name Name of the field * @param mixed $value Value to set the field to - * @return void + * @access public */ - function SetDBField($name,$value) + public function SetDBField($name,$value) { $this->Records[$this->CurrentIndex][$name] = $value; } @@ -1008,7 +1201,7 @@ * @param string $special * @access public */ - function linkToParent($special) + public function linkToParent($special) { $parent_prefix = $this->Application->getUnitOption($this->Prefix, 'ParentPrefix'); if ($parent_prefix) { @@ -1040,8 +1233,9 @@ * Returns true if list was queried (same name as for kDBItem for easy usage) * * @return bool + * @access public */ - function isLoaded() + public function isLoaded() { return $this->Queried && !$this->EOL(); } @@ -1054,8 +1248,9 @@ * @param bool $formatted * @param string $format * @return Array + * @access public */ - function GetCol($field, $formatted = false, $format = null) + public function GetCol($field, $formatted = false, $format = null) { $i = 0; $ret = Array (); @@ -1086,8 +1281,10 @@ * @param string $field * @param string $pseudo * @param string $error_label + * @param Array $error_params + * @access public */ - function SetError($field, $pseudo, $error_label = null, $error_params = null) + public function SetError($field, $pseudo, $error_label = null, $error_params = null) { $error_field = isset($this->Fields[$field]['error_field']) ? $this->Fields[$field]['error_field'] : $field; $this->FieldErrors[$error_field]['pseudo'] = $pseudo; @@ -1105,4 +1302,70 @@ return true; } + /** + * Group list records by header, saves internal order in group + * + * @param string $heading_field + * @access public + */ + public function groupRecords($heading_field) + { + $i = 0; + $sorted = Array (); + + while ($i < $this->SelectedCount) { + $sorted[ $this->Records[$i][$heading_field] ][] = $this->Records[$i]; + $i++; + } + + $this->Records = Array (); + + foreach ($sorted as $heading => $heading_records) { + $this->Records = array_merge_recursive($this->Records, $heading_records); + } + } + + /** + * Reset list (use for requering purposes) + * + * @access public + */ + public function reset() + { + $this->Counted = false; + $this->clearFilters(); + $this->ClearOrderFields(); + } + + /** + * Checks if list was counted + * + * @return bool + * @access public + */ + public function isCounted() + { + return $this->Counted; + } + + /** + * Tells, that given list is main + * + * @return bool + * @access public + */ + public function isMainList() + { + return $this->mainList; + } + + /** + * Makes given list as main + * + * @access public + */ + public function becameMain() + { + $this->mainList = true; + } } \ No newline at end of file