Index: trunk/core/kernel/db/dblist.php
===================================================================
diff -u -r3559 -r3703
--- trunk/core/kernel/db/dblist.php (.../dblist.php) (revision 3559)
+++ trunk/core/kernel/db/dblist.php (.../dblist.php) (revision 3703)
@@ -32,14 +32,14 @@
*/
class kDBList extends kDBBase {
-
+
/**
* Holds totals for fields specified in config
*
* @var Array
*/
var $Totals = Array();
-
+
/**
* Description
*
@@ -277,7 +277,7 @@
$this->NoFilterCount = $this->RecordsCount;
return;
}
-
+
$sql = $this->getCountSQL($system_sql);
if( $this->GetGroupClause() )
{
@@ -287,7 +287,7 @@
{
$this->NoFilterCount = (int)$this->Conn->GetOne($sql);
}
-
+
$this->Counted = true;
}
@@ -316,7 +316,7 @@
{
if (!$force && $this->Queried) return true;
$q = $this->GetSelectSQL();
-
+
//$rs = $this->Conn->SelectLimit($q, $this->PerPage, $this->Offset);
//in case we have not counted records try to select one more item to find out if we have something more than perpage
@@ -340,28 +340,28 @@
function CalculateTotals()
{
$this->Totals = Array();
-
+
$fields = Array();
foreach($this->Fields as $field_name => $field_options)
{
$totals = getArrayValue($field_options, 'totals');
if(!$totals) continue;
-
+
$calculated_field = isset($this->CalculatedFields[$field_name]) && isset($this->VirtualFields[$field_name]);
$db_field = !isset($this->VirtualFields[$field_name]);
-
+
if($calculated_field || $db_field)
{
$field_expression = $calculated_field ? $this->CalculatedFields[$field_name] : '`'.$this->TableName.'`.`'.$field_name.'`';
$fields[$field_name] = $totals.'('.$field_expression.') AS '.$field_name.'_'.$totals;
}
}
-
+
if(!$fields) return false;
-
+
$sql = $this->GetSelectSQL(true, false);
$fields = implode(', ', $fields);
-
+
if ( preg_match("/DISTINCT(.*?)FROM(?!_)/is",$sql,$regs ) )
{
$sql = preg_replace("/^.*SELECT DISTINCT(.*?)FROM(?!_)/is", 'SELECT '.$fields.' FROM', $sql);
@@ -370,9 +370,9 @@
{
$sql = preg_replace("/^.*SELECT(.*?)FROM(?!_)/is", 'SELECT '.$fields.' FROM ', $sql);
}
-
+
$totals = $this->Conn->Query($sql);
-
+
foreach($totals as $totals_row)
{
foreach($totals_row as $total_field => $field_value)
@@ -382,12 +382,12 @@
}
}
}
-
+
function getTotal($field, $total_function)
{
return $this->Totals[$field.'_'.$total_function];
}
-
+
/**
* Builds full select query except for LIMIT clause
*
@@ -533,12 +533,12 @@
$lang = $this->Application->GetVar('m_lang');
$field = 'l'.$lang.'_'.$field;
}
-
+
if( !isset($this->Fields[$field]) )
{
trigger_error('Incorrect sorting defined (field = '.$field.'; direction = '.$direction.') in config for prefix '.$this->Prefix.'', E_USER_WARNING);
}
-
+
$this->OrderFields[] = Array($field, $direction);
}
@@ -752,8 +752,12 @@
if($parent_prefix)
{
$parent_table_key = $this->Application->getUnitOption($this->Prefix, 'ParentTableKey');
+ if (is_array($parent_table_key)) $parent_table_key = getArrayValue($parent_table_key, $parent_prefix);
$foreign_key_field = $this->Application->getUnitOption($this->Prefix, 'ForeignKey');
+ if (is_array($foreign_key_field)) $foreign_key_field = getArrayValue($foreign_key_field, $parent_prefix);
+ if (!$parent_table_key || !$foreign_key_field) return ;
+
$parent_object =& $this->Application->recallObject($parent_prefix.'.'.$special);
$parent_id = $parent_object->GetDBField($parent_table_key);