summaryrefslogtreecommitdiffstats
path: root/app/class/object.class.php
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-03-26 05:47:34 -0400
committerMalf Furious <m@lfurio.us>2017-03-26 05:47:34 -0400
commit69cc5d30f4e0446c504ce78152e2c305608b3866 (patch)
tree93a944964c8945cded36ef6886d9c9fa85a3d0a7 /app/class/object.class.php
parent0555c1a786144102fa1b9381f634138d2bd8c181 (diff)
downloadscrott-69cc5d30f4e0446c504ce78152e2c305608b3866.tar.gz
scrott-69cc5d30f4e0446c504ce78152e2c305608b3866.zip
Add functions for adding and removing object members
Functions object::addMember() and object::remMember()
Diffstat (limited to 'app/class/object.class.php')
-rw-r--r--app/class/object.class.php30
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;
+ }
}
?>