Commit 254fc24e24058cc9c6f911cef00e2f1f82f612c5
1 parent
fbf61149
Add addMember and removeMember methods to Group, taking User objects,
doing the expected things. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3416 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
41 additions
and
0 deletions
lib/groups/Group.inc
| ... | ... | @@ -214,6 +214,7 @@ class Group extends KTEntity { |
| 214 | 214 | return parent::delete(); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | + // {{{ hasMember | |
| 217 | 218 | function hasMember($oUser) { |
| 218 | 219 | global $default; |
| 219 | 220 | |
| ... | ... | @@ -229,6 +230,46 @@ class Group extends KTEntity { |
| 229 | 230 | } |
| 230 | 231 | return false; |
| 231 | 232 | } |
| 233 | + // }}} | |
| 234 | + | |
| 235 | + // {{{ addMember | |
| 236 | + function addMember($oUser) { | |
| 237 | + global $default; | |
| 238 | + if ($this->hasMember($oUser)) { | |
| 239 | + return true; | |
| 240 | + } | |
| 241 | + $aParams = array( | |
| 242 | + "user_id" => $oUser->getID(), | |
| 243 | + "group_id" => $this->getID(), | |
| 244 | + ); | |
| 245 | + $res = DBUtil::autoInsert($default->users_groups_table, $aParams); | |
| 246 | + if (PEAR::isError($res)) { | |
| 247 | + return $res; | |
| 248 | + } | |
| 249 | + return true; | |
| 250 | + } | |
| 251 | + // }}} | |
| 252 | + | |
| 253 | + // {{{ removeMember | |
| 254 | + function removeMember($oUser) { | |
| 255 | + global $default; | |
| 256 | + if (!$this->hasMember($oUser)) { | |
| 257 | + return true; | |
| 258 | + } | |
| 259 | + $aParams = array( | |
| 260 | + "user_id" => $oUser->getID(), | |
| 261 | + "group_id" => $this->getID(), | |
| 262 | + ); | |
| 263 | + $res = DBUtil::whereDelete($default->users_groups_table, $aParams); | |
| 264 | + if (PEAR::isError($res)) { | |
| 265 | + return $res; | |
| 266 | + } | |
| 267 | + if ($this->hasMember($oUser)) { | |
| 268 | + return PEAR::raiseError("Tried to remove member from database, apparently successfully, but hasMember thinks they're still members?"); | |
| 269 | + } | |
| 270 | + return true; | |
| 271 | + } | |
| 272 | + // }}} | |
| 232 | 273 | } |
| 233 | 274 | |
| 234 | 275 | /** | ... | ... |