From 3d25ad7de4fdbb3eba2cde2a62422e6be5d79a0a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 25 Aug 2026 22:57:22 +0000
Subject: [PATCH] =It's been a minute. I went through the Routes and associated Managers and ensured they played together well. Reworked the Cache.php, and I think I caught all the references. Moving away from JVBase() root class, to individuall classes that are Instanced. Double checked for the ABSPATH check in every file, and added index.php to every directory that didn't already have it. Also still working on the MenuBlock to work with WooCommerce for now for Northeh
---
inc/rest/routes/ApprovalRoutes.php | 66 +++++---------------------------
1 files changed, 11 insertions(+), 55 deletions(-)
diff --git a/inc/rest/routes/ApprovalRoutes.php b/inc/rest/routes/ApprovalRoutes.php
index b4129a7..963ff45 100644
--- a/inc/rest/routes/ApprovalRoutes.php
+++ b/inc/rest/routes/ApprovalRoutes.php
@@ -2,7 +2,10 @@
namespace JVBase\rest\routes;
-use JVBase\managers\CustomTable;
+use JVBase\Instance;
+use JVBase\managers\Approvals;
+use JVBase\managers\Cache;
+
use JVBase\registrar\Registrar;
use JVBase\rest\PermissionHandler;
use JVBase\rest\Rest;
@@ -11,7 +14,6 @@
use JVBase\base\Site;
use WP_REST_Request;
use WP_REST_Response;
-use Exception;
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
@@ -19,6 +21,7 @@
class ApprovalRoutes extends Rest
{
+ use Instance;
protected array $userTypes;
protected array $termTypes;
protected array $allTypes;
@@ -31,6 +34,7 @@
$this->cacheName = 'approvals';
$this->hasMemberApproval = Site::membership() && Site::membership()->has('member_verified');
parent::__construct();
+ $this->cache = Cache::for('approvals', 'custom', $this->cacheTtl);
$this->initTypes();
}
@@ -106,7 +110,7 @@
if (!in_array($vote, ['approve', 'reject', 'dismiss'])) {
return false;
}
- $result = JVB()->approvals()->markApproval($request_id, $user_id, $type, $vote, $notes);
+ $result = Approvals::getInstance()->markApproval($request_id, $user_id, $type, $vote, $notes);
return $result['success'];
}
@@ -147,11 +151,11 @@
*/
public function getVerificationDetails(int $requestID, string $type): array|false
{
- $request = JVB()->approvals()->getRequest($requestID, $type);
+ $request = Approvals::getInstance()->getRequest($requestID, $type);
if (!$request) {
return false;
}
- $votes = JVB()->approvals()->getVotes($requestID, $type);
+ $votes = Approvals::getInstance()->getVotes($requestID, $type);
// Join with user data for display names
foreach ($votes as &$vote) {
@@ -187,7 +191,7 @@
int $required_approvals = 3
): int|false {
- $result = JVB()->approvals()->createApproval(
+ $result = Approvals::getInstance()->createApproval(
$user_id,
$taxonomy,
$name,
@@ -196,64 +200,16 @@
return $result['success'];
}
- protected function getTableName(string $type, string $suffix): string
- {
- return match ($type) {
- 'term' => "approval_term_{$suffix}",
- default => "approval_{$type}_{$suffix}",
- };
- }
-
public function getApprovals(WP_REST_Request $request): WP_REST_Response
{
$user_id = get_current_user_id();
$type = sanitize_text_field($request->get_param('type') ?? 'all');
$status = sanitize_text_field($request->get_param('status') ?? 'pending');
- $cacheKey = compact('user_id', 'type', 'status');
-
- $result = $this->cache->remember($cacheKey, function() use ($type, $status) {
- $data = [];
-
- if ($type === 'user' || $type === 'all') {
- $data['user_approvals'] = $this->getUserApprovals($status);
- }
-
- if ($type === 'term' || $type === 'all') {
- $data['term_approvals'] = $this->getTermApprovals($status);
- }
-
- return $data;
- });
+ $result = Approvals::getInstance()->getApprovalRequests($user_id, $type === 'all' ? null : $type);
return $this->success($result);
}
- private function getUserApprovals(string $status = 'pending'): array
- {
- $table = CustomTable::for($this->getTableName('artist', 'requests'));
-
- $query = $table;
-
- if ($status !== 'all') {
- $query = $query->where(['status' => $status]);
- }
-
- return $query->orderBy('created_at', 'DESC')->getResults(ARRAY_A);
- }
-
- private function getTermApprovals(string $status = 'pending'): array
- {
- $table = CustomTable::for($this->getTableName('term', 'requests'));
-
- if ($status === 'all') {
- return $table->orderBy('created_at', 'DESC')->getResults(ARRAY_A);
- }
-
- return $table
- ->where(['status' => $status])
- ->orderBy('created_at', 'DESC')
- ->getResults(ARRAY_A);
- }
}
--
Gitblit v1.10.0