Process etymology field in the backend

This commit is contained in:
Robbie Antenesse 2019-10-01 14:53:15 -06:00
parent d03abfa566
commit 981490473f
3 changed files with 19 additions and 4 deletions

View File

@ -219,7 +219,7 @@ WHERE dictionary=$dictionary";
$results = $this->db->query($query)->fetchAll(); $results = $this->db->query($query)->fetchAll();
if ($results) { if ($results) {
return array_map(function ($row) { return array_map(function ($row) {
return array( $word = array(
'name' => $row['name'], 'name' => $row['name'],
'pronunciation' => $row['pronunciation'], 'pronunciation' => $row['pronunciation'],
'partOfSpeech' => $row['part_of_speech'], 'partOfSpeech' => $row['part_of_speech'],
@ -229,6 +229,12 @@ WHERE dictionary=$dictionary";
'createdOn' => intval($row['created_on']), 'createdOn' => intval($row['created_on']),
'wordId' => intval($row['word_id']), 'wordId' => intval($row['word_id']),
); );
if (!is_null($row['etymology'])) {
$word['etymology'] = $row['etymology'];
}
return $word;
}, $results); }, $results);
} }
return array(); return array();
@ -253,7 +259,7 @@ WHERE dictionary=$dictionary";
return true; return true;
} }
$query = 'INSERT INTO words (dictionary, word_id, name, pronunciation, part_of_speech, definition, details, last_updated, created_on) VALUES '; $query = 'INSERT INTO words (dictionary, word_id, name, pronunciation, part_of_speech, definition, details, etymology, last_updated, created_on) VALUES ';
$params = array(); $params = array();
$word_ids = array(); $word_ids = array();
$most_recent_word_update = 0; $most_recent_word_update = 0;
@ -263,7 +269,7 @@ WHERE dictionary=$dictionary";
$most_recent_word_update = $last_updated; $most_recent_word_update = $last_updated;
} }
$word_ids[] = $word['wordId']; $word_ids[] = $word['wordId'];
$query .= "(?, ?, ?, ?, ?, ?, ?, ?, ?), "; $query .= "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?), ";
$params[] = $dictionary; $params[] = $dictionary;
$params[] = $word['wordId']; $params[] = $word['wordId'];
$params[] = $word['name']; $params[] = $word['name'];
@ -271,6 +277,7 @@ WHERE dictionary=$dictionary";
$params[] = $word['partOfSpeech']; $params[] = $word['partOfSpeech'];
$params[] = $word['definition']; $params[] = $word['definition'];
$params[] = $word['details']; $params[] = $word['details'];
$params[] = isset($word['etymology']) ? $word['etymology'] : null;
$params[] = $last_updated; $params[] = $last_updated;
$params[] = $word['createdOn']; $params[] = $word['createdOn'];
} }
@ -280,6 +287,7 @@ pronunciation=VALUES(pronunciation),
part_of_speech=VALUES(part_of_speech), part_of_speech=VALUES(part_of_speech),
definition=VALUES(definition), definition=VALUES(definition),
details=VALUES(details), details=VALUES(details),
etymology=VALUES(etymology),
last_updated=VALUES(last_updated), last_updated=VALUES(last_updated),
created_on=VALUES(created_on)'; created_on=VALUES(created_on)';

View File

@ -81,7 +81,7 @@ class PublicDictionary {
$words = $this->getWordsAsEntered(); $words = $this->getWordsAsEntered();
if ($words) { if ($words) {
return array_map(function ($row) use ($dictionary) { return array_map(function ($row) use ($dictionary) {
return array( $word = array(
'name' => $this->translateOrthography($row['name'], $dictionary), 'name' => $this->translateOrthography($row['name'], $dictionary),
'pronunciation' => $row['pronunciation'], 'pronunciation' => $row['pronunciation'],
'partOfSpeech' => $row['part_of_speech'], 'partOfSpeech' => $row['part_of_speech'],
@ -91,6 +91,12 @@ class PublicDictionary {
'createdOn' => intval($row['created_on']), 'createdOn' => intval($row['created_on']),
'wordId' => intval($row['word_id']), 'wordId' => intval($row['word_id']),
); );
if (!is_null($row['etymology'])) {
$word['etymology'] = $row['etymology'];
}
return $word;
}, $this->sortWords($words)); }, $this->sortWords($words));
} }
} }

View File

@ -86,6 +86,7 @@ CREATE TABLE IF NOT EXISTS `words` (
`part_of_speech` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `part_of_speech` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`definition` text COLLATE utf8_unicode_ci NOT NULL, `definition` text COLLATE utf8_unicode_ci NOT NULL,
`details` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'Markdown', `details` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'Markdown',
`etymology` text COLLATE utf8_unicode_ci DEFAULT NULL,
`last_updated` int(11) DEFAULT NULL, `last_updated` int(11) DEFAULT NULL,
`created_on` int(11) NOT NULL, `created_on` int(11) NOT NULL,
UNIQUE KEY `unique_index` (`dictionary`,`word_id`) UNIQUE KEY `unique_index` (`dictionary`,`word_id`)