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 = ''");
32 function onUpdate($old, $req)
34 $x = $this->factory($this->tableName());
35 $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')");
36 if ($old->etype != $this->etype) {
37 $x->query("SELECT core_enum_seqmax_update('". $this->escape($old->etype) ."')");
41 function beforeUpdate($old, $request,$roo)
43 $tn = $this->tableName();
44 $x = $this->factory($tn);
45 if(!($old->etype == $request['etype'] && $old->name == $request['name'])){
46 $x->whereAdd("etype = '{$request['etype']}' AND name = '{$request['name']}'");
49 $roo->jerr('is exsiting');
53 function beforeInsert($req, $roo)
55 $tn = $this->tableName();
56 $x = $this->factory($tn);
58 if(empty($req['etype'])){
59 if($x->get('name', $req['name'])){
60 $roo->jerr('name is exsiting');
63 $x->whereAdd("etype = '{$req['etype']}' AND name = '{$req['name']}'");
66 $roo->jerr('is exsiting');
70 function onInsert($req)
72 $x = $this->factory($this->tableName());
73 $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')");
77 function lookup($etype,$name) {
78 $ce = DB_DataObject::Factory('core_enum');
81 if ($ce->find(true)) {
88 function lookupObject($etype,$name, $create= false)
91 static $cache = array();
92 $key = "$etype:$name";
93 if (isset($cache[$key]) ) {
96 $ce = DB_DataObject::Factory('core_enum');
99 if ($ce->find(true)) {
116 * The base enums that the system always needs,
117 * If we need to add modular enums, then this can be extended, and the two
120 * This might be moved to an external file later? - eg json...
128 'name' => 'company_type',
129 'display_name' => 'Company Types',
133 'display_name' => 'Owner',
134 'seqid' => 999, // last...
145 function initEnums($data = false, $base = array())
147 DB_DataObject::DebugLevel(1);
148 if ($data === false) {
149 $this->initEnums($this->baseEnums());
152 foreach($data as $row) {
153 $t = DB_DAtaObject::Factory('core_enum');
158 if (!$t->find(true)) {
161 if (!empty($row['cn'])) {
162 $this->initEnums($row['cn'], array('etype', $t->name));