*/
function onTableChange($roo, $obj, $chg)
{
-
$ff = HTML_FlexyFramework::get()->Pman_Core;
if(empty($ff['DataObjects_Core_templatestr']['tables'])){
return;
}
$cols = $ff['DataObjects_Core_templatestr']['tables'][$tn];
-
-
+
+ $used = array();
foreach($cols as $c) {
+
+ if(strpos($c, ',') !== false) {
+ $arr = explode(',', $c);
+ $c = $arr[0];
+ $cond = $arr[1];
+
+ $ar = explode('=', $cond);
+ $key = $ar[0];
+
+ // skip if condition not fulfilled
+ if($obj->{$ar[0]} != $ar[1]) {
+ continue;
+ }
+ }
+
+ // skip if empty string
+ if(empty($obj->$c)) {
+ continue;
+ }
+
$x = $this->factory($this->tableName());
$x->on_id = $obj->pid();
$x->on_table = $tn;
$x->on_col = $c;
$x->lang = ''; /// eg. base language..
$up = $x->find(true);
- if ($up && $x->txt == $obj->$c) {
- continue; // update an no change..
+
+ // skip when no change
+ if($up && $x->txt == $obj->$c) {
+ $used[] = $x->id;
+ continue;
}
+
$x->active = 1;
$x->src_id = 0;
$x->txt = $obj->$c;
$x->updated = date('Y-m-d H:i:s', strtotime("NOW"));
$up ? $x->update() : $x->insert();
}
+
+ // make sure the used one are active
+ if(count($used)) {
+ $t = DB_DataObject::factory($this->tableName());
+ // activate the aprent data
+ $t->query("UPDATE core_templatestr
+ SET active = 1 WHERE id in (" . implode(',' ,$used) . ")
+ ");
+ // activate the child data
+ $t->query("UPDATE core_templatestr
+ SET active = 1
+ WHERE
+ src_id IN (". implode(',' ,$used) . ")
+ AND
+ lang != ''
+ ");
+ }
}
$v = trim($v);
+
+ // skip empty words
+ if(empty($v)) {
+ continue;
+ }
$md = $keyvalue ? $k : md5($v);
$active[] = $cur[$md];
// we have it already? -
- $tt->query("UPDATE {$this->tableName()}
+ $t = DB_DataObject::factory($this->tableName());
+ $t->query("UPDATE {$this->tableName()}
SET active= 1
WHERE
id = ".$cur[$md]);
}
+ function toRooArray($req) {
+ $ret = $this->toArray();
+
+ if (empty($req['csvCols'])) {
+ return $ret;
+ }
+
+ // for download
+
+ // translations for table columns
+ if(!empty($ret['on_table']) && !empty($ret['on_id']) && !empty($ret['on_col'])) {
+ $ret['template_id_view_name'] = 'database';
+ $ret['template_id_template'] = $ret['on_table'] . ':' . $ret['on_col'];
+ }
+
+ return $ret;
+ }
+
+ function postListFilter($ar, $au, $req)
+ {
+ if (empty($req['csvCols'])) {
+ return $ar;
+ }
+
+ // for download
+
+ $ret = array();
+
+ foreach($ar as $v) {
+ if(empty($v['on_table']) || empty($v['on_id']) || empty($v['on_col'])) {
+ $ret[] = $v;
+ continue;
+ }
+
+ // translations for table columns
+ // avoid duplicate (same src_id_mdsum, same on_table, same on_col, but different on_id)
+
+ $key = $v['on_table'] . ':' . $v['on_col'] . ':' . $v['src_id_mdsum'];
+
+ if(!empty($ret[$key])) {
+ continue;
+ }
+
+ $ret[$key] = $v;
+ }
+
+ $ret = array_values($ret);
+
+ return $ret;
+
+ }
}