From a76dde927b799dc5370601745d5bb583a2dfca86 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sat, 11 Mar 2023 20:27:09 +0100 Subject: [PATCH] AccountSettings: list tags owned by current user --- controllers/AccountSettings.php | 5 +++++ models/Tag.php | 19 +++++++++++++++++++ templates/MyTagsView.php | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 templates/MyTagsView.php diff --git a/controllers/AccountSettings.php b/controllers/AccountSettings.php index 4bbb056..4f4a431 100644 --- a/controllers/AccountSettings.php +++ b/controllers/AccountSettings.php @@ -73,6 +73,11 @@ class AccountSettings extends HTMLController $formview = new FormView($form, $form_title); $this->page->adopt($formview); + // Fetch user tags + $tags = Tag::getAllByOwner($user->getUserId()); + if (!empty($tags)) + $this->page->adopt(new MyTagsView($tags)); + // Left a message? if (isset($_SESSION['account_msg'])) { diff --git a/models/Tag.php b/models/Tag.php index d5bbccc..13af5c7 100644 --- a/models/Tag.php +++ b/models/Tag.php @@ -96,6 +96,25 @@ class Tag return $rows; } + public static function getAllByOwner($id_user_owner) + { + $db = Registry::get('db'); + $res = $db->query(' + SELECT * + FROM tags + WHERE id_user_owner = {int:id_user_owner} + ORDER BY tag', + [ + 'id_user_owner' => $id_user_owner, + ]); + + $objects = []; + while ($row = $db->fetch_assoc($res)) + $objects[$row['id_tag']] = new Tag($row); + + return $objects; + } + public static function getAlbums($id_parent = 0, $offset = 0, $limit = 24, $return_format = 'array') { $rows = Registry::get('db')->queryAssocs(' diff --git a/templates/MyTagsView.php b/templates/MyTagsView.php new file mode 100644 index 0000000..2b06fd9 --- /dev/null +++ b/templates/MyTagsView.php @@ -0,0 +1,32 @@ +tags = $tags; + } + + protected function html_content() + { + echo ' +

Tags you can edit

+

You can currently edit the tags below. Click a tag to edit it.

+ '; + } +}