2020-08-12 14:36:18 +03:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
namespace openvk\VKAPI\Handlers;
|
2022-11-10 16:27:54 +03:00
|
|
|
use openvk\Web\Models\Exceptions\InvalidUserNameException;
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
|
|
final class Account extends VKAPIRequestHandler
|
|
|
|
{
|
|
|
|
function getProfileInfo(): object
|
|
|
|
{
|
|
|
|
$this->requireUser();
|
|
|
|
|
|
|
|
return (object) [
|
2022-07-21 22:13:09 +03:00
|
|
|
"first_name" => $this->getUser()->getFirstName(),
|
|
|
|
"id" => $this->getUser()->getId(),
|
|
|
|
"last_name" => $this->getUser()->getLastName(),
|
|
|
|
"home_town" => $this->getUser()->getHometown(),
|
|
|
|
"status" => $this->getUser()->getStatus(),
|
2022-10-01 13:13:50 +03:00
|
|
|
"bdate" => is_null($this->getUser()->getBirthday()) ? '01.01.1970' : $this->getUser()->getBirthday()->format('%e.%m.%Y'),
|
2022-08-11 23:20:36 +03:00
|
|
|
"bdate_visibility" => $this->getUser()->getBirthdayPrivacy(),
|
2022-07-21 22:13:09 +03:00
|
|
|
"phone" => "+420 ** *** 228", # TODO
|
|
|
|
"relation" => $this->getUser()->getMaritalStatus(),
|
|
|
|
"sex" => $this->getUser()->isFemale() ? 1 : 2
|
2020-08-12 14:36:18 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getInfo(): object
|
|
|
|
{
|
|
|
|
$this->requireUser();
|
|
|
|
|
|
|
|
return (object) [
|
2022-08-11 23:20:36 +03:00
|
|
|
"2fa_required" => $this->getUser()->is2faEnabled() ? 1 : 0,
|
2022-07-21 22:13:09 +03:00
|
|
|
"country" => "CZ", # TODO
|
|
|
|
"eu_user" => false, # TODO
|
|
|
|
"https_required" => 1,
|
|
|
|
"intro" => 0,
|
|
|
|
"community_comments" => false,
|
|
|
|
"is_live_streaming_enabled" => false,
|
2020-08-12 14:36:18 +03:00
|
|
|
"is_new_live_streaming_enabled" => false,
|
2022-07-21 22:13:09 +03:00
|
|
|
"lang" => 1,
|
|
|
|
"no_wall_replies" => 0,
|
|
|
|
"own_posts_default" => 0
|
2020-08-12 14:36:18 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-10-08 23:17:45 +03:00
|
|
|
function setOnline(): int
|
2020-08-12 14:36:18 +03:00
|
|
|
{
|
|
|
|
$this->requireUser();
|
|
|
|
|
2023-03-13 17:45:45 +03:00
|
|
|
$this->getUser()->updOnline($this->getPlatform());
|
2022-08-13 05:41:59 +03:00
|
|
|
|
2020-08-12 14:36:18 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-03-09 13:49:36 +03:00
|
|
|
function setOffline(): int
|
2020-08-12 14:36:18 +03:00
|
|
|
{
|
|
|
|
$this->requireUser();
|
|
|
|
|
2022-05-08 13:06:26 +03:00
|
|
|
# Цiй метод є заглушка
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-03-29 12:26:29 +03:00
|
|
|
function getAppPermissions(): int
|
2020-08-12 14:36:18 +03:00
|
|
|
{
|
|
|
|
return 9355263;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCounters(string $filter = ""): object
|
|
|
|
{
|
2023-05-30 11:41:03 +03:00
|
|
|
$this->requireUser();
|
|
|
|
|
2020-08-12 14:36:18 +03:00
|
|
|
return (object) [
|
2022-07-21 22:13:09 +03:00
|
|
|
"friends" => $this->getUser()->getFollowersCount(),
|
2021-01-17 01:11:04 +03:00
|
|
|
"notifications" => $this->getUser()->getNotificationsCount(),
|
2022-07-21 22:13:09 +03:00
|
|
|
"messages" => $this->getUser()->getUnreadMessagesCount()
|
2020-08-12 14:36:18 +03:00
|
|
|
];
|
|
|
|
|
2022-05-08 13:06:26 +03:00
|
|
|
# TODO: Filter
|
2020-08-12 14:36:18 +03:00
|
|
|
}
|
2022-11-10 16:27:54 +03:00
|
|
|
|
|
|
|
function saveProfileInfo(string $first_name = "", string $last_name = "", string $screen_name = "", int $sex = -1, int $relation = -1, string $bdate = "", int $bdate_visibility = -1, string $home_town = "", string $status = ""): object
|
|
|
|
{
|
|
|
|
$this->requireUser();
|
2023-02-08 14:20:50 +03:00
|
|
|
$this->willExecuteWriteAction();
|
|
|
|
|
2022-11-10 16:27:54 +03:00
|
|
|
$user = $this->getUser();
|
|
|
|
|
|
|
|
$output = [
|
|
|
|
"changed" => 0,
|
|
|
|
];
|
|
|
|
|
|
|
|
if(!empty($first_name) || !empty($last_name)) {
|
|
|
|
$output["name_request"] = [
|
|
|
|
"id" => random_int(1, 2048), # For compatibility with original VK API
|
|
|
|
"status" => "success",
|
|
|
|
"first_name" => !empty($first_name) ? $first_name : $user->getFirstName(),
|
|
|
|
"last_name" => !empty($last_name) ? $last_name : $user->getLastName(),
|
|
|
|
];
|
|
|
|
|
|
|
|
try {
|
|
|
|
if(!empty($first_name))
|
|
|
|
$user->setFirst_name($first_name);
|
|
|
|
if(!empty($last_name))
|
|
|
|
$user->setLast_Name($last_name);
|
|
|
|
} catch (InvalidUserNameException $e) {
|
|
|
|
$output["name_request"]["status"] = "declined";
|
|
|
|
return (object) $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!empty($screen_name))
|
|
|
|
if (!$user->setShortCode($screen_name))
|
|
|
|
$this->fail(1260, "Invalid screen name");
|
|
|
|
|
|
|
|
# For compatibility with original VK API
|
|
|
|
if($sex > 0)
|
|
|
|
$user->setSex($sex == 1 ? 1 : 0);
|
|
|
|
|
|
|
|
if($relation > -1)
|
|
|
|
$user->setMarital_Status($relation);
|
|
|
|
|
|
|
|
if(!empty($bdate)) {
|
|
|
|
$birthday = strtotime($bdate);
|
|
|
|
if (!is_int($birthday))
|
|
|
|
$this->fail(100, "invalid value of bdate.");
|
|
|
|
|
|
|
|
$user->setBirthday($birthday);
|
|
|
|
}
|
|
|
|
|
|
|
|
# For compatibility with original VK API
|
|
|
|
switch($bdate_visibility) {
|
|
|
|
case 0:
|
|
|
|
$this->fail(946, "Hiding date of birth is not implemented.");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
$user->setBirthday_privacy(0);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$user->setBirthday_privacy(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!empty($home_town))
|
|
|
|
$user->setHometown($home_town);
|
|
|
|
|
|
|
|
if(!empty($status))
|
|
|
|
$user->setStatus($status);
|
|
|
|
|
|
|
|
if($sex > 0 || $relation > -1 || $bdate_visibility > 1 || !empty("$first_name$last_name$screen_name$bdate$home_town$status")) {
|
|
|
|
$output["changed"] = 1;
|
|
|
|
$user->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (object) $output;
|
|
|
|
}
|
2020-08-12 14:36:18 +03:00
|
|
|
}
|