MOVED DataObjects/Office.php to DataObjects/Core_office.php
authorAlan Knowles <alan@roojs.com>
Fri, 7 Oct 2016 06:24:18 +0000 (14:24 +0800)
committerAlan Knowles <alan@roojs.com>
Fri, 7 Oct 2016 06:24:18 +0000 (14:24 +0800)
DataObjects/Core_office.php [new file with mode: 0644]

diff --git a/DataObjects/Core_office.php b/DataObjects/Core_office.php
new file mode 100644 (file)
index 0000000..75d47c2
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+/**
+ * Table Definition for Office
+ */
+require_once 'DB/DataObject.php';
+
+class Pman_Core_DataObjects_Office extends DB_DataObject 
+{
+    ###START_AUTOCODE
+    /* the code below is auto generated do not remove the above tag */
+
+    public $__table = 'Office';                          // table name
+    public $id;                              // int(11)  not_null primary_key auto_increment
+    public $company_id;                      // int(11)  not_null
+    public $name;                            // string(64)  not_null
+    public $address;                         // blob(65535)  not_null blob
+    public $address2;                         // blob(65535)  not_null blob
+    public $address3;                         // blob(65535)  not_null blob 
+    public $phone;                           // string(32)  not_null
+    public $fax;                             // string(32)  not_null
+    public $email;                           // string(128)  not_null
+    public $role;                            // string(32)  not_null
+    public $country;                         // string(4)
+    
+    /* the code above is auto generated do not remove the tag below */
+    ###END_AUTOCODE
+    function applyFilters($q, $au)
+    {
+        //DB_DataObject::debugLevel(1);
+        $tn  = $this->tableName();
+        $this->selectAdd("   i18n_translate('c' , {$tn}.country, 'en') as office_id_country_name");
+    }
+    
+    
+    function toEventString() {
+        return $this->name;
+    }
+    /**
+     * check who is trying to access this. false == access denied..
+     */
+    function checkPerm($lvl, $au) 
+    {
+        return $au->hasPerm("Core.Offices", $lvl);    
+    }
+    
+    function company()
+    {
+        $c = DB_DataObject::Factory('Companies');
+        $c->get($this->company_id);
+        return $c;
+        
+    }
+    
+    function beforeDelete($dependants_array, $roo)
+    {
+        if (count($dependants_array) != 1) {
+            //$roo->jerr("more than one dependant type....");
+            return true; // standard error message.
+        }
+        
+        $p = DB_DAtaObject::Factory('Person');
+        
+        if (!is_a($dependants_array[0], get_class($p))) {
+            $roo->jerr("dep is not a person..");
+            return true;
+        }
+        
+        $p->office_id = $this->id;
+        if ($p->count() > 1) {
+            return true; // default err..
+        }
+        $p->find(true);
+        $pp = clone($p);
+        $p->office_id = 0;
+        $p->update($pp);
+        return true;
+    }
+    
+    
+}
\ No newline at end of file