| | |
| | | <?php |
| | | namespace JVBase\rest\routes; |
| | | |
| | | use JVBase\JVB; |
| | | use JVBase\registrar\Registrar; |
| | | use JVBase\rest\Rest; |
| | | use JVBase\managers\TaxonomyRelationships; |
| | | use JVBase\managers\UserTermsManager; |
| | | use JVBase\rest\Route; |
| | | use JVBase\utility\Features; |
| | | use JVBase\base\Site; |
| | | use WP_REST_Request; |
| | | use WP_REST_Response; |
| | | use Exception; |
| | |
| | | |
| | | // Add relationship data if requested |
| | | if ($request->get_param('include_relationships')) { |
| | | $relationship_manager = new TaxonomyRelationships(); |
| | | $relationship_manager = JVB()->termRelationships(); |
| | | $related_taxonomies = $request->get_param('related_taxonomies') ?: ['jvb_style', 'jvb_theme', 'jvb_city']; |
| | | |
| | | $data['relationships'] = []; |
| | |
| | | if (array_key_exists('content', $data)) { |
| | | // If content_type is provided, use the specialized endpoint |
| | | $content_type = $request->get_param('content'); |
| | | global $feed_types; |
| | | if (taxIsJVBContentTax($content_type)) { |
| | | $registrar = Registrar::getInstance($content_type); |
| | | if ($registrar->hasFeature('is_content')) { |
| | | $response = $this->getTermsForContentType($request); |
| | | return $this->addCacheHeaders($response); |
| | | } |
| | |
| | | if ($request->get_param('main_context') && in_array(jvbCheckBase(json_decode($request->get_param('main_context'), true)['context']), jvbUserTypes())) { |
| | | |
| | | $main_context = json_decode($request->get_param('main_context'), true); |
| | | $userID = get_post_meta($main_context['id'], BASE.'link', true); |
| | | $userID = get_post_meta($main_context['id'], BASE.'profile_link', true); |
| | | $manager = new UserTermsManager(); |
| | | $related = $manager->getUserTermIDs($userID, $taxonomy); |
| | | $related = $manager->fetchUserTerms($userID, $taxonomy); |
| | | |
| | | if (empty($related)) { |
| | | $response = $this->emptyResult(); |
| | |
| | | $main_context = json_decode($request->get_param('main_context'), true); |
| | | $thisTaxonomy = str_replace('taxonomy:', '', $main_context['context']); |
| | | $ID = (int)$main_context['id']; |
| | | $manager = new TaxonomyRelationships(); |
| | | $manager = JVB()->termRelationships(); |
| | | $related = $manager->getRelatedTerms($ID, BASE.$request->get_param('taxonomy')); |
| | | |
| | | if (empty($related)) { |
| | |
| | | $match = $request->get_param('match') ?? 'any'; |
| | | $context = json_decode($request['context'], true); |
| | | |
| | | $relationshipManager = new TaxonomyRelationships(); |
| | | $relationshipManager = JVB()->termRelationships(); |
| | | // Prepare array to collect term IDs that match the context |
| | | $related_term_ids = []; |
| | | |
| | |
| | | */ |
| | | public function getTermsForContentType(WP_REST_Request $request):WP_REST_Response |
| | | { |
| | | $manager = new TaxonomyRelationships(); |
| | | $manager = JVB()->termRelationships(); |
| | | $content_type = BASE . $request->get_param('content'); |
| | | $taxonomy = BASE . $request->get_param('taxonomy'); |
| | | $search = $request->get_param('search'); |
| | |
| | | ]]); |
| | | } |
| | | |
| | | if (Features::forMembership()->has('term_approval')) { |
| | | $membership = Site::membership(); |
| | | if ($membership && $membership->has('term_approval')) { |
| | | $approval_routes = JVB()->routes('approvals'); |
| | | $request_id = $approval_routes->createTermApprovalRequest( |
| | | $user_id, |