From cc1f573a276bd5f022831f837bb9c1234df56ad9 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 9 Apr 2017 20:08:05 -0400 Subject: Add agent function getPads_ordByOwnByName() --- app/class/agent.class.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'app/class/agent.class.php') diff --git a/app/class/agent.class.php b/app/class/agent.class.php index 038c485..a2c8c2e 100644 --- a/app/class/agent.class.php +++ b/app/class/agent.class.php @@ -13,6 +13,7 @@ */ require_once "class/object.class.php"; +require_once "class/pad.class.php"; /* * This is a supertype for users and groups, since these two object types @@ -68,6 +69,35 @@ abstract class agent extends object return $user->name; } + /* + * Get all pads this agent owns or is a member of. This isn't + * necessarily all pads this agent has access permission for. + * Results are sorted by ownership, then by name. + */ + public function getPads_ordByOwnByName() : array + { + $pads = array(); + + /* owner */ + $query = "SELECT guid FROM objects WHERE objtype = 'pad' AND " . + "owner = '" . database::esc($this->guid) . "' ORDER BY name"; + $res = database::query($query); + + foreach ($res as $p) + $pads[] = new pad($p['guid']); + + /* members */ + $query = "SELECT o.guid FROM objects o JOIN members m ON " . + "o.guid = m.guid WHERE o.objtype = 'pad' AND " . + "m.member = '" . database::esc($this->guid) . "' ORDER BY o.name"; + $res = database::query($query); + + foreach ($res as $p) + $pads[] = new pad($p['guid']); + + return $pads; + } + /* * Check whether this agent has access permission for given * object -- cgit v1.2.3