Exemplo n.º 1
0
 public function saveTerm(Term $term, $vocabulary)
 {
     if (is_string($vocabulary)) {
         $vocabulary = $this->fetchVocabularyByName($vocabulary);
     }
     $term->setVocabulary($vocabulary);
     $data = $this->termHydrator->extract($term);
     if (empty($data['id'])) {
         $this->dbal->insert('taxonomyTerms', $data);
         $term->setId($this->dbal->lastInsertId());
     } else {
         $response = $this->dbal->update('taxonomyTerms', $data, ['id' => $data['id']]);
     }
     return $term;
 }
Exemplo n.º 2
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']);
     }
 }