From 8cc3b469f9cb71e2795ef249d3d69095bdfb46c7 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Fri, 8 May 2020 00:02:51 -0600 Subject: [PATCH] Display principal parts on public dictionary --- src/js/view/render.js | 3 +++ src/php/api/PublicDictionary.php | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/js/view/render.js b/src/js/view/render.js index df9d0ef..ebf27f8 100644 --- a/src/js/view/render.js +++ b/src/js/view/render.js @@ -186,6 +186,8 @@ export function renderWords() { : originalWord.etymology.join(', '), related: typeof originalWord.related === 'undefined' || originalWord.related.length < 1 ? null : originalWord.related.join(', '), + principalParts: typeof originalWord.principalParts === 'undefined' || originalWord.principalParts.length < 1 ? null + : originalWord.principalParts.join(', '), wordId: originalWord.wordId, }); @@ -197,6 +199,7 @@ export function renderWords() { wordsHTML += `

${word.name}${homonymnNumber > 0 ? ' ' + homonymnNumber.toString() + '' : ''}

+ ${word.principalParts === null ? '' : `(${word.principalParts})`} ${word.pronunciation} ${word.partOfSpeech} diff --git a/src/php/api/PublicDictionary.php b/src/php/api/PublicDictionary.php index 45a11cd..825cf05 100644 --- a/src/php/api/PublicDictionary.php +++ b/src/php/api/PublicDictionary.php @@ -107,6 +107,12 @@ class PublicDictionary { }, explode(',', $row['related'])); } } + + if (!is_null($row['principal_parts'])) { + if (strlen($row['principal_parts']) > 0) { + $word['principalParts'] = explode(',', $row['principal_parts']); + } + } return $word; }, $this->sortWords($words)); @@ -117,7 +123,7 @@ class PublicDictionary { public function getSpecificPublicDictionaryWord ($dictionary, $word) { if (is_numeric($dictionary) && is_numeric($word)) { - $query = "SELECT words.*, wa.etymology, wa.related FROM words + $query = "SELECT words.*, wa.etymology, wa.related, wa.principal_parts FROM words LEFT JOIN words_advanced wa ON wa.dictionary = words.dictionary AND wa.word_id = words.word_id JOIN dictionaries ON dictionaries.id = words.dictionary WHERE words.dictionary=? AND words.word_id=? AND dictionaries.is_public=1"; @@ -150,6 +156,12 @@ class PublicDictionary { } } + if (!is_null($result['principal_parts'])) { + if (strlen($result['principal_parts']) > 0) { + $word['principalParts'] = explode(',', $result['principal_parts']); + } + } + return $word; } } @@ -158,7 +170,7 @@ class PublicDictionary { private function getWordsAsEntered() { if (!isset($this->original_words)) { - $query = "SELECT words.*, wa.etymology, wa.related FROM words + $query = "SELECT words.*, wa.etymology, wa.related, wa.principal_parts FROM words LEFT JOIN words_advanced wa ON wa.dictionary = words.dictionary AND wa.word_id = words.word_id JOIN dictionaries ON dictionaries.id = words.dictionary WHERE words.dictionary=? AND is_public=1";