36405069ae250d6c28ffb4bde841552404099e7b
[Pman.Core] / DataObjects / Office.php
1 <?php
2 /**
3  * Table Definition for Office
4  */
5 require_once 'DB/DataObject.php';
6
7 class Pman_Core_DataObjects_Office extends DB_DataObject 
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'Office';                          // table name
13     public $id;                              // int(11)  not_null primary_key auto_increment
14     public $company_id;                      // int(11)  not_null
15     public $name;                            // string(64)  not_null
16     public $address;                         // blob(65535)  not_null blob
17     public $address2;                         // blob(65535)  not_null blob
18     public $address3;                         // blob(65535)  not_null blob 
19     public $phone;                           // string(32)  not_null
20     public $fax;                             // string(32)  not_null
21     public $email;                           // string(128)  not_null
22     public $role;                            // string(32)  not_null
23     public $country;                         // string(4)
24     
25     /* the code above is auto generated do not remove the tag below */
26     ###END_AUTOCODE
27     function applyFilters($q, $au)
28     {
29         //DB_DataObject::debugLevel(1);
30         $tn  = $this->tableName();
31         if (isset($q['_distinct']) && in_array('office_id_country_name', explode(',', $q['_distinct']))) {
32             $this->selectAdd("   distinct( i18n_translate('c' , {$tn}.country, 'en')) as  office_id_country_name");
33         } else {
34             $this->selectAdd("   i18n_translate('c' , {$tn}.country, 'en') as office_id_country_name");
35         }
36         
37         
38         $this->_extra_cols = array('office_id_country_name');
39     }
40     
41     
42     function toEventString() {
43         return $this->name;
44     }
45     /**
46      * check who is trying to access this. false == access denied..
47      */
48     function checkPerm($lvl, $au) 
49     {
50         return $au->hasPerm("Core.Offices", $lvl);    
51     }
52     
53     function company()
54     {
55         $c = DB_DataObject::Factory('Companies');
56         $c->get($this->company_id);
57         return $c;
58         
59     }
60     
61     function beforeDelete($dependants_array, $roo)
62     {
63         if (count($dependants_array) != 1) {
64             //$roo->jerr("more than one dependant type....");
65             return true; // standard error message.
66         }
67         
68         $p = DB_DAtaObject::Factory('Person');
69         
70         if (!is_a($dependants_array[0], get_class($p))) {
71             $roo->jerr("dep is not a person..");
72             return true;
73         }
74         
75         $p->office_id = $this->id;
76         if ($p->count() > 1) {
77             return true; // default err..
78         }
79         $p->find(true);
80         $pp = clone($p);
81         $p->office_id = 0;
82         $p->update($pp);
83         return true;
84     }
85     
86     
87 }