From 94e2f440bea4ac929d2048fffe9fe039409e0460 Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Thu, 19 Dec 2024 21:48:35 +0300 Subject: [PATCH] add gui 4 dis --- .../UserInfoEntities/AdditionalField.php | 32 +++++----- Web/Presenters/UserPresenter.php | 34 ++++++++++- Web/Presenters/templates/@layout.xml | 1 + Web/Presenters/templates/User/Edit.xml | 55 ++++++++++++++++++ Web/static/css/main.css | 22 +++++++ Web/static/js/al_wall.js | 58 +++++++++++++++++++ locales/en.strings | 20 +++++-- locales/ru.strings | 20 +++++-- 8 files changed, 215 insertions(+), 27 deletions(-) diff --git a/Web/Models/Entities/UserInfoEntities/AdditionalField.php b/Web/Models/Entities/UserInfoEntities/AdditionalField.php index b2a936df..47c69de3 100644 --- a/Web/Models/Entities/UserInfoEntities/AdditionalField.php +++ b/Web/Models/Entities/UserInfoEntities/AdditionalField.php @@ -16,14 +16,14 @@ class AdditionalField extends RowModel return (int) $this->getRecord()->owner; } - function getName(): string + function getName(bool $tr = true): string { $orig_name = $this->getRecord()->name; $name = $orig_name; - if($name[0] === "_") - $name = tr("custom_fav_" . substr($name, 1)); + if($tr && $name[0] === "_") + $name = tr("custom_field_" . substr($name, 1)); - if(str_contains($name, "custom_fav")) + if(str_contains($name, "custom_field")) return $orig_name; return $name; @@ -46,6 +46,11 @@ class AdditionalField extends RowModel return "contact"; } + function isContact(): bool + { + return $this->getRecord()->place == AdditionalField::PLACE_CONTACTS; + } + function toVkApiStruct(): object { return (object) [ @@ -58,9 +63,7 @@ class AdditionalField extends RowModel static function getById(int $id) { $ctx = DatabaseConnection::i()->getContext(); - $entry = $ctx->table("additional_fields")->where([ - "id" => $id, - ])->fetch(); + $entry = $ctx->table("additional_fields")->where("id", $id)->fetch(); if(!$entry) return NULL; @@ -71,9 +74,7 @@ class AdditionalField extends RowModel static function getByOwner(int $owner): \Traversable { $ctx = DatabaseConnection::i()->getContext(); - $entries = $ctx->table("additional_fields")->where([ - "owner" => $owner, - ]); + $entries = $ctx->table("additional_fields")->where("owner", $owner); foreach($entries as $entry) { yield new AdditionalField($entry); @@ -82,8 +83,13 @@ class AdditionalField extends RowModel static function getCountByOwner(int $owner): \Traversable { - return DatabaseConnection::i()->getContext()->table("additional_fields")->where([ - "owner" => $owner, - ])->count(); + return DatabaseConnection::i()->getContext()->table("additional_fields")->where("owner", $owner)->count(); + } + + static function resetByOwner(int $owner): bool + { + DatabaseConnection::i()->getContext()->table("additional_fields")->where("owner", $owner)->delete(); + + return true; } } diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 3d070b1c..41c2db1e 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -297,10 +297,40 @@ final class UserPresenter extends OpenVKPresenter $this->returnJson([ "success" => true ]); + } elseif($_GET['act'] === "additional") { + $maxAddFields = ovkGetQuirk("users.max-fields"); + $items = []; + + for($i = 0; $i < $maxAddFields; $i++) { + if(!$this->postParam("name_".$i)) { + continue; + } + + $items[] = [ + "name" => $this->postParam("name_".$i), + "text" => $this->postParam("text_".$i), + "place" => $this->postParam("place_".$i), + ]; + } + + \openvk\Web\Models\Entities\UserInfoEntities\AdditionalField::resetByOwner($this->user->id); + foreach($items as $new_field_info) { + $place = (int)($new_field_info["place"]); + + $new_field = new \openvk\Web\Models\Entities\UserInfoEntities\AdditionalField; + $new_field->setOwner($this->user->id); + $new_field->setName(ovk_proc_strtr($new_field_info["name"], 50)); + $new_field->setText(ovk_proc_strtr($new_field_info["text"], 1000)); + $new_field->setPlace([0, 1][$place] ? $place : 0); + + $new_field->save(); + } } try { - $user->save(); + if($_GET['act'] !== "additional") { + $user->save(); + } } catch(\PDOException $ex) { if($ex->getCode() == 23000) $this->flashFail("err", tr("error"), tr("error_shorturl")); @@ -312,7 +342,7 @@ final class UserPresenter extends OpenVKPresenter } $this->template->mode = in_array($this->queryParam("act"), [ - "main", "contacts", "interests", "avatar", "backdrop" + "main", "contacts", "interests", "avatar", "backdrop", "additional" ]) ? $this->queryParam("act") : "main"; diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 811548cd..3990c741 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -452,6 +452,7 @@ "max_filesize_mb": 5, "current_id": {$thisUser ? $thisUser->getId() : 0}, "disable_ajax": {$disable_ajax ? $disable_ajax : 0}, + "max_add_fields": {ovkGetQuirk("users.max-fields")}, } diff --git a/Web/Presenters/templates/User/Edit.xml b/Web/Presenters/templates/User/Edit.xml index b0eea51f..163ea6a2 100644 --- a/Web/Presenters/templates/User/Edit.xml +++ b/Web/Presenters/templates/User/Edit.xml @@ -13,6 +13,7 @@ {var $isMain = $mode === 'main'} {var $isContacts = $mode === 'contacts'} {var $isInterests = $mode === 'interests'} + {var $isAdditional = $mode === 'additional'} {var $isAvatar = $mode === 'avatar'} {var $isBackDrop = $mode === 'backdrop'} @@ -31,6 +32,9 @@
+{tr("additional_fields_description", ovkGetQuirk("users.max-fields"))}
+ {/if} diff --git a/Web/static/css/main.css b/Web/static/css/main.css index 928ef300..677ea4fc 100644 --- a/Web/static/css/main.css +++ b/Web/static/css/main.css @@ -506,6 +506,28 @@ table { text-align: left; } +.outline_table td { + text-align: right; + font-weight: normal; + color: gray; +} + +.outline_table { + border-bottom: 1px solid #cbcbcb; + padding: 5px 0px; +} + +.outline_table:last-of-type { + border-bottom: unset; +} + +.flex_column_center_gap5px { + display: flex; + flex-direction: column; + align-items: center; + gap: 5px; +} + .information { padding: 9px; background-color: #c3e4ff; diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index 58ba9437..6b1cfb35 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -2887,3 +2887,61 @@ u(document).on('click', '#_bl_toggler', async (e) => { } } }) + +/* Additional fields */ + +u(document).on("click", "#additional_field_append", (e) => { + let iterator = 0 + if(u(`table[data-iterator]`).last()) { + iterator = Number(u(`table[data-iterator]`).last().dataset.iterator) + 1 + } + + if(iterator >= window.openvk.max_add_fields) { + return + } + + u('.edit_field_container_inserts').append(` +${tr("additional_field_name")} | ++ | + |
${tr("additional_field_text")} | ++ | |
${tr("additional_field_place")} | ++ + | + |