DataObjects/Core_domain.php
[Pman.Core] / DataObjects / Groups.php
index 03786a1..2efc94a 100755 (executable)
@@ -1,6 +1,14 @@
 <?php
 /**
  * Table Definition for Groups
+ *
+ *group types
+ *
+ * 0 = permission group..
+ * 1 = team
+ * 2 = contact group
+ *
+ * 
  */
 require_once 'DB/DataObject.php';
 
@@ -88,23 +96,48 @@ class Pman_Core_DataObjects_Groups extends DB_DataObject
             $gm->insert();
         }
     }
+    /**
+     *
+     *  grab a list of members - default is the array of person objects..
+     *  @param $what  = set to 'email' to get a list of email addresses.
+     *
+     *
+     */
     
-    function members()
+    function members($what = false)
     {
-        
-        
         $ids = $this->memberIds();
         if (!$ids) {
             return array();
         }
-        $p = DB_Dataobject::factory(empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable']);
+        //$p = DB_Dataobject::factory(empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable']);
+        // groups databse is hard coded to person.. so this should not be used for other tables.????
+        $p = DB_Dataobject::factory( 'Person' );
+        
         $p->whereAdd('id IN ('. implode(',', $ids) .')');
         $p->active = 1;
-        return $p->fetchAll();
-     
-        
+        return $p->fetchAll($what);
+    }
+    
+    function lookup($k,$v = false) {
+        if ($v === false) {
+            $v = $k;
+            $k = 'id';
+        }
+        $this->get($k,$v);
+
+        return $this;
+    } 
+    
+    function lookUpMembers($name, $what=false)
+    {
+        if (!$this->get('name', $name)) {
+            return array();
+        }
+        return $this->members($what);
         
     }
+    
     function postListFilter($ar, $au, $req)
     {      
         
@@ -114,7 +147,43 @@ class Pman_Core_DataObjects_Groups extends DB_DataObject
             //$ret[] = array( 'id' => 999999, 'name' => 'ADMINISTRATORS');
 
     }
+    
+    function initGroups()
+    {
         
+        $g = DB_DataObject::factory('Groups');
+        $g->type = 0;
+        $g->name = 'Administrators';
+        if ($g->count()) {
+            return;
+        }
+        $g->insert();
+        $gr = DB_DataObject::factory('group_rights');
+        $gr->genDefault();
+    }
+    
+    function initDatabase($roo, $data)
+    {
+        $this->initGroups();
+        
+        foreach($data as $gi) {
+            $g = DB_DataObject::factory('Groups');
+            $g->setFrom($gi);
+            
+            if(!$g->find(true)){
+                $g->insert();
+            }
+            
+            if(count($g->members()) || empty($gi['members'])){
+                continue;
+            }
+            
+            foreach ($gi['members'] as $m){
+                $g->addMember($m);
+            }
+            
+        }
      
+    }
     
 }