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
+ * @param String column to fetch.. eg. group_id or 'name'
+ *
+ */
+
+
function listGroupMembership($person, $arrayof = 'group_id')
{
$this->inAdmin = false;
$t = clone($this);
//DB_DataObject::debugLevel(1);
-
- $t->joinAdd(DB_DataObject::factory('Groups'), 'LEFT');
+ $grp = DB_DataObject::factory('Groups');
+ $t->joinAdd($grp , 'LEFT');
//$person->id = (int)$person->id;
$t->whereAdd("
user_id = {$person->id}
");
$t->selectAdd();
- $t->selectAdd('distinct(group_id), Groups.name as name');
+ $t->selectAdd("distinct(group_id), {$grp->tableName()}.name as name");
+ $t->whereAdd('group_id IS NOT NULL');
$t->find();
- $ret = $arrayof == 'group_id' ? array(0) : array(); // default member of 'All groups'!!
+ $ret = array() ;
+ // $ret = $arrayof == 'group_id' ? array(0) : array();
+ // default member of 'All groups'!!
while ($t->fetch()) {
$ret[] = $t->$arrayof;
$this->inAdmin = true;
}
}
+ if ($arrayof == 'group_id' && !count($ret)) {
+ $ret = array(0); /// default if they are not a member of any group.
+ }
+ //var_dump($ret);
return $ret;
}
{
return false;
}
- function fetchAll($k= false) {
- if ($k !== false) {
- $this->selectAdd();
- $this->selectAdd($k);
- }
-
- $this->find();
- $ret = array();
- while ($this->fetch()) {
- $ret[] = $k === false ? clone($this) : $this->$k;
- }
- return $ret;
-
- }
+
}