orderBy('fullpath'); } function getListName() { return $this->fullpath; } function canDelete() { // can it be deleted? // first check has it got children? $children = new DataObjects_Grp; $children->owner=$this->id; if ($children->count()) { return FALSE; } return $this->canEdit(); } function canCreate() { $auth = &PEAR::getStaticProperty('Auth','singleton'); if ($auth->isAdmin()) { return TRUE; } if ($this->id == 0) { //only admin can create top level groups return; } $person = $auth->getUser(); $topgroups = $person->getMembershipArray(TRUE); if (in_array($this->top, $topgroups)) { return TRUE; } if (in_array($this->id, $topgroups)) { return TRUE; } } function canEdit() { $auth = &PEAR::getStaticProperty('Auth','singleton'); if ($auth->isAdmin()) { return TRUE; } // member of top level groups... $person = $auth->getUser(); $topgroups = $person->getMembershipArray(TRUE); if (in_array($this->top, $topgroups)) { return TRUE; } /* should this be here? - allows admin group members to edit the group */ if (in_array($this->id, $topgroups)) { return TRUE; } } function canRead() { $auth = &PEAR::getStaticProperty('Auth','singleton'); if ($auth->isAdmin()) { return TRUE; } // member of top level groups... $person = $auth->getUser(); $topgroups = $person->getMembershipArray(TRUE); if (in_array($this->top, $topgroups)) { return TRUE; } if (in_array($this->id, $topgroups)) { return TRUE; } } function getMembersArray() { $ret = array(); $mem = new DataObjects_Member; $mem->selectAdd(); $mem->selectAdd('uid'); $mem->gid = $this->id; $mem->find(); while ($mem->fetch()) { $ret[] = $mem->uid; } return $ret; } function setMembersArray($new) { $original = $this->getMembersArray(); // remove old members; if ($original) { foreach($original as $id) { if (!in_array($id, $new)) { $mem = new DataObjects_Member; $mem->uid = $id; $mem->gid = $this->id; $mem->delete(); } } } // add new members if (!$new) { return; } foreach($new as $id) { if (!in_array($id,$original)) { $mem = new DataObjects_Member; $mem->uid = $id; $mem->gid = $this->id; $mem->istop = (int) ($this->owner == 0); $mem->insert(); } } } function listChildren($id=0) { if ($id < 0 ) { $id =0; } //$this->selectAdd(); //$this->selectAdd('id,name'); //$this->orderBy('fullpath'); $this->whereAdd("owner = " .((int) $id)); return $this->find(); } function getLinkArray($key) { $ret = array(); return $ret; } function getFullPath() { $ret = $this->name; $current = $this; $this->top = $current->owner; while($current->owner) { $this->top = $current->owner; $current = DataObjects_Grp::staticGet($current->owner); $ret = $current->name . "/" . $ret; } $this->fullpath = $ret; } function update() { $this->getFullPath(); $ret = parent::update(); $this->updateChildren(); return $ret; } function insert() { $this->getFullPath(); return parent::insert(); } function delete() { $id = $this->id; if (parent::delete()) { $mem = new DataObjects_Member(); $mem->gid = $id; $mem->delete(); } } function updateChildren() { $sub = new DataObjects_Grp; $sub->owner = $this->id; if (!$sub->find()) return; while ($sub->fetch()) { $update = $sub; $update->update(); } } } ?>