From 762208664a9173bc9507a66fbd0c8020e382db88 Mon Sep 17 00:00:00 2001
From: Malf Furious <m@lfurio.us>
Date: Sat, 10 Nov 2018 09:12:01 -0500
Subject: Add function agent::getContainedUsers()

This function helps further abstract agents.  We want to get all users
belonging to a pad that is owned by a group, or more specifically - an
agent.  If this agent is a user, that user is our only user to collect.
If this agent is a group, we want to capture _it's_ owner along with all
of it's members.

Signed-off-by: Malf Furious <m@lfurio.us>
---
 app/class/agent.class.php |  7 +++++++
 app/class/group.class.php | 11 +++++++++++
 app/class/user.class.php  |  9 +++++++++
 3 files changed, 27 insertions(+)

diff --git a/app/class/agent.class.php b/app/class/agent.class.php
index 4c75f0b..4651a10 100644
--- a/app/class/agent.class.php
+++ b/app/class/agent.class.php
@@ -89,6 +89,13 @@ abstract class agent extends obj
         return false;
     }
 
+    /*
+     * Get all contained users.  For users, this is an array containing
+     * only $this.  For groups, this is an array containing the owner
+     * and all members.
+     */
+    public abstract function getContainedUsers() : array;
+
     /*
      * Send an email message to this agent using stored configuration
      * parameters.  If config is not established, delivery is not
diff --git a/app/class/group.class.php b/app/class/group.class.php
index 1191d71..600fb6d 100644
--- a/app/class/group.class.php
+++ b/app/class/group.class.php
@@ -63,6 +63,17 @@ class group extends agent
         return $group;
     }
 
+    /*
+     * Get all contained users.  This is an array of all members and
+     * the group owner.
+     */
+    public function getContainedUsers() : array
+    {
+        $cus = $this->getMembers();
+        $cus[] = $this->getOwner();
+        return $cus;
+    }
+
     /*
      * Send an email message to this group using stored configuration
      * parameters.  If config is not established, delivery is not
diff --git a/app/class/user.class.php b/app/class/user.class.php
index 90aac44..231111d 100644
--- a/app/class/user.class.php
+++ b/app/class/user.class.php
@@ -293,6 +293,15 @@ class user extends agent
         return $groups;
     }
 
+    /*
+     * Get all contained users.  This is just an array containing
+     * the user object.
+     */
+    public function getContainedUsers() : array
+    {
+        return array($this);
+    }
+
     /*
      * Send an email message to this user using stored configuration
      * parameters.  If config is not established, delivery is not
-- 
cgit v1.2.3