Add ability to mention user in marital status (#947)

This commit is contained in:
n1rwana 2023-11-14 22:13:13 +03:00 committed by GitHub
parent 1f340e392f
commit 92435ae6a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 75 additions and 14 deletions

View file

@ -348,10 +348,11 @@ class User extends RowModel
return $this->getRecord()->marital_status;
}
function getLocalizedMaritalStatus(): string
function getLocalizedMaritalStatus(?bool $prefix = false): string
{
$status = $this->getMaritalStatus();
$string = "relationship_$status";
if ($prefix) $string .= "_prefix";
if($this->isFemale()) {
$res = tr($string . "_fem");
if($res != ("@" . $string . "_fem"))
@ -361,6 +362,17 @@ class User extends RowModel
return tr($string);
}
function getMaritalStatusUser(): ?User
{
if (!$this->getRecord()->marital_status_user) return NULL;
return (new Users)->get($this->getRecord()->marital_status_user);
}
function getMaritalStatusUserPrefix(): ?string
{
return $this->getLocalizedMaritalStatus(true);
}
function getContactEmail(): ?string
{
return $this->getRecord()->email_contact;

View file

@ -167,6 +167,19 @@ final class UserPresenter extends OpenVKPresenter
if ($this->postParam("marialstatus") <= 8 && $this->postParam("marialstatus") >= 0)
$user->setMarital_Status($this->postParam("marialstatus"));
if ($this->postParam("maritalstatus-user")) {
if (in_array((int) $this->postParam("marialstatus"), [0, 1, 8])) {
$user->setMarital_Status_User(NULL);
} else {
$mUser = (new Users)->getByAddress($this->postParam("maritalstatus-user"));
if ($mUser) {
if ($mUser->getId() !== $this->user->id) {
$user->setMarital_Status_User($mUser->getId());
}
}
}
}
if ($this->postParam("politViews") <= 9 && $this->postParam("politViews") >= 0)
$user->setPolit_Views($this->postParam("politViews"));

View file

@ -101,7 +101,7 @@
<span class="nobold">{_relationship}: </span>
</td>
<td>
<select name="marialstatus">
<select name="marialstatus" onChange="toggleMaritalStatus(this)">
<option n:foreach="range(0, 8) as $i" n:attr="selected => ($user->getMaritalStatus() == $i)" value="{$i}">
{if $user->isFemale()}
{var $str = "relationship_$i"}
@ -117,23 +117,23 @@
</select>
</td>
</tr>
<tr id="maritalstatus-user"
n:attr="style => $user->getMaritalStatusUser() || ($user->getMaritalStatus() && !in_array($user->getMaritalStatus(), [0, 1, 8])) ? '' : 'display: none;'">
<td width="120" valign="top"></td>
<td>
<input type="text" placeholder="{_page_address}" name="maritalstatus-user"
n:attr="value => $user->getMaritalStatusUser() ? $user->getMaritalStatusUser()->getId() : ''" />
</td>
</tr>
<tr>
<td width="120" valign="top">
<span class="nobold">{_politViews}: </span>
</td>
<td>
<select name="politViews">
<option value="0" {if $user->getPoliticalViews() == 0}selected{/if}>{_politViews_0}</option>
<option value="1" {if $user->getPoliticalViews() == 1}selected{/if}>{_politViews_1}</option>
<option value="2" {if $user->getPoliticalViews() == 2}selected{/if}>{_politViews_2}</option>
<option value="3" {if $user->getPoliticalViews() == 3}selected{/if}>{_politViews_3}</option>
<option value="4" {if $user->getPoliticalViews() == 4}selected{/if}>{_politViews_4}</option>
<option value="5" {if $user->getPoliticalViews() == 5}selected{/if}>{_politViews_5}</option>
<option value="6" {if $user->getPoliticalViews() == 6}selected{/if}>{_politViews_6}</option>
<option value="7" {if $user->getPoliticalViews() == 7}selected{/if}>{_politViews_7}</option>
<option value="8" {if $user->getPoliticalViews() == 8}selected{/if}>{_politViews_8}</option>
<option value="9" {if $user->getPoliticalViews() == 9}selected{/if}>{_politViews_9}</option>
<option n:foreach="range(0, 9) as $i" n:attr="selected => ($user->getPoliticalViews() == $i)" value="{$i}">
{tr("politViews_" . $i)}
</option>
</select>
</td>
</tr>
@ -178,6 +178,17 @@
</tr>
</tbody>
</table>
<script>
function toggleMaritalStatus(e) {
let elem = $("#maritalstatus-user");
$("#maritalstatus-user-select").empty();
if ([0, 1, 8].includes(Number(e.value))) {
elem.hide();
} else {
elem.show();
}
}
</script>
</form>
{elseif $isContacts}

View file

@ -456,7 +456,15 @@
</tr>
<tr>
<td class="label"><span class="nobold">{_relationship}:</span></td>
<td class="data">{$user->getLocalizedMaritalStatus()}</td>
<td class="data">
{$user->getLocalizedMaritalStatus()}
{if $user->getMaritalStatusUser()}
{$user->getMaritalStatusUserPrefix()}
<a href="{$user->getMaritalStatusUser()->getURL()}" target="_blank">
{$user->getMaritalStatusUser()->getCanonicalName()}
</a>
{/if}
</td>
</tr>
<tr>
<td class="label"><span class="nobold">{_registration_date}: </span></td>

View file

@ -0,0 +1,2 @@
ALTER TABLE `profiles`
ADD `marital_status_user` BIGINT UNSIGNED NULL DEFAULT NULL AFTER `marital_status`;

View file

@ -113,6 +113,14 @@
"relationship_7" = "Everything is complicated";
"relationship_8" = "Actively searching";
/* xd */
"relationship_2_prefix" = "with";
"relationship_3_prefix" = "with";
"relationship_4_prefix" = "with";
"relationship_5_prefix" = "with";
"relationship_6_prefix" = "with";
"relationship_7_prefix" = "with";
"politViews" = "Polit. Views";
"politViews_0" = "Not Selected";

View file

@ -103,6 +103,13 @@
"relationship_3_fem" = "Помолвлена";
"relationship_4_fem" = "Замужем";
"relationship_6_fem" = "Влюблена";
"relationship_2_prefix" = "с";
"relationship_3_prefix" = "с";
"relationship_4_prefix" = "на";
"relationship_4_prefix_fem" = "за";
"relationship_5_prefix" = "с";
"relationship_6_prefix" = "в";
"relationship_7_prefix" = "с";
"politViews" = "Полит. взгляды";
"politViews_0" = "Не выбраны";
"politViews_1" = "Индифферентные";