X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=DataObjects%2FCore_templatestr.php;h=88a9785abecc433254803656fd66313214418aa8;hp=44e58e11f72d1ddd44714d7d3d26d11ccca44a3d;hb=HEAD;hpb=e0d16cf1663e3d752cdfd32556d74c43b1f189ff diff --git a/DataObjects/Core_templatestr.php b/DataObjects/Core_templatestr.php index 44e58e11..a8007505 100644 --- a/DataObjects/Core_templatestr.php +++ b/DataObjects/Core_templatestr.php @@ -84,7 +84,6 @@ class Pman_Core_DataObjects_Core_templatestr extends DB_DataObject */ function onTableChange($roo, $obj, $chg) { - $ff = HTML_FlexyFramework::get()->Pman_Core; if(empty($ff['DataObjects_Core_templatestr']['tables'])){ @@ -95,18 +94,42 @@ class Pman_Core_DataObjects_Core_templatestr extends DB_DataObject 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; @@ -115,6 +138,23 @@ class Pman_Core_DataObjects_Core_templatestr extends DB_DataObject $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 != '' + "); + } } @@ -261,9 +301,8 @@ class Pman_Core_DataObjects_Core_templatestr extends DB_DataObject //print_r($words);exit; // grab original $tt = DB_DataObject::factory($this->tableName()); - - - $t = DB_DataObject::factory($this->tableName()); + + $t = clone($tt); $t->template_id = $tmpl->id; $t->whereAdd("lang = ''"); @@ -290,6 +329,11 @@ class Pman_Core_DataObjects_Core_templatestr extends DB_DataObject $v = trim($v); + + // skip empty words + if(empty($v)) { + continue; + } $md = $keyvalue ? $k : md5($v); @@ -316,7 +360,8 @@ class Pman_Core_DataObjects_Core_templatestr extends DB_DataObject $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]); @@ -443,18 +488,23 @@ class Pman_Core_DataObjects_Core_templatestr extends DB_DataObject // find all the id's from lang that have not been generated.. - //find the origanal - $t = DB_DataObject::factory($tn); - $t->whereAdd("lang = ''"); - $t->active = 1; - //old code, this did not support the on_table -// $id_tmp = $t->fetchAll('id','template_id'); -// $ids = array_keys($id_tmp); - $id_tmp = array(); - //new code for support the sync tables - foreach($t->fetchAll() as $ori){ - $id_tmp[$ori->id] = $ori; + static $id_tmp = false; + + if ($id_tmp == false) { + //find the origanal + $t = DB_DataObject::factory($tn); + $t->whereAdd("lang = ''"); + $t->active = 1; + + //old code, this did not support the on_table + // $id_tmp = $t->fetchAll('id','template_id'); + // $ids = array_keys($id_tmp); + $id_tmp = array(); + //new code for support the sync tables + foreach($t->fetchAll() as $ori){ + $id_tmp[$ori->id] = $ori; + } } $ids = array_keys($id_tmp); @@ -465,25 +515,33 @@ class Pman_Core_DataObjects_Core_templatestr extends DB_DataObject //$t->active = 1; $got = $t->fetchAll('src_id'); $missing = array_diff($ids, $got); - foreach($missing as $id) { - - $t = DB_DataObject::factory($tn); - $t->setFrom(array( - 'src_id' => $id, - 'txt' => '', - 'lang' => $lang, - 'updated' => date('Y-m-d H:i:s', strtotime("NOW")), - 'template_id'=> $id_tmp[$id]->template_id, - 'on_table' => $id_tmp[$id]->on_table, - 'on_id' => $id_tmp[$id]->on_id, - 'on_col' => $id_tmp[$id]->on_col, - 'active' => 1, - // no md5um - )); - $t->insert(); - } - + if (empty($missing)) { + return; + } + $t = DB_DataObject::factory($tn); + $q = "CREATE TEMPORARY TABLE core_templatestr_insert SELECT + id as src_id, + '' as txt, + '$lang' as lang, + NOW() as updated, + template_id, + on_table, + on_id, + on_col, + 1 as active + FROM core_templatestr + WHERE + id IN (". implode(',', $missing) . ") + "; + //echo $q; exit; + DB_DataObject::factory($tn)->query($q); + $q = "INSERT INTO $tn (src_id, txt, lang, updated, template_id, on_table,on_id, on_col, active) SELECT * FROM core_templatestr_insert"; + DB_DataObject::factory($tn)->query($q); + $q = "DROP TEMPORARY TABLE core_templatestr_insert"; + DB_DataObject::factory($tn)->query($q); + + } @@ -693,4 +751,55 @@ class Pman_Core_DataObjects_Core_templatestr extends DB_DataObject } + 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; + + } }