summaryrefslogtreecommitdiff
path: root/it_dbi.class
diff options
context:
space:
mode:
Diffstat (limited to 'it_dbi.class')
-rw-r--r--it_dbi.class27
1 files changed, 26 insertions, 1 deletions
diff --git a/it_dbi.class b/it_dbi.class
index 413ca8d..b02960d 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -36,6 +36,7 @@ class it_dbi
'charset' => null, # client charset (requires MySQL 5.0.7 or later)
'classprefix' => "",
'getfieldinfo' => true, # do not read schema. only select() allowed
+ 'localized_defaultlanguage' => "de", # Localize fields with this suffix, e.g. copy title_de to title on read
);
var $_key; # Key of currently loaded record or null (public readonly)
@@ -418,7 +419,7 @@ function _write_pre_process(/* &$tags */)
*/
function clear($pp = true)
{
- foreach ((array)$this->_fields as $field => $dummy)
+ foreach ((array)$this->_fields + (array)$this->_localizedfields as $field => $dummy)
unset($this->$field);
unset($this->_data);
unset($this->_key);
@@ -592,6 +593,26 @@ function iterate()
foreach ($this->_data as $field => $value)
$this->$field = isset($value) && $this->_isint[$field] ? ($this->_data[$field] = intval($value)) : $value;
+ if ($localizedfields = $this->_localizedfields)
+ {
+ $lang = T_lang();
+ foreach ($localizedfields as $field => $dummy)
+ {
+ $value = $this->{$field . "_" . $lang};
+
+ if (!isset($value))
+ $value = $this->{$field . "_" . $this->_p['localized_defaultlanguage']};
+
+ if (isset($value))
+ {
+ if (isset($this->$field))
+ it::fatal("Field name clash: Overwriting {$this->_p['table']}.$field with {$field}_{$lang}, only use one of those fields");
+ else
+ $this->$field = $value;
+ }
+ }
+ }
+
if (!empty($this->_p['keyfield']))
$this->_key = $this->_data[$this->_p['keyfield']];
}
@@ -741,6 +762,10 @@ function _get_field_info()
$this->_isint[$field['Field']] = preg_match('/^(tiny|small|medium|)int/', $field['Type']);
}
+ # Consider all fields which have _{localized_defaultlanguage} suffix as localized
+ foreach (preg_grep('/_' . $this->_p['localized_defaultlanguage'] . '$/', array_keys($this->_fields)) as $field)
+ $this->_localizedfields[substr($field, 0, -1 - strlen($this->_p['localized_defaultlanguage']))] = true;
+
$state = it_dbi::_state_get($dbid); # State could have been modified by query above
$state['fields'][$this->_p['table']] = $this->_fields;
$state['isint'][$this->_p['table']] = $this->_isint;