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']);
33 $this->whereAddIn('name', $names, 'string');
40 function onUpdate($old, $req)
42 $x = $this->factory($this->tableName());
43 $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')");
44 if ($old->etype != $this->etype) {
45 $x->query("SELECT core_enum_seqmax_update('". $this->escape($old->etype) ."')");
49 function beforeUpdate($old, $request,$roo)
51 $tn = $this->tableName();
52 $x = $this->factory($tn);
53 if(!($old->etype == $request['etype'] && $old->name == $request['name'])){
54 $x->whereAdd("etype = '{$request['etype']}' AND name = '{$request['name']}'");
57 $roo->jerr('is exsiting');
61 function beforeInsert($req, $roo)
63 $tn = $this->tableName();
64 $x = $this->factory($tn);
66 if(empty($req['etype'])){
67 if($x->get('name', $req['name'])){
68 $roo->jerr('name is exsiting');
71 $x->whereAdd("etype = '{$req['etype']}' AND name = '{$req['name']}'");
74 $roo->jerr('is exsiting');
78 function onInsert($req)
80 $x = $this->factory($this->tableName());
81 $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')");
85 function lookup($etype,$name) {
86 $ce = DB_DataObject::Factory('core_enum');
89 if ($ce->find(true)) {
96 function lookupObject($etype,$name, $create= false)
99 static $cache = array();
100 $key = "$etype:$name";
101 if (isset($cache[$key]) ) {
104 $ce = DB_DataObject::Factory('core_enum');
107 if ($ce->find(true)) {
124 * The base enums that the system always needs,
125 * If we need to add modular enums, then this can be extended, and the two
128 * This might be moved to an external file later? - eg json...
137 'name' => 'COMPTYPE',
138 'display_name' => 'Company Types',
142 'display_name' => 'Owner',
143 'seqid' => 999, // last...
154 function initEnums($data = false, $base = array())
157 if ($data === false) {
158 $this->initEnums($this->baseEnums());
162 if (!empty($base['etype'])) {
164 $t = DB_DAtaObject::Factory('core_enum');
165 $t->etype = $base['etype'];
167 $t->selectAdD('max(seqid) as seqid');
168 if ($t->find(true)) {
169 $seq_id = $t->seqid+1;
172 foreach($data as $row) {
173 $t = DB_DAtaObject::Factory('core_enum');
178 if (!$t->find(true)) {
179 if (!empty($base['etype']) && empty($row['seqid'])) {
185 if (!empty($row['cn'])) {
186 $this->initEnums($row['cn'], array('etype' => $t->name));