diff --git a/src/php/api/Dictionary.php b/src/php/api/Dictionary.php index 02cfc73..487c5a0 100644 --- a/src/php/api/Dictionary.php +++ b/src/php/api/Dictionary.php @@ -219,7 +219,7 @@ WHERE dictionary=$dictionary"; $results = $this->db->query($query)->fetchAll(); if ($results) { return array_map(function ($row) { - return array( + $word = array( 'name' => $row['name'], 'pronunciation' => $row['pronunciation'], 'partOfSpeech' => $row['part_of_speech'], @@ -229,6 +229,12 @@ WHERE dictionary=$dictionary"; 'createdOn' => intval($row['created_on']), 'wordId' => intval($row['word_id']), ); + + if (!is_null($row['etymology'])) { + $word['etymology'] = $row['etymology']; + } + + return $word; }, $results); } return array(); @@ -253,7 +259,7 @@ WHERE dictionary=$dictionary"; 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(); $word_ids = array(); $most_recent_word_update = 0; @@ -263,7 +269,7 @@ WHERE dictionary=$dictionary"; $most_recent_word_update = $last_updated; } $word_ids[] = $word['wordId']; - $query .= "(?, ?, ?, ?, ?, ?, ?, ?, ?), "; + $query .= "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?), "; $params[] = $dictionary; $params[] = $word['wordId']; $params[] = $word['name']; @@ -271,6 +277,7 @@ WHERE dictionary=$dictionary"; $params[] = $word['partOfSpeech']; $params[] = $word['definition']; $params[] = $word['details']; + $params[] = isset($word['etymology']) ? $word['etymology'] : null; $params[] = $last_updated; $params[] = $word['createdOn']; } @@ -280,6 +287,7 @@ pronunciation=VALUES(pronunciation), part_of_speech=VALUES(part_of_speech), definition=VALUES(definition), details=VALUES(details), +etymology=VALUES(etymology), last_updated=VALUES(last_updated), created_on=VALUES(created_on)'; diff --git a/src/php/api/PublicDictionary.php b/src/php/api/PublicDictionary.php index 2f6bd87..2a64d60 100644 --- a/src/php/api/PublicDictionary.php +++ b/src/php/api/PublicDictionary.php @@ -81,7 +81,7 @@ class PublicDictionary { $words = $this->getWordsAsEntered(); if ($words) { return array_map(function ($row) use ($dictionary) { - return array( + $word = array( 'name' => $this->translateOrthography($row['name'], $dictionary), 'pronunciation' => $row['pronunciation'], 'partOfSpeech' => $row['part_of_speech'], @@ -91,6 +91,12 @@ class PublicDictionary { 'createdOn' => intval($row['created_on']), 'wordId' => intval($row['word_id']), ); + + if (!is_null($row['etymology'])) { + $word['etymology'] = $row['etymology']; + } + + return $word; }, $this->sortWords($words)); } } diff --git a/src/structure.sql b/src/structure.sql index ebf0346..1c643aa 100644 --- a/src/structure.sql +++ b/src/structure.sql @@ -86,6 +86,7 @@ CREATE TABLE IF NOT EXISTS `words` ( `part_of_speech` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `definition` text COLLATE utf8_unicode_ci NOT NULL, `details` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'Markdown', + `etymology` text COLLATE utf8_unicode_ci DEFAULT NULL, `last_updated` int(11) DEFAULT NULL, `created_on` int(11) NOT NULL, UNIQUE KEY `unique_index` (`dictionary`,`word_id`)