1
0
forked from mirzaev/pot-php

fixed by garden/campanula

This commit is contained in:
2026-01-07 14:57:15 +05:00
parent 190ef8eabd
commit a0ca54bf25
7 changed files with 102 additions and 89 deletions

View File

@@ -7,11 +7,7 @@ namespace ${REPO_OWNER}\${REPO_NAME}\models;
// Files of the project
use ${REPO_OWNER}\${REPO_NAME}\models\core,
${REPO_OWNER}\${REPO_NAME}\models\authorizations,
${REPO_OWNER}\${REPO_NAME}\models\chat,
${REPO_OWNER}\${REPO_NAME}\models\settings,
${REPO_OWNER}\${REPO_NAME}\models\tariff,
${REPO_OWNER}\${REPO_NAME}\models\code,
${REPO_OWNER}\${REPO_NAME}\models\enumerations\tariff as tariff_type;
${REPO_OWNER}\${REPO_NAME}\models\settings;
// The library for languages support
use mirzaev\languages\language;
@@ -84,6 +80,7 @@ final class account extends core implements record_interface
new column('language', type::string, ['length' => 2]),
new column('robot', type::char),
/* new column('', type::), */
new column('active', type::char),
new column('updated', type::integer_unsigned),
new column('created', type::integer_unsigned)
)
@@ -115,8 +112,7 @@ final class account extends core implements record_interface
if (
$$account->domain !== (string) $$telegram->getUsername() ||
$$account->name_first !== (string) $$telegram->getFirstName() ||
$$account->name_second !== (string) $$telegram->getLastName() ||
$$account->language !== (string) $$telegram->getLanguageCode()
$$account->name_second !== (string) $$telegram->getLastName()
) {
// The telegram account was updated
@@ -128,7 +124,6 @@ final class account extends core implements record_interface
$$record->domain = (string) $$telegram->getUsername();
$$record->name_first = (string) $$telegram->getFirstName();
$$record->name_second = (string) $$telegram->getLastName();
$$record->language = (string) $$telegram->getLanguageCode();
$$record->updated = svoboda::timestamp();
},
amount: 1
@@ -211,7 +206,7 @@ final class account extends core implements record_interface
$$record = $$this->write(
telegram_identifier: (int) $$telegram->getId(),
name_first: (string) $$telegram->getFirstName(),
name_last: (string) $$telegram->getLastName(),
name_second: (string) $$telegram->getLastName(),
domain: (string) $$telegram->getUsername(),
language: (string) $$telegram->getLanguageCode(),
robot: (bool) $$telegram->isBot()
@@ -232,18 +227,6 @@ final class account extends core implements record_interface
// Creating the account settings
$$settings->write(account: $$record->identifier);
// Initializing the chat model
$$chat = new chat();
// Creating the account chat
$$record->chat = $$chat->write(account: $$record->identifier, network: NETWORK_DEFAULT);
// Initializing the tariff model
$$tariff = new tariff();
// Creating the tariff record
$$record->tariff = $$tariff->write(account: $$record->identifier, invoice: 0, active: 1, type: TARIFF_DEFAULT ?? tariff_type::free);
// Writing the record into the database
$$record = $$this->database->read(
filter: fn(record $$_record) => $$_record->identifier === $$record->identifier,
@@ -264,10 +247,11 @@ final class account extends core implements record_interface
*
* @param int $$telegram_identifier The telegram account identifier
* @param string $$name_first
* @param string $$name_last
* @param string $$name_second
* @param string $$domain
* @param language|string $$language
* @param bool $$robot Is a robot?
* @param bool $$active Is the record active?
*
* @return record|false The record, if created
*/
@@ -275,9 +259,10 @@ final class account extends core implements record_interface
int $$telegram_identifier,
string $$domain = '',
string $$name_first = '',
string $$name_last = '',
string $$name_second = '',
language|string $$language = LANGUAGE_DEFAULT ?? language::en,
bool $$robot = false,
bool $$active = true,
): record|false {
// Initializing the record
$$record = $$this->database->record(
@@ -285,10 +270,11 @@ final class account extends core implements record_interface
(int) $$telegram_identifier,
$$domain,
$$name_first,
$$name_last,
$$name_second,
$$language instanceof language ? $$language->name : (string) $$language,
(int) $$robot,
/* */
(int) $$active,
svoboda::timestamp(),
svoboda::timestamp()
);
@@ -309,6 +295,8 @@ final class account extends core implements record_interface
{
// Serializing the record parameters
$$this->record->language = $$this->record->language->name;
$$this->record->robot = (int) $$this->record->robot;
$$this->record->active = (int) $$this->record->active;
// Exit (success)
return $$this;
@@ -323,6 +311,8 @@ final class account extends core implements record_interface
{
// Deserializing the record parameters
$$this->record->language = language::{$$this->record->language} ?? LANGUAGE_DEFAULT ?? language::en;
$$this->record->robot = (bool) $$this->record->robot;
$$this->record->active = (bool) $$this->record->active;
// Exit (success)
return $$this;