mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +03:00
VKAPI: new method account.saveProfileInfo (again) (#777)
This commit is contained in:
parent
559619f7c8
commit
24b2b1d7f0
1 changed files with 74 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\VKAPI\Handlers;
|
||||
use openvk\Web\Models\Exceptions\InvalidUserNameException;
|
||||
|
||||
final class Account extends VKAPIRequestHandler
|
||||
{
|
||||
|
@ -74,4 +75,77 @@ final class Account extends VKAPIRequestHandler
|
|||
|
||||
# TODO: Filter
|
||||
}
|
||||
|
||||
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();
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue