DataObjects/Core_watch.php
[Pman.Core] / DataObjects / Core_enum.php
1 <?php
2 /**
3  * Table Definition for core company
4  */
5 require_once 'DB/DataObject.php';
6
7 class Pman_Core_DataObjects_Core_enum extends DB_DataObject 
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
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
19     public $display_name;
20     
21     /* the code above is auto generated do not remove the tag below */
22     ###END_AUTOCODE
23     function applyFilters($q, $au)
24     {
25         
26         //DB_DataObject::debugLevel(1);
27         if (!empty($q['query']['empty_etype'])) {
28             $this->whereAdd("etype = ''");
29         }
30     }
31     
32     function onUpdate($old, $req)
33     {
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) ."')");
38         }
39         
40     }
41     
42     function onInsert($req)
43     {
44         $x = $this->factory($this->tableName());
45         $x->query("SELECT core_enum_seqmax_update('". $this->escape($this->etype) ."')");
46          
47     }
48     
49     function lookup($etype,$name) {
50         $ce = DB_DataObject::Factory('core_enum');
51         $ce->etype = $etype;
52         $ce->name = $name;
53         if ($ce->find(true)) {
54             return $ce->id;
55         }
56         return 0;
57         
58     }
59     
60     function lookupObject($etype,$name, $create= false)
61     {
62         
63         static $cache = array();
64         $key = "$etype:$name";
65         if (isset($cache[$key]) ) {
66             return $cache[$key];
67         }
68         $ce = DB_DataObject::Factory('core_enum');
69         $ce->etype = $etype;
70         $ce->name = $name;
71         if ($ce->find(true)) {
72             $cache[$key] = $ce;
73             return $ce;
74         }
75         if ($create) {
76             $ce->active = 1;
77             $ce->insert();
78             $cache[$key] = $ce;
79             return $ce->id;
80             
81         }
82         
83         
84         return false;
85         
86     }
87     
88 }