Index: trunk/core/kernel/kbase.php =================================================================== diff -u -r3840 -r4029 --- trunk/core/kernel/kbase.php (.../kbase.php) (revision 3840) +++ trunk/core/kernel/kbase.php (.../kbase.php) (revision 4029) @@ -149,15 +149,22 @@ * @var Array * @access private */ - var $Fields=Array(); + var $Fields = Array(); /** + * Holds custom field names for item + * + * @var Array + */ + var $customFields = Array(); + + /** * All virtual field names * * @var Array * @access private */ - var $VirtualFields=Array(); + var $VirtualFields = Array(); /** * Fields that need to be queried using custom expression, e.g. IF(...) AS value @@ -245,10 +252,14 @@ $this->SelectClause = $sql; } - function GetSelectSQL($base_query=null) + function GetSelectSQL($base_query = null) { - if( !isset($base_query) ) $base_query = $this->SelectClause; - return $q = str_replace( Array('%1$s','%s'), $this->TableName, $base_query); + if (!isset($base_query)) { + $base_query = $this->SelectClause; + } + $query = str_replace( Array('%1$s','%s'), $this->TableName, $base_query); + $query = $this->replaceModePrefix($query); + return $query; } /** @@ -277,6 +288,19 @@ } /** + * Allows substables to be in same mode as main item (e.g. LEFT JOINED ones) + * + * @param string $query + * @return string + */ + function replaceModePrefix($query) + { + $live_table = substr(kTempTablesHandler::GetLiveName($this->TableName), strlen(TABLE_PREFIX)); + preg_match('/'.preg_quote(TABLE_PREFIX, '/').'(.*)'.preg_quote($live_table, '/').'/', $this->TableName, $rets); + return str_replace('%3$s', $rets[1], $query); + } + + /** * Adds calculated field declaration to object. * * @param string $name @@ -319,6 +343,7 @@ function defineFields() { $this->setConfigFields( $this->Application->getUnitOption($this->Prefix, 'Fields') ); + $this->setCustomFields( $this->Application->getUnitOption($this->Prefix, 'CustomFields', Array()) ); $this->setVirtualFields( $this->Application->getUnitOption($this->Prefix, 'VirtualFields') ); $this->setCalculatedFields( $this->Application->getUnitOption($this->Prefix, 'CalculatedFields') ); } @@ -335,6 +360,18 @@ * @param Array $fields * @access public */ + function setCustomFields($fields) + { + $this->customFields = $fields; + } + + /** + * Set's field names from table + * from config + * + * @param Array $fields + * @access public + */ function setConfigFields($fields) { $this->Fields = $fields;