Display related words in public dictionary render

This commit is contained in:
Robbie Antenesse 2020-05-07 23:09:19 -06:00
parent d1bcfc5b97
commit 4d63aa9034
2 changed files with 18 additions and 4 deletions

View File

@ -184,6 +184,8 @@ export function renderWords() {
details: originalWord.details, details: originalWord.details,
etymology: typeof originalWord.etymology === 'undefined' || originalWord.etymology.length < 1 ? null etymology: typeof originalWord.etymology === 'undefined' || originalWord.etymology.length < 1 ? null
: originalWord.etymology.join(', '), : originalWord.etymology.join(', '),
related: typeof originalWord.related === 'undefined' || originalWord.related.length < 1 ? null
: originalWord.related.join(', '),
wordId: originalWord.wordId, wordId: originalWord.wordId,
}); });
@ -204,11 +206,15 @@ export function renderWords() {
<dd class="details"> <dd class="details">
${md(word.details)} ${md(word.details)}
</dd> </dd>
${word.etymology === null ? '' : `<hr> ${word.etymology === null && word.related === null ? '' : `<hr>`}
<dt>Etymology <small>(Root Word${originalWord.etymology.length !== 1 ? 's' : ''})</small></dt> ${word.etymology === null ? '' : `<dt>Etymology <small>(Root Word${originalWord.etymology.length !== 1 ? 's' : ''})</small></dt>
<dd class="etymology"> <dd class="etymology">
${md(word.etymology).replace(/<\/?p>/g, '')} ${md(word.etymology).replace(/<\/?p>/g, '')}
</dd>`} </dd>`}
${word.related === null ? '' : `<dt>Related Word${originalWord.related.length !== 1 ? 's' : ''}</dt>
<dd class="related">
${md(word.related).replace(/<\/?p>/g, '')}
</dd>`}
</dl> </dl>
</article>`; </article>`;
}); });

View File

@ -99,6 +99,14 @@ class PublicDictionary {
}, explode(',', $row['etymology'])); }, explode(',', $row['etymology']));
} }
} }
if (!is_null($row['related'])) {
if (strlen($row['related']) > 0) {
$word['related'] = array_map(function ($root) use($dictionary) {
return $this->getWordReferenceHTML(strip_tags($root), $dictionary);
}, explode(',', $row['related']));
}
}
return $word; return $word;
}, $this->sortWords($words)); }, $this->sortWords($words));
@ -129,8 +137,8 @@ class PublicDictionary {
private function getWordsAsEntered() { private function getWordsAsEntered() {
if (!isset($this->original_words)) { if (!isset($this->original_words)) {
$query = "SELECT words.*, words_advanced.etymology FROM words $query = "SELECT words.*, wa.etymology, wa.related FROM words
LEFT JOIN words_advanced ON words_advanced.dictionary = words.dictionary AND words_advanced.word_id = words.word_id LEFT JOIN words_advanced wa ON wa.dictionary = words.dictionary AND wa.word_id = words.word_id
JOIN dictionaries ON dictionaries.id = words.dictionary JOIN dictionaries ON dictionaries.id = words.dictionary
WHERE words.dictionary=? AND is_public=1"; WHERE words.dictionary=? AND is_public=1";
$this->original_words = $this->db->query($query, array($this->details['externalID']))->fetchAll(); $this->original_words = $this->db->query($query, array($this->details['externalID']))->fetchAll();