diff options
-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; + } } ?> |