| | |
| | | <?php |
| | | namespace JVBase\rest\routes; |
| | | |
| | | use JVBase\Instance; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\managers\queue\executors\ContentTermExecutor; |
| | | use JVBase\managers\queue\Queue; |
| | | use JVBase\managers\queue\TypeConfig; |
| | | use JVBase\managers\Roles; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\rest\Rest; |
| | | use JVBase\rest\Route; |
| | |
| | | */ |
| | | class ContentTermsRoutes extends Rest |
| | | { |
| | | use Instance; |
| | | protected string $taxonomy; |
| | | protected Registrar $registrar; |
| | | protected ?CustomTable $historyTable = null; |
| | | protected ?CustomTable $requestsTable = null; |
| | | |
| | | public function __construct(string $taxonomy = '') |
| | | //TODO: This needs some work. We need to move most logic into it's own manager class |
| | | protected function __construct(string $taxonomy = '') |
| | | { |
| | | $this->taxonomy = jvbNoBase($taxonomy); |
| | | |
| | |
| | | $this->registrar = Registrar::getInstance($this->taxonomy); |
| | | $this->cacheName = $this->taxonomy; |
| | | parent::__construct(); |
| | | $this->cache = Cache::for($this->taxonomy, 'term', DAY_IN_SECONDS); |
| | | $this->setupTables(); |
| | | $this->setupCacheConnections(); |
| | | } |
| | |
| | | |
| | | public function registerContentTermsExecutors():void |
| | | { |
| | | $registry = JVB()->queue()->registry(); |
| | | $registry = Queue::getInstance()->registry(); |
| | | $executor = new ContentTermExecutor(); |
| | | $taxonomies = Registrar::withFeature('is_content', 'term'); |
| | | |
| | |
| | | } |
| | | |
| | | return user_can($userID, 'manage_options') || |
| | | JVB()->roles()->isManager($userID, $termID); |
| | | Roles::getInstance()()->isManager($userID, $termID); |
| | | } |
| | | |
| | | public function checkOwnerPermission(WP_REST_Request $request): bool |
| | |
| | | } |
| | | |
| | | return user_can($userID, 'manage_options') || |
| | | JVB()->roles()->isOwner($userID, $termID); |
| | | Roles::getInstance()()->isOwner($userID, $termID); |
| | | } |
| | | |
| | | /** |
| | |
| | | unset($data['user'], $data['term_id']); |
| | | |
| | | // Queue the update |
| | | $op = JVB()->queue()->add( |
| | | $op = Queue::getInstance()->add( |
| | | "{$this->taxonomy}_update", |
| | | $userID, |
| | | array_merge(['term_id' => $termID], $data), |
| | |
| | | $targetUserID = (int)$request->get_param('target_user'); |
| | | |
| | | // Queue the operation |
| | | $op = JVB()->queue()->add( |
| | | $op = Queue::getInstance()->add( |
| | | "{$this->taxonomy}_member_{$action}", |
| | | $userID, |
| | | [ |
| | |
| | | }); |
| | | |
| | | // Notify user |
| | | JVB()->notification()->addNotification( |
| | | NotificationManager::getInstance()->addNotification( |
| | | $requestData['user_id'], |
| | | 'request_' . $status, |
| | | [ |
| | |
| | | return $this->error('Invalid target user'); |
| | | } |
| | | |
| | | $roleManager = JVB()->roles(); |
| | | $roleManager = Roles::getInstance()(); |
| | | |
| | | try { |
| | | $result = match($role) { |
| | |
| | | */ |
| | | protected function notifyTermManagers(int $termID, int $actingUserID, string $notificationType): void |
| | | { |
| | | $roleManager = JVB()->roles(); |
| | | $roleManager = Roles::getInstance()(); |
| | | $managers = $roleManager->getManagedTerms($actingUserID, $this->taxonomy); |
| | | |
| | | $term = get_term($termID, jvbCheckBase($this->taxonomy)); |
| | | |
| | | foreach ($managers as $managerID) { |
| | | JVB()->notification()->addNotification( |
| | | NotificationManager::getInstance()->addNotification( |
| | | $managerID, |
| | | $notificationType, |
| | | [ |