*/
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 != ''
+ ");
+ }
}
//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 = ''");
$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]);
// 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);
//$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);
+
+
}
}
- // determine if a complied template need recompling
function translateChanged($flexy)
+ {
+
+ $date = $this->lastUpdated($flexy);
+ if ($date === false) {
+ return false;
+ }
+ $utime = file_exists($flexy->compiledTemplate) ? filemtime( $flexy->compiledTemplate) : 0;
+ return strtotime($date) > $utime;
+ }
+
+ // determine if a complied template need recompling
+
+ function lastUpdated($flexy)
{
//return true;
// var_dump('check changed?');
//var_dump($flexy->compiledTemplate);
$utime = file_exists($flexy->compiledTemplate) ? filemtime( $flexy->compiledTemplate) : 0;
-
+
static $cache = array(); // cache of templates..
$ff = HTML_FlexyFramework::get();
$view_name = isset($ff->Pman_Core['view_name']) ? $ff->Pman_Core['view_name'] : false;
+ // find which of the template directories was actually used for the template.
+
$tempdir = '';
foreach($flexy->options['templateDir'] as $td) {
if (substr($flexy->currentTemplate, 0, strlen($td)) == $td) {
$tmpname = substr($flexy->currentTemplate, strlen($td) +1);
+ // we do not have any record of this template..
if (isset($cache[$tmpname]) && $cache[$tmpname] === false) {
return false;
}
$x->lang = $flexy->options['locale'];
$x->active = 1;
$x->template_id = $tmpl->id;
- $x->whereAdd("updated > '". date('Y-m-d H:i:s', $utime)."'");
-
- return $x->count() ? true : false;
+ //$x->whereAdd("updated > '". date('Y-m-d H:i:s', $utime)."'");
+ if ($x->count() < 1) {
+ return false; // we don't have any record of it.
+ }
+ $x->selectAdd();
+ $x->selectAdd('max(updated) as max_updated');
+ $x->find(true);
+ return $x->max_updated;
}
+ 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;
+
+ }
}