diff options
author | Malf Furious <m@lfurio.us> | 2017-03-26 05:47:34 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2017-03-26 05:47:34 -0400 |
commit | 69cc5d30f4e0446c504ce78152e2c305608b3866 (patch) | |
tree | 93a944964c8945cded36ef6886d9c9fa85a3d0a7 /app/class/object.class.php | |
parent | 0555c1a786144102fa1b9381f634138d2bd8c181 (diff) | |
download | scrott-69cc5d30f4e0446c504ce78152e2c305608b3866.tar.gz scrott-69cc5d30f4e0446c504ce78152e2c305608b3866.zip |
Add functions for adding and removing object members
Functions object::addMember() and object::remMember()
Diffstat (limited to '')
-rw-r--r-- | app/class/object.class.php | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/class/object.class.php b/app/class/object.class.php index 6a77b37..8cd4603 100644 --- a/app/class/object.class.php +++ b/app/class/object.class.php @@ -84,6 +84,36 @@ class object extends table return $memb; } + + /* + * Add a user as a member of this object. Returns false if user is + * already a member, or if another error occurs; true otherwise. + */ + public function addMember(user $user) : bool + { + if ($user->isMemberOf($this) || !isset($user->guid)) + return false; + + $query = "INSERT INTO members (guid, member) VALUES ('" . database::esc($this->guid) . "', '" . + database::esc($user->guid) . "')"; + database::query($query); + return true; + } + + /* + * Remove a user as a member of this object. Returns false if user + * is not a member, or if another error occurs; true otherwise. + */ + public function remMember(user $user) : bool + { + if (!$user->isMemberOf($this) || !isset($user->guid)) + return false; + + $query = "DELETE FROM members WHERE guid = '" . database::esc($this->guid) . "' AND " . + "member = '" . database::esc($user->guid) . "'"; + database::query($query); + return true; + } } ?> |