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         //DB_DataObject::debugLevel(1);
30         
31         if(!empty($q['_join_country_with_person'])){
32             $tn = $this->tableName();
33             $this->selectAdd();
34             $this->selectAdd(" i18n_translate('c' , Office.country, 'en') as office_id_country_name");
35             $this->_extra_col = array('office_country_name');
36             //$this->query('_distinct=office_id_country&cols=office_id_country,office_id_country_name');
37             //then the query should be _distinct=office_id_country&cols=office_id_country,office_id_country_name
38 //            $p = DB_DataObject::factory('Person');
39 //            $p->whereAdd("office_id > 0");
40 //            $p->selectAdd();
41 //            $p->selectAdd("DISTINCT(office_id) as office_id");
42 //            $officeIds = $p->fetchAll('office_id');
43 //            $this->whereAddIn($tn.'.id', $officeIds, 'INT');
44 //            $this->selectAdd();
45 //            $this->selectAdd("DISTINCT({$tn}.country) as country");
46 //            $this->joinAddCountryWithPerson();
47         }
48     }
49     
50     function joinAddCountryWithPerson()
51     {
52         $this->_join .= "
53             LEFT JOIN
54                 i18n AS join_country
55             ON
56                 (join_country.lkey = Office.country AND join_country.inlang = 'en')
57         ";
58         $item = DB_DataObject::Factory('I18n');
59         $this->selectAs($item, 'country_id_%s', 'join_country');
60     }
61     function toEventString() {
62         return $this->name;
63     }
64     /**
65      * check who is trying to access this. false == access denied..
66      */
67     function checkPerm($lvl, $au) 
68     {
69         return $au->hasPerm("Core.Offices", $lvl);    
70     } 
71 }