Add User::getMorphedName

This commit is contained in:
Celestora 2022-04-12 20:10:35 +03:00
parent 2c6fa71e20
commit f3f62a63ac
5 changed files with 193 additions and 101 deletions

View file

@ -38,6 +38,7 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/console" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php80" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/service-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/wapmorgan/morphos" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

View file

@ -39,6 +39,7 @@
<path value="$PROJECT_DIR$/vendor/symfony/console" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
<path value="$PROJECT_DIR$/vendor/symfony/service-contracts" />
<path value="$PROJECT_DIR$/vendor/wapmorgan/morphos" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.4">

View file

@ -1,5 +1,6 @@
<?php declare(strict_types=1);
namespace openvk\Web\Models\Entities;
use morphos\Gender;
use openvk\Web\Themes\{Themepack, Themepacks};
use openvk\Web\Util\DateTime;
use openvk\Web\Models\RowModel;
@ -9,6 +10,7 @@ use openvk\Web\Models\Exceptions\InvalidUserNameException;
use Nette\Database\Table\ActiveRow;
use Chandler\Database\DatabaseConnection;
use Chandler\Security\User as ChandlerUser;
use function morphos\Russian\inflectName;
class User extends RowModel
{
@ -167,12 +169,23 @@ class User extends RowModel
return $this->getFirstName() . $pseudo . $this->getLastName();
}
function getMorphedName(string $case = "genitive", bool $fullName = true): string
{
$name = $fullName ? ($this->getLastName() . " " . $this->getFirstName()) : $this->getFirstName();
if(!preg_match("%^[А-яё\-]+$%", $name))
return $name; # name is probably not russian
$inflected = inflectName($name, $case, $this->isFemale() ? Gender::FEMALE : Gender::MALE);
return $inflected ?: $name;
}
function getCanonicalName(): string
{
if($this->getRecord()->deleted)
if($this->getRecord()->deleted)
return "DELETED";
else
return $this->getFirstName() . ' ' . $this->getLastName();
else
return $this->getFirstName() . " " . $this->getLastName();
}
function getPhone(): ?string

View file

@ -16,7 +16,9 @@
"erusev/parsedown": "dev-master",
"bhaktaraz/php-rss-generator": "dev-master",
"ext-simplexml": "*",
"symfony/console": "5.4.x-dev"
"symfony/console": "5.4.x-dev",
"wapmorgan/morphos": "dev-master",
"ext-sodium": "*"
},
"minimum-stability": "dev"
}

79
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "878bd996183ccbb15637a7399ba03ab9",
"content-hash": "63feb555e36a6e7ab5a0a5ec71adecdd",
"packages": [
{
"name": "al/emoji-detector",
@ -2222,6 +2222,80 @@
},
"time": "2018-09-26T17:10:59+00:00"
},
{
"name": "wapmorgan/morphos",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/wapmorgan/Morphos.git",
"reference": "ec18034d4a439139902c769a64bb67e59e3402a8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/wapmorgan/Morphos/zipball/ec18034d4a439139902c769a64bb67e59e3402a8",
"reference": "ec18034d4a439139902c769a64bb67e59e3402a8",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
},
"suggest": {
"ext-readline": "For using interactive version of script"
},
"default-branch": true,
"type": "library",
"autoload": {
"files": [
"src/English/functions.php",
"src/Russian/functions.php"
],
"psr-4": {
"morphos\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Sergey Vanyushin",
"email": "wapmorgan@gmail.com",
"role": "developer"
}
],
"description": "A morphological solution for Russian and English language written completely in PHP. Provides classes to inflect personal names, geographical names, decline and pluralize nouns, generate cardinal and ordinal numerals, spell out money amounts and time.",
"homepage": "http://morphos.io",
"keywords": [
"Numerals",
"adjectives",
"cardinal",
"declension",
"english",
"geographical names",
"human-friendly",
"inflection",
"language",
"money",
"morphology",
"nouns",
"ordinal",
"personal names",
"pluralization",
"russian",
"spelling",
"time"
],
"support": {
"issues": "https://github.com/wapmorgan/Morphos/issues",
"source": "https://github.com/wapmorgan/Morphos/tree/master"
},
"time": "2021-11-22T09:15:18+00:00"
},
{
"name": "whichbrowser/parser",
"version": "dev-master",
@ -2356,7 +2430,8 @@
"vearutop/php-obscene-censor-rus": 20,
"erusev/parsedown": 20,
"bhaktaraz/php-rss-generator": 20,
"symfony/console": 20
"symfony/console": 20,
"wapmorgan/morphos": 20
},
"prefer-stable": false,
"prefer-lowest": false,