Jake Vanderwerf
2026-05-01 48721c85ebcfa973ee81719d2467ca80e4253dc9
base/Membership.php
@@ -1,5 +1,7 @@
<?php
namespace JVBase\base;
use JVBase\registrar\Registrar;
/**
 * JVB_MEMBERSHIP defines the structure of the directory
 *         Options include:
@@ -38,6 +40,7 @@
{
   protected bool $member_content = true;
   protected bool $invitable = false;
   protected bool $member_verified = false;
   protected array $can_invite = [];
   protected bool $notifications = true;
   protected bool $member_expires = false;
@@ -89,6 +92,35 @@
      return false;
   }
   public function setInvitable(array $invitable):void
   {
      $users = Registrar::getRegistered('user');
      $invitable = array_filter($invitable, function($role) use ($users) {
         if (!in_array($role, $users)) {
            error_log('[Membership]::set Invitable role '.$role.' does not exist.');
            return false;
         }
         return true;
      }, ARRAY_FILTER_USE_KEY);
      $allowed = [];
      foreach ($invitable as $inviter => $canInvites) {
         $canInvites = array_filter($canInvites, function($role) use ($users){
            if (!in_array($role, $users)) {
               error_log('[Membership]::set Invitable role '.$role.' does not exist.');
               return false;
            }
            return true;
         });
         if (!empty($canInvites)) {
            $allowed[$inviter] = $canInvites;
         }
      }
      if (!empty($allowed)) {
         $this->can_invite = $allowed;
      }
   }
   public function getInviters():array
   {
      return $this->can_invite;
@@ -102,6 +134,13 @@
      return array_key_exists($role, $this->can_invite) ? $this->can_invite[$role] : [];
   }
   public function setApprovers(array $roles):void
   {
      $allowed = Registrar::getRegistered('users');
      $this->can_approve = array_filter($roles, function($role) use ($allowed){
         return in_array($role, $allowed);
      });
   }
   public function getApprovers():array
   {
      return $this->can_approve;
@@ -113,6 +152,13 @@
   }
   public function setCanSeeForum(array $roles):void
   {
      $allowed = Registrar::getRegistered('users');
      $this->member_only = array_filter($roles, function($role) use ($allowed){
         return in_array($role, $allowed);
      });
   }
   public function canSeeForum(string $role):bool
   {
      return $this->forum && (empty($this->member_only) || in_array($role, $this->member_only));