Index: branches/5.3.x/core/kernel/db/dblist.php =================================================================== diff -u -N -r15483 -r15698 --- branches/5.3.x/core/kernel/db/dblist.php (.../dblist.php) (revision 15483) +++ branches/5.3.x/core/kernel/db/dblist.php (.../dblist.php) (revision 15698) @@ -1,6 +1,6 @@ Totals = Array(); + $fields = Array (); + $this->Totals = Array (); - if ($this->gridName) { - $grids = $this->Application->getUnitOption($this->Prefix, 'Grids'); - $grid_fields = $grids[$this->gridName]['Fields']; + if ( $this->gridName ) { + $grid = $this->getUnitConfig()->getGridByName($this->gridName); + $grid_fields = $grid['Fields']; } else { $grid_fields = $this->Fields; } foreach ($grid_fields as $field_name => $field_options) { - if ($this->gridName && array_key_exists('totals', $field_options) && $field_options['totals']) { + if ( $this->gridName && array_key_exists('totals', $field_options) && $field_options['totals'] ) { $totals = $field_options['totals']; } - elseif (array_key_exists('totals', $this->Fields[$field_name]) && $this->Fields[$field_name]['totals']) { + elseif ( array_key_exists('totals', $this->Fields[$field_name]) && $this->Fields[$field_name]['totals'] ) { $totals = $this->Fields[$field_name]['totals']; } else { @@ -577,38 +577,37 @@ $calculated_field = array_key_exists($field_name, $this->CalculatedFields) && array_key_exists($field_name, $this->VirtualFields); $db_field = !array_key_exists($field_name, $this->VirtualFields); - 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 ( $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 ; + if ( !$fields ) { + return; } $sql = $this->GetSelectSQL(true, false); $fields = str_replace('%1$s', $this->TableName, implode(', ', $fields)); - if ( preg_match("/DISTINCT(.*?\s)FROM(?!_)/is",$sql,$regs ) ) - { - $sql = preg_replace("/^\s*SELECT DISTINCT(.*?\s)FROM(?!_)/is", 'SELECT '.$fields.' FROM', $sql); + if ( preg_match("/DISTINCT(.*?\s)FROM(?!_)/is", $sql, $regs) ) { + $sql = preg_replace("/^\s*SELECT DISTINCT(.*?\s)FROM(?!_)/is", 'SELECT ' . $fields . ' FROM', $sql); } - else - { - $sql = preg_replace("/^\s*SELECT(.*?\s)FROM(?!_)/is", 'SELECT '.$fields.' FROM ', $sql); + else { + $sql = preg_replace("/^\s*SELECT(.*?\s)FROM(?!_)/is", 'SELECT ' . $fields . ' FROM ', $sql); } $totals = $this->Conn->Query($sql); - foreach($totals as $totals_row) - { - foreach($totals_row as $total_field => $field_value) - { - if(!isset($this->Totals[$total_field])) $this->Totals[$total_field] = 0; + foreach ($totals as $totals_row) { + foreach ($totals_row as $total_field => $field_value) { + if ( !isset($this->Totals[$total_field]) ) { + $this->Totals[$total_field] = 0; + } $this->Totals[$total_field] += $field_value; } } + $this->TotalsCalculated = true; } @@ -636,18 +635,18 @@ function getTotalFunction($field) { - if ($this->gridName) { - $grids = $this->Application->getUnitOption($this->Prefix, 'Grids'); - $field_options = $grids[$this->gridName]['Fields'][$field]; + if ( $this->gridName ) { + $grid = $this->getUnitConfig()->getGridByName($this->gridName); + $field_options = $grid['Fields'][$field]; } else { $field_options = $this->Fields[$field]; } - if ($this->gridName && array_key_exists('totals', $field_options) && $field_options['totals']) { + if ( $this->gridName && array_key_exists('totals', $field_options) && $field_options['totals'] ) { return $field_options['totals']; } - elseif (array_key_exists('totals', $this->Fields[$field]) && $this->Fields[$field]['totals']) { + elseif ( array_key_exists('totals', $this->Fields[$field]) && $this->Fields[$field]['totals'] ) { return $this->Fields[$field]['totals']; } @@ -1298,24 +1297,25 @@ */ public function linkToParent($special) { - $parent_prefix = $this->Application->getUnitOption($this->Prefix, 'ParentPrefix'); - 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); + $config = $this->getUnitConfig(); + $parent_prefix = $config->getParentPrefix(); - if (!$parent_table_key || !$foreign_key_field) { - return ; + if ( $parent_prefix ) { + $parent_table_key = $config->getParentTableKey($parent_prefix); + $foreign_key_field = $config->getForeignKey($parent_prefix); + + if ( !$parent_table_key || !$foreign_key_field ) { + return; } - $parent_object = $this->Application->recallObject($parent_prefix.'.'.$special); + $parent_object = $this->Application->recallObject($parent_prefix . '.' . $special); /* @var $parent_object kDBItem */ - if (!$parent_object->isLoaded()) { + if ( !$parent_object->isLoaded() ) { $this->addFilter('parent_filter', 'FALSE'); - trigger_error('Parent ID not found (prefix: "' . rtrim($parent_prefix.'.'.$special, '.') . '"; sub-prefix: "' . $this->getPrefixSpecial() . '")', E_USER_NOTICE); - return ; + trigger_error('Parent ID not found (prefix: "' . rtrim($parent_prefix . '.' . $special, '.') . '"; sub-prefix: "' . $this->getPrefixSpecial() . '")', E_USER_NOTICE); + + return; } // only for list in this case