From c204185ae86a98994f80010abf35a190c9406739 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 12 Jul 2026 18:08:19 +0000
Subject: [PATCH] =Refactor of Integrations.php. Separated different functionality into traits that classes can use to add that functionality. Hopefully will make maintaining it a little easier. Still have to finish up, as well as refactoring the individual classes to utilize the new system.

---
 inc/managers/ReferralManager.php |   38 +++++++++++++++++---------------------
 1 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/inc/managers/ReferralManager.php b/inc/managers/ReferralManager.php
index 55f95a6..626d036 100644
--- a/inc/managers/ReferralManager.php
+++ b/inc/managers/ReferralManager.php
@@ -55,11 +55,11 @@
 		$this->default_settings['referral_role'] = $this->role;
 
 		$this->cache = Cache::for('referrals', WEEK_IN_SECONDS);
-		$this->requestCache = Cache::for('referral_requests', WEEK_IN_SECONDS)->connect('referrals', true);
-		$this->statsCache = Cache::for('referral_stats', WEEK_IN_SECONDS)->connect('referrals', true);
+//		$this->requestCache = Cache::for('referral_requests', WEEK_IN_SECONDS)->connect('referrals', true);
+		$this->statsCache = Cache::for('referral_stats', WEEK_IN_SECONDS)->connect('referrals', true)->user();
 		if (JVB_TESTING) {
 			$this->cache->flush();
-			$this->requestCache->flush();
+//			$this->requestCache->flush();
 			$this->statsCache->flush();
 		}
 
@@ -95,7 +95,8 @@
 		add_action('admin_notices', [$this, 'showReferralPageNotice']);
 
 
-		add_filter('jvbDashboardPage', [$this, 'renderDashPage'], 10, 2);
+		add_action(BASE.'dashboard_page_referrals', [$this, 'renderDashPage'], 10);
+//		add_filter('jvbDashboardPage', [$this, 'renderDashPage'], 10, 2);
 
 		// Handle settings save
 		add_action('admin_init', [$this, 'registerSettings']);
@@ -707,8 +708,8 @@
 	{
 		$defaults = [
 			'status' => 'all',
-			'limit' => 100,
-			'offset' => 0,
+			'per_page' => 100,
+			'page' => 1,
 			'orderby' => 'created_at',
 			'order' => 'DESC'
 		];
@@ -719,8 +720,8 @@
 			'where' => [
 				'from_user'	=> $user_id,
 			],
-			'limit'		=> $args['limit'],
-			'offset'	=> $args['offset'],
+			'per_page'		=> $args['per_page'],
+			'page'		=> $args['page'],
 			'orderby'	=> $args['orderby'],
 			'order'		=> $args['order']
 		];
@@ -795,7 +796,7 @@
 	public function getTopReferrers(int $limit = 10, string $period = 'all'): array
 	{
 		return $this->statsCache->remember(
-			$this->statsCache->generateKey(['limit' => $limit, 'period' => $period]),
+			$this->statsCache->generateKey(['per_page' => $limit, 'period' => $period]),
 			function() use ($limit, $period) {
 				$where = '';
 				if ($period !== 'all') {
@@ -1033,7 +1034,7 @@
 
 		$referral_code = get_user_meta($user->ID, BASE . 'referral_code', true);
 		$stats = $this->getUserStats($user->ID);
-		$referrals = $this->getUserReferrals($user->ID, ['limit' => 10]);
+		$referrals = $this->getUserReferrals($user->ID, ['per_page' => 10]);
 
 		?>
 		<h2>Referral Information</h2>
@@ -1265,7 +1266,7 @@
 				<p class="hint">Can\'t find it? Check your spam folder.</p>
 			</div>',
 			jvbFormStatus(),
-			esc_attr(get_option(BASE.'referral_role','client')),
+			esc_attr(Site::getReferralRole()),
 			Form::render('referral_name', '', [
 				'required'	=> true,
 				'type'		=> 'text',
@@ -1301,6 +1302,7 @@
 			'<form id="login-form">%s%s%s
 			<button type="submit">%sLogin With Magic Link</button>
 		</form>
+
 		<div class="success-content" hidden>
 			<h3>Check Your Email!</h3>
 			<p>We\'ve sent you a magic link to log in - no password required! Click the link in your email to log in.</p>
@@ -2615,12 +2617,8 @@
 		}
 	}
 
-	public function renderDashPage(string $content, string $page): string
+	public function renderDashPage():void
 	{
-		if ($page !== 'Referrals') {
-			return $content;
-		}
-
 		// Regular users get their referral dashboard
 		$user_id = get_current_user_id();
 
@@ -2630,9 +2628,8 @@
 			$referral_code = $this->generateReferralCode($user);
 		}
 
-		$referrals = $this->getUserReferrals($user_id, ['limit' => 20]);
+		$referrals = $this->getUserReferrals($user_id, ['per_page' => 20]);
 
-		ob_start();
 
 		$tabs = new Tabs();
 		$tabs->addTab('share')
@@ -2647,11 +2644,10 @@
 
 		?>
 		<div class="referral-dashboard">
-			<?= $tabs->render(true);?>
+			<?= $tabs->render();?>
 		</div>
 
 		<?php
-		return ob_get_clean();
 	}
 
 	protected function shareDashboard(int $user_id, string $referral_code):string
@@ -3137,7 +3133,7 @@
 			array_push($values, $like, $like, $like, $like);
 		}
 
-		array_push($values, absint($args['limit'] ?? 50), absint($args['offset'] ?? 0));
+		array_push($values, absint($args['per_page'] ?? 50), absint($args['offset'] ?? 0));
 
 		return $this->referrals->queryResults(
 			"SELECT {table}.*, u.display_name as from_name

--
Gitblit v1.10.0