/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- function applyFilters($q, $au)
+ function applyFilters($q, $au, $roo)
{
// DB_DataObject::debugLevel(1);
if (!empty($q['query']['empty_etype'])) {
- $this->whereAdd("etype = ''");
+ $this->whereAdd("core_enum.etype = ''");
}
// this should be handled by roo... using '!name[0]' ....
core_enum.display_name LIKE '%{$name}%'
");
}
+ if (isset($q['_etypes'])) {
+ $this->whereAddIn('core_enum.etype', explode(',', $q['_etypes']), 'string');
+ }
}
$tn = $this->tableName();
$x = $this->factory($tn);
- if(!($old->etype == $request['etype'] && $old->name == $request['name'])){
+ // check if record exists?
+ if(isset($request['etype']) && !($old->etype == $request['etype'] && $old->name == $request['name'])){
$x->whereAdd("etype = '{$this->escape($request['etype'])}' AND name = '{$this->escape($request['name'])}'");
+ $x->whereAdd("id != ".((int) $this->id));
$x->find(true);
if($x->count() > 0){
- $roo->jerr('is exsiting');
+ $roo->jerr('a duplicate record already exists');
}
}
}
}
}
- function onInsert($req)
+ function onInsert($req, $roo)
{
$x = $this->factory($this->tableName());
$x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')"); // no idea why need to do this!!??
}
+
function onUpdate($old, $req)
{
$x = $this->factory($this->tableName());
if ($old->etype != $this->etype) {
$x->query("SELECT core_enum_seqmax_update('". $this->escape($old->etype) ."')");
}
- if($this->name != $old->name && empty($old->etype) && empty($this->etype)){
+
+ if($this->name != $old->name && !empty($old->name) && empty($old->etype) && empty($this->etype)){
$x->query("UPDATE core_enum SET etype = '". $this->escape($this->name)
."' WHERE etype = '". $this->escape($old->name)."'");
}
}
- function merge($id, $roo)
+ function merge($merge_to, $roo)
{
$affects = array();
$chk = DB_DataObject::factory($ka[0]);
if (!is_a($chk,'DB_DataObject')) {
- $this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
+ $roo->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
}
- // print_r(array($chk->tablename() , $ka[1] , $xx->tablename() , $this->key ));
- $chk->{$ka[1]} = $xx->{$this->key};
+
+ $chk->{$ka[1]} = $this->id;
- if (count($chk->keys())) {
- $matches = $chk->count();
- } else {
- //DB_DataObject::DebugLevel(1);
- $matches = $chk->count($ka[1]);
+ foreach ($chk->fetchAll() as $c){
+ $cc = clone ($c);
+ $c->{$ka[1]} = $merge_to;
+ $c->update($cc);
}
-
- if ($matches) {
- $chk->_match_key = $ka[1];
- $match_ar[] = clone($chk);
- continue;
- }
}
+ $this->delete();
+
+ $roo->jok('Merged');
+
}