diff --git a/VKAPI/Handlers/Users.php b/VKAPI/Handlers/Users.php index b09e82a55..a65dada83 100644 --- a/VKAPI/Handlers/Users.php +++ b/VKAPI/Handlers/Users.php @@ -377,6 +377,17 @@ public function get(string $user_ids = "0", string $fields = "", int $offset = 0 $response[$i]->bdate = null; } break; + case 'personal': + $response[$i]->personal = (object) [ + 'political' => $usr->getPoliticalViews(), + 'langs' => [], // FIXME: not implemented + 'inspired_by' => $usr->getInspires(), + 'people_main' => $usr->getMainInPeople(), + 'life_main' => $usr->getMainInLife(), + 'smoking' => $usr->getViewsOnSmoking(), + 'alcohol' => $usr->getViewsOnAlcohol(), + ]; + break; } } diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 819efdd40..d39bc26c9 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -42,6 +42,14 @@ class User extends RowModel public const NSFW_TOLERANT = 1; public const NSFW_FULL_TOLERANT = 2; + + public const PREFERENCES_COUNTS = [ + 'politViews' => 10, + 'mainInLife' => 9, + 'mainInPeople' => 7, + 'viewsOnSubstances' => 6, + ]; + /* aggressive caching */ private $_avatarAlbum = null; private $_avatarPhoto = false; // false - not resolved, null - no avatar @@ -414,6 +422,36 @@ public function getPoliticalViews(): int return $this->getRecord()->polit_views; } + public function getWorldview(): string + { + return $this->getRecord()->worldview; + } + + public function getMainInLife(): int + { + return $this->getRecord()->main_in_life; + } + + public function getMainInPeople(): int + { + return $this->getRecord()->main_in_people; + } + + public function getViewsOnSmoking(): int + { + return $this->getRecord()->views_on_smoking; + } + + public function getViewsOnAlcohol(): int + { + return $this->getRecord()->views_on_alcohol; + } + + public function getInspires(): string + { + return $this->getRecord()->inspires; + } + public function getMaritalStatus(): int { return $this->getRecord()->marital_status; @@ -530,6 +568,60 @@ public function getAdditionalFields(bool $split = false): array return $result; } + public function getPersonalInfo() + { + $info = []; + if ($this->getPoliticalViews() > 0) { + $info[] = [ + 'label' => tr('politViews'), + 'value' => tr('politViews_' . $this->getPoliticalViews()), + ]; + } + if ($this->getWorldview() != '') { + $info[] = [ + 'label' => tr('worldview'), + 'value' => $this->getWorldview(), + ]; + } + + if ($this->getMainInLife() > 0) { + $info[] = [ + 'label' => tr('mainInLife'), + 'value' => tr('mainInLife_' . $this->getMainInLife()), + ]; + } + + if ($this->getMainInPeople() > 0) { + $info[] = [ + 'label' => tr('mainInPeople'), + 'value' => tr('mainInPeople_' . $this->getMainInPeople()), + ]; + } + + if ($this->getViewsOnSmoking() > 0) { + $info[] = [ + 'label' => tr('viewsOnSmoking'), + 'value' => tr('viewsOnSubstances_' . $this->getViewsOnSmoking()), + ]; + } + + if ($this->getViewsOnAlcohol() > 0) { + $info[] = [ + 'label' => tr('viewsOnAlcohol'), + 'value' => tr('viewsOnSubstances_' . $this->getViewsOnAlcohol()), + ]; + } + + if ($this->getInspires() != '') { + $info[] = [ + 'label' => tr('inspires'), + 'value' => $this->getInspires(), + ]; + } + + return $info; + } + public function getNotificationOffset(): int { return $this->getRecord()->notification_offset; diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 4a7e759df..3c4149afa 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -7,7 +7,7 @@ use Nette\InvalidStateException; use openvk\Web\Util\Sms; use openvk\Web\Themes\Themepacks; -use openvk\Web\Models\Entities\{Photo, Post, EmailChangeVerification}; +use openvk\Web\Models\Entities\{Photo, Post, EmailChangeVerification, User}; use openvk\Web\Models\Entities\Notifications\{CoinsTransferNotification, RatingUpNotification}; use openvk\Web\Models\Repositories\{Users, Clubs, Albums, Videos, Notes, Vouchers, EmailChangeVerifications, Audios, Faves}; use openvk\Web\Models\Exceptions\InvalidUserNameException; @@ -195,11 +195,20 @@ public function renderEdit(): void $this->notFound(); } + + + $act = in_array($this->queryParam("act"), [ + "main", "contacts", "interests", "avatar", "backdrop", "additional", "personal", + ]) ? $this->queryParam("act") + : "main"; + + $this->template->mode = $act; + $user = $this->users->get($id); if ($_SERVER["REQUEST_METHOD"] === "POST") { $this->willExecuteWriteAction($_GET['act'] === "status"); - if ($_GET['act'] === "main" || $_GET['act'] == null) { + if ($act === "main" || $act == null) { try { $user->setFirst_Name(empty($this->postParam("first_name")) ? $user->getFirstName() : $this->postParam("first_name")); $user->setLast_Name(empty($this->postParam("last_name")) ? "" : $this->postParam("last_name")); @@ -239,10 +248,6 @@ public function renderEdit(): void } } - if ($this->postParam("politViews") <= 9 && $this->postParam("politViews") >= 0) { - $user->setPolit_Views($this->postParam("politViews")); - } - if ($this->postParam("pronouns") <= 2 && $this->postParam("pronouns") >= 0) { switch ($this->postParam("pronouns")) { case '0': @@ -269,7 +274,26 @@ public function renderEdit(): void $this->flashFail("err", tr("error_segmentation"), "котлетки: Remote err!"); } } - } elseif ($_GET['act'] === "contacts") { + } elseif ($act === "personal") { + + if ($this->postParam("politViews") < User::PREFERENCES_COUNTS['politViews'] && $this->postParam("politViews") >= 0) { + $user->setPolit_Views($this->postParam("politViews")); + } + $user->setWorldview(mb_substr($this->postParam("worldview") ?? "", 0, 256)); + if ($this->postParam("mainInLife") < User::PREFERENCES_COUNTS['mainInLife'] && $this->postParam("mainInLife") >= 0) { + $user->setMain_In_Life($this->postParam("mainInLife")); + } + if ($this->postParam("mainInPeople") < User::PREFERENCES_COUNTS['mainInPeople'] && $this->postParam("mainInPeople") >= 0) { + $user->setMain_In_People($this->postParam("mainInPeople")); + } + if ($this->postParam("viewsOnSmoking") < User::PREFERENCES_COUNTS['viewsOnSubstances'] && $this->postParam("viewsOnSmoking") >= 0) { + $user->setViews_On_Smoking($this->postParam("viewsOnSmoking")); + } + if ($this->postParam("viewsOnAlcohol") < User::PREFERENCES_COUNTS['viewsOnSubstances'] && $this->postParam("viewsOnAlcohol") >= 0) { + $user->setViews_On_Alcohol($this->postParam("viewsOnAlcohol")); + } + $user->setInspires(mb_substr($this->postParam("inspires") ?? "", 0, 256)); + } elseif ($act === "contacts") { if (empty($this->postParam("email_contact")) || Validator::i()->emailValid($this->postParam("email_contact"))) { $user->setEmail_Contact(empty($this->postParam("email_contact")) ? null : $this->postParam("email_contact")); } else { @@ -296,7 +320,7 @@ public function renderEdit(): void } else { $user->setWebsite((!parse_url($website, PHP_URL_SCHEME) ? "https://" : "") . $website); } - } elseif ($_GET['act'] === "interests") { + } elseif ($act === "interests") { $user->setInterests(empty($this->postParam("interests")) ? null : ovk_proc_strtr($this->postParam("interests"), 1000)); $user->setFav_Music(empty($this->postParam("fav_music")) ? null : ovk_proc_strtr($this->postParam("fav_music"), 1000)); $user->setFav_Films(empty($this->postParam("fav_films")) ? null : ovk_proc_strtr($this->postParam("fav_films"), 1000)); @@ -332,7 +356,7 @@ public function renderEdit(): void $user->setBackDropPictures($pic1, $pic2); $user->save(); $this->flashFail("succ", tr("backdrop_succ"), tr("backdrop_succ_desc")); - } elseif ($_GET['act'] === "status") { + } elseif ($act === "status") { if (mb_strlen($this->postParam("status")) > 255) { $statusLength = (string) mb_strlen($this->postParam("status")); $this->flashFail("err", tr("error"), tr("error_status_too_long", $statusLength), null, true); @@ -345,7 +369,7 @@ public function renderEdit(): void $this->returnJson([ "success" => true, ]); - } elseif ($_GET['act'] === "additional") { + } elseif ($act === "additional") { $maxAddFields = ovkGetQuirk("users.max-fields"); $items = []; @@ -382,7 +406,7 @@ public function renderEdit(): void } try { - if ($_GET['act'] !== "additional") { + if ($act !== "additional") { $user->save(); } } catch (\PDOException $ex) { @@ -396,11 +420,6 @@ public function renderEdit(): void $this->flash("succ", tr("changes_saved"), tr("changes_saved_comment")); } - $this->template->mode = in_array($this->queryParam("act"), [ - "main", "contacts", "interests", "avatar", "backdrop", "additional", - ]) ? $this->queryParam("act") - : "main"; - $this->template->user = $user; } diff --git a/Web/Presenters/templates/User/Edit.latte b/Web/Presenters/templates/User/Edit.latte index 5b721ea36..758683ee2 100644 --- a/Web/Presenters/templates/User/Edit.latte +++ b/Web/Presenters/templates/User/Edit.latte @@ -16,6 +16,7 @@ {var $isAdditional = $mode === 'additional'} {var $isAvatar = $mode === 'avatar'} {var $isBackDrop = $mode === 'backdrop'} + {var $isPersonal = $mode === 'personal'}
+ class="name-checkmark"
+ src="/assets/packages/static/openvk/img/checkmark.png"
+ />
({_this_is_you})
-
+