fields['objects'] = array( "guid", "owner", "parent", "name", "created", "updated", "membModify", "membMemb", "membAccs", "membCres", "membModifys", "membMembs", "pubAcc", "pubAccs", "pubCres", "objtype", ); parent::__construct($guid); } /* * Get the object type for the given GUID */ public static function typeOf(string $guid) : string { $obj = new object($guid); return $obj->objtype; } /* * Get the owner of this object. Either a user object or a group * object will be returned. If this object does not have an owner, * NULL will be returned. */ public function getOwner() : ?agent { if (!isset($this->owner) || $this->owner == "") return NULL; if (self::typeOf($this->owner) == "group") return new group($this->owner); return new user($this->owner); } /* * Update the owner of this object */ public function setOwner(agent $owner) : void { $this->owner = $owner->guid; $this->saveObj(); } /* * Get the parent of this object. If this object does not have a * parent, NULL will be returned. */ public function getParent() : ?object { if (!isset($this->parent) || $this->parent == "") return NULL; $parent = new object($this->parent); return new $parent->objtype($parent->guid); } /* * Update the parent of this object */ public function setParent(object $parent) : void { $this->parent = $parent->guid; $this->saveObj(); } /* * Get an array of all members of this object */ public function getMembers() : array { $memb = array(); $query = "SELECT member FROM members WHERE guid = '" . database::esc($this->guid) . "'"; $res = database::query($query); foreach ($res as $m) $memb[] = new user($m['member']); 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; } } ?>