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 */
24 function applyFilters($q, $au)
27 //DB_DataObject::debugLevel(1);
28 if (!empty($q['query']['empty_etype'])) {
29 $this->whereAdd("etype = ''");
32 if(!empty($q['!name'])){
33 $names = explode(',', $q['!name']);
34 foreach($names as $name){
36 core_enum.name NOT IN ('$name')
42 function onUpdate($old, $req)
44 $x = $this->factory($this->tableName());
45 $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')");
46 if ($old->etype != $this->etype) {
47 $x->query("SELECT core_enum_seqmax_update('". $this->escape($old->etype) ."')");
51 function beforeUpdate($old, $request,$roo)
53 $tn = $this->tableName();
54 $x = $this->factory($tn);
55 if(!($old->etype == $request['etype'] && $old->name == $request['name'])){
56 $x->whereAdd("etype = '{$request['etype']}' AND name = '{$request['name']}'");
59 $roo->jerr('is exsiting');
63 function beforeInsert($req, $roo)
65 $tn = $this->tableName();
66 $x = $this->factory($tn);
68 if(empty($req['etype'])){
69 if($x->get('name', $req['name'])){
70 $roo->jerr('name is exsiting');
73 $x->whereAdd("etype = '{$req['etype']}' AND name = '{$req['name']}'");
76 $roo->jerr('is exsiting');
80 function onInsert($req)
82 $x = $this->factory($this->tableName());
83 $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')");
87 function lookup($etype,$name) {
88 $ce = DB_DataObject::Factory('core_enum');
91 if ($ce->find(true)) {
98 function fetchAllByType($etype, $fetchArg1=false, $fetchArg2=false, $fetchArg3=false)
103 function lookupObject($etype,$name, $create= false)
106 static $cache = array();
107 $key = "$etype:$name";
108 if (isset($cache[$key]) ) {
111 $ce = DB_DataObject::Factory('core_enum');
114 if ($ce->find(true)) {
131 * The base enums that the system always needs,
132 * If we need to add modular enums, then this can be extended, and the two
135 * This might be moved to an external file later? - eg json...
144 'name' => 'COMPTYPE',
145 'display_name' => 'Company Types',
149 'display_name' => 'Owner',
150 'seqid' => 999, // last...
161 function initEnums($data, $base = array())
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');
181 unset($t->seqid); // these might have been changed
182 unset($t->displayName); // these might have been changed
190 if (!empty($base['etype']) && empty($row['seqid'])) {
196 if (!empty($row['cn'])) {
197 $this->initEnums($row['cn'], array('etype' => $t->name));