* NOTE - used to be called Groups ....
*
*/
-require_once 'DB/DataObject.php';
+class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
-class Pman_Core_DataObjects_Core_groups extends DB_DataObject
+class Pman_Core_DataObjects_Core_group extends DB_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
- public $__table = 'core_groups'; // table name
+ public $__table = 'core_group'; // table name
public $id; // int(11) not_null primary_key auto_increment
public $name; // string(64) not_null
public $type; // int(11)
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
-
- function memberTable()
- {
- return 'core_group_members';
- }
- function rightsTable()
- {
- return 'core_group_rights';
- }
+
function personTable()
{
$ff = HTML_FlexyFramework::get();
- return empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
+ return empty($ff->Pman['authTable']) ? 'core_person' : $ff->Pman['authTable'];
}
return $this->name;
}
+ function beforeInsert($q,$roo)
+ {
+ if (isset($q['_action'])) {
+ // add // sub...
+ $g = clone($this);
+ if (!$g->get($q['group_id'])) {
+ $roo->jerr("missing group id");
+
+ }
+ foreach(explode(',', $q['user_ids']) as $uid) {
+ switch($q['_action']) {
+ case 'add':
+ $g->addMember($uid);
+ break;
+ case 'sub':
+ $g->removeMember($uid);
+ break;
+ default:
+ $roo->jerr('invalid action');
+ }
+ }
+ $roo->jok('updated');
+
+
+
+
+ }
+
+
+ }
+
+
function beforeDelete()
{
- $x = DB_DataObject::factory($this->tableName());
- $x->query("DELETE FROM {$this->rightsTable()} WHERE group_id = {$this->id}");
- $x->query("DELETE FROM {$this->membersTable()} WHERE group_id = {$this->id}");
+ $x = DB_DataObject::factory('core_group_right');
+ $x->query("DELETE FROM {$x->tableName()} WHERE group_id = {$this->id}");
+ $x = DB_DataObject::factory('core_group_member');
+ $x->query("DELETE FROM {$x->tableName()} WHERE group_id = {$this->id}");
}
/**
* check who is trying to access this. false == access denied..
return true;
}
- $pi = DB_DataObject::factory($this->personTable());
+ $pi = DB_DataObject::factory('core_person');
$pi->get($this->leader);
- $p = DB_DataObject::factory($this->membersTable());
+ $p = DB_DataObject::factory('core_group_member');
$p->group_id = $this->id;
$p->user_id = $this->leader;
//$p->type = 1; //???????
function memberCount()
{
- $gm = DB_Dataobject::factory($this->membersTable());
+ $gm = DB_Dataobject::factory('core_group_member');
$gm->group_id = $this->id;
return $gm->count();
}
function memberIds()
{
- $gm = DB_Dataobject::factory($this->membersTable());
+ $gm = DB_Dataobject::factory('core_group_member');
$gm->group_id = $this->id;
return $gm->fetchAll('user_id');
}
-
+ function isMember($person)
+ {
+ $gm = DB_Dataobject::factory('core_group_member');
+ $gm->group_id = $this->id;
+ $gm->user_id = is_object($person) ? $person->id : $person;
+ return $gm->count();
+ }
function addMember($person)
{
- $gm = DB_Dataobject::factory($this->membersTable());
+ $gm = DB_Dataobject::factory('core_group_member');
$gm->group_id = $this->id;
- $gm->user_id = $person->id;
+ $gm->user_id = is_object($person) ? $person->id : $person;
if (!$gm->count()) {
$gm->insert();
}
}
+
+ function removeMember($person)
+ {
+ $gm = DB_Dataobject::factory('core_group_member');
+ $gm->group_id = $this->id;
+ $gm->user_id = is_object($person) ? $person->id : $person;
+ if ($gm->count()) {
+ $gm->delete();
+ }
+ }
+
/**
*
* grab a list of members - default is the array of person objects..
}
//$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 = DB_Dataobject::factory( 'core_person' );
+
+
$p->whereAdd('id IN ('. implode(',', $ids) .')');
$p->active = 1;
function postListFilter($ar, $au, $req)
{
- if(!empty($req['_direct_return'])){
+ if(empty($req['_add_everyone'])){
return $ar;
}
$g->type = 0;
$g->name = 'Administrators';
if ($g->count()) {
- return;
+ $g->find(true);;
+ } else {
+ $g->insert();
+ $gr = DB_DataObject::factory('core_group_right');
+ $gr->genDefault();
+ }
+ $m = $g->members();
+ if (empty($m)) {
+ $p = DB_DAtaObject::factory('core_person');
+ $p->orderBy('id ASC');
+ $p->limit(1);
+ if ($p->find(true)) {
+ $g->addMember($p);
+ }
+
+
}
- $g->insert();
- $gr = DB_DataObject::factory($this->rightsTable());
- $gr->genDefault();
}
function initDatabase($roo, $data)