From 69cc5d30f4e0446c504ce78152e2c305608b3866 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 26 Mar 2017 05:47:34 -0400 Subject: Add functions for adding and removing object members Functions object::addMember() and object::remMember() --- app/class/object.class.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'app/class') 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; + } } ?> -- cgit v1.2.3