diff options
-rw-r--r-- | app/class/object.class.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/app/class/object.class.php b/app/class/object.class.php new file mode 100644 index 0000000..a000a10 --- /dev/null +++ b/app/class/object.class.php @@ -0,0 +1,89 @@ +<?php + +/* + * SCROTT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * For more information, please refer to UNLICENSE + */ + +require_once "class/table.class.php"; +require_once "class/agent.class.php"; +require_once "class/user.class.php"; +require_once "class/group.class.php"; + +/* + * This is a generic database object. This is a supertype of all Scrott + * datatypes and defines fields common to all of them. + */ +class object extends table +{ + /* + * Constructor + */ + public function __construct(?string $guid = NULL) + { + $this->fields['objects'] = array( + "guid", + "owner", + "parent", + "name", + "created", + "updated", + + "membModify", + "membMemb", + "membAccs", + "membCres", + "membModifys", + "membMembs", + "pubAcc", + "pubAccs", + "pubCres", + + "objtype", + ); + + parent::__construct($guid); + } + + /* + * 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; + + $obj = new object($this->owner); + + if ($obj->objtype == "group") + return new group($this->owner); + + return new user($this->owner); + } + + /* + * Get an array of all members of this object + */ + public function getMembers() : array + { + $memb = array(); + $query = "SELECT member FROM members WHERE guid = '" . $this->db->esc($this->guid) . "'"; + $res = $this->db->query($query); + + foreach ($res as $m) + $memb[] = new user($m['member']); + + return $memb; + } +} + +?> |