Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot] e1e14d473e
Merge f7935f6267 into bfb74a0000 2022-12-09 04:17:19 +00:00
1 changed files with 19 additions and 14 deletions

View File

@ -10,7 +10,7 @@ class PublicDictionary {
public $details; public $details;
public $words; public $words;
function __construct ($dictionary_id, $details_only = false) { function __construct ($dictionary_id) {
$this->db = new Db(); $this->db = new Db();
$this->token = new Token(); $this->token = new Token();
@ -19,7 +19,7 @@ class PublicDictionary {
); );
$this->details = $this->getPublicDictionaryDetails($dictionary_id); $this->details = $this->getPublicDictionaryDetails($dictionary_id);
$this->words = $details_only ? [] : $this->getPublicDictionaryWords($dictionary_id); $this->words = $this->getPublicDictionaryWords($dictionary_id);
if ($this->details !== false) { if ($this->details !== false) {
$this->details['wordStats'] = $this->getWordStats(); $this->details['wordStats'] = $this->getWordStats();
} }
@ -123,10 +123,13 @@ class PublicDictionary {
return array(); return array();
} }
public function getSpecificPublicDictionaryWord ($dictionary, $word_id) { public function getSpecificPublicDictionaryWord ($dictionary, $word) {
if (is_numeric($dictionary) && is_numeric($word_id)) { if (is_numeric($dictionary) && is_numeric($word)) {
$results = array_filter($this->getWordsAsEntered(), fn ($row) => $row['word_id'] == $word_id); $query = "SELECT words.*, wa.etymology, wa.related, wa.principal_parts FROM words
$result = array_values($results)[0] ?? null; 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";
$result = $this->db->query($query, array($dictionary, $word))->fetch();
if ($result) { if ($result) {
$word = array( $word = array(
'name' => $this->translateOrthography($result['name'], $dictionary), 'name' => $this->translateOrthography($result['name'], $dictionary),
@ -262,7 +265,7 @@ WHERE words.dictionary=? AND is_public=1";
} }
$target_id = false; $target_id = false;
$reference_ids = $this->getWordIdsFromName($word_to_find); $reference_ids = $this->getWordIdsWithName($dictionary_id, $word_to_find);
if (count($reference_ids) > 0) { if (count($reference_ids) > 0) {
if ($homonymn !== false && $homonymn > 0) { if ($homonymn !== false && $homonymn > 0) {
@ -290,13 +293,15 @@ WHERE words.dictionary=? AND is_public=1";
return $reference; return $reference;
} }
private function getWordIdsFromName($word_name) { private function getWordIdsWithName($dictionary, $word_name) {
$results = array_filter($this->getWordsAsEntered(), fn ($row) => $row['name'] == $word_name); if (is_numeric($dictionary)) {
$results = array_values($results); $query = "SELECT word_id FROM words WHERE dictionary=? AND name=?";
if ($results) { $results = $this->db->query($query, array($dictionary, $word_name))->fetchAll();
return array_map(function ($row) { if ($results) {
return intval($row['word_id']); return array_map(function ($row) {
}, $results); return intval($row['word_id']);
}, $results);
}
} }
return array(); return array();
} }