DataObjects/Core_company.php
[Pman.Core] / DataObjects / Core_company.php
index 17c657c..dc4f370 100644 (file)
@@ -240,13 +240,21 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
             $this->update();
         }
         
-        
-        
-        
+    }
+    
+    function beforeInsert($q, $roo)
+    {
+        if(!empty($q['_check_name'])){
+            $this->checkName($roo);
+        }
     }
     
     function beforeUpdate($old, $q,$roo)
     {
+        if(!empty($q['_check_name'])){
+            $this->checkName($roo);
+        }
+        
         if(!empty($q['_merge_id'])){
             $this->merge($q['_merge_id'], $roo);
         }
@@ -466,4 +474,22 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
         $roo->jok('Merged');
         
     }
+    
+    function checkName($roo)
+    {
+        $company = DB_DataObject::factory('core_company');
+        $company->setFrom(array(
+            'name' => $this->name
+        ));
+        
+        if(!empty($this->id)){
+            $company->whereAdd("id != {$this->id}");
+        }
+        
+        if(!$company->find(true)){
+            $roo->jok('OK');
+        }
+        
+        $roo->jok('EXISTS');
+    }
 }