DataObjects/Office.php
[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         
30         //$this->joinAddCountry();
31         $tn = $this->tableName();
32         //$this->selectAdd(" i18n_translate('c' , 'CN', 'en') as country_name");
33         $p = DB_DataObject::factory('Person');
34         $p->whereAdd("Person.office_id > 0");
35         $p->selectAdd("DISTINECT(office_id) as office_id");
36         $officeIds = $p->fetchAll('office_id');
37         $this->whereAddIn('id', $officeIds, 'INT');
38         
39 //        $this->whereAdd("
40 //                {$tn}.id = (SELECT DISTINCT(office_id) FROM Person WHERE Person.office_id > 0)
41 //            ");
42         
43 //        $this->selectAdd("
44 //                SELECT DISTINCT(office_id) FROM Person WHERE Person.office_id > 0
45 //            ");
46     }
47     
48     function joinAddCountry()
49     {
50         $this->_join .= '
51             LEFT JOIN
52                 i18n AS join_country
53             ON
54                 (join_country.lkey = Office.country)
55         ';
56         $item = DB_DataObject::Factory('I18n');
57         $this->selectAs($item, 'country_id_%s', 'join_country');
58     }
59     function toEventString() {
60         return $this->name;
61     }
62     /**
63      * check who is trying to access this. false == access denied..
64      */
65     function checkPerm($lvl, $au) 
66     {
67         return $au->hasPerm("Core.Offices", $lvl);    
68     } 
69 }