| | |
| | | |
| | | use JVBase\managers\queue\executors\ContentTermExecutor; |
| | | use JVBase\managers\queue\TypeConfig; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\rest\Rest; |
| | | use JVBase\rest\Route; |
| | | use JVBase\rest\PermissionHandler; |
| | |
| | | class ContentTermsRoutes extends Rest |
| | | { |
| | | protected string $taxonomy; |
| | | protected array $config; |
| | | protected Registrar $registrar; |
| | | protected ?CustomTable $historyTable = null; |
| | | protected ?CustomTable $requestsTable = null; |
| | | |
| | |
| | | { |
| | | $this->taxonomy = jvbNoBase($taxonomy); |
| | | |
| | | if ($taxonomy && isset(JVB_TAXONOMY[$this->taxonomy])) { |
| | | $this->config = JVB_TAXONOMY[$this->taxonomy]; |
| | | if ($taxonomy !== '' && Registrar::getInstance($this->taxonomy)) { |
| | | $this->registrar = Registrar::getInstance($this->taxonomy); |
| | | $this->cacheName = $this->taxonomy; |
| | | parent::__construct(); |
| | | $this->setupTables(); |
| | |
| | | { |
| | | $registry = JVB()->queue()->registry(); |
| | | $executor = new ContentTermExecutor(); |
| | | $taxonomies = Features::getTypesWithFeature('is_content', 'taxonomy'); |
| | | $taxonomies = Registrar::getFeatured('is_content', 'term'); |
| | | |
| | | foreach($taxonomies as $taxonomy) { |
| | | $registry->register("{$taxonomy}_update", new TypeConfig( |
| | | executor: $executor, |
| | | )); |
| | | |
| | | if (Features::forTaxonomy($taxonomy)->has('track_changes')) { |
| | | $registrar = Registrar::getInstance($taxonomy); |
| | | if ($registrar && $registrar->hasFeature('track_changes')) { |
| | | $registry->register("{$taxonomy}_member_add", new TypeConfig( |
| | | executor: $executor |
| | | )); |
| | |
| | | |
| | | protected function setupTables(): void |
| | | { |
| | | $content = $this->config['for_content'] ?? []; |
| | | $content = $this->registrar->registrar->for; |
| | | |
| | | if (Features::forTaxonomy($this->taxonomy)->has('track_changes') && !empty($content)) { |
| | | if ($this->registrar->hasFeature('track_changes') && !empty($content)) { |
| | | foreach ($content as $contentType) { |
| | | $tableName = "history_{$contentType}_{$this->taxonomy}"; |
| | | $this->historyTable = CustomTable::for($tableName); |
| | |
| | | } |
| | | } |
| | | |
| | | if (Features::forTaxonomy($this->taxonomy)->has('verify_entry') && !empty($content)) { |
| | | if ($this->registrar->hasFeature('verify_entry') && !empty($content)) { |
| | | foreach ($content as $contentType) { |
| | | $tableName = "{$contentType}_{$this->taxonomy}_requests"; |
| | | $this->requestsTable = CustomTable::for($tableName); |
| | |
| | | |
| | | public function registerRoutes(): void |
| | | { |
| | | if (!Features::forTaxonomy($this->taxonomy)->has('is_content')) { |
| | | if (!$this->registrar->hasFeature('is_content')) { |
| | | return; |
| | | } |
| | | |
| | |
| | | ->register(); |
| | | |
| | | // Member management (if track_changes enabled) |
| | | if (Features::forTaxonomy($this->taxonomy)->has('track_changes')) { |
| | | if ($this->registrar->hasFeature('track_changes')) { |
| | | Route::for("{$base}/:term_id/members") |
| | | ->get([$this, 'getMembers']) |
| | | ->args([ |
| | |
| | | } |
| | | |
| | | // Membership requests (if verify_entry enabled) |
| | | if (Features::forTaxonomy($this->taxonomy)->has('verify_entry')) { |
| | | if ($this->registrar->hasFeature('verify_entry')) { |
| | | Route::for("{$base}/:term_id/requests") |
| | | ->get([$this, 'getRequests']) |
| | | ->args([ |
| | |
| | | } |
| | | |
| | | // Ownership/management (if is_ownable enabled) |
| | | if (Features::forTaxonomy($this->taxonomy)->has('is_ownable')) { |
| | | if ($this->registrar->hasFeature('is_ownable')) { |
| | | Route::for("{$base}/:term_id/permissions") |
| | | ->post([$this, 'updatePermissions']) |
| | | ->args([ |