DataObjects/Core_notify.php
[Pman.Core] / DataObjects / Companies.php
index 0c3e3f0..163e131 100644 (file)
@@ -40,7 +40,7 @@ class Pman_Core_DataObjects_Companies extends DB_DataObject
     
     function applyFilters($q, $au)
     {
-        
+        $tn = $this->tableName();
         //DB_DataObject::debugLevel(1);
         $x = DB_DataObject::factory('Companies');
         $x->comptype= 'OWNER';
@@ -70,24 +70,38 @@ class Pman_Core_DataObjects_Companies extends DB_DataObject
             $this->whereAdd("Companies.id IN (
                 SELECT distinct(company_id) FROM ProjectDirectory where project_id IN ($pids)
             ) $add" );
-            
-           
-            
+             
         }
         if (!empty($q['query']['comptype'])) {
            
             $this->whereAddIn('comptype', explode(',', $q['query']['comptype']), 'string');
             
         }
-         
+        
+        // depricated - should be moved to module specific (texon afair)
+        
          if (!empty($q['query']['province'])) {
              $prov = $this->escape($q['query']['province']);
             $this->whereAdd("province LIKE '$prov%'");
             
             
         }
+        // ADD comptype_display name.. = for combos..
+        $this->selectAdd("
+            (SELECT display_name
+                FROM
+                    core_enum
+                WHERE
+                    etype='comptype'
+                    AND
+                    name={$tn}.comptype
+                LIMIT 1
+                ) as comptype_display_name
+        ");
+        
          
     }
+    
     function toEventString() {
         return $this->name;
     }
@@ -267,8 +281,57 @@ class Pman_Core_DataObjects_Companies extends DB_DataObject
         }
         return $i->toHTML($size);
         
+    }
+     function firstImage($filter='image/%')
+    {
+        $i = DB_DataObject::factory('Images');
+        //DB_DataObject::debugLevel(1);
+        $im = $i->gather($this, $filter);
+        if (empty($im)) {
+            return false;
+        }
+        return $im[0];
     }
     
+    function firstImageTag($size =-1, $base="/Images/Thumb", $filter='image/%')
+    {
+        $fm = $this->firstImage($filter);
+         if (empty($fm)) {
+            return '';
+        }
+        return $fm->toHTML($size, $base);
+    }
+    
+    function toRooSingleArray($authUser, $request)
+    {
+        $ret = $this->toArray();
+       // DB_DataObject::debugLevel(1);
+        // get the comptype display
+        $e = DB_DataObject::Factory('core_enum');
+        $e->etype = 'COMPTYPE';
+        $e->name = $this->comptype;
+        $ret['comptype_display'] = $ret['comptype'];
+        if ($e->find(true) && !empty($e->name_display)) {
+            $ret['comptype_display'] = $e->name_display;
+        }
+        
+        
+        return $ret;
+    }
     
+    function initCompanies($roo, $name, $type)
+    {
+        $companies = DB_DataObject::factory('companies');
+        $companies->setFrom(array(
+            'name' => $name,
+            'comptype' => $type,
+            'background_color' => '',
+            'created_dt' => $this->sqlValue('NOW()'),
+            'updated_dt' => $this->sqlValue('NOW()')
+        ));
+        
+        $companies->insert();
+        $companies->onInsert(array(), $roo);
+    }
     
 }