mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
add additional fields
This commit is contained in:
parent
996108289c
commit
813306f38e
10 changed files with 212 additions and 1 deletions
|
@ -296,4 +296,49 @@ final class Account extends VKAPIRequestHandler
|
|||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function saveInterestsInfo(
|
||||
string $interests = NULL,
|
||||
string $fav_music = NULL,
|
||||
string $fav_films = NULL,
|
||||
string $fav_shows = NULL,
|
||||
string $fav_books = NULL,
|
||||
string $fav_quote = NULL,
|
||||
string $fav_games = NULL,
|
||||
string $about = NULL,
|
||||
)
|
||||
{
|
||||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
|
||||
$user = $this->getUser();
|
||||
$changes = 0;
|
||||
$changes_array = [
|
||||
"interests" => $interests,
|
||||
"fav_music" => $fav_music,
|
||||
"fav_films" => $fav_films,
|
||||
"fav_books" => $fav_books,
|
||||
"fav_shows" => $fav_shows,
|
||||
"fav_quote" => $fav_quote,
|
||||
"fav_games" => $fav_games,
|
||||
"about" => $about,
|
||||
];
|
||||
|
||||
foreach($changes_array as $change_name => $change_value) {
|
||||
$set_name = "set".ucfirst($change_name);
|
||||
$get_name = "get".str_replace("Fav", "Favorite", str_replace("_", "", ucfirst($change_name)));
|
||||
if(!is_null($change_value) && $change_value !== $user->$get_name()) {
|
||||
$user->$set_name(ovk_proc_strtr($change_value, 1000));
|
||||
$changes += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if($changes > 0) {
|
||||
$user->save();
|
||||
}
|
||||
|
||||
return (object) [
|
||||
"changed" => (int)($changes > 0),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -293,6 +293,17 @@ final class Users extends VKAPIRequestHandler
|
|||
|
||||
$response[$i]->blacklisted = (int)$this->getUser()->isBlacklistedBy($usr);
|
||||
break;
|
||||
case "custom_fields":
|
||||
if(sizeof($usrs) > 1)
|
||||
break;
|
||||
|
||||
$c_fields = \openvk\Web\Models\Entities\UserInfoEntities\AdditionalField::getByOwner($usr->getId());
|
||||
$append_array = [];
|
||||
foreach($c_fields as $c_field)
|
||||
$append_array[] = $c_field->toVkApiStruct();
|
||||
|
||||
$response[$i]->custom_fields = $append_array;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -228,6 +228,11 @@ class User extends RowModel
|
|||
return $this->getRecord()->about;
|
||||
}
|
||||
|
||||
function getAbout(): ?string
|
||||
{
|
||||
return $this->getRecord()->about;
|
||||
}
|
||||
|
||||
function getStatus(): ?string
|
||||
{
|
||||
return $this->getRecord()->status;
|
||||
|
@ -430,6 +435,30 @@ class User extends RowModel
|
|||
return $this->getRecord()->address;
|
||||
}
|
||||
|
||||
function getAdditionalFields(bool $split = false): array
|
||||
{
|
||||
$all = \openvk\Web\Models\Entities\UserInfoEntities\AdditionalField::getByOwner($this->getId());
|
||||
$result = [
|
||||
"interests" => [],
|
||||
"contacts" => [],
|
||||
];
|
||||
|
||||
if($split) {
|
||||
foreach($all as $field) {
|
||||
if($field->getPlace() == "contact")
|
||||
$result["contacts"][] = $field;
|
||||
else if($field->getPlace() == "interest")
|
||||
$result["interests"][] = $field;
|
||||
}
|
||||
} else {
|
||||
$result = [];
|
||||
foreach($all as $field)
|
||||
$result[] = $field;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getNotificationOffset(): int
|
||||
{
|
||||
return $this->getRecord()->notification_offset;
|
||||
|
|
89
Web/Models/Entities/UserInfoEntities/AdditionalField.php
Normal file
89
Web/Models/Entities/UserInfoEntities/AdditionalField.php
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\Web\Models\Entities\UserInfoEntities;
|
||||
use openvk\Web\Models\RowModel;
|
||||
use openvk\Web\Models\Repositories\Users;
|
||||
use Chandler\Database\DatabaseConnection;
|
||||
|
||||
class AdditionalField extends RowModel
|
||||
{
|
||||
protected $tableName = "additional_fields";
|
||||
|
||||
const PLACE_CONTACTS = 0;
|
||||
const PLACE_INTERESTS = 1;
|
||||
|
||||
function getOwner(): int
|
||||
{
|
||||
return (int) $this->getRecord()->owner;
|
||||
}
|
||||
|
||||
function getName(): string
|
||||
{
|
||||
$orig_name = $this->getRecord()->name;
|
||||
$name = $orig_name;
|
||||
if($name[0] === "_")
|
||||
$name = tr("custom_fav_" . substr($name, 1));
|
||||
|
||||
if(str_contains($name, "custom_fav"))
|
||||
return $orig_name;
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
function getContent(): string
|
||||
{
|
||||
return $this->getRecord()->text;
|
||||
}
|
||||
|
||||
function getPlace(): string
|
||||
{
|
||||
switch($this->getRecord()->place) {
|
||||
case AdditionalField::PLACE_CONTACTS:
|
||||
return "contact";
|
||||
case AdditionalField::PLACE_INTERESTS:
|
||||
return "interest";
|
||||
}
|
||||
|
||||
return "contact";
|
||||
}
|
||||
|
||||
function toVkApiStruct(): object
|
||||
{
|
||||
return (object) [
|
||||
"type" => $this->getRecord()->place,
|
||||
"name" => $this->getName(),
|
||||
"text" => $this->getContent()
|
||||
];
|
||||
}
|
||||
|
||||
static function getById(int $id)
|
||||
{
|
||||
$ctx = DatabaseConnection::i()->getContext();
|
||||
$entry = $ctx->table("additional_fields")->where([
|
||||
"id" => $id,
|
||||
])->fetch();
|
||||
|
||||
if(!$entry)
|
||||
return NULL;
|
||||
|
||||
return new AdditionalField($entry);
|
||||
}
|
||||
|
||||
static function getByOwner(int $owner): \Traversable
|
||||
{
|
||||
$ctx = DatabaseConnection::i()->getContext();
|
||||
$entries = $ctx->table("additional_fields")->where([
|
||||
"owner" => $owner,
|
||||
]);
|
||||
|
||||
foreach($entries as $entry) {
|
||||
yield new AdditionalField($entry);
|
||||
}
|
||||
}
|
||||
|
||||
static function getCountByOwner(int $owner): \Traversable
|
||||
{
|
||||
return DatabaseConnection::i()->getContext()->table("additional_fields")->where([
|
||||
"owner" => $owner,
|
||||
])->count();
|
||||
}
|
||||
}
|
|
@ -64,6 +64,7 @@ final class UserPresenter extends OpenVKPresenter
|
|||
$this->template->audios = (new Audios)->getRandomThreeAudiosByEntityId($user->getId());
|
||||
$this->template->audiosCount = (new Audios)->getUserCollectionSize($user);
|
||||
$this->template->audioStatus = $user->getCurrentAudioStatus();
|
||||
$this->template->additionalFields = $user->getAdditionalFields(true);
|
||||
|
||||
$this->template->user = $user;
|
||||
|
||||
|
|
|
@ -506,6 +506,12 @@
|
|||
<td class="label"><span class="nobold">{_address}:</span></td>
|
||||
<td class="data">{$user->getPhysicalAddress()}</td>
|
||||
</tr>
|
||||
{if $additionalFields}
|
||||
<tr n:foreach="$additionalFields['contacts'] as $field">
|
||||
<td class="label"><span class="nobold">{$field->getName()}:</span></td>
|
||||
<td class="data">{$field->getContent()}</td>
|
||||
</tr>
|
||||
{/if}
|
||||
</tbody>
|
||||
</table>
|
||||
{/capture}
|
||||
|
@ -571,6 +577,12 @@
|
|||
<td class="label"><span class="nobold">{_favorite_games}: </span></td>
|
||||
<td class="data">{$user->getFavoriteGames()}</td>
|
||||
</tr>
|
||||
{if $additionalFields}
|
||||
<tr n:foreach="$additionalFields['interests'] as $field">
|
||||
<td class="label"><span class="nobold">{$field->getName()}:</span></td>
|
||||
<td class="data">{$field->getContent()}</td>
|
||||
</tr>
|
||||
{/if}
|
||||
<tr n:if="!is_null($user->getDescription())">
|
||||
<td class="label"><span class="nobold">{_information_about}: </span></td>
|
||||
<td class="data">{$user->getDescription()}</td>
|
||||
|
|
|
@ -1 +1,10 @@
|
|||
ALTER TABLE `profiles` ADD `fav_games` MEDIUMTEXT NULL DEFAULT NULL AFTER `fav_quote`;
|
||||
CREATE TABLE `additional_fields` (
|
||||
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
|
||||
`owner` BIGINT(20) UNSIGNED NOT NULL,
|
||||
`name` VARCHAR(255) COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`text` MEDIUMTEXT COLLATE utf8mb4_unicode_520_ci NOT NULL,
|
||||
`place` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = InnoDB;
|
||||
ALTER TABLE `additional_fields` ADD INDEX(`owner`);
|
||||
|
|
|
@ -153,6 +153,13 @@
|
|||
"favorite_books" = "Favorite books";
|
||||
"favorite_quotes" = "Favorite quotes";
|
||||
"favorite_games" = "Favorite games";
|
||||
"custom_fav_favorite_performers" = "Favourite performers";
|
||||
"custom_fav_favorite_content_makers" = "Favourite content-makers";
|
||||
"custom_fav_favorite_anime" = "Favourite anime";
|
||||
"custom_fav_favorite_manga" = "Favourite manga";
|
||||
"custom_fav_favorite_vtubers" = "Favourite vtubers";
|
||||
"custom_fav_favorite_albums" = "Favourite music albums";
|
||||
|
||||
"information_about" = "About";
|
||||
|
||||
"updated_at" = "Updated at $1";
|
||||
|
|
|
@ -137,6 +137,13 @@
|
|||
"favorite_books" = "Любимые книги";
|
||||
"favorite_quotes" = "Любимые цитаты";
|
||||
"favorite_games" = "Любимые игры";
|
||||
"custom_fav_favorite_performers" = "Любимые исполнители";
|
||||
"custom_fav_favorite_content_makers" = "Любимые контент-мейкеры";
|
||||
"custom_fav_favorite_anime" = "Любимые аниме";
|
||||
"custom_fav_favorite_manga" = "Любимая манга";
|
||||
"custom_fav_favorite_vtubers" = "Любимые витуберы";
|
||||
"custom_fav_favorite_albums" = "Любимые альбомы";
|
||||
|
||||
"information_about" = "О себе";
|
||||
"updated_at" = "Обновлено $1";
|
||||
"user_banned" = "К сожалению, нам пришлось заблокировать страницу пользователя <b>$1</b>.";
|
||||
|
|
|
@ -46,3 +46,4 @@ comments.allow-graffiti: 0
|
|||
wall.repost-liking-recursion-limit: 10
|
||||
|
||||
polls.max-opts: 10
|
||||
users.max-fields: 7
|
||||
|
|
Loading…
Reference in a new issue