Example #1
0
 public function getTerms(Application $app, $vocabularyName, $termName = null)
 {
     /** @var \Mentoring\Taxonomy\TaxonomyService $taxonomyService */
     $taxonomyService = $app['taxonomy.service'];
     try {
         $vocabulary = $taxonomyService->fetchVocabularyByName($vocabularyName);
         $terms = $taxonomyService->fetchAllTerms($vocabulary);
         $termHydrator = new TermHydrator();
         $termData = [];
         foreach ($terms as $term) {
             $termData[] = $termHydrator->extract($term);
         }
         return new Response(json_encode(['vocabulary' => $vocabularyName, 'count' => count($termData), 'terms' => $termData]), 200, ['Content-Type' => 'application/json']);
     } catch (VocabularyNotFoundException $e) {
         return new Response(json_encode(['error' => $e->getMessage()]), 404, ['Content-Type' => 'application/json']);
     }
 }
Example #2
0
 public function fetchTermsForUser(User $user, Vocabulary $vocabulary)
 {
     $data = $this->dbal->fetchAll('SELECT
             t.*
         FROM
             taxonomyTerms t
         JOIN
             userTags u ON t.id=u.term_id
         WHERE
             u.user_id = :user_id
             AND t.vocabulary_id = :vocabulary_id
         ', ['vocabulary_id' => $vocabulary->getId(), 'user_id' => $user->getId()]);
     $terms = [];
     foreach ($data as $termData) {
         $term = $this->termHydrator->hydrate($termData, new Term());
         $term->setVocabulary($vocabulary);
         $terms[] = $term;
     }
     return $terms;
 }