3 * Table Definition for core company
5 require_once 'DB/DataObject.php';
7 class Pman_Core_DataObjects_Core_enum extends DB_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'core_enum'; // table name
13 public $id; // int(11) not_null primary_key auto_increment
14 public $etype; // string(32) not_null
15 public $name; // string(255) not_null
16 public $active; // int(2) not_null
17 public $seqid; // int(11) not_null multiple_key
18 public $seqmax; // int(11) not_null multiple_key
21 /* the code above is auto generated do not remove the tag below */
23 function applyFilters($q, $au)
26 //DB_DataObject::debugLevel(1);
27 if (!empty($q['query']['empty_etype'])) {
28 $this->whereAdd("etype = ''");
31 if(!empty($q['!name'])){
32 $names = explode(',', $q['!name']);
34 core_enum.name NOT IN ({$q['!name']})
36 //$this->whereAddIn('name', $names, 'string', 'NOT');
44 function onUpdate($old, $req)
46 $x = $this->factory($this->tableName());
47 $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')");
48 if ($old->etype != $this->etype) {
49 $x->query("SELECT core_enum_seqmax_update('". $this->escape($old->etype) ."')");
53 function beforeUpdate($old, $request,$roo)
55 $tn = $this->tableName();
56 $x = $this->factory($tn);
57 if(!($old->etype == $request['etype'] && $old->name == $request['name'])){
58 $x->whereAdd("etype = '{$request['etype']}' AND name = '{$request['name']}'");
61 $roo->jerr('is exsiting');
65 function beforeInsert($req, $roo)
67 $tn = $this->tableName();
68 $x = $this->factory($tn);
70 if(empty($req['etype'])){
71 if($x->get('name', $req['name'])){
72 $roo->jerr('name is exsiting');
75 $x->whereAdd("etype = '{$req['etype']}' AND name = '{$req['name']}'");
78 $roo->jerr('is exsiting');
82 function onInsert($req)
84 $x = $this->factory($this->tableName());
85 $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')");
89 function lookup($etype,$name) {
90 $ce = DB_DataObject::Factory('core_enum');
93 if ($ce->find(true)) {
100 function lookupObject($etype,$name, $create= false)
103 static $cache = array();
104 $key = "$etype:$name";
105 if (isset($cache[$key]) ) {
108 $ce = DB_DataObject::Factory('core_enum');
111 if ($ce->find(true)) {
128 * The base enums that the system always needs,
129 * If we need to add modular enums, then this can be extended, and the two
132 * This might be moved to an external file later? - eg json...
141 'name' => 'COMPTYPE',
142 'display_name' => 'Company Types',
146 'display_name' => 'Owner',
147 'seqid' => 999, // last...
158 function initEnums($data = false, $base = array())
161 if ($data === false) {
162 $this->initEnums($this->baseEnums());
166 if (!empty($base['etype'])) {
168 $t = DB_DAtaObject::Factory('core_enum');
169 $t->etype = $base['etype'];
171 $t->selectAdD('max(seqid) as seqid');
172 if ($t->find(true)) {
173 $seq_id = $t->seqid+1;
176 foreach($data as $row) {
177 $t = DB_DAtaObject::Factory('core_enum');
182 if (!$t->find(true)) {
183 if (!empty($base['etype']) && empty($row['seqid'])) {
189 if (!empty($row['cn'])) {
190 $this->initEnums($row['cn'], array('etype' => $t->name));