Index: trunk/core/kernel/kbase.php =================================================================== diff -u -r3307 -r3703 --- trunk/core/kernel/kbase.php (.../kbase.php) (revision 3307) +++ trunk/core/kernel/kbase.php (.../kbase.php) (revision 3703) @@ -21,7 +21,7 @@ * @access public */ var $Prefix=''; - + /** * Special, that was used * to create an object @@ -30,9 +30,9 @@ * @access public */ var $Special=''; - + var $OriginalParams; - + /** * Set's application * @@ -43,7 +43,7 @@ { $this->Application =& kApplication::Instance(); } - + /** * Create new instance of object * @@ -53,7 +53,7 @@ { return new kBase(); } - + /** * Set's prefix and special * @@ -68,7 +68,7 @@ $this->Special=$special; $this->OriginalParams = $event_params; } - + /** * Returns joined prefix * and special if any @@ -83,39 +83,39 @@ $ret = $this->Prefix.$separator.$this->Special; return rtrim($ret, $separator); } - + function &getProperty($property_name) { return $this->$property_name; } - + function setProperty($property_name, &$property_value) { $this->$property_name =& $property_value; } } class kHelper extends kBase { - + /** * Connection to database * * @var kDBConnection * @access public */ var $Conn; - + function kHelper() { parent::kBase(); $this->Conn =& $this->Application->GetADODBConnection(); } - + function InitHelper() { - + } - + } class kDBBase extends kBase { @@ -126,69 +126,69 @@ * @access public */ var $Conn; - + /** * Description * * @var string Name of primary key field for the item * @access public */ var $IDField; - + /** * Holds SELECT, FROM, JOIN parts of SELECT query * * @var string * @access public */ var $SelectClause; - + /** * Fields allowed to be set (from table + virtual) * * @var Array * @access private */ var $Fields=Array(); - + /** * All virtual field names * * @var Array * @access private */ var $VirtualFields=Array(); - + /** * Fields that need to be queried using custom expression, e.g. IF(...) AS value * * @var Array * @access private */ var $CalculatedFields = Array(); - + /** * Description * * @var string Item' database table name, without prefix * @access public */ var $TableName; - + /** * Allows to determine object's table status ('temp' - temp table, '' - live table) * * @var string * @access public */ var $mode=''; - + function kDBBase() { parent::kBase(); $this->Conn =& $this->Application->GetADODBConnection(); } - + /** * Set current item' database table name * @@ -200,7 +200,7 @@ { $this->TableName = $table_name; } - + /** * Set object' TableName to Live table from config * @@ -210,7 +210,7 @@ { $this->TableName = $this->Application->getUnitOption($this->Prefix, 'TableName'); } - + /** * Set object' TableName to Temp table from config * @@ -222,7 +222,7 @@ $this->SetTableName( kTempTablesHandler::GetTempName($this->TableName) ); $this->mode = 't'; } - + /** * Checks if object uses temp table * @@ -232,7 +232,7 @@ { return kTempTablesHandler::IsTempTable($this->TableName); } - + /** * Sets SELECT part of list' query * @@ -244,13 +244,13 @@ { $this->SelectClause = $sql; } - + 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); } - + /** * Insert calculated fields sql into query in place of %2$s, * return processed query. @@ -275,7 +275,7 @@ return str_replace('%2$s', '', $query); } } - + /** * Adds calculated field declaration to object. * @@ -286,7 +286,7 @@ { $this->CalculatedFields[$name] = $sql_clause; } - + /** * Sets ID Field name used as primary key for loading items * @@ -299,19 +299,19 @@ { $this->IDField = $field_name; } - + function Configure() { $this->setTableName( $this->Application->getUnitOption($this->Prefix, 'TableName') ); $this->setIDField( $this->Application->getUnitOption($this->Prefix, 'IDField') ); - + $this->defineFields(); - + $this->ApplyFieldModifiers(); // should be called only after all fields definitions been set $this->prepareConfigOptions(); // this should go last, but before setDefaultValues, order is significant! $this->SetDefaultValues(); } - + /** * Add field definitions from all possible sources (DB Fields, Virtual Fields, Calcualted Fields, e.t.c.) * @@ -322,12 +322,12 @@ $this->setVirtualFields( $this->Application->getUnitOption($this->Prefix, 'VirtualFields') ); $this->setCalculatedFields( $this->Application->getUnitOption($this->Prefix, 'CalculatedFields') ); } - + function setCalculatedFields($fields) { $this->CalculatedFields = isset($fields[$this->Special]) ? $fields[$this->Special] : (isset($fields['']) ? $fields[''] : false); } - + /** * Set's field names from table * from config @@ -339,7 +339,7 @@ { $this->Fields = $fields; } - + /** * Override field options with ones defined in submit via "field_modfiers" array (common for all prefixes) * @@ -351,13 +351,13 @@ // $this->Application->APCalled[] = $this->getPrefixSpecial(); $allowed_modifiers = Array('required'); - + $field_modifiers = $this->Application->GetVar('field_modifiers'); if(!$field_modifiers) return false; - + $field_modifiers = getArrayValue($field_modifiers, $this->getPrefixSpecial()); if(!$field_modifiers) return false; - + foreach ($field_modifiers as $field => $field_options) { foreach ($field_options as $option_name => $option_value) @@ -367,9 +367,9 @@ } } } - + /** - * Set fields (+options) for fields that physically doesn't exist in database + * Set fields (+options) for fields that physically doesn't exist in database * * @param Array $fields * @access public @@ -382,7 +382,7 @@ $this->Fields = array_merge_recursive2($this->VirtualFields, $this->Fields); } } - + function SetDefaultValues() { foreach($this->Fields as $field => $options) @@ -393,17 +393,17 @@ } } } - + function SetFieldOptions($field, $options) { $this->Fields[$field] = $options; } - + function GetFieldOptions($field) { return isset($this->Fields[$field]) ? $this->Fields[$field] : Array(); } - + /** * Returns formatted field value * @@ -422,17 +422,17 @@ } return $res; } - + function HasField($name) { - + } - + function GetFieldValues() { - + } - + function UpdateFormattersSubFields() { foreach ($this->Fields as $field => $options) { @@ -442,7 +442,7 @@ } } } - + function prepareConfigOptions() { foreach (array_keys($this->Fields) as $field_name) @@ -453,19 +453,19 @@ // replace with query result $select_clause = $field_options['option_title_field'].','.$field_options['option_key_field']; $sql = sprintf($field_options['options_sql'], $select_clause); - + $options_hash = getArrayValue($field_options,'options'); if($options_hash === false) $options_hash = Array(); - + $dynamic_options = $this->Conn->GetCol($sql, $field_options['option_key_field']); $field_options['options'] = array_merge_recursive2($options_hash, $dynamic_options); - + unset($field_options['options_sql']); } $this->PrepareOptions($field_name); } } - + function PrepareOptions($field_name) { if( $formatter_class = getArrayValue($this->Fields[$field_name], 'formatter') ) @@ -474,7 +474,7 @@ $formatter->PrepareOptions($field_name, $this->Fields[$field_name], $this); } } - + /** * Returns unformatted field value * @@ -484,9 +484,9 @@ */ function GetDBField($field) { - + } - + /** * Returns ID of currently processed record * @@ -497,7 +497,7 @@ { return $this->GetDBField($this->IDField); } - + /** * Returns parent table information * @@ -518,13 +518,19 @@ 'ParentTableKey' => $this->Application->getUnitOption($this->Prefix,'ParentTableKey'), 'ParentPrefix' => $parent_prefix ); - + if (is_array($table_info['ForeignKey'])) { + $table_info['ForeignKey'] = getArrayValue($table_info, 'ForeignKey', $parent_prefix); + } + if (is_array($table_info['ParentTableKey'])) { + $table_info['ParentTableKey'] = getArrayValue($table_info, 'ParentTableKey', $parent_prefix); + } + $main_object =& $this->Application->recallObject($parent_prefix.'.'.$special); return array_merge($table_info, Array('ParentId'=> $main_object->GetDBField( $table_info['ParentTableKey'] ) ) ); } return false; } - + } ?> \ No newline at end of file