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'])){
38 function onUpdate($old, $req)
40 $x = $this->factory($this->tableName());
41 $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')");
42 if ($old->etype != $this->etype) {
43 $x->query("SELECT core_enum_seqmax_update('". $this->escape($old->etype) ."')");
47 function beforeUpdate($old, $request,$roo)
49 $tn = $this->tableName();
50 $x = $this->factory($tn);
51 if(!($old->etype == $request['etype'] && $old->name == $request['name'])){
52 $x->whereAdd("etype = '{$request['etype']}' AND name = '{$request['name']}'");
55 $roo->jerr('is exsiting');
59 function beforeInsert($req, $roo)
61 $tn = $this->tableName();
62 $x = $this->factory($tn);
64 if(empty($req['etype'])){
65 if($x->get('name', $req['name'])){
66 $roo->jerr('name is exsiting');
69 $x->whereAdd("etype = '{$req['etype']}' AND name = '{$req['name']}'");
72 $roo->jerr('is exsiting');
76 function onInsert($req)
78 $x = $this->factory($this->tableName());
79 $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')");
83 function lookup($etype,$name) {
84 $ce = DB_DataObject::Factory('core_enum');
87 if ($ce->find(true)) {
94 function lookupObject($etype,$name, $create= false)
97 static $cache = array();
98 $key = "$etype:$name";
99 if (isset($cache[$key]) ) {
102 $ce = DB_DataObject::Factory('core_enum');
105 if ($ce->find(true)) {
122 * The base enums that the system always needs,
123 * If we need to add modular enums, then this can be extended, and the two
126 * This might be moved to an external file later? - eg json...
135 'name' => 'COMPTYPE',
136 'display_name' => 'Company Types',
140 'display_name' => 'Owner',
141 'seqid' => 999, // last...
152 function initEnums($data = false, $base = array())
155 if ($data === false) {
156 $this->initEnums($this->baseEnums());
160 if (!empty($base['etype'])) {
162 $t = DB_DAtaObject::Factory('core_enum');
163 $t->etype = $base['etype'];
165 $t->selectAdD('max(seqid) as seqid');
166 if ($t->find(true)) {
167 $seq_id = $t->seqid+1;
170 foreach($data as $row) {
171 $t = DB_DAtaObject::Factory('core_enum');
176 if (!$t->find(true)) {
177 if (!empty($base['etype']) && empty($row['seqid'])) {
183 if (!empty($row['cn'])) {
184 $this->initEnums($row['cn'], array('etype' => $t->name));