DataObjects/Core_event_audit.php
[Pman.Core] / DataObjects / Group_Members.php
index 76f0841..0c85de2 100755 (executable)
@@ -14,12 +14,32 @@ class Pman_Core_DataObjects_Group_Members extends DB_DataObject
     public $id;                              // int(11)  not_null primary_key auto_increment
     public $user_id;                         // int(11)  not_null
 
-  
+    
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
     
     var $inAdmin = false;
     
+    
+    function change($person, $group, $state)
+    {
+        $gm = DB_DataObject::factory('Group_Members');
+        $gm->group_id = $group->id;
+        $gm->user_id = $person->id;
+        $gm->find(true);
+        if ($state) {
+            if (!$gm->id) {
+                $gm->insert();
+            }
+            return;
+        }
+        // remove..
+        if ($gm->id) {
+            $gm->delete();
+        }
+        
+    }
+    
     /**
      * Get a list of memberships for a person
      * @param Pman_Core_DataObjects_Person $person who
@@ -27,6 +47,7 @@ class Pman_Core_DataObjects_Group_Members extends DB_DataObject
      *
      */
     
+    
     function listGroupMembership($person, $arrayof = 'group_id') 
     {
         $this->inAdmin = false;
@@ -44,7 +65,8 @@ class Pman_Core_DataObjects_Group_Members extends DB_DataObject
         
         $t->find();
         
-        $ret = $arrayof == 'group_id' ? array(0) : array();
+        $ret = array() ;
+       // $ret = $arrayof == 'group_id' ? array(0) : array();
         // default member of 'All groups'!!
         
         while ($t->fetch()) {
@@ -53,6 +75,10 @@ class Pman_Core_DataObjects_Group_Members extends DB_DataObject
                 $this->inAdmin = true;
             }
         }
+        if ($arrayof == 'group_id' && !count($ret)) {
+            $ret = array(0); /// default if they are not a member of any group.
+        }
+        
         return $ret;
         
     }