Users: Improve the birthday field

Now you can hide the year of birth. Also people who were born on January 1, 1970 can specify their date of birth
This commit is contained in:
Maxim Leshchenko 2022-07-09 15:33:55 +01:00
parent e9cc9286ff
commit 5b5d095121
No known key found for this signature in database
GPG key ID: BB9C44A8733FBEEE
9 changed files with 34 additions and 10 deletions

View file

@ -364,9 +364,17 @@ class User extends RowModel
function getBirthday(): ?DateTime
{
if(is_null($this->getRecord()->birthday))
return NULL;
else
return new DateTime($this->getRecord()->birthday);
}
function getBirthdayPrivacy(): int
{
return $this->getRecord()->birthday_privacy;
}
function getAge(): ?int
{
return (int)floor((time() - $this->getBirthday()->timestamp()) / YEAR);

View file

@ -97,7 +97,7 @@ final class AuthPresenter extends OpenVKPresenter
$user->setEmail($this->postParam("email"));
$user->setSince(date("Y-m-d H:i:s"));
$user->setRegistering_Ip(CONNECTING_IP);
$user->setBirthday(strtotime($this->postParam("birthday")));
$user->setBirthday(empty($this->postParam("birthday")) ? NULL : strtotime($this->postParam("birthday")));
$user->setActivated((int)!OPENVK_ROOT_CONF['openvk']['preferences']['security']['requireEmail']);
} catch(InvalidUserNameException $ex) {
$this->flashFail("err", tr("error"), tr("invalid_real_name"));

View file

@ -157,7 +157,10 @@ final class UserPresenter extends OpenVKPresenter
if (strtotime($this->postParam("birthday")) < time())
$user->setBirthday(strtotime($this->postParam("birthday")));
$user->setBirthday(empty($this->postParam("birthday")) ? NULL : strtotime($this->postParam("birthday")));
if ($this->postParam("birthday_privacy") <= 1 && $this->postParam("birthday_privacy") >= 0)
$user->setBirthday_Privacy($this->postParam("birthday_privacy"));
if ($this->postParam("marialstatus") <= 8 && $this->postParam("marialstatus") >= 0)
$user->setMarital_Status($this->postParam("marialstatus"));

View file

@ -145,7 +145,11 @@
<span class="nobold">{_"birth_date"}: </span>
</td>
<td>
<input max={date('Y-m-d')} name="birthday" value={$user->getBirthday()->format('%Y-%m-%d')} type="date"/>
<input max={date('Y-m-d')} name="birthday" value={is_null($user->getBirthday()) ? NULL : $user->getBirthday()->format('%Y-%m-%d')} type="date" style="margin-bottom: 7px;" />
<select name="birthday_privacy">
<option value="0" {if $user->getBirthdayPrivacy() == 0}selected{/if}>{_show_my_birthday}</option>
<option value="1" {if $user->getBirthdayPrivacy() == 1}selected{/if}>{_show_only_month_and_day}</option>
</select>
</td>
</tr>
<tr>

View file

@ -372,13 +372,12 @@
<td class="label"><span class="nobold">{_"politViews"}:</span></td>
<td class="data">{var $pviews = $user->getPoliticalViews()}{_"politViews_$pviews"}</td>
</tr>
{if $user->getBirthday()->timestamp() > 0}
<tr>
<tr n:if="!is_null($user->getBirthday())">
<td class="label"><span class="nobold">{_"birth_date"}:</span></td>
<td class="data">{$user->getBirthday()->format('%e %B %Y')},
<td n:if="$user->getBirthdayPrivacy() == 0" class="data">{$user->getBirthday()->format('%e %B %Y')},
{tr("years", $user->getAge())}</td>
<td n:if="$user->getBirthdayPrivacy() == 1" class="data">{$user->getBirthday()->format('%e %B')}</td>
</tr>
{/if}
</tbody>
</table>
</div>

View file

@ -569,6 +569,7 @@ input[type~="email"],
input[type~="phone"],
input[type="search"],
input[type~="search"],
input[type~="date"],
select {
border: 1px solid #C0CAD5;
padding: 3px;

View file

@ -0,0 +1,3 @@
ALTER TABLE `profiles` ADD COLUMN `birthday_privacy` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0;
UPDATE `profiles` SET `birthday_privacy` = 2 WHERE `birthday` = 0;
UPDATE `profiles` SET `birthday` = NULL WHERE `birthday` = 0;

View file

@ -90,6 +90,9 @@
"years_one" = "1 year old";
"years_other" = "$1 years old";
"show_my_birthday" = "Show my birthday";
"show_only_month_and_day" = "Show only month and day";
"relationship" = "Relationship";
"relationship_0" = "Not selected";

View file

@ -91,6 +91,9 @@
"years_many" = "$1 лет";
"years_other" = "$1 лет";
"show_my_birthday" = "Показывать дату рождения";
"show_only_month_and_day" = "Показывать только день и месяц";
"relationship" = "Семейное положение";
"relationship_0" = "Не выбрано";