From 1bc75f2256780d8bc2aa0470f9ff39dc3dfedf4a Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Mon, 27 May 2019 22:52:50 -0600 Subject: [PATCH] Make view.html a template for router.php to use Also add public_name to Dictionary->getPublicDictionaryDetails() --- src/php/api/Dictionary.php | 3 ++- src/php/api/router.php | 23 +++++++++++++++++++++++ view.html | 8 +++++++- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/php/api/router.php diff --git a/src/php/api/Dictionary.php b/src/php/api/Dictionary.php index 6b92ebf..3682025 100644 --- a/src/php/api/Dictionary.php +++ b/src/php/api/Dictionary.php @@ -91,7 +91,7 @@ VALUES ($new_id, ?, ?, ?, ?)"; public function getPublicDictionaryDetails ($dictionary_hash) { $dictionary = $this->token->unhash($dictionary_hash); if ($dictionary !== false) { - $query = "SELECT * FROM dictionaries JOIN dictionary_linguistics ON dictionary = id WHERE id=? AND is_public=1"; + $query = "SELECT d.*, dl.*, u.public_name FROM dictionaries d JOIN dictionary_linguistics dl ON dl.dictionary = d.id JOIN users u ON u.id = d.user WHERE d.id=? AND d.is_public=1"; $result = $this->db->query($query, array($dictionary))->fetch(); if ($result) { // Default json values in case they are somehow not created by front end first @@ -102,6 +102,7 @@ VALUES ($new_id, ?, ?, ?, ?)"; 'name' => $result['name'], 'specification' => $result['specification'], 'description' => $result['description'], + 'createdBy' => $result['public_name'], 'partsOfSpeech' => explode(',', $partsOfSpeech), 'details' => array( 'phonology' => array( diff --git a/src/php/api/router.php b/src/php/api/router.php new file mode 100644 index 0000000..4ae1e08 --- /dev/null +++ b/src/php/api/router.php @@ -0,0 +1,23 @@ +getPublicDictionaryDetails($dict); + if ($dictionary_data !== false) { + $dictionary_data['words'] = $dictionary->getPublicDictionaryWords($dict); + $html = str_replace('{{dict}}', $dict, $html); + $html = str_replace('{{dict_name}}', $dictionary_data['name'] . ' ' . $dictionary_data['specification'], $html); + $html = str_replace('{{public_name}}', $dictionary_data['createdBy'], $html); + $html = str_replace('{{dict_json}}', json_encode($dictionary_data), $html); + } + echo $html; + } + break; + } +} \ No newline at end of file diff --git a/view.html b/view.html index b1fd0c9..ae2b342 100644 --- a/view.html +++ b/view.html @@ -4,7 +4,13 @@ - Lexiconga + {{dict_name}} | Lexiconga + + + + + +