From a45eaca11fe19fcb8aff321049c6e8bfb3fd7974 Mon Sep 17 00:00:00 2001 From: Little Fluffy Clouds Date: Fri, 11 Jul 2025 15:45:27 +0300 Subject: [PATCH] switch tabs to spaces, editorconfig --- .editorconfig | 7 + LICENSE | 22 +- composer.json | 108 +- install.sh | 5 +- mirzaev/deeproots/system/controllers/core.php | 84 +- .../deeproots/system/controllers/index.php | 74 +- .../system/localizations/english.php | 332 +- .../system/localizations/russian.php | 332 +- mirzaev/deeproots/system/models/account.php | 18 +- mirzaev/deeproots/system/models/answer.php | 148 +- mirzaev/deeproots/system/models/core.php | 35 +- mirzaev/deeproots/system/models/question.php | 124 +- .../system/models/question/localization.php | 150 +- .../buttons/account/localization/create.php | 332 +- .../buttons/account/localization/update.php | 128 +- .../telegram/buttons/question/search.php | 1100 ++--- .../system/models/telegram/middlewares.php | 73 - .../telegram/processes/language/select.php | 204 +- .../telegram/processes/question/create.php | 164 +- .../question/localization/create.php | 2198 ++++----- .../telegram/processes/question/search.php | 4320 ++++++++--------- .../system/models/telegram/settings.php | 218 +- .../system/models/telegram/traits/escape.php | 76 +- mirzaev/deeproots/system/public/telegram.php | 2 +- mirzaev/deeproots/system/views/templater.php | 323 +- .../system/views/themes/default/aside.html | 2 +- .../system/views/themes/default/core.html | 39 +- .../system/views/themes/default/index.html | 6 +- 28 files changed, 5277 insertions(+), 5347 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4f25585 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 4 \ No newline at end of file diff --git a/LICENSE b/LICENSE index e007a57..7a3094a 100755 --- a/LICENSE +++ b/LICENSE @@ -1,11 +1,11 @@ -DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE -Version 2, December 2004 - -Copyright (C) 2004 Sam Hocevar - -Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. - -DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE -TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. You just DO WHAT THE FUCK YOU WANT TO. +DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE +Version 2, December 2004 + +Copyright (C) 2004 Sam Hocevar + +Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. + +DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/composer.json b/composer.json index 0c05d9f..b496ddb 100755 --- a/composer.json +++ b/composer.json @@ -1,56 +1,56 @@ { - "name": "mirzaev/deeproots", - "description": "", - "homepage": "https://git.svoboda.works/mirzaev/deeproots", - "type": "site", - "keywords": [ - "minimal", - "baza" - ], - "readme": "README.md", - "license": "WTFPL", - "authors": [ - { - "name": "mirzaev", - "email": "mirzaev@gmail.com", - "homepage": "https://mirzaev.page", - "role": "Programmer" - } - ], - "support": { - "wiki": "https://git.svoboda.works/mirzaev/deeproots/wiki", - "issues": "https://git.svoboda.works/mirzaev/deeproots/issues" - }, - "require": { - "php": "^8.4", - "mirzaev/minimal": "^3.4", - "mirzaev/baza": "^3.3", - "twig/twig": "^3.10", - "twig/extra-bundle": "^3.7", - "twig/intl-extra": "^3.10", - "svoboda/time": "^1.0", - "badfarm/zanzara": "^0.9.1", - "nyholm/psr7": "^1.8", - "react/filesystem": "^0.1.2", - "react/async": "^4.3" - }, - "autoload": { - "psr-4": { - "mirzaev\\deeproots\\": "mirzaev/deeproots/system" - } - }, - "autoload-dev": { - "psr-4": { - "mirzaev\\deeproots\\tests\\": "mirzaev/deeproots/tests" - } - }, - "scripts": { - "pre-update-cmd": "./install.sh" - }, - "config": { - "allow-plugins": { - "php-http/discovery": true, - "wyrihaximus/composer-update-bin-autoload-path": true - } - } + "name": "mirzaev/deeproots", + "description": "", + "homepage": "https://git.svoboda.works/mirzaev/deeproots", + "type": "site", + "keywords": [ + "minimal", + "baza" + ], + "readme": "README.md", + "license": "WTFPL", + "authors": [ + { + "name": "mirzaev", + "email": "mirzaev@gmail.com", + "homepage": "https://mirzaev.page", + "role": "Programmer" + } + ], + "support": { + "wiki": "https://git.svoboda.works/mirzaev/deeproots/wiki", + "issues": "https://git.svoboda.works/mirzaev/deeproots/issues" + }, + "require": { + "php": "^8.4", + "mirzaev/minimal": "^3.4", + "mirzaev/baza": "^3.3", + "twig/twig": "^3.10", + "twig/extra-bundle": "^3.7", + "twig/intl-extra": "^3.10", + "svoboda/time": "^1.0", + "badfarm/zanzara": "^0.9.1", + "nyholm/psr7": "^1.8", + "react/filesystem": "^0.1.2", + "react/async": "^4.3" + }, + "autoload": { + "psr-4": { + "mirzaev\\deeproots\\": "mirzaev/deeproots/system" + } + }, + "autoload-dev": { + "psr-4": { + "mirzaev\\deeproots\\tests\\": "mirzaev/deeproots/tests" + } + }, + "scripts": { + "pre-update-cmd": "./install.sh" + }, + "config": { + "allow-plugins": { + "php-http/discovery": true, + "wyrihaximus/composer-update-bin-autoload-path": true + } + } } diff --git a/install.sh b/install.sh index add8160..c7e5d68 100755 --- a/install.sh +++ b/install.sh @@ -1,10 +1,9 @@ #!/bin/bash if [ -d author/project ]; then - mv author/project author/deeproots + mv author/project author/deeproots fi if [ -d author ]; then - mv author mirzaev + mv author mirzaev fi - diff --git a/mirzaev/deeproots/system/controllers/core.php b/mirzaev/deeproots/system/controllers/core.php index 982e8f9..149724c 100755 --- a/mirzaev/deeproots/system/controllers/core.php +++ b/mirzaev/deeproots/system/controllers/core.php @@ -9,9 +9,9 @@ use mirzaev\deeproots\models\core as models; // Framework for PHP use mirzaev\minimal\core as minimal, - mirzaev\minimal\controller, - mirzaev\minimal\http\response, - mirzaev\minimal\http\enumerations\status; + mirzaev\minimal\controller, + mirzaev\minimal\http\response, + mirzaev\minimal\http\enumerations\status; /** * Controllers core @@ -29,47 +29,47 @@ use mirzaev\minimal\core as minimal, */ class core extends controller { - /** - * Language - * - * @var language $language Language - */ - protected language $language = language::en; + /** + * Language + * + * @var language $language Language + */ + protected language $language = language::en; - /** - * Response - * - * @see https://wiki.php.net/rfc/property-hooks (find a table about backed and virtual hooks) - * - * @var response $response Response - */ - protected response $response { - // Read - get => $this->response ??= $this->request->response(); - } + /** + * Response + * + * @see https://wiki.php.net/rfc/property-hooks (find a table about backed and virtual hooks) + * + * @var response $response Response + */ + protected response $response { + // Read + get => $this->response ??= $this->request->response(); + } - /** - * Errors - * - * @var array $errors Registry of errors - */ - protected array $errors = [ - ]; + /** + * Errors + * + * @var array $errors Registry of errors + */ + protected array $errors = [ + ]; - /** - * Constructor - * - * @param minimal $core Instance of the MINIMAL - * @param bool $initialize Initialize a controller? - * - * @return void - */ - public function __construct(minimal $core, bool $initialize = true) - { - // Blocking requests from CloudFlare (better to write this blocking into nginx config file) - if (isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] === 'nginx-ssl early hints') return status::bruh->label; + /** + * Constructor + * + * @param minimal $core Instance of the MINIMAL + * @param bool $initialize Initialize a controller? + * + * @return void + */ + public function __construct(minimal $core, bool $initialize = true) + { + // Blocking requests from CloudFlare (better to write this blocking into nginx config file) + if (isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] === 'nginx-ssl early hints') return status::bruh->label; - // For the extends system - parent::__construct(core: $core); - } + // For the extends system + parent::__construct(core: $core); + } } diff --git a/mirzaev/deeproots/system/controllers/index.php b/mirzaev/deeproots/system/controllers/index.php index 8cbe57d..ee60166 100755 --- a/mirzaev/deeproots/system/controllers/index.php +++ b/mirzaev/deeproots/system/controllers/index.php @@ -9,7 +9,7 @@ use mirzaev\deeproots\controllers\core; // Framework for PHP use mirzaev\minimal\http\enumerations\content, - mirzaev\minimal\http\enumerations\status; + mirzaev\minimal\http\enumerations\status; /** * Index @@ -26,46 +26,46 @@ use mirzaev\minimal\http\enumerations\content, */ final class index extends core { - /** - * Errors - * - * @var array $errors Registry of errors - */ - protected array $errors = [ - 'system' => [] - ]; + /** + * Errors + * + * @var array $errors Registry of errors + */ + protected array $errors = [ + 'system' => [] + ]; - /** - * Main page - * - * @return null - */ - public function index(): null - { - if (str_contains($this->request->headers['accept'], content::any->value)) { - // Request for any response + /** + * Main page + * + * @return null + */ + public function index(): null + { + if (str_contains($this->request->headers['accept'], content::any->value)) { + // Request for any response - // Render page - $page = $this->view->render('index.html'); + // Render page + $page = $this->view->render('index.html'); - // Sending response - $this->response - ->start() - ->clean() - ->sse() - ->write($page) - ->validate($this->request) - ?->body() - ->end(); + // Sending response + $this->response + ->start() + ->clean() + ->sse() + ->write($page) + ->validate($this->request) + ?->body() + ->end(); - // Deinitializing rendered page - unset($page); + // Deinitializing rendered page + unset($page); - // Exit (success) - return null; - } + // Exit (success) + return null; + } - // Exit (fail) - return null; - } + // Exit (fail) + return null; + } } diff --git a/mirzaev/deeproots/system/localizations/english.php b/mirzaev/deeproots/system/localizations/english.php index 578a9f8..586f41f 100644 --- a/mirzaev/deeproots/system/localizations/english.php +++ b/mirzaev/deeproots/system/localizations/english.php @@ -2,183 +2,183 @@ // Exit (success) return [ - // System - 'deeproots' => 'DeepRoots', - 'empty' => 'Empty', - 'yes' => 'Yes', - 'no' => 'No', + // System + 'deeproots' => 'DeepRoots', + 'empty' => 'Empty', + 'yes' => 'Yes', + 'no' => 'No', - // Main menu - 'menu_title' => 'Main menu', - 'menu_button_start' => 'Start', - 'menu_button_rating' => 'Rating', - 'menu_button_balance' => 'Balance', - 'menu_button_system_accounts' => 'Accounts', - 'menu_button_system_questions' => 'Questions', - 'menu_button_system_settings' => 'Settings', - 'menu_system_authorized' => 'System authorization found', + // Main menu + 'menu_title' => 'Main menu', + 'menu_button_start' => 'Start', + 'menu_button_rating' => 'Rating', + 'menu_button_balance' => 'Balance', + 'menu_button_system_accounts' => 'Accounts', + 'menu_button_system_questions' => 'Questions', + 'menu_button_system_settings' => 'Settings', + 'menu_system_authorized' => 'System authorization found', - // Account - 'account_title' => 'Account', - 'account_identifier' => 'Identifier', - 'account_authorized_system' => 'Access to the system', - 'account_authorized_game_play' => 'Access to play games', - 'account_authorized_rating_display' => 'Access to display in the rating', - 'account_authorized_balance_deposit' => 'Access to deposit into the balance', - 'account_authorized_balance_withdraw' => 'Access to withdraw from the balance', - 'account_authorized_settings' => 'Access to settings', - 'account_authorized_system_accounts' => 'System access to accounts', - 'account_authorized_system_questions' => 'System access to questions', - 'account_authorized_system_settings' => 'System access to system settings', + // Account + 'account_title' => 'Account', + 'account_identifier' => 'Identifier', + 'account_authorized_system' => 'Access to the system', + 'account_authorized_game_play' => 'Access to play games', + 'account_authorized_rating_display' => 'Access to display in the rating', + 'account_authorized_balance_deposit' => 'Access to deposit into the balance', + 'account_authorized_balance_withdraw' => 'Access to withdraw from the balance', + 'account_authorized_settings' => 'Access to settings', + 'account_authorized_system_accounts' => 'System access to accounts', + 'account_authorized_system_questions' => 'System access to questions', + 'account_authorized_system_settings' => 'System access to system settings', - // Language setting - 'settings_select_language_title' => 'Select language', - 'settings_select_language_description' => 'The selected language will be writed in your account settings', - 'settings_language_update_success' => 'Language replaced:', - 'settings_language_update_fail' => 'Failed to replace language', + // Language setting + 'settings_select_language_title' => 'Select language', + 'settings_select_language_description' => 'The selected language will be writed in your account settings', + 'settings_language_update_success' => 'Language replaced:', + 'settings_language_update_fail' => 'Failed to replace language', - // Language selection - 'select_language_title' => 'Select language', - 'select_language_description' => 'The selected language will be used in the current process', - 'select_language_button_add' => 'Add a language', + // Language selection + 'select_language_title' => 'Select language', + 'select_language_description' => 'The selected language will be used in the current process', + 'select_language_button_add' => 'Add a language', - // Repository - 'repository_title' => 'Repository', - 'repository_text' => << 'Repository', + 'repository_text' => << 'The code', - 'repository_button_issues' => 'Issues', - 'repository_button_suggestions' => 'Suggestions', + The code is under the [WTFPL](https://en.wikipedia.org/wiki/WTFPL) license + You can help me with the development, or use my code for free\! + TXT, + 'repository_button_code' => 'The code', + 'repository_button_issues' => 'Issues', + 'repository_button_suggestions' => 'Suggestions', - // Author - 'author_title' => 'Author', - 'author_text' => << 'Neurojournal', - 'author_button_projects' => 'Projects', - 'author_button_twitter' => 'Twitter', - 'author_button_bluesky' => 'Bluesky', - 'author_button_bastyon' => 'Bastyon', - 'author_button_youtube_english' => 'YouTube', - 'author_button_youtube_russian' => 'YouTube', - 'author_button_message' => 'Send a message', + // Author + 'author_title' => 'Author', + 'author_text' => << 'Neurojournal', + 'author_button_projects' => 'Projects', + 'author_button_twitter' => 'Twitter', + 'author_button_bluesky' => 'Bluesky', + 'author_button_bastyon' => 'Bastyon', + 'author_button_youtube_english' => 'YouTube', + 'author_button_youtube_russian' => 'YouTube', + 'author_button_message' => 'Send a message', - // Questions (system) - 'system_questions_title' => 'The questions registry', - 'system_questions_questions' => 'Questions', - 'system_questions_answers' => 'Answers', - 'system_questions_answers_amount_matches' => 'The amount of questions matches the amount of answers', - 'system_questions_answers_amount_different' => 'The amount of questions does not match the amount of answers', - 'system_questions_amount_matches' => 'The amount of questions matches the amount of localizations', - 'system_questions_amount_different' => 'The amount of questions does not match the amount of localizations', - 'system_questions_localizations_amount_matches' => 'Amounts of localizations matches with each other', - 'system_questions_localizations_amount_different' => 'Amounts of localizations does not match with each other', - 'system_questions_button_search' => 'Search', - 'system_questions_button_create' => 'Create', + // Questions (system) + 'system_questions_title' => 'The questions registry', + 'system_questions_questions' => 'Questions', + 'system_questions_answers' => 'Answers', + 'system_questions_answers_amount_matches' => 'The amount of questions matches the amount of answers', + 'system_questions_answers_amount_different' => 'The amount of questions does not match the amount of answers', + 'system_questions_amount_matches' => 'The amount of questions matches the amount of localizations', + 'system_questions_amount_different' => 'The amount of questions does not match the amount of localizations', + 'system_questions_localizations_amount_matches' => 'Amounts of localizations matches with each other', + 'system_questions_localizations_amount_different' => 'Amounts of localizations does not match with each other', + 'system_questions_button_search' => 'Search', + 'system_questions_button_create' => 'Create', - // Question create (system) - 'system_questions_create_created' => 'The question was created', + // Question create (system) + 'system_questions_create_created' => 'The question was created', - // Question search (system) - 'system_questions_search_title' => 'The question search process', - 'system_questions_search_continued' => 'The process of the question search found and continued', - 'system_questions_search_started' => 'The process of the question search started', - 'system_questions_search_not_started' => 'The process of the question search is not started', - 'system_questions_search_ended' => 'The process of the question search ended', - 'system_questions_search_page_next_exists' => 'There are more questions in the registry', - 'system_questions_search_page_next_not_exists' => 'There are no more questions in the registry', - 'system_questions_search_empty' => 'No questions found', - 'system_questions_search_question_title' => 'Question', - 'system_questions_search_question_answer' => 'Answer', - 'system_questions_search_identifier_request_title' => 'Enter identifier', - 'system_questions_search_identifier_request_not_acceptable' => 'Failed to process the identifier', - 'system_questions_search_identifier_request_too_short' => 'Identifier length must be \>\= 1 and \<\= 12', - 'system_questions_search_identifier_request_too_long' => 'Identifier length must be \>\= 1 and \<\= 12', - 'system_questions_search_identifier_request_restricted_characters_title' => "Restricted any characters except digits", - 'system_questions_search_identifier_request_restricted_characters_description' => "Remove these characters:", - 'system_questions_search_identifier_cancel_success' => 'Cancelled the identifier replacing process', - 'system_questions_search_identifier_delete_success' => 'Identifier deleted', - 'system_questions_search_identifier_update_success' => 'Identifier replaced:', - 'system_questions_search_identifier_update_fail' => 'Failed to replace identifier', - 'system_questions_search_text_request_title' => 'Enter text', - 'system_questions_search_text_request_not_acceptable' => 'Failed to process the text', - 'system_questions_search_text_request_too_short' => 'Text length must be \>\= 3 and \<\= 256', - 'system_questions_search_text_request_too_long' => 'Text length must be \>\= 3 and \<\= 256', - 'system_questions_search_text_cancel_success' => 'Cancelled the text replacing process', - 'system_questions_search_text_delete_success' => 'Text deleted', - 'system_questions_search_text_update_success' => 'Text replaced:', - 'system_questions_search_text_update_fail' => 'Failed to replace text', - 'system_questions_search_a_request_title' => 'Enter A\-answer', - 'system_questions_search_a_request_not_acceptable' => 'Failed to process the A\-answer', - 'system_questions_search_a_request_too_short' => 'A\-answer length must be \>\= 3 and \<\= 128', - 'system_questions_search_a_request_too_long' => 'A\-answer length must be \>\= 3 and \<\= 128', - 'system_questions_search_a_cancel_success' => 'Cancelled the A\-answer replacing process', - 'system_questions_search_a_delete_success' => 'A\-answer deleted', - 'system_questions_search_a_update_success' => 'A\-answer replaced:', - 'system_questions_search_a_update_fail' => 'Failed to replace A\-answer', - 'system_questions_search_b_request_title' => 'Enter B\-answer', - 'system_questions_search_b_request_not_acceptable' => 'Failed to process the B\-answer', - 'system_questions_search_b_request_too_short' => 'B\-answer length must be \>\= 3 and \<\= 128', - 'system_questions_search_b_request_too_long' => 'B\-answer length must be \>\= 3 and \<\= 128', - 'system_questions_search_b_cancel_success' => 'Cancelled the B\-answer replacing process', - 'system_questions_search_b_delete_success' => 'B\-answer deleted', - 'system_questions_search_b_update_success' => 'B\-answer replaced:', - 'system_questions_search_b_update_fail' => 'Failed to replace B\-answer', - 'system_questions_search_c_request_title' => 'Enter C\-answer', - 'system_questions_search_c_request_not_acceptable' => 'Failed to process the C\-answer', - 'system_questions_search_c_request_too_short' => 'C\-answer length must be \>\= 3 and \<\= 128', - 'system_questions_search_c_request_too_long' => 'C\-answer length must be \>\= 3 and \<\= 128', - 'system_questions_search_c_cancel_success' => 'Cancelled the C\-answer replacing process', - 'system_questions_search_c_delete_success' => 'C\-answer deleted', - 'system_questions_search_c_update_success' => 'C\-answer replaced:', - 'system_questions_search_c_update_fail' => 'Failed to replace C\-answer', - 'system_questions_search_d_request_title' => 'Enter D\-answer', - 'system_questions_search_d_request_not_acceptable' => 'Failed to process the D\-answer', - 'system_questions_search_d_request_too_short' => 'D\-answer length must be \>\= 3 and \<\= 128', - 'system_questions_search_d_request_too_long' => 'D\-answer length must be \>\= 3 and \<\= 128', - 'system_questions_search_d_cancel_success' => 'Cancelled the D\-answer replacing process', - 'system_questions_search_d_delete_success' => 'D\-answer deleted', - 'system_questions_search_d_update_success' => 'D\-answer replaced:', - 'system_questions_search_d_update_fail' => 'Failed to replace D\-answer', - 'system_questions_search_button_delete' => 'Delete', - 'system_questions_search_button_author' => 'Author', - 'system_questions_search_button_active' => 'Active', - 'system_questions_search_button_inactive' => 'Inactive', - 'system_questions_search_button_answer' => 'Answer', - 'system_questions_search_button_localizations' => 'Localizations', - 'system_questions_search_button_identifier' => 'Identifier', - 'system_questions_search_button_text' => 'Text', - 'system_questions_search_button_a' => 'A', - 'system_questions_search_button_b' => 'B', - 'system_questions_search_button_c' => 'C', - 'system_questions_search_button_d' => 'D', - 'system_questions_search_button_delete' => 'Delete', - 'system_questions_search_button_cancel' => 'Cancel', - 'system_questions_search_button_page_next' => 'Next page', - 'system_questions_search_button_end' => 'End the search process', - 'system_questions_search_not_localized' => 'Failed to initialize the question localization', + // Question search (system) + 'system_questions_search_title' => 'The question search process', + 'system_questions_search_continued' => 'The process of the question search found and continued', + 'system_questions_search_started' => 'The process of the question search started', + 'system_questions_search_not_started' => 'The process of the question search is not started', + 'system_questions_search_ended' => 'The process of the question search ended', + 'system_questions_search_page_next_exists' => 'There are more questions in the registry', + 'system_questions_search_page_next_not_exists' => 'There are no more questions in the registry', + 'system_questions_search_empty' => 'No questions found', + 'system_questions_search_question_title' => 'Question', + 'system_questions_search_question_answer' => 'Answer', + 'system_questions_search_identifier_request_title' => 'Enter identifier', + 'system_questions_search_identifier_request_not_acceptable' => 'Failed to process the identifier', + 'system_questions_search_identifier_request_too_short' => 'Identifier length must be \>\= 1 and \<\= 12', + 'system_questions_search_identifier_request_too_long' => 'Identifier length must be \>\= 1 and \<\= 12', + 'system_questions_search_identifier_request_restricted_characters_title' => "Restricted any characters except digits", + 'system_questions_search_identifier_request_restricted_characters_description' => "Remove these characters:", + 'system_questions_search_identifier_cancel_success' => 'Cancelled the identifier replacing process', + 'system_questions_search_identifier_delete_success' => 'Identifier deleted', + 'system_questions_search_identifier_update_success' => 'Identifier replaced:', + 'system_questions_search_identifier_update_fail' => 'Failed to replace identifier', + 'system_questions_search_text_request_title' => 'Enter text', + 'system_questions_search_text_request_not_acceptable' => 'Failed to process the text', + 'system_questions_search_text_request_too_short' => 'Text length must be \>\= 3 and \<\= 256', + 'system_questions_search_text_request_too_long' => 'Text length must be \>\= 3 and \<\= 256', + 'system_questions_search_text_cancel_success' => 'Cancelled the text replacing process', + 'system_questions_search_text_delete_success' => 'Text deleted', + 'system_questions_search_text_update_success' => 'Text replaced:', + 'system_questions_search_text_update_fail' => 'Failed to replace text', + 'system_questions_search_a_request_title' => 'Enter A\-answer', + 'system_questions_search_a_request_not_acceptable' => 'Failed to process the A\-answer', + 'system_questions_search_a_request_too_short' => 'A\-answer length must be \>\= 3 and \<\= 128', + 'system_questions_search_a_request_too_long' => 'A\-answer length must be \>\= 3 and \<\= 128', + 'system_questions_search_a_cancel_success' => 'Cancelled the A\-answer replacing process', + 'system_questions_search_a_delete_success' => 'A\-answer deleted', + 'system_questions_search_a_update_success' => 'A\-answer replaced:', + 'system_questions_search_a_update_fail' => 'Failed to replace A\-answer', + 'system_questions_search_b_request_title' => 'Enter B\-answer', + 'system_questions_search_b_request_not_acceptable' => 'Failed to process the B\-answer', + 'system_questions_search_b_request_too_short' => 'B\-answer length must be \>\= 3 and \<\= 128', + 'system_questions_search_b_request_too_long' => 'B\-answer length must be \>\= 3 and \<\= 128', + 'system_questions_search_b_cancel_success' => 'Cancelled the B\-answer replacing process', + 'system_questions_search_b_delete_success' => 'B\-answer deleted', + 'system_questions_search_b_update_success' => 'B\-answer replaced:', + 'system_questions_search_b_update_fail' => 'Failed to replace B\-answer', + 'system_questions_search_c_request_title' => 'Enter C\-answer', + 'system_questions_search_c_request_not_acceptable' => 'Failed to process the C\-answer', + 'system_questions_search_c_request_too_short' => 'C\-answer length must be \>\= 3 and \<\= 128', + 'system_questions_search_c_request_too_long' => 'C\-answer length must be \>\= 3 and \<\= 128', + 'system_questions_search_c_cancel_success' => 'Cancelled the C\-answer replacing process', + 'system_questions_search_c_delete_success' => 'C\-answer deleted', + 'system_questions_search_c_update_success' => 'C\-answer replaced:', + 'system_questions_search_c_update_fail' => 'Failed to replace C\-answer', + 'system_questions_search_d_request_title' => 'Enter D\-answer', + 'system_questions_search_d_request_not_acceptable' => 'Failed to process the D\-answer', + 'system_questions_search_d_request_too_short' => 'D\-answer length must be \>\= 3 and \<\= 128', + 'system_questions_search_d_request_too_long' => 'D\-answer length must be \>\= 3 and \<\= 128', + 'system_questions_search_d_cancel_success' => 'Cancelled the D\-answer replacing process', + 'system_questions_search_d_delete_success' => 'D\-answer deleted', + 'system_questions_search_d_update_success' => 'D\-answer replaced:', + 'system_questions_search_d_update_fail' => 'Failed to replace D\-answer', + 'system_questions_search_button_delete' => 'Delete', + 'system_questions_search_button_author' => 'Author', + 'system_questions_search_button_active' => 'Active', + 'system_questions_search_button_inactive' => 'Inactive', + 'system_questions_search_button_answer' => 'Answer', + 'system_questions_search_button_localizations' => 'Localizations', + 'system_questions_search_button_identifier' => 'Identifier', + 'system_questions_search_button_text' => 'Text', + 'system_questions_search_button_a' => 'A', + 'system_questions_search_button_b' => 'B', + 'system_questions_search_button_c' => 'C', + 'system_questions_search_button_d' => 'D', + 'system_questions_search_button_delete' => 'Delete', + 'system_questions_search_button_cancel' => 'Cancel', + 'system_questions_search_button_page_next' => 'Next page', + 'system_questions_search_button_end' => 'End the search process', + 'system_questions_search_not_localized' => 'Failed to initialize the question localization', - // Question localization create (system) - 'system_questions_localization_create_created' => 'The question localization was created', + // Question localization create (system) + 'system_questions_localization_create_created' => 'The question localization was created', - // Authorization - 'not_authorized_system' => 'You do not have access to the system', - 'not_authorized_game_play' => 'You do not have access to play games', - 'not_authorized_rating_display' => 'You do not have access to display in the rating', - 'not_authorized_balance_deposit' => 'You do not have access to deposit into the balance', - 'not_authorized_balance_withdraw' => 'You do not have access to withdraw from the balance', - 'not_authorized_settings' => 'You do not have access to the settings', - 'not_authorized_system_accounts' => 'You do not have system access to the accounts', - 'not_authorized_system_questions' => 'You do not have system access to the questions', - 'not_authorized_system_settings' => 'You do not have system access to the system settings', + // Authorization + 'not_authorized_system' => 'You do not have access to the system', + 'not_authorized_game_play' => 'You do not have access to play games', + 'not_authorized_rating_display' => 'You do not have access to display in the rating', + 'not_authorized_balance_deposit' => 'You do not have access to deposit into the balance', + 'not_authorized_balance_withdraw' => 'You do not have access to withdraw from the balance', + 'not_authorized_settings' => 'You do not have access to the settings', + 'not_authorized_system_accounts' => 'You do not have system access to the accounts', + 'not_authorized_system_questions' => 'You do not have system access to the questions', + 'not_authorized_system_settings' => 'You do not have system access to the system settings', - // Other - 'why_so_shroomious' => 'why so shroomious', + // Other + 'why_so_shroomious' => 'why so shroomious', ]; diff --git a/mirzaev/deeproots/system/localizations/russian.php b/mirzaev/deeproots/system/localizations/russian.php index 4506d7e..925c5ea 100644 --- a/mirzaev/deeproots/system/localizations/russian.php +++ b/mirzaev/deeproots/system/localizations/russian.php @@ -2,183 +2,183 @@ // Exit (success) return [ - // Система - 'deeproots' => 'DeepRoots', - 'empty' => 'Пусто', - 'yes' => 'Да', - 'no' => 'Нет', + // Система + 'deeproots' => 'DeepRoots', + 'empty' => 'Пусто', + 'yes' => 'Да', + 'no' => 'Нет', - // Главное меню - 'menu_title' => 'Главное меню', - 'menu_button_start' => 'Начать', - 'menu_button_rating' => 'Рейтинг', - 'menu_button_balance' => 'Баланс', - 'menu_button_system_accounts' => 'Аккаунты', - 'menu_button_system_questions' => 'Вопросы', - 'menu_button_system_settings' => 'Настройки', - 'menu_system_authorized' => 'Найдена системная авторизация', + // Главное меню + 'menu_title' => 'Главное меню', + 'menu_button_start' => 'Начать', + 'menu_button_rating' => 'Рейтинг', + 'menu_button_balance' => 'Баланс', + 'menu_button_system_accounts' => 'Аккаунты', + 'menu_button_system_questions' => 'Вопросы', + 'menu_button_system_settings' => 'Настройки', + 'menu_system_authorized' => 'Найдена системная авторизация', - // Аккаунт - 'account_title' => 'Аккаунт', - 'account_identifier' => 'Идентификатор', - 'account_authorized_system' => 'Доступ к системе', - 'account_authorized_game_play' => 'Доступ к играм', - 'account_authorized_rating_display' => 'Доступ к отображению в рейтинге', - 'account_authorized_balance_deposit' => 'Доступ к пополнению баланса', - 'account_authorized_balance_withdraw' => 'Доступ к выводу баланса', - 'account_authorized_settings' => 'Доступ к настроекам', - 'account_authorized_system_accounts' => 'Системный доступ к аккаунтам', - 'account_authorized_system_questions' => 'Системный доступ к вопросам', - 'account_authorized_system_settings' => 'Системный доступ к системным настройкам', + // Аккаунт + 'account_title' => 'Аккаунт', + 'account_identifier' => 'Идентификатор', + 'account_authorized_system' => 'Доступ к системе', + 'account_authorized_game_play' => 'Доступ к играм', + 'account_authorized_rating_display' => 'Доступ к отображению в рейтинге', + 'account_authorized_balance_deposit' => 'Доступ к пополнению баланса', + 'account_authorized_balance_withdraw' => 'Доступ к выводу баланса', + 'account_authorized_settings' => 'Доступ к настроекам', + 'account_authorized_system_accounts' => 'Системный доступ к аккаунтам', + 'account_authorized_system_questions' => 'Системный доступ к вопросам', + 'account_authorized_system_settings' => 'Системный доступ к системным настройкам', - // Настройки языка - 'settings_select_language_title' => 'Выбери язык', - 'settings_select_language_description' => 'Выбранный язык будет записан в настройки аккаунта', - 'settings_language_update_success' => 'Язык заменён:', - 'settings_language_update_fail' => 'Не удалось заменить язык', + // Настройки языка + 'settings_select_language_title' => 'Выбери язык', + 'settings_select_language_description' => 'Выбранный язык будет записан в настройки аккаунта', + 'settings_language_update_success' => 'Язык заменён:', + 'settings_language_update_fail' => 'Не удалось заменить язык', - // Выбор языка - 'select_language_title' => 'Выбери язык', - 'select_language_description' => 'Выбранный язык будет использован в текущем процессе', - 'select_language_button_add' => 'Добавить язык', + // Выбор языка + 'select_language_title' => 'Выбери язык', + 'select_language_description' => 'Выбранный язык будет использован в текущем процессе', + 'select_language_button_add' => 'Добавить язык', - // Репозиторий - 'repository_title' => 'Репозиторий', - 'repository_text' => << 'Репозиторий', + 'repository_text' => << 'Код', - 'repository_button_issues' => 'Проблемы', - 'repository_button_suggestions' => 'Предложения', + Код находится под лицензией [WTFPL](https://en.wikipedia.org/wiki/WTFPL) + Помогай с разработкой или используй мой код бесплатно\! + TXT, + 'repository_button_code' => 'Код', + 'repository_button_issues' => 'Проблемы', + 'repository_button_suggestions' => 'Предложения', - // Автор - 'author_title' => 'Автор', - 'author_text' => << 'Нейрожурнал', - 'author_button_projects' => 'Проекты', - 'author_button_twitter' => 'Twitter', - 'author_button_bluesky' => 'Bluesky', - 'author_button_bastyon' => 'Bastyon', - 'author_button_youtube_english' => 'YouTube', - 'author_button_youtube_russian' => 'YouTube', - 'author_button_message' => 'Отправить сообщение', + // Автор + 'author_title' => 'Автор', + 'author_text' => << 'Нейрожурнал', + 'author_button_projects' => 'Проекты', + 'author_button_twitter' => 'Twitter', + 'author_button_bluesky' => 'Bluesky', + 'author_button_bastyon' => 'Bastyon', + 'author_button_youtube_english' => 'YouTube', + 'author_button_youtube_russian' => 'YouTube', + 'author_button_message' => 'Отправить сообщение', - // Вопросы (система) - 'system_questions_title' => 'Реестр вопросов', - 'system_questions_questions' => 'Вопросы', - 'system_questions_answers' => 'Ответы', - 'system_questions_answers_amount_matches' => 'Количество вопросов совпадает с количеством ответов', - 'system_questions_answers_amount_different' => 'Количество вопросов не совпадает с количеством ответов', - 'system_questions_amount_matches' => 'Количество вопросов совпадает с количеством локализаций', - 'system_questions_amount_different' => 'Количество вопросов не совпадает с количеством локализаций', - 'system_questions_localizations_amount_matches' => 'Количества локализаций совпадает друг с другом', - 'system_questions_localizations_amount_different' => 'Количества локализаций не совпадает друг с другом', - 'system_questions_button_search' => 'Поиск', - 'system_questions_button_create' => 'Создать', + // Вопросы (система) + 'system_questions_title' => 'Реестр вопросов', + 'system_questions_questions' => 'Вопросы', + 'system_questions_answers' => 'Ответы', + 'system_questions_answers_amount_matches' => 'Количество вопросов совпадает с количеством ответов', + 'system_questions_answers_amount_different' => 'Количество вопросов не совпадает с количеством ответов', + 'system_questions_amount_matches' => 'Количество вопросов совпадает с количеством локализаций', + 'system_questions_amount_different' => 'Количество вопросов не совпадает с количеством локализаций', + 'system_questions_localizations_amount_matches' => 'Количества локализаций совпадает друг с другом', + 'system_questions_localizations_amount_different' => 'Количества локализаций не совпадает друг с другом', + 'system_questions_button_search' => 'Поиск', + 'system_questions_button_create' => 'Создать', - // Создание вопроса (система) - 'system_questions_create_created' => 'Создан вопрос', + // Создание вопроса (система) + 'system_questions_create_created' => 'Создан вопрос', - // Поиск вопроса (система) - 'system_questions_search_title' => 'Процесс поиска вопроса', - 'system_questions_search_continued' => 'Процесс поиска вопроса найден и продолжен', - 'system_questions_search_started' => 'Процесс поиска вопроса начат', - 'system_questions_search_not_started' => 'Процесс поиска вопроса не начат', - 'system_questions_search_ended' => 'Процесс поиска вопроса завершён', - 'system_questions_search_page_next_exists' => 'В реестре есть ещё вопросы', - 'system_questions_search_page_next_not_exists' => 'В реестре больше нет вопросов', - 'system_questions_search_empty' => 'Вопросы не найдены', - 'system_questions_search_question_title' => 'Вопрос', - 'system_questions_search_question_answer' => 'Ответ', - 'system_questions_search_identifier_request_title' => 'Введи идентификатор', - 'system_questions_search_identifier_request_not_acceptable' => 'Не удалось обработать идентификатор', - 'system_questions_search_identifier_request_too_short' => 'Длина идентификатора должна быть \>\= 1 и \<\= 12', - 'system_questions_search_identifier_request_too_long' => 'Длина идентификатора должна быть \>\= 1 и \<\= 12', - 'system_questions_search_identifier_request_restricted_characters_title' => "Запрещены любые символы, кроме цифр", - 'system_questions_search_identifier_request_restricted_characters_description' => "Удали эти символы:", - 'system_questions_search_identifier_cancel_success' => 'Отменён процесс замены идентификатора', - 'system_questions_search_identifier_delete_success' => 'Идентификатор удалён', - 'system_questions_search_identifier_update_success' => 'Идентификатор заменён:', - 'system_questions_search_identifier_update_fail' => 'Не удалось заменить идентификатор', - 'system_questions_search_text_request_title' => 'Введи текст', - 'system_questions_search_text_request_not_acceptable' => 'Не удалось обработать текст', - 'system_questions_search_text_request_too_short' => 'Длина текста должна быть \>\= 3 и \<\= 256', - 'system_questions_search_text_request_too_long' => 'Длина текста должна быть \>\= 3 и \<\= 256', - 'system_questions_search_text_cancel_success' => 'Отменён процесс замены текста', - 'system_questions_search_text_delete_success' => 'Текст удалён', - 'system_questions_search_text_update_success' => 'Текст заменён:', - 'system_questions_search_text_update_fail' => 'Не удалось заменить текст', - 'system_questions_search_a_request_title' => 'Введи A\-ответ', - 'system_questions_search_a_request_not_acceptable' => 'Не удалось обработать A\-ответ', - 'system_questions_search_a_request_too_short' => 'Длина A\-ответа должна быть \>\= 3 и \<\= 128', - 'system_questions_search_a_request_too_long' => 'Длина A\-ответа должна быть \>\= 3 и \<\= 128', - 'system_questions_search_a_cancel_success' => 'Отменён процесс замены A\-ответа', - 'system_questions_search_a_delete_success' => 'A\-ответ удалён', - 'system_questions_search_a_update_success' => 'A\-ответ заменён:', - 'system_questions_search_a_update_fail' => 'Не удалось заменить A\-ответ', - 'system_questions_search_b_request_title' => 'Введи B\-ответ', - 'system_questions_search_b_request_not_acceptable' => 'Не удалось обработать B\-ответ', - 'system_questions_search_b_request_too_short' => 'Длина B\-ответа должна быть \>\= 3 и \<\= 128', - 'system_questions_search_b_request_too_long' => 'Длина B\-ответа должна быть \>\= 3 и \<\= 128', - 'system_questions_search_b_cancel_success' => 'Отменён процесс замены B\-ответа', - 'system_questions_search_b_delete_success' => 'B\-ответ удалён', - 'system_questions_search_b_update_success' => 'B\-ответ заменён:', - 'system_questions_search_b_update_fail' => 'Не удалось заменить B\-ответ', - 'system_questions_search_c_request_title' => 'Введи C\-ответ', - 'system_questions_search_c_request_not_acceptable' => 'Не удалось обработать C\-ответ', - 'system_questions_search_c_request_too_short' => 'Длина C\-ответа должна быть \>\= 3 и \<\= 128', - 'system_questions_search_c_request_too_long' => 'Длина C\-ответа должна быть \>\= 3 и \<\= 128', - 'system_questions_search_c_cancel_success' => 'Отменён процесс замены C\-ответа', - 'system_questions_search_c_delete_success' => 'C\-ответ удалён', - 'system_questions_search_c_update_success' => 'C\-ответ заменён:', - 'system_questions_search_c_update_fail' => 'Не удалось заменить C\-ответ', - 'system_questions_search_d_request_title' => 'Введи D\-ответ', - 'system_questions_search_d_request_not_acceptable' => 'Не удалось обработать D\-ответ', - 'system_questions_search_d_request_too_short' => 'Длина D\-ответа должна быть \>\= 3 и \<\= 128', - 'system_questions_search_d_request_too_long' => 'Длина D\-ответа должна быть \>\= 3 и \<\= 128', - 'system_questions_search_d_cancel_success' => 'Отменён процесс замены D\-ответа', - 'system_questions_search_d_delete_success' => 'D\-ответ удалён', - 'system_questions_search_d_update_success' => 'D\-ответ заменён:', - 'system_questions_search_d_update_fail' => 'Не удалось заменить D\-ответ', - 'system_questions_search_button_delete' => 'Удалить', - 'system_questions_search_button_author' => 'Автор', - 'system_questions_search_button_active' => 'Активен', - 'system_questions_search_button_inactive' => 'Неактивен', - 'system_questions_search_button_answer' => 'Ответ', - 'system_questions_search_button_localizations' => 'Локализации', - 'system_questions_search_button_identifier' => 'Идентифиикатор', - 'system_questions_search_button_text' => 'Текст', - 'system_questions_search_button_a' => 'А', - 'system_questions_search_button_b' => 'Б', - 'system_questions_search_button_c' => 'В', - 'system_questions_search_button_d' => 'Г', - 'system_questions_search_button_delete' => 'Удалить', - 'system_questions_search_button_cancel' => 'Отменить', - 'system_questions_search_button_page_next' => 'Следующая страница', - 'system_questions_search_button_end' => 'Завершить процесс поиска', - 'system_questions_search_not_localized' => 'Не удалось инициализировать локализацию вопроса', + // Поиск вопроса (система) + 'system_questions_search_title' => 'Процесс поиска вопроса', + 'system_questions_search_continued' => 'Процесс поиска вопроса найден и продолжен', + 'system_questions_search_started' => 'Процесс поиска вопроса начат', + 'system_questions_search_not_started' => 'Процесс поиска вопроса не начат', + 'system_questions_search_ended' => 'Процесс поиска вопроса завершён', + 'system_questions_search_page_next_exists' => 'В реестре есть ещё вопросы', + 'system_questions_search_page_next_not_exists' => 'В реестре больше нет вопросов', + 'system_questions_search_empty' => 'Вопросы не найдены', + 'system_questions_search_question_title' => 'Вопрос', + 'system_questions_search_question_answer' => 'Ответ', + 'system_questions_search_identifier_request_title' => 'Введи идентификатор', + 'system_questions_search_identifier_request_not_acceptable' => 'Не удалось обработать идентификатор', + 'system_questions_search_identifier_request_too_short' => 'Длина идентификатора должна быть \>\= 1 и \<\= 12', + 'system_questions_search_identifier_request_too_long' => 'Длина идентификатора должна быть \>\= 1 и \<\= 12', + 'system_questions_search_identifier_request_restricted_characters_title' => "Запрещены любые символы, кроме цифр", + 'system_questions_search_identifier_request_restricted_characters_description' => "Удали эти символы:", + 'system_questions_search_identifier_cancel_success' => 'Отменён процесс замены идентификатора', + 'system_questions_search_identifier_delete_success' => 'Идентификатор удалён', + 'system_questions_search_identifier_update_success' => 'Идентификатор заменён:', + 'system_questions_search_identifier_update_fail' => 'Не удалось заменить идентификатор', + 'system_questions_search_text_request_title' => 'Введи текст', + 'system_questions_search_text_request_not_acceptable' => 'Не удалось обработать текст', + 'system_questions_search_text_request_too_short' => 'Длина текста должна быть \>\= 3 и \<\= 256', + 'system_questions_search_text_request_too_long' => 'Длина текста должна быть \>\= 3 и \<\= 256', + 'system_questions_search_text_cancel_success' => 'Отменён процесс замены текста', + 'system_questions_search_text_delete_success' => 'Текст удалён', + 'system_questions_search_text_update_success' => 'Текст заменён:', + 'system_questions_search_text_update_fail' => 'Не удалось заменить текст', + 'system_questions_search_a_request_title' => 'Введи A\-ответ', + 'system_questions_search_a_request_not_acceptable' => 'Не удалось обработать A\-ответ', + 'system_questions_search_a_request_too_short' => 'Длина A\-ответа должна быть \>\= 3 и \<\= 128', + 'system_questions_search_a_request_too_long' => 'Длина A\-ответа должна быть \>\= 3 и \<\= 128', + 'system_questions_search_a_cancel_success' => 'Отменён процесс замены A\-ответа', + 'system_questions_search_a_delete_success' => 'A\-ответ удалён', + 'system_questions_search_a_update_success' => 'A\-ответ заменён:', + 'system_questions_search_a_update_fail' => 'Не удалось заменить A\-ответ', + 'system_questions_search_b_request_title' => 'Введи B\-ответ', + 'system_questions_search_b_request_not_acceptable' => 'Не удалось обработать B\-ответ', + 'system_questions_search_b_request_too_short' => 'Длина B\-ответа должна быть \>\= 3 и \<\= 128', + 'system_questions_search_b_request_too_long' => 'Длина B\-ответа должна быть \>\= 3 и \<\= 128', + 'system_questions_search_b_cancel_success' => 'Отменён процесс замены B\-ответа', + 'system_questions_search_b_delete_success' => 'B\-ответ удалён', + 'system_questions_search_b_update_success' => 'B\-ответ заменён:', + 'system_questions_search_b_update_fail' => 'Не удалось заменить B\-ответ', + 'system_questions_search_c_request_title' => 'Введи C\-ответ', + 'system_questions_search_c_request_not_acceptable' => 'Не удалось обработать C\-ответ', + 'system_questions_search_c_request_too_short' => 'Длина C\-ответа должна быть \>\= 3 и \<\= 128', + 'system_questions_search_c_request_too_long' => 'Длина C\-ответа должна быть \>\= 3 и \<\= 128', + 'system_questions_search_c_cancel_success' => 'Отменён процесс замены C\-ответа', + 'system_questions_search_c_delete_success' => 'C\-ответ удалён', + 'system_questions_search_c_update_success' => 'C\-ответ заменён:', + 'system_questions_search_c_update_fail' => 'Не удалось заменить C\-ответ', + 'system_questions_search_d_request_title' => 'Введи D\-ответ', + 'system_questions_search_d_request_not_acceptable' => 'Не удалось обработать D\-ответ', + 'system_questions_search_d_request_too_short' => 'Длина D\-ответа должна быть \>\= 3 и \<\= 128', + 'system_questions_search_d_request_too_long' => 'Длина D\-ответа должна быть \>\= 3 и \<\= 128', + 'system_questions_search_d_cancel_success' => 'Отменён процесс замены D\-ответа', + 'system_questions_search_d_delete_success' => 'D\-ответ удалён', + 'system_questions_search_d_update_success' => 'D\-ответ заменён:', + 'system_questions_search_d_update_fail' => 'Не удалось заменить D\-ответ', + 'system_questions_search_button_delete' => 'Удалить', + 'system_questions_search_button_author' => 'Автор', + 'system_questions_search_button_active' => 'Активен', + 'system_questions_search_button_inactive' => 'Неактивен', + 'system_questions_search_button_answer' => 'Ответ', + 'system_questions_search_button_localizations' => 'Локализации', + 'system_questions_search_button_identifier' => 'Идентифиикатор', + 'system_questions_search_button_text' => 'Текст', + 'system_questions_search_button_a' => 'А', + 'system_questions_search_button_b' => 'Б', + 'system_questions_search_button_c' => 'В', + 'system_questions_search_button_d' => 'Г', + 'system_questions_search_button_delete' => 'Удалить', + 'system_questions_search_button_cancel' => 'Отменить', + 'system_questions_search_button_page_next' => 'Следующая страница', + 'system_questions_search_button_end' => 'Завершить процесс поиска', + 'system_questions_search_not_localized' => 'Не удалось инициализировать локализацию вопроса', - // Создание локализации вопроса (система) - 'system_questions_localization_create_created' => 'Создана локализация вопроса', + // Создание локализации вопроса (система) + 'system_questions_localization_create_created' => 'Создана локализация вопроса', - // Авторизация - 'not_authorized_system' => 'У тебя нет доступа к системе', - 'not_authorized_game_play' => 'У тебя нет доступа к играм', - 'not_authorized_rating_display' => 'У тебя нет доступа к отображению в рейтинге', - 'not_authorized_balance_deposit' => 'У тебя нет доступа к пополнению баланса', - 'not_authorized_balance_withdraw' => 'У тебя нет доступа к выводу баланса', - 'not_authorized_settings' => 'У тебя нет доступа к настройкам', - 'not_authorized_system_accounts' => 'У тебя нет системного доступа к аккаунтам', - 'not_authorized_system_questions' => 'У тебя нет системного доступа к вопросам', - 'not_authorized_system_settings' => 'У тебя нет системного доступа к системным настройкам', + // Авторизация + 'not_authorized_system' => 'У тебя нет доступа к системе', + 'not_authorized_game_play' => 'У тебя нет доступа к играм', + 'not_authorized_rating_display' => 'У тебя нет доступа к отображению в рейтинге', + 'not_authorized_balance_deposit' => 'У тебя нет доступа к пополнению баланса', + 'not_authorized_balance_withdraw' => 'У тебя нет доступа к выводу баланса', + 'not_authorized_settings' => 'У тебя нет доступа к настройкам', + 'not_authorized_system_accounts' => 'У тебя нет системного доступа к аккаунтам', + 'not_authorized_system_questions' => 'У тебя нет системного доступа к вопросам', + 'not_authorized_system_settings' => 'У тебя нет системного доступа к системным настройкам', - // Прочее - 'why_so_shroomious' => 'почему такой грибъёзный', + // Прочее + 'why_so_shroomious' => 'почему такой грибъёзный', ]; diff --git a/mirzaev/deeproots/system/models/account.php b/mirzaev/deeproots/system/models/account.php index ea6bcc1..13cffc1 100755 --- a/mirzaev/deeproots/system/models/account.php +++ b/mirzaev/deeproots/system/models/account.php @@ -202,15 +202,15 @@ final class account extends core $identifier, $name, $language->name, - ACCOUNT_ACCESS_SYSTEM, - ACCOUNT_ACCESS_GAME_PLAY, - ACCOUNT_ACCESS_RATING_DISPLAY, - ACCOUNT_ACCESS_BALANCE_DEPOSIT, - ACCOUNT_ACCESS_BALANCE_WITHDRAW, - ACCOUNT_ACCESS_SETTINGS, - ACCOUNT_ACCESS_SYSTEM_ACCOUNTS, - ACCOUNT_ACCESS_SYSTEM_QUESTIONS, - ACCOUNT_ACCESS_SYSTEM_SETTINGS, + 1, // ACCOUNT_ACCESS_SYSTEM + 1, // ACCOUNT_ACCESS_GAME_PLAY + 1, // ACCOUNT_ACCESS_RATING_DISPLAY + 1, // ACCOUNT_ACCESS_BALANCE_DEPOSIT + 1, // ACCOUNT_ACCESS_BALANCE_WITHDRAW + 1, // ACCOUNT_ACCESS_SETTINGS + 0, // ACCOUNT_ACCESS_SYSTEM_ACCOUNTS + 0, // ACCOUNT_ACCESS_SYSTEM_QUESTIONS + 0, // ACCOUNT_ACCESS_SYSTEM_SETTINGS svoboda::timestamp(), svoboda::timestamp() ); diff --git a/mirzaev/deeproots/system/models/answer.php b/mirzaev/deeproots/system/models/answer.php index 500b2e6..fc87d5a 100755 --- a/mirzaev/deeproots/system/models/answer.php +++ b/mirzaev/deeproots/system/models/answer.php @@ -6,22 +6,22 @@ namespace mirzaev\deeproots\models; // Files of the project use mirzaev\deeproots\models\core, - mirzaev\deeproots\models\question, - mirzaev\deeproots\models\enumerations\language; + mirzaev\deeproots\models\question, + mirzaev\deeproots\models\enumerations\language; // Svoboda time use svoboda\time\statement as svoboda; // Baza database use mirzaev\baza\database, - mirzaev\baza\column, - mirzaev\baza\record, - mirzaev\baza\enumerations\encoding, - mirzaev\baza\enumerations\type; + mirzaev\baza\column, + mirzaev\baza\record, + mirzaev\baza\enumerations\encoding, + mirzaev\baza\enumerations\type; // Built-in libraries use Exception as exception, - RuntimeException as exception_runtime; + RuntimeException as exception_runtime; /** * Answer @@ -34,77 +34,77 @@ use Exception as exception, */ final class answer extends core { - /** - * File - * - * @var string $database Path to the database file - */ - protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'answers.baza'; + /** + * File + * + * @var string $database Path to the database file + */ + protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'answers.baza'; - /** - * Database - * - * @var database $database The database - */ - public protected(set) database $database; + /** + * Database + * + * @var database $database The database + */ + public protected(set) database $database; - /** - * Constructor - * - * @param language $language Questions language - * - * @return void - */ - public function __construct() - { - // Initializing the database - $this->database = new database() - ->encoding(encoding::ascii) - ->columns( - new column('identifier', type::long_long_unsigned), - new column('A', type::char), - new column('B', type::char), - new column('C', type::char), - new column('D', type::char), - new column('updated', type::integer_unsigned), - new column('created', type::integer_unsigned) - ) - ->connect($this->file); - } + /** + * Constructor + * + * @param language $language Questions language + * + * @return void + */ + public function __construct() + { + // Initializing the database + $this->database = new database() + ->encoding(encoding::ascii) + ->columns( + new column('identifier', type::long_long_unsigned), + new column('A', type::char), + new column('B', type::char), + new column('C', type::char), + new column('D', type::char), + new column('updated', type::integer_unsigned), + new column('created', type::integer_unsigned) + ) + ->connect($this->file); + } - /** - * Create - * - * Creates the record in the database - * - * @param int $identifier Identifier (same for questions in every language) - * @param int $a Number of points for answer A - * @param int $b Number of points for answer B - * @param int $c Number of points for answer C - * @param int $d Number of points for answer D - * - * @return int|false The record identifier, if created - */ - public function create(?int $identifier, int $a = 0, int $b = 0, int $c = 0, int $d = 0): int|false - { - // Initializing the identifier - $identifier ??= $this->database->count() + 1; + /** + * Create + * + * Creates the record in the database + * + * @param int $identifier Identifier (same for questions in every language) + * @param int $a Number of points for answer A + * @param int $b Number of points for answer B + * @param int $c Number of points for answer C + * @param int $d Number of points for answer D + * + * @return int|false The record identifier, if created + */ + public function create(?int $identifier, int $a = 0, int $b = 0, int $c = 0, int $d = 0): int|false + { + // Initializing the identifier + $identifier ??= $this->database->count() + 1; - // Initializing the record - $record = $this->database->record( - $identifier, - $a, - $b, - $c, - $d, - svoboda::timestamp(), - svoboda::timestamp() - ); + // Initializing the record + $record = $this->database->record( + $identifier, + $a, + $b, + $c, + $d, + svoboda::timestamp(), + svoboda::timestamp() + ); - // Creating the record in the database - $created = $this->database->write($record); + // Creating the record in the database + $created = $this->database->write($record); - // Exit (success) - return $created ? $identifier : false; - } + // Exit (success) + return $created ? $identifier : false; + } } diff --git a/mirzaev/deeproots/system/models/core.php b/mirzaev/deeproots/system/models/core.php index 732a542..d9472a6 100755 --- a/mirzaev/deeproots/system/models/core.php +++ b/mirzaev/deeproots/system/models/core.php @@ -6,7 +6,7 @@ namespace mirzaev\deeproots\models; // Framework for PHP use mirzaev\minimal\model, - mirzaev\minimal\http\enumerations\status; + mirzaev\minimal\http\enumerations\status; // Built-in libraries use exception; @@ -23,22 +23,21 @@ use exception; */ class core extends model { - /** - * File - * - * @var string database Path to the database file - */ - protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'example.baza'; + /** + * File + * + * @var string database Path to the database file + */ + protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'example.baza'; - /** - * Constructor - * - * Initialize the database - * - * @return void - */ - public function __construct() - { - } + /** + * Constructor + * + * Initialize the database + * + * @return void + */ + public function __construct() + { + } } - diff --git a/mirzaev/deeproots/system/models/question.php b/mirzaev/deeproots/system/models/question.php index 5fd0639..1de11e2 100755 --- a/mirzaev/deeproots/system/models/question.php +++ b/mirzaev/deeproots/system/models/question.php @@ -6,22 +6,22 @@ namespace mirzaev\deeproots\models; // Files of the project use mirzaev\deeproots\models\core, - mirzaev\deeproots\models\question\localization, - mirzaev\deeproots\models\enumerations\language; + mirzaev\deeproots\models\question\localization, + mirzaev\deeproots\models\enumerations\language; // Svoboda time use svoboda\time\statement as svoboda; // Baza database use mirzaev\baza\database, - mirzaev\baza\column, - mirzaev\baza\record, - mirzaev\baza\enumerations\encoding, - mirzaev\baza\enumerations\type; + mirzaev\baza\column, + mirzaev\baza\record, + mirzaev\baza\enumerations\encoding, + mirzaev\baza\enumerations\type; // Built-in libraries use Exception as exception, - RuntimeException as exception_runtime; + RuntimeException as exception_runtime; /** * Question @@ -34,65 +34,65 @@ use Exception as exception, */ final class question extends core { - /** - * File - * - * @var string $database Path to the database file - */ - protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'questions.baza'; + /** + * File + * + * @var string $database Path to the database file + */ + protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'questions.baza'; - /** - * Database - * - * @var database $database The database - */ - public protected(set) database $database; + /** + * Database + * + * @var database $database The database + */ + public protected(set) database $database; - /** - * Constructor - * - * @return void - */ - public function __construct() - { - // Initializing the database - $this->database = new database() - ->encoding(encoding::ascii) - ->columns( - new column('identifier', type::long_long_unsigned), - new column('active', type::char), - new column('updated', type::integer_unsigned), - new column('created', type::integer_unsigned) - ) - ->connect($this->file); - } + /** + * Constructor + * + * @return void + */ + public function __construct() + { + // Initializing the database + $this->database = new database() + ->encoding(encoding::ascii) + ->columns( + new column('identifier', type::integer_unsigned), + new column('active', type::char), + new column('updated', type::integer_unsigned), + new column('created', type::integer_unsigned) + ) + ->connect($this->file); + } - /** - * Create - * - * Creates the record in the database - * - * @param bool $active Is the question active? - * - * @return int|false The record identifier, if created - */ - public function create(bool $active = false): int|false - { - // Initializing the identifier - $identifier ??= $this->database->count() + 1; + /** + * Create + * + * Creates the record in the database + * + * @param bool $active Is the question active? + * + * @return int|false The record identifier, if created + */ + public function create(bool $active = false): int|false + { + // Initializing the identifier + $identifier ??= $this->database->count() + 1; - // Initializing the record - $record = $this->database->record( - $identifier, - (int) $active, - svoboda::timestamp(), - svoboda::timestamp() - ); + // Initializing the record + $record = $this->database->record( + $identifier, + (int) $active, + svoboda::timestamp(), + svoboda::timestamp() + ); - // Creating the record in the database - $created = $this->database->write($record); + // Creating the record in the database + $created = $this->database->write($record); - // Exit (success) - return $created ? $identifier : false; - } + // Exit (success) + return $created ? $identifier : false; + } } diff --git a/mirzaev/deeproots/system/models/question/localization.php b/mirzaev/deeproots/system/models/question/localization.php index 1fd587c..dd93c61 100755 --- a/mirzaev/deeproots/system/models/question/localization.php +++ b/mirzaev/deeproots/system/models/question/localization.php @@ -6,22 +6,22 @@ namespace mirzaev\deeproots\models\question; // Files of the project use mirzaev\deeproots\models\core, - mirzaev\deeproots\models\question, - mirzaev\deeproots\models\enumerations\language; + mirzaev\deeproots\models\question, + mirzaev\deeproots\models\enumerations\language; // Svoboda time use svoboda\time\statement as svoboda; // Baza database use mirzaev\baza\database, - mirzaev\baza\column, - mirzaev\baza\record, - mirzaev\baza\enumerations\encoding, - mirzaev\baza\enumerations\type; + mirzaev\baza\column, + mirzaev\baza\record, + mirzaev\baza\enumerations\encoding, + mirzaev\baza\enumerations\type; // Built-in libraries use Exception as exception, - RuntimeException as exception_runtime; + RuntimeException as exception_runtime; /** * Question localization @@ -34,77 +34,77 @@ use Exception as exception, */ final class localization extends core { - /** - * Files - * - * @var string $database Path to the database files - */ - protected string $files = DATABASES . DIRECTORY_SEPARATOR . 'questions' . DIRECTORY_SEPARATOR . 'localizations'; + /** + * Files + * + * @var string $database Path to the database files + */ + protected string $files = DATABASES . DIRECTORY_SEPARATOR . 'questions' . DIRECTORY_SEPARATOR . 'localizations'; - /** - * Database - * - * @var database $database The database - */ - public protected(set) database $database; + /** + * Database + * + * @var database $database The database + */ + public protected(set) database $database; - /** - * Constructor - * - * @param language $language Language - * - * @return void - */ - public function __construct(language $language) - { - // Initializing the database - $this->database = new database() - ->encoding(encoding::ascii) - ->columns( - new column('identifier', type::long_long_unsigned), - new column('text', type::string, ['length' => 256]), - new column('A', type::string, ['length' => 128]), - new column('B', type::string, ['length' => 128]), - new column('C', type::string, ['length' => 128]), - new column('D', type::string, ['length' => 128]), - new column('updated', type::integer_unsigned), - new column('created', type::integer_unsigned) - ) - ->connect($this->files . DIRECTORY_SEPARATOR . strtolower($language->label()) . '.baza'); - } + /** + * Constructor + * + * @param language $language Language + * + * @return void + */ + public function __construct(language $language) + { + // Initializing the database + $this->database = new database() + ->encoding(encoding::ascii) + ->columns( + new column('identifier', type::long_long_unsigned), + new column('text', type::string, ['length' => 256]), + new column('A', type::string, ['length' => 128]), + new column('B', type::string, ['length' => 128]), + new column('C', type::string, ['length' => 128]), + new column('D', type::string, ['length' => 128]), + new column('updated', type::integer_unsigned), + new column('created', type::integer_unsigned) + ) + ->connect($this->files . DIRECTORY_SEPARATOR . strtolower($language->label()) . '.baza'); + } - /** - * Create - * - * Creates the record in the database - * - * @param int $identifier Identifier of the question::class record - * @param string $text Text (length: 256) - * @param string $a Answer A (length: 128) - * @param string $b Answer B (length: 128) - * @param string $c Answer C (length: 128) - * @param string $d Answer D (length: 128) - * - * @return int|false The record identifier, if created - */ - public function create(int $identifier, string $text, string $a, string $b, string $c, string $d): int|false - { - // Initializing the record - $record = $this->database->record( - $identifier, - $text, - $a, - $b, - $c, - $d, - svoboda::timestamp(), - svoboda::timestamp() - ); + /** + * Create + * + * Creates the record in the database + * + * @param int $identifier Identifier of the question::class record + * @param string $text Text (length: 256) + * @param string $a Answer A (length: 128) + * @param string $b Answer B (length: 128) + * @param string $c Answer C (length: 128) + * @param string $d Answer D (length: 128) + * + * @return int|false The record identifier, if created + */ + public function create(int $identifier, string $text, string $a, string $b, string $c, string $d): int|false + { + // Initializing the record + $record = $this->database->record( + $identifier, + $text, + $a, + $b, + $c, + $d, + svoboda::timestamp(), + svoboda::timestamp() + ); - // Creating the record in the database - $created = $this->database->write($record); + // Creating the record in the database + $created = $this->database->write($record); - // Exit (success) - return $created ? $identifier : false; - } + // Exit (success) + return $created ? $identifier : false; + } } diff --git a/mirzaev/deeproots/system/models/telegram/buttons/account/localization/create.php b/mirzaev/deeproots/system/models/telegram/buttons/account/localization/create.php index 04386cb..333cb55 100755 --- a/mirzaev/deeproots/system/models/telegram/buttons/account/localization/create.php +++ b/mirzaev/deeproots/system/models/telegram/buttons/account/localization/create.php @@ -6,14 +6,14 @@ namespace svoboda\svoboder\models\telegram\buttons\account\localization; // Files of the project use svoboda\svoboder\models\core, - svoboda\svoboder\models\enumerations\language, - svoboda\svoboder\models\account, - svoboda\svoboder\models\telegram\selections, - svoboda\svoboder\models\telegram\processes\account\localization\create as process_account_localization_create; + svoboda\svoboder\models\enumerations\language, + svoboda\svoboder\models\account, + svoboda\svoboder\models\telegram\selections, + svoboda\svoboder\models\telegram\processes\account\localization\create as process_account_localization_create; // Framework for Telegram use Zanzara\Context as context, - Zanzara\Telegram\Type\Message as message; + Zanzara\Telegram\Type\Message as message; // Baza database use mirzaev\baza\record; @@ -28,201 +28,201 @@ use mirzaev\baza\record; */ final class create extends core { - /** - * Language - * - * Send the language selection menu - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function language(context $context) - { - // Initializing the account - $account = $context->get('account'); + /** + * Language + * + * Send the language selection menu + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function language(context $context) + { + // Initializing the account + $account = $context->get('account'); - if ($account instanceof record) { - // Initialized the account + if ($account instanceof record) { + // Initialized the account - // Initializing language - $language = $context->get('language'); + // Initializing language + $language = $context->get('language'); - if ($language) { - // Initialized language + if ($language) { + // Initialized language - // Initializing localization - $localization = $context->get('localization'); + // Initializing localization + $localization = $context->get('localization'); - if ($localization) { - // Initialized localization + if ($localization) { + // Initialized localization - // Reading from the telegram user buffer - $context->getUserDataItem(process_account_localization_create::PROCESS) - ->then(function (?array $process) use ($context, $account, $localization) { - // Readed from the telegram user buffer + // Reading from the telegram user buffer + $context->getUserDataItem(process_account_localization_create::PROCESS) + ->then(function (?array $process) use ($context, $account, $localization) { + // Readed from the telegram user buffer - if ($process) { - // Found started account localization create process + if ($process) { + // Found started account localization create process - // Initializing the account model - $model_account = new account; + // Initializing the account model + $model_account = new account; - // Initializing the account localizations - $existed = $model_account->localization->database->read( - filter: fn(record $localization) => $localization->account === $account->identifier, - amount: ACCOUNT_LOCALIZATION_CREATE_ACCOUNT_LOCALIZATIONS_AMOUNT - ); + // Initializing the account localizations + $existed = $model_account->localization->database->read( + filter: fn(record $localization) => $localization->account === $account->identifier, + amount: ACCOUNT_LOCALIZATION_CREATE_ACCOUNT_LOCALIZATIONS_AMOUNT + ); - // Declaring the buffer of languages to exclude - $exclude = []; + // Declaring the buffer of languages to exclude + $exclude = []; - // Initializing languages to exclude - foreach ($existed as $record) $exclude[] = $record->language; + // Initializing languages to exclude + foreach ($existed as $record) $exclude[] = $record->language; - if (count($exclude) !== count(language::cases())) { - // Not all languages in the registry have localizations created (expected) + if (count($exclude) !== count(language::cases())) { + // Not all languages in the registry have localizations created (expected) - // Sending the language selection - selections::language( - context: $context, - prefix: 'account_localization_create_select_language_', - title: '🌏 *' . $localization['account_localization_create_select_language_title'] . '*', - description: '🌏 *' . $localization['account_localization_create_select_language_description'] . '*', - exclude: $exclude - ); - } else { - // All languages in the registry have localizations created (expected) + // Sending the language selection + selections::language( + context: $context, + prefix: 'account_localization_create_select_language_', + title: '🌏 *' . $localization['account_localization_create_select_language_title'] . '*', + description: '🌏 *' . $localization['account_localization_create_select_language_description'] . '*', + exclude: $exclude + ); + } else { + // All languages in the registry have localizations created (expected) - // Sending the message - $context->sendMessage('⚠️ *' . $localization['account_localization_create_every_language_created'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *' . $localization['account_localization_create_every_language_created'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not found started account localization create process + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not found started account localization create process - // Sending the message - $context->sendMessage('⚠️ *' . $localization['account_localization_create_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *' . $localization['account_localization_create_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - }); - } else { - // Not initialized localization + // Ending the conversation process + $context->endConversation(); + }); + } + }); + } else { + // Not initialized localization - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized language + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized language - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize language*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize language*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } + // Ending the conversation process + $context->endConversation(); + }); + } + } - /** - * Name - * - * Request to enter name - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function name(context $context) - { - // Initializing the account - $account = $context->get('account'); + /** + * Name + * + * Request to enter name + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function name(context $context) + { + // Initializing the account + $account = $context->get('account'); - if ($account instanceof record) { - // Initialized the account + if ($account instanceof record) { + // Initialized the account - // Initializing localization - $localization = $context->get('localization'); + // Initializing localization + $localization = $context->get('localization'); - if ($localization) { - // Initialized localization + if ($localization) { + // Initialized localization - // Reading from the telegram user buffer - $context->getUserDataItem(process_account_localization_create::PROCESS) - ->then(function (?array $process) use ($context, $account, $localization) { - // Readed from the telegram user buffer + // Reading from the telegram user buffer + $context->getUserDataItem(process_account_localization_create::PROCESS) + ->then(function (?array $process) use ($context, $account, $localization) { + // Readed from the telegram user buffer - if ($process) { - // Found started account localization create process + if ($process) { + // Found started account localization create process - // Sending the message - $context->sendMessage('📄 *' . $localization['account_localization_create_name_request'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('📄 *' . $localization['account_localization_create_name_request'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message - // Writing into the account localization create buffer - $context->nextStep([process_account_localization_create::class, 'name']); - }); - } else { - // Not found started account localization create process + // Writing into the account localization create buffer + $context->nextStep([process_account_localization_create::class, 'name']); + }); + } else { + // Not found started account localization create process - // Sending the message - $context->sendMessage('⚠️ *' . $localization['account_localization_create_not_started'] . '*'); - } - }); - } else { - // Not initialized localization + // Sending the message + $context->sendMessage('⚠️ *' . $localization['account_localization_create_not_started'] . '*'); + } + }); + } else { + // Not initialized localization - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } + // Ending the conversation process + $context->endConversation(); + }); + } + } } diff --git a/mirzaev/deeproots/system/models/telegram/buttons/account/localization/update.php b/mirzaev/deeproots/system/models/telegram/buttons/account/localization/update.php index d5abe5e..658b32d 100755 --- a/mirzaev/deeproots/system/models/telegram/buttons/account/localization/update.php +++ b/mirzaev/deeproots/system/models/telegram/buttons/account/localization/update.php @@ -6,14 +6,14 @@ namespace svoboda\svoboder\models\telegram\buttons\account\localization; // Files of the project use svoboda\svoboder\models\core, - svoboda\svoboder\models\enumerations\language, - svoboda\svoboder\models\account, - svoboda\svoboder\models\telegram\selections, - svoboda\svoboder\models\telegram\processes\account\localization\update as process_account_localization_update; + svoboda\svoboder\models\enumerations\language, + svoboda\svoboder\models\account, + svoboda\svoboder\models\telegram\selections, + svoboda\svoboder\models\telegram\processes\account\localization\update as process_account_localization_update; // Framework for Telegram use Zanzara\Context as context, - Zanzara\Telegram\Type\Message as message; + Zanzara\Telegram\Type\Message as message; // Baza database use mirzaev\baza\record; @@ -28,75 +28,75 @@ use mirzaev\baza\record; */ final class update extends core { - /** - * Name - * - * Request to enter name - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function name(context $context) - { - // Initializing the account - $account = $context->get('account'); + /** + * Name + * + * Request to enter name + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function name(context $context) + { + // Initializing the account + $account = $context->get('account'); - if ($account instanceof record) { - // Initialized the account + if ($account instanceof record) { + // Initialized the account - // Initializing localization - $localization = $context->get('localization'); + // Initializing localization + $localization = $context->get('localization'); - if ($localization) { - // Initialized localization + if ($localization) { + // Initialized localization - // Reading from the telegram user buffer - $context->getUserDataItem(process_account_localization_update::PROCESS) - ->then(function (?array $process) use ($context, $account, $localization) { - // Readed from the telegram user buffer + // Reading from the telegram user buffer + $context->getUserDataItem(process_account_localization_update::PROCESS) + ->then(function (?array $process) use ($context, $account, $localization) { + // Readed from the telegram user buffer - if ($process) { - // Found started account localization update process + if ($process) { + // Found started account localization update process - // Sending the message - $context->sendMessage('📄 *' . $localization['account_localization_update_name_request'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('📄 *' . $localization['account_localization_update_name_request'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message - // Writing into the account localization update buffer - $context->nextStep([process_account_localization_update::class, 'name']); - }); - } else { - // Not found started account localization update process + // Writing into the account localization update buffer + $context->nextStep([process_account_localization_update::class, 'name']); + }); + } else { + // Not found started account localization update process - // Sending the message - $context->sendMessage('⚠️ *' . $localization['account_localization_update_not_started'] . '*'); - } - }); - } else { - // Not initialized localization + // Sending the message + $context->sendMessage('⚠️ *' . $localization['account_localization_update_not_started'] . '*'); + } + }); + } else { + // Not initialized localization - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } + // Ending the conversation process + $context->endConversation(); + }); + } + } } diff --git a/mirzaev/deeproots/system/models/telegram/buttons/question/search.php b/mirzaev/deeproots/system/models/telegram/buttons/question/search.php index 2a3889a..29b50d6 100755 --- a/mirzaev/deeproots/system/models/telegram/buttons/question/search.php +++ b/mirzaev/deeproots/system/models/telegram/buttons/question/search.php @@ -6,13 +6,13 @@ namespace mirzaev\deeproots\models\telegram\buttons\question; // Files of the project use mirzaev\deeproots\models\core, - mirzaev\deeproots\models\question, - mirzaev\deeproots\models\telegram\processes\question\search as process_question_search, - mirzaev\deeproots\models\enumerations\membership\status; + mirzaev\deeproots\models\question, + mirzaev\deeproots\models\telegram\processes\question\search as process_question_search, + mirzaev\deeproots\models\enumerations\membership\status; // Framework for Telegram use Zanzara\Context as context, - Zanzara\Telegram\Type\Message as message; + Zanzara\Telegram\Type\Message as message; // Svoboda time use svoboda\time\statement as svoboda; @@ -30,550 +30,550 @@ use mirzaev\baza\record; */ final class search extends core { - /** - * Process - * - * @var const string PROCESS Name of the process in the telegram user buffer - */ - public const string PROCESS = process_question_search::PROCESS; - - /** - * Identifier - * - * Request to enter identifier - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function identifier(context $context) - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function ($search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Sending the message - $context->sendMessage( - '📄 *' . $localization[static::PROCESS . '_identifier_request_title'] . '*', - [ - 'reply_markup' => [ - 'inline_keyboard' => [ - [ - [ - 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], - 'callback_data' => 'delete' - ], - [ - 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], - 'callback_data' => 'cancel' - ] - ], - ], - 'disable_notification' => true - ] - ] - )->then(function (message $message) use ($context) { - // Sended the message - - // Writing into the distribution search buffer - $context->nextStep([process_question_search::class, 'identifier']); - }); - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*'); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Text - * - * Request to enter text - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function text(context $context) - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function ($search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Sending the message - $context->sendMessage( - '📄 *' . $localization[static::PROCESS . '_text_request_title'] . '*', - [ - 'reply_markup' => [ - 'inline_keyboard' => [ - [ - [ - 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], - 'callback_data' => 'delete' - ], - [ - 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], - 'callback_data' => 'cancel' - ] - ], - ], - 'disable_notification' => true - ] - ] - )->then(function (message $message) use ($context) { - // Sended the message - - // Writing into the distribution search buffer - $context->nextStep([process_question_search::class, 'text']); - }); - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*'); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * A - * - * Request to enter A-answer - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function a(context $context) - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function ($search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Sending the message - $context->sendMessage( - '📄 *' . $localization[static::PROCESS . '_a_request_title'] . '*', - [ - 'reply_markup' => [ - 'inline_keyboard' => [ - [ - [ - 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], - 'callback_data' => 'delete' - ], - [ - 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], - 'callback_data' => 'cancel' - ] - ], - ], - 'disable_notification' => true - ] - ] - )->then(function (message $message) use ($context) { - // Sended the message - - // Writing into the distribution search buffer - $context->nextStep([process_question_search::class, 'a']); - }); - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*'); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * B - * - * Request to enter B-answer - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function b(context $context) - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function ($search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Sending the message - $context->sendMessage( - '📄 *' . $localization[static::PROCESS . '_b_request_title'] . '*', - [ - 'reply_markup' => [ - 'inline_keyboard' => [ - [ - [ - 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], - 'callback_data' => 'delete' - ], - [ - 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], - 'callback_data' => 'cancel' - ] - ], - ], - 'disable_notification' => true - ] - ] - )->then(function (message $message) use ($context) { - // Sended the message - - // Writing into the distribution search buffer - $context->nextStep([process_question_search::class, 'b']); - }); - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*'); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * C - * - * Request to enter C-answer - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function c(context $context) - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function ($search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Sending the message - $context->sendMessage( - '📄 *' . $localization[static::PROCESS . '_c_request_title'] . '*', - [ - 'reply_markup' => [ - 'inline_keyboard' => [ - [ - [ - 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], - 'callback_data' => 'delete' - ], - [ - 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], - 'callback_data' => 'cancel' - ] - ], - ], - 'disable_notification' => true - ] - ] - )->then(function (message $message) use ($context) { - // Sended the message - - // Writing into the distribution search buffer - $context->nextStep([process_question_search::class, 'c']); - }); - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*'); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * D - * - * Request to enter D-answer - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function d(context $context) - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function ($search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Sending the message - $context->sendMessage( - '📄 *' . $localization[static::PROCESS . '_d_request_title'] . '*', - [ - 'reply_markup' => [ - 'inline_keyboard' => [ - [ - [ - 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], - 'callback_data' => 'delete' - ], - [ - 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], - 'callback_data' => 'cancel' - ] - ], - ], - 'disable_notification' => true - ] - ] - )->then(function (message $message) use ($context) { - // Sended the message - - // Writing into the distribution search buffer - $context->nextStep([process_question_search::class, 'd']); - }); - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*'); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } + /** + * Process + * + * @var const string PROCESS Name of the process in the telegram user buffer + */ + public const string PROCESS = process_question_search::PROCESS; + + /** + * Identifier + * + * Request to enter identifier + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function identifier(context $context) + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function ($search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Sending the message + $context->sendMessage( + '📄 *' . $localization[static::PROCESS . '_identifier_request_title'] . '*', + [ + 'reply_markup' => [ + 'inline_keyboard' => [ + [ + [ + 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], + 'callback_data' => 'delete' + ], + [ + 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], + 'callback_data' => 'cancel' + ] + ], + ], + 'disable_notification' => true + ] + ] + )->then(function (message $message) use ($context) { + // Sended the message + + // Writing into the distribution search buffer + $context->nextStep([process_question_search::class, 'identifier']); + }); + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*'); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Text + * + * Request to enter text + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function text(context $context) + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function ($search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Sending the message + $context->sendMessage( + '📄 *' . $localization[static::PROCESS . '_text_request_title'] . '*', + [ + 'reply_markup' => [ + 'inline_keyboard' => [ + [ + [ + 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], + 'callback_data' => 'delete' + ], + [ + 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], + 'callback_data' => 'cancel' + ] + ], + ], + 'disable_notification' => true + ] + ] + )->then(function (message $message) use ($context) { + // Sended the message + + // Writing into the distribution search buffer + $context->nextStep([process_question_search::class, 'text']); + }); + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*'); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * A + * + * Request to enter A-answer + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function a(context $context) + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function ($search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Sending the message + $context->sendMessage( + '📄 *' . $localization[static::PROCESS . '_a_request_title'] . '*', + [ + 'reply_markup' => [ + 'inline_keyboard' => [ + [ + [ + 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], + 'callback_data' => 'delete' + ], + [ + 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], + 'callback_data' => 'cancel' + ] + ], + ], + 'disable_notification' => true + ] + ] + )->then(function (message $message) use ($context) { + // Sended the message + + // Writing into the distribution search buffer + $context->nextStep([process_question_search::class, 'a']); + }); + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*'); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * B + * + * Request to enter B-answer + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function b(context $context) + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function ($search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Sending the message + $context->sendMessage( + '📄 *' . $localization[static::PROCESS . '_b_request_title'] . '*', + [ + 'reply_markup' => [ + 'inline_keyboard' => [ + [ + [ + 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], + 'callback_data' => 'delete' + ], + [ + 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], + 'callback_data' => 'cancel' + ] + ], + ], + 'disable_notification' => true + ] + ] + )->then(function (message $message) use ($context) { + // Sended the message + + // Writing into the distribution search buffer + $context->nextStep([process_question_search::class, 'b']); + }); + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*'); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * C + * + * Request to enter C-answer + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function c(context $context) + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function ($search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Sending the message + $context->sendMessage( + '📄 *' . $localization[static::PROCESS . '_c_request_title'] . '*', + [ + 'reply_markup' => [ + 'inline_keyboard' => [ + [ + [ + 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], + 'callback_data' => 'delete' + ], + [ + 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], + 'callback_data' => 'cancel' + ] + ], + ], + 'disable_notification' => true + ] + ] + )->then(function (message $message) use ($context) { + // Sended the message + + // Writing into the distribution search buffer + $context->nextStep([process_question_search::class, 'c']); + }); + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*'); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * D + * + * Request to enter D-answer + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function d(context $context) + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function ($search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Sending the message + $context->sendMessage( + '📄 *' . $localization[static::PROCESS . '_d_request_title'] . '*', + [ + 'reply_markup' => [ + 'inline_keyboard' => [ + [ + [ + 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], + 'callback_data' => 'delete' + ], + [ + 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], + 'callback_data' => 'cancel' + ] + ], + ], + 'disable_notification' => true + ] + ] + )->then(function (message $message) use ($context) { + // Sended the message + + // Writing into the distribution search buffer + $context->nextStep([process_question_search::class, 'd']); + }); + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*'); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } } diff --git a/mirzaev/deeproots/system/models/telegram/middlewares.php b/mirzaev/deeproots/system/models/telegram/middlewares.php index 515ac90..b4306ef 100755 --- a/mirzaev/deeproots/system/models/telegram/middlewares.php +++ b/mirzaev/deeproots/system/models/telegram/middlewares.php @@ -412,79 +412,6 @@ final class middlewares extends core } } - /** - * Join (middleware) - * - * Check the account for access to join to distributions - * - * @param context $context - * @param node $next - * - * @return void - */ - public static function join(context $context, node $next): void - { - // Is the process stopped? - if ($context->get('stop')) return; - - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - if ($account->authorized_joins) { - // Authorized the account to joint to distributions - - // Continuation of the process - $next($context); - } else { - // Not authorized the account to joint to distributions - - // Sending the message - $context->sendMessage('⛔ *' . $localization['not_authorized_joins'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - - // Stopping the process - $context->set('stop', true); - } - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - /** * Settings (middleware) * diff --git a/mirzaev/deeproots/system/models/telegram/processes/language/select.php b/mirzaev/deeproots/system/models/telegram/processes/language/select.php index 02f15e4..07b0d7d 100755 --- a/mirzaev/deeproots/system/models/telegram/processes/language/select.php +++ b/mirzaev/deeproots/system/models/telegram/processes/language/select.php @@ -6,17 +6,17 @@ namespace mirzaev\deeproots\models\telegram\processes\language; // Files of the project use mirzaev\deeproots\models\core, - mirzaev\deeproots\models\enumerations\language; + mirzaev\deeproots\models\enumerations\language; // Framework for Telegram use Zanzara\Context as context, - Zanzara\Telegram\Type\Message as message; + Zanzara\Telegram\Type\Message as message; // Baza database use mirzaev\baza\record; /** - * Telegram language select + * Telegram language select * * @package mirzaev\deeproots\models\telegram\processes\language * @@ -25,126 +25,126 @@ use mirzaev\baza\record; */ final class select extends core { - /** - * Language - * - * Send the language choose menu - * - * @param context $context Request data from Telegram - * @param string $prefix Prefix for 'callback_data' (`$prefix . $language->name`) - * @param string $title Title of the message - * @param string $description Description of the message - * @param array $exclude Languages that will be excluded ['ru', 'en'...] - * - * @return void - */ - public static function menu(context $context, string $prefix, string $title, string $description, array $exclude = []): void - { - // Initializing the account - $account = $context->get('account'); + /** + * Language + * + * Send the language choose menu + * + * @param context $context Request data from Telegram + * @param string $prefix Prefix for 'callback_data' (`$prefix . $language->name`) + * @param string $title Title of the message + * @param string $description Description of the message + * @param array $exclude Languages that will be excluded ['ru', 'en'...] + * + * @return void + */ + public static function menu(context $context, string $prefix, string $title, string $description, array $exclude = []): void + { + // Initializing the account + $account = $context->get('account'); - if ($account instanceof record) { - // Initialized the account + if ($account instanceof record) { + // Initialized the account - // Initializing language - $language = $context->get('language'); + // Initializing language + $language = $context->get('language'); - if ($language) { - // Initialized language + if ($language) { + // Initialized language - // Initializing localization - $localization = $context->get('localization'); + // Initializing localization + $localization = $context->get('localization'); - if ($localization) { - // Initialized localization + if ($localization) { + // Initialized localization - // Declaring the buffer of generated keyboard with languages - $keyboard = []; + // Declaring the buffer of generated keyboard with languages + $keyboard = []; - // Initializing the iterator of rows - $row = 0; + // Initializing the iterator of rows + $row = 0; - // Initializing buffer of languages - $languages = language::cases(); + // Initializing buffer of languages + $languages = language::cases(); - // Deleting the actual language from buffer of languages - unset($languages[array_search($language, $languages, strict: true)]); + // Deleting the actual language from buffer of languages + unset($languages[array_search($language, $languages, strict: true)]); - // Sorting buffer of languages by the actual language - $languages = [$language, ...$languages]; + // Sorting buffer of languages by the actual language + $languages = [$language, ...$languages]; - foreach ($languages as $language) { - // Iterating over languages + foreach ($languages as $language) { + // Iterating over languages - // Skipping excluded languages - if (array_search($language->name, $exclude, strict: true) !== false) continue; + // Skipping excluded languages + if (array_search($language->name, $exclude, strict: true) !== false) continue; - // Initializing the row - $keyboard[$row] ??= []; + // Initializing the row + $keyboard[$row] ??= []; - // Writing the language choose button into the buffer of generated keyboard with languages - $keyboard[$row][] = [ - 'text' => ($language->flag() ? $language->flag() . ' ' : '') . $language->label($language), - 'callback_data' => $prefix . $language->name - ]; + // Writing the language choose button into the buffer of generated keyboard with languages + $keyboard[$row][] = [ + 'text' => ($language->flag() ? $language->flag() . ' ' : '') . $language->label($language), + 'callback_data' => $prefix . $language->name + ]; - // When reaching 4 buttons in a row, move to the next row - if (count($keyboard[$row]) === 4) ++$row; - } + // When reaching 4 buttons in a row, move to the next row + if (count($keyboard[$row]) === 4) ++$row; + } - // Writing the button for helping lozalizing - $keyboard[$row === 0 && empty($keyboard[0]) ? 0 : ++$row] = [ - [ - 'text' => '🗂 ' . $localization['select_language_button_add'], - 'url' => 'https://git.svoboda.works/mirzaev/deeproots/src/branch/stable/mirzaev/deeproots/system/localizations' - ] - ]; + // Writing the button for helping lozalizing + $keyboard[$row === 0 && empty($keyboard[0]) ? 0 : ++$row] = [ + [ + 'text' => '🗂 ' . $localization['select_language_button_add'], + 'url' => 'https://git.svoboda.works/mirzaev/deeproots/src/branch/stable/mirzaev/deeproots/system/localizations' + ] + ]; - // Sending the message - $context->sendMessage( - $title ?? '🌏 *' . $localization['select_language_title'] . "*\n" . ($description ?? $localization['select_language_description']), - [ - 'reply_markup' => [ - 'inline_keyboard' => $keyboard, - 'disable_notification' => true - ], - ] - ); - } else { - // Not initialized localization + // Sending the message + $context->sendMessage( + $title ?? '🌏 *' . $localization['select_language_title'] . "*\n" . ($description ?? $localization['select_language_description']), + [ + 'reply_markup' => [ + 'inline_keyboard' => $keyboard, + 'disable_notification' => true + ], + ] + ); + } else { + // Not initialized localization - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized language + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized language - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize language*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize language*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } + // Ending the conversation process + $context->endConversation(); + }); + } + } } diff --git a/mirzaev/deeproots/system/models/telegram/processes/question/create.php b/mirzaev/deeproots/system/models/telegram/processes/question/create.php index 8938f2a..4920438 100755 --- a/mirzaev/deeproots/system/models/telegram/processes/question/create.php +++ b/mirzaev/deeproots/system/models/telegram/processes/question/create.php @@ -6,22 +6,22 @@ namespace mirzaev\deeproots\models\telegram\processes\question; // Files of the project use mirzaev\deeproots\models\core, - mirzaev\deeproots\models\question, - mirzaev\deeproots\models\question\localization, - mirzaev\deeproots\models\answer, - mirzaev\deeproots\models\enumerations\language, - mirzaev\deeproots\models\telegram\commands, - mirzaev\deeproots\models\telegram\processes\question\search as process_question_search; + mirzaev\deeproots\models\question, + mirzaev\deeproots\models\question\localization, + mirzaev\deeproots\models\answer, + mirzaev\deeproots\models\enumerations\language, + mirzaev\deeproots\models\telegram\commands, + mirzaev\deeproots\models\telegram\processes\question\search as process_question_search; // Framework for Telegram use Zanzara\Context as context, - Zanzara\Telegram\Type\Message as message; + Zanzara\Telegram\Type\Message as message; // Baza database use mirzaev\baza\record; /** - * Question create (system) + * Question create (system) * * @package mirzaev\deeproots\models\telegram\processes\question * @@ -30,95 +30,95 @@ use mirzaev\baza\record; */ final class create extends core { - /** - * Process - * - * @var const string PROCESS Name of the process in the telegram user buffer - */ - public const string PROCESS = 'system_questions_create'; + /** + * Process + * + * @var const string PROCESS Name of the process in the telegram user buffer + */ + public const string PROCESS = 'system_questions_create'; - /** - * Start - * - * Starting the process - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function start(context $context): void - { - // Initializing the account - $account = $context->get('account'); + /** + * Start + * + * Starting the process + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function start(context $context): void + { + // Initializing the account + $account = $context->get('account'); - if ($account instanceof record) { - // Initialized the account + if ($account instanceof record) { + // Initialized the account - // Initializing language - $language = $context->get('language'); + // Initializing language + $language = $context->get('language'); - if ($language instanceof language) { - // Initialized language + if ($language instanceof language) { + // Initialized language - // Initializing localization - $localization = $context->get('localization'); + // Initializing localization + $localization = $context->get('localization'); - if ($localization) { - // Initialized localization + if ($localization) { + // Initialized localization - // Initializing the question model - $model_question = new question(); + // Initializing the question model + $model_question = new question(); - // Creating the question - $question = $model_question->create(); + // Creating the question + $question = $model_question->create(); - if ($question) { - // Created the question + if ($question) { + // Created the question - // Sending the message - $context->sendMessage('✅ *' . $localization[static::PROCESS . '_created'] . '*') - ->then(function (message $message) use ($context, $question) { - // Sended the message + // Sending the message + $context->sendMessage('✅ *' . $localization[static::PROCESS . '_created'] . '*') + ->then(function (message $message) use ($context, $question) { + // Sended the message - // Sending the question search menu - process_question_search::start($context, $question); - }); - }; - } else { - // Not initialized localization + // Sending the question search menu + process_question_search::start($context, $question); + }); + }; + } else { + // Not initialized localization - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized language + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized language - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize language*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize language*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message - // Ending the conversation process - $context->endConversation(); - }); - } - } + // Ending the conversation process + $context->endConversation(); + }); + } + } } diff --git a/mirzaev/deeproots/system/models/telegram/processes/question/localization/create.php b/mirzaev/deeproots/system/models/telegram/processes/question/localization/create.php index f441380..63dc6b3 100755 --- a/mirzaev/deeproots/system/models/telegram/processes/question/localization/create.php +++ b/mirzaev/deeproots/system/models/telegram/processes/question/localization/create.php @@ -6,21 +6,21 @@ namespace mirzaev\deeproots\models\telegram\processes\question\localization; // Files of the project use mirzaev\deeproots\models\core, - mirzaev\deeproots\models\question, - mirzaev\deeproots\models\question\localization, - mirzaev\deeproots\models\answer, - mirzaev\deeproots\models\enumerations\language, - mirzaev\deeproots\models\telegram\commands; + mirzaev\deeproots\models\question, + mirzaev\deeproots\models\question\localization, + mirzaev\deeproots\models\answer, + mirzaev\deeproots\models\enumerations\language, + mirzaev\deeproots\models\telegram\commands; // Framework for Telegram use Zanzara\Context as context, - Zanzara\Telegram\Type\Message as message; + Zanzara\Telegram\Type\Message as message; // Baza database use mirzaev\baza\record; /** - * Question localization create (system) + * Question localization create (system) * * @package mirzaev\deeproots\models\telegram\processes\question\localization * @@ -29,1096 +29,1096 @@ use mirzaev\baza\record; */ final class create extends core { - /** - * Process - * - * @var const string PROCESS Name of the process in the telegram user buffer - */ - public const string PROCESS = 'system_questions_localization_create'; - - /** - * Start - * - * Starting the process - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function start(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing language - $language = $context->get('language'); - - if ($language instanceof language) { - // Initialized language - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function (?array $question) use ($context, $account, $language, $localization) { - // Readed from the telegram user buffer - - if ($question) { - // Found started question create process - - // Sending the message - $context->sendMessage('📂 *' . $localization[static::PROCESS . '_continiued'] . '*') - ->then(function (message $message) use ($context, $account, $language, $localization) { - // Sended the message - - // Sending the question create menu - static::menu($context); - }); - } else { - // Not found started question create process - - // Initializing the question model - $model_question = new question(); - - // Creating the question - $question = $model_question->create(); - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $question) - ->then(function () use ($context, $account, $localization) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('📂 *' . $localization[static::PROCESS . '_started'] . '*') - ->then(function (message $message) use ($context, $account, $localization) { - // Sended the message - - // Sending the question create menu - static::menu($context); - }); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized language - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize language*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Cancel - * - * Ending the question create process - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function cancel(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function (?array $distribution) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($distribution) { - // Found started question create process - - // Deleting in the telegram user buffer - $context->deleteUserDataItem(static::PROCESS) - ->then(function () use ($context, $localization) { - // Deleted in the telegram user buffer - - // Sending the message - $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_canceled'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - }); - } else { - // Not found started question create process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * End - * - * Ending the question create process - * and creating the distribution record in the database - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function end(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing language - $language = $context->get('language'); - - if ($language instanceof language) { - // Initialized language - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function (?array $distribution) use ($context, $account, $language, $localization) { - // Readed from the telegram user buffer - - if ($distribution) { - // Found started question create process - - // Initializing the distribution model - $model_distribution = new distribution; - - // Creating the distribution - $created_distribution = $model_distribution->create( - creator: $account->identifier, - latitude: $distribution['latitude'], - longitude: $distribution['longitude'] - ); - - if ($created_distribution) { - // Created the distribution - - // Sending the message - $context->sendMessage('✏️ *' . $localization[static::PROCESS . '_created_distribution'] . '*') - ->then(function (message $message) use ($context, $account, $language, $localization, $distribution, $model_distribution, $created_distribution) { - // Sended the message - - // Initializing the distribution localization - $created_localization = $model_distribution->localization->create( - distribution: $created_distribution, - language: $distribution['localization']['language'], - name: $distribution['localization']['name'] - ); - - if ($created_localization) { - // Created the localization - - // Sending the message - $context->sendMessage('✏️ *' . $localization[static::PROCESS . '_created_localization'] . '*') - ->then(function (message $message) use ($context, $localization) { - // Sended the message - - // Deleting from the telegram user buffer - $context->deleteUserDataItem(static::PROCESS) - ->then(function () use ($context, $localization) { - // Deleted from the telegram user buffer - - // Sending the message - $context->sendMessage('✅ *' . $localization[static::PROCESS . '_completed'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - }); - }); - } else { - // Not created the distribution localization - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_created_localization'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - }); - } else { - // Not created the distribution - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_created_distribution'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not found started question create process - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized language - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize language*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Generation - * - * Sends the question create menu with parameters: language, name, location - * When all parameters was initialized then sends the complete button - * - * @param context $context Request data from Telegram - * - * @return void - */ - protected static function menu(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing language - $language = $context->get('language'); - - if ($language) { - // Initialized language - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function (?array $distribution) use ($context, $account, $language, $localization) { - // Readed from the telegram user buffer - - if ($distribution) { - // Found started question create process - - // Initializing the buffer of generated keyboard with languages - $keyboard = [ - [ - [ - 'text' => empty($distribution['localization']['language']) ? '🟢 ' . $localization[static::PROCESS . '_button_language'] : '🟢 ' . $localization['distribution_declaration_button_language'] . ': ' . $distribution['localization']['language']->flag() . ' ' . $distribution['localization']['language']->label($language), - 'callback_data' => static::PROCESS . '_language' - ] - ], - [ - [ - 'text' => empty($distribution['localization']['name']) ? '🔴 ' . $localization[static::PROCESS . '_button_name'] : '🟢 ' . $localization['distribution_declaration_button_name'] . ': ' . $distribution['localization']['name'], - 'callback_data' => static::PROCESS . '_name' - ] - ], - [ - [ - 'text' => empty($distribution['latitude']) || empty('longitude') ? '🔴 ' . $localization[static::PROCESS . '_button_location'] : '🟢 ' . $localization['distribution_declaration_button_location'] . ': ' . $distribution['latitude'] . ', ' . $distribution['longitude'], - 'callback_data' => static::PROCESS . '_location' - ] - ], - ]; - - // Initializing the index of last row - $last = count($keyboard); - - // Initializing the last row - $keyboard[$last] ??= []; - - // Initializing the button for canceling the generation process - $keyboard[$last][] = [ - 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], - 'callback_data' => static::PROCESS . '_cancel' - ]; - - if ( - !empty($distribution['localization']['language']) && - !empty($distribution['localization']['name']) && - !empty($distribution['latitude']) && - !empty($distribution['longitude']) - ) { - // Initialized all requeired parameters - - // Initializing the button for completing the generation process - $keyboard[$last][] = [ - 'text' => '✅ ' . $localization[static::PROCESS . '_button_confirm'], - 'callback_data' => static::PROCESS . '_end' - ]; - } - - // Ending the conversation process - $context->endConversation() - ->then(function () use ($context, $localization, $keyboard) { - // Deinitialized the conversation process - - // Sending the message - $context->sendMessage( - '📀 *' . $localization[static::PROCESS . '_generation'] . '*', - [ - 'reply_markup' => [ - 'inline_keyboard' => $keyboard, - 'disable_notification' => true, - 'remove_keyboard' => true - ], - ] - ); - }); - } else { - // Not found started question create process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized language - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize language*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function ($message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Language - * - * Write language into the question create buffer - * - * @param context $context Request data from Telegram - * @param language $new The language - * - * @return void - */ - public static function language(context $context, language $new): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing language - $language = $context->get('language'); - - if ($language instanceof language) { - // Initialized language - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function (?array $distribution) use ($context, $account, $language, $localization, $new) { - // Readed from the telegram user buffer - - if ($distribution) { - // Found started question create process - - try { - // Initializing the old language - $old = $distribution['localization']['language']; - - // Writing into the question create process buffer - $distribution['localization']['language'] = $new; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $distribution) - ->then(function () use ($context, $account, $language, $localization, $new, $old) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('✅ *' . $localization[static::PROCESS . '_language_update_success'] . '* ' . ($old->flag() ? $old->flag() . ' ' : '') . $old->label($language) . ' → *' . ($new->flag() ? $new->flag() . ' ' : '') . $new->label($language) . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Sending the question create menu - static::menu($context); - }); - }); - } catch (error $error) { - // Failed to send the message about language update - - // Sending the message - $context->sendMessage('❎ *' . $localization[static::PROCESS . '_language_update_fail']) - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not found started question create process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized language - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize language*') - ->then(function ($message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Name - * - * Write name into the question create buffer - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function name(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function (?array $distribution) use ($context, $account, $localization) { - // Readed from the telegram user buffer - - if ($distribution) { - // Found started question create process - - // Initializing the new name - $new = $context->getMessage()->getText(); - - if (!empty($new)) { - // Initialized the new name - - if (mb_strlen($new) >= 3) { - // Passed minimum length check - - if (mb_strlen($new) <= 64) { - // Passed maximum length check - - // Search for restricted characters - preg_match_all('/[\W\d]/u', $new, $matches); - - // Declaring the buffer of found restricted characters (except spaces) - $characters = []; - - // Declaring the counter of found spaces - $spaces = 0; - - foreach ($matches[0] as $match) { - // Iterating over found restricted characters - - if ($match === ' ') { - // Space-character - - // Increasing the counter of found spaces - ++$spaces; - } else { - // Not space-character - - // Writing into the buffer of found restricted characers (except spaces) - $characters[] = $match; - } - } - - if (empty($characters)) { - // Not found restricted characters - - if ($spaces <= 2) { - // Number of spaces is not more than 2 - - try { - // Initializing the old name - $old = empty($distribution['localization']['name']) ? '_' . $localization['empty'] . '_' : $distribution['localization']['name']; - - // Writing into the question create process buffer - $distribution['localization']['name'] = $new; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $distribution) - ->then(function () use ($context, $account, $localization, $new, $old) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('✅ *' . $localization[static::PROCESS . '_name_update_success'] . "* $old → *$new*") - ->then(function (message $message) use ($context) { - // Sended the message - - // Sending the question create menu - static::menu($context); - }); - }); - } catch (error $error) { - // Failed to send the message about name update - - // Sending the message - $context->sendMessage('❎ *' . $localization[static::PROCESS . '_name_update_fail']) - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Number of spaces is more than 2 - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_name_request_spaces'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter name again - button_question_create::name($context); - }); - } - } else { - // Found restricted characters - - // Initializing title of the message - $title = '⚠️ *' . $localization[static::PROCESS . '_name_request_restricted_characters_title'] . '*'; - - // Initializing description of the message - $description = '*' . $localization[static::PROCESS . '_name_request_restricted_characters_description'] . '* \\' . implode(', \\', $characters); - - // Sending the message - $context->sendMessage( - <<then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter name again - button_question_create::name($context); - }); - } - } else { - // Not passed maximum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_name_request_too_long'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter name again - button_question_create::name($context); - }); - } - } else { - // Not passed minimum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_name_request_too_short'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter name again - button_question_create::name($context); - }); - } - } else { - // Failed to initialize the new name - - // Sending the message - $context->sendMessage('📄 *' . $localization[static::PROCESS . '_name_request_not_acceptable'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter name again - button_question_create::name($context); - }); - } - } else { - // Not found started question create process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Location - * - * Write latitude and longitude into the question create buffer - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function location(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function (?array $distribution) use ($context, $account, $localization) { - // Readed from the telegram user buffer - - if ($distribution) { - // Found started declaration process - - // Initializing the new location - preg_match_all('/(\-?\d{1,2})\.?(\d*)/', $context->getMessage()->getText(), $matches); - - if ($matches[0]) { - // Initialized the new location - - // Initializing the new latitude - $latitude = round((float) $matches[0][0], 6); - - // Initializing the new longitude - $longitude = round((float) $matches[0][1], 6); - - if (!empty($latitude) && !empty($longitude)) { - // Initialized the new latitude and the new longitude - - if ($latitude >= 0) { - // Passed latitude minimum value check - - if ($latitude <= 90) { - // Passed latitude maximum value check - - if ($longitude >= 0) { - // Passed longitude minimum value check - - if ($longitude <= 180) { - // Passed longitude maximum value check - - try { - // Initializing the old location - $old = str_replace('.', '\\.', (empty($distribution['latitude']) ? '_' . $localization['empty'] . '_' : $distribution['latitude']) . ', ' . (empty($distribution['longitude']) ? '_' . $localization['empty'] . '_' : $distribution['longitude'])); - - // Writing into the question create process buffer - $distribution['latitude'] = $latitude; - $distribution['longitude'] = $longitude; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $distribution) - ->then(function () use ($context, $account, $localization, $latitude, $longitude, $old) { - // Writed to the telegram user buffer - - // Initializing the new location - $new = str_replace('.', '\\.', $latitude . ', ' . $longitude); - - // Sending the message - $context->sendMessage('✅ *' . $localization[static::PROCESS . '_location_update_success'] . "*\n$old → *$new*") - ->then(function (message $message) use ($context) { - // Sended the message - - // Sending the question create menu - static::menu($context); - }); - }); - } catch (error $error) { - // Failed to send the message about name update - - // Sending the message - $context->sendMessage('❎ *' . $localization[static::PROCESS . '_name_update_fail']) - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not passed longitude maximum value check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_location_send_longitude_too_big'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter locaztion again - button_question_create::location($context); - }); - } - } else { - // Not passed longitude minimum value check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_location_send_longitude_too_small'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter locaztion again - button_question_create::location($context); - }); - } - } else { - // Not passed latitude maximum value check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_location_send_latitude_too_big'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter locaztion again - button_question_create::location($context); - }); - } - } else { - // Not passed latitude minimum value check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_location_send_latitude_too_small'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter locaztion again - button_question_create::location($context); - }); - } - } else { - // Failed to initialize the new name - - // Sending the message - $context->sendMessage('📄 *' . $localization[static::PROCESS . '_location_send_not_acceptable'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to send location again - button_question_create::location($context); - }); - } - } else { - // Not initialized the new location - - // Sending the message - $context->sendMessage('📄 *' . $localization[static::PROCESS . '_location_send_not_acceptable'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to send locaztion again - button_question_create::location($context); - }); - } - } else { - // Not found started distribution declaratoin process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } + /** + * Process + * + * @var const string PROCESS Name of the process in the telegram user buffer + */ + public const string PROCESS = 'system_questions_localization_create'; + + /** + * Start + * + * Starting the process + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function start(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing language + $language = $context->get('language'); + + if ($language instanceof language) { + // Initialized language + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function (?array $question) use ($context, $account, $language, $localization) { + // Readed from the telegram user buffer + + if ($question) { + // Found started question create process + + // Sending the message + $context->sendMessage('📂 *' . $localization[static::PROCESS . '_continiued'] . '*') + ->then(function (message $message) use ($context, $account, $language, $localization) { + // Sended the message + + // Sending the question create menu + static::menu($context); + }); + } else { + // Not found started question create process + + // Initializing the question model + $model_question = new question(); + + // Creating the question + $question = $model_question->create(); + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $question) + ->then(function () use ($context, $account, $localization) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('📂 *' . $localization[static::PROCESS . '_started'] . '*') + ->then(function (message $message) use ($context, $account, $localization) { + // Sended the message + + // Sending the question create menu + static::menu($context); + }); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized language + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize language*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Cancel + * + * Ending the question create process + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function cancel(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function (?array $distribution) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($distribution) { + // Found started question create process + + // Deleting in the telegram user buffer + $context->deleteUserDataItem(static::PROCESS) + ->then(function () use ($context, $localization) { + // Deleted in the telegram user buffer + + // Sending the message + $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_canceled'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + }); + } else { + // Not found started question create process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * End + * + * Ending the question create process + * and creating the distribution record in the database + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function end(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing language + $language = $context->get('language'); + + if ($language instanceof language) { + // Initialized language + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function (?array $distribution) use ($context, $account, $language, $localization) { + // Readed from the telegram user buffer + + if ($distribution) { + // Found started question create process + + // Initializing the distribution model + $model_distribution = new distribution; + + // Creating the distribution + $created_distribution = $model_distribution->create( + creator: $account->identifier, + latitude: $distribution['latitude'], + longitude: $distribution['longitude'] + ); + + if ($created_distribution) { + // Created the distribution + + // Sending the message + $context->sendMessage('✏️ *' . $localization[static::PROCESS . '_created_distribution'] . '*') + ->then(function (message $message) use ($context, $account, $language, $localization, $distribution, $model_distribution, $created_distribution) { + // Sended the message + + // Initializing the distribution localization + $created_localization = $model_distribution->localization->create( + distribution: $created_distribution, + language: $distribution['localization']['language'], + name: $distribution['localization']['name'] + ); + + if ($created_localization) { + // Created the localization + + // Sending the message + $context->sendMessage('✏️ *' . $localization[static::PROCESS . '_created_localization'] . '*') + ->then(function (message $message) use ($context, $localization) { + // Sended the message + + // Deleting from the telegram user buffer + $context->deleteUserDataItem(static::PROCESS) + ->then(function () use ($context, $localization) { + // Deleted from the telegram user buffer + + // Sending the message + $context->sendMessage('✅ *' . $localization[static::PROCESS . '_completed'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + }); + }); + } else { + // Not created the distribution localization + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_created_localization'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + }); + } else { + // Not created the distribution + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_created_distribution'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not found started question create process + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized language + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize language*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Generation + * + * Sends the question create menu with parameters: language, name, location + * When all parameters was initialized then sends the complete button + * + * @param context $context Request data from Telegram + * + * @return void + */ + protected static function menu(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing language + $language = $context->get('language'); + + if ($language) { + // Initialized language + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function (?array $distribution) use ($context, $account, $language, $localization) { + // Readed from the telegram user buffer + + if ($distribution) { + // Found started question create process + + // Initializing the buffer of generated keyboard with languages + $keyboard = [ + [ + [ + 'text' => empty($distribution['localization']['language']) ? '🟢 ' . $localization[static::PROCESS . '_button_language'] : '🟢 ' . $localization['distribution_declaration_button_language'] . ': ' . $distribution['localization']['language']->flag() . ' ' . $distribution['localization']['language']->label($language), + 'callback_data' => static::PROCESS . '_language' + ] + ], + [ + [ + 'text' => empty($distribution['localization']['name']) ? '🔴 ' . $localization[static::PROCESS . '_button_name'] : '🟢 ' . $localization['distribution_declaration_button_name'] . ': ' . $distribution['localization']['name'], + 'callback_data' => static::PROCESS . '_name' + ] + ], + [ + [ + 'text' => empty($distribution['latitude']) || empty('longitude') ? '🔴 ' . $localization[static::PROCESS . '_button_location'] : '🟢 ' . $localization['distribution_declaration_button_location'] . ': ' . $distribution['latitude'] . ', ' . $distribution['longitude'], + 'callback_data' => static::PROCESS . '_location' + ] + ], + ]; + + // Initializing the index of last row + $last = count($keyboard); + + // Initializing the last row + $keyboard[$last] ??= []; + + // Initializing the button for canceling the generation process + $keyboard[$last][] = [ + 'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'], + 'callback_data' => static::PROCESS . '_cancel' + ]; + + if ( + !empty($distribution['localization']['language']) && + !empty($distribution['localization']['name']) && + !empty($distribution['latitude']) && + !empty($distribution['longitude']) + ) { + // Initialized all requeired parameters + + // Initializing the button for completing the generation process + $keyboard[$last][] = [ + 'text' => '✅ ' . $localization[static::PROCESS . '_button_confirm'], + 'callback_data' => static::PROCESS . '_end' + ]; + } + + // Ending the conversation process + $context->endConversation() + ->then(function () use ($context, $localization, $keyboard) { + // Deinitialized the conversation process + + // Sending the message + $context->sendMessage( + '📀 *' . $localization[static::PROCESS . '_generation'] . '*', + [ + 'reply_markup' => [ + 'inline_keyboard' => $keyboard, + 'disable_notification' => true, + 'remove_keyboard' => true + ], + ] + ); + }); + } else { + // Not found started question create process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized language + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize language*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function ($message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Language + * + * Write language into the question create buffer + * + * @param context $context Request data from Telegram + * @param language $new The language + * + * @return void + */ + public static function language(context $context, language $new): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing language + $language = $context->get('language'); + + if ($language instanceof language) { + // Initialized language + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function (?array $distribution) use ($context, $account, $language, $localization, $new) { + // Readed from the telegram user buffer + + if ($distribution) { + // Found started question create process + + try { + // Initializing the old language + $old = $distribution['localization']['language']; + + // Writing into the question create process buffer + $distribution['localization']['language'] = $new; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $distribution) + ->then(function () use ($context, $account, $language, $localization, $new, $old) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('✅ *' . $localization[static::PROCESS . '_language_update_success'] . '* ' . ($old->flag() ? $old->flag() . ' ' : '') . $old->label($language) . ' → *' . ($new->flag() ? $new->flag() . ' ' : '') . $new->label($language) . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Sending the question create menu + static::menu($context); + }); + }); + } catch (error $error) { + // Failed to send the message about language update + + // Sending the message + $context->sendMessage('❎ *' . $localization[static::PROCESS . '_language_update_fail']) + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not found started question create process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized language + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize language*') + ->then(function ($message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Name + * + * Write name into the question create buffer + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function name(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function (?array $distribution) use ($context, $account, $localization) { + // Readed from the telegram user buffer + + if ($distribution) { + // Found started question create process + + // Initializing the new name + $new = $context->getMessage()->getText(); + + if (!empty($new)) { + // Initialized the new name + + if (mb_strlen($new) >= 3) { + // Passed minimum length check + + if (mb_strlen($new) <= 64) { + // Passed maximum length check + + // Search for restricted characters + preg_match_all('/[\W\d]/u', $new, $matches); + + // Declaring the buffer of found restricted characters (except spaces) + $characters = []; + + // Declaring the counter of found spaces + $spaces = 0; + + foreach ($matches[0] as $match) { + // Iterating over found restricted characters + + if ($match === ' ') { + // Space-character + + // Increasing the counter of found spaces + ++$spaces; + } else { + // Not space-character + + // Writing into the buffer of found restricted characers (except spaces) + $characters[] = $match; + } + } + + if (empty($characters)) { + // Not found restricted characters + + if ($spaces <= 2) { + // Number of spaces is not more than 2 + + try { + // Initializing the old name + $old = empty($distribution['localization']['name']) ? '_' . $localization['empty'] . '_' : $distribution['localization']['name']; + + // Writing into the question create process buffer + $distribution['localization']['name'] = $new; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $distribution) + ->then(function () use ($context, $account, $localization, $new, $old) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('✅ *' . $localization[static::PROCESS . '_name_update_success'] . "* $old → *$new*") + ->then(function (message $message) use ($context) { + // Sended the message + + // Sending the question create menu + static::menu($context); + }); + }); + } catch (error $error) { + // Failed to send the message about name update + + // Sending the message + $context->sendMessage('❎ *' . $localization[static::PROCESS . '_name_update_fail']) + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Number of spaces is more than 2 + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_name_request_spaces'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter name again + button_question_create::name($context); + }); + } + } else { + // Found restricted characters + + // Initializing title of the message + $title = '⚠️ *' . $localization[static::PROCESS . '_name_request_restricted_characters_title'] . '*'; + + // Initializing description of the message + $description = '*' . $localization[static::PROCESS . '_name_request_restricted_characters_description'] . '* \\' . implode(', \\', $characters); + + // Sending the message + $context->sendMessage( + <<then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter name again + button_question_create::name($context); + }); + } + } else { + // Not passed maximum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_name_request_too_long'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter name again + button_question_create::name($context); + }); + } + } else { + // Not passed minimum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_name_request_too_short'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter name again + button_question_create::name($context); + }); + } + } else { + // Failed to initialize the new name + + // Sending the message + $context->sendMessage('📄 *' . $localization[static::PROCESS . '_name_request_not_acceptable'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter name again + button_question_create::name($context); + }); + } + } else { + // Not found started question create process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Location + * + * Write latitude and longitude into the question create buffer + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function location(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function (?array $distribution) use ($context, $account, $localization) { + // Readed from the telegram user buffer + + if ($distribution) { + // Found started declaration process + + // Initializing the new location + preg_match_all('/(\-?\d{1,2})\.?(\d*)/', $context->getMessage()->getText(), $matches); + + if ($matches[0]) { + // Initialized the new location + + // Initializing the new latitude + $latitude = round((float) $matches[0][0], 6); + + // Initializing the new longitude + $longitude = round((float) $matches[0][1], 6); + + if (!empty($latitude) && !empty($longitude)) { + // Initialized the new latitude and the new longitude + + if ($latitude >= 0) { + // Passed latitude minimum value check + + if ($latitude <= 90) { + // Passed latitude maximum value check + + if ($longitude >= 0) { + // Passed longitude minimum value check + + if ($longitude <= 180) { + // Passed longitude maximum value check + + try { + // Initializing the old location + $old = str_replace('.', '\\.', (empty($distribution['latitude']) ? '_' . $localization['empty'] . '_' : $distribution['latitude']) . ', ' . (empty($distribution['longitude']) ? '_' . $localization['empty'] . '_' : $distribution['longitude'])); + + // Writing into the question create process buffer + $distribution['latitude'] = $latitude; + $distribution['longitude'] = $longitude; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $distribution) + ->then(function () use ($context, $account, $localization, $latitude, $longitude, $old) { + // Writed to the telegram user buffer + + // Initializing the new location + $new = str_replace('.', '\\.', $latitude . ', ' . $longitude); + + // Sending the message + $context->sendMessage('✅ *' . $localization[static::PROCESS . '_location_update_success'] . "*\n$old → *$new*") + ->then(function (message $message) use ($context) { + // Sended the message + + // Sending the question create menu + static::menu($context); + }); + }); + } catch (error $error) { + // Failed to send the message about name update + + // Sending the message + $context->sendMessage('❎ *' . $localization[static::PROCESS . '_name_update_fail']) + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not passed longitude maximum value check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_location_send_longitude_too_big'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter locaztion again + button_question_create::location($context); + }); + } + } else { + // Not passed longitude minimum value check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_location_send_longitude_too_small'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter locaztion again + button_question_create::location($context); + }); + } + } else { + // Not passed latitude maximum value check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_location_send_latitude_too_big'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter locaztion again + button_question_create::location($context); + }); + } + } else { + // Not passed latitude minimum value check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_location_send_latitude_too_small'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter locaztion again + button_question_create::location($context); + }); + } + } else { + // Failed to initialize the new name + + // Sending the message + $context->sendMessage('📄 *' . $localization[static::PROCESS . '_location_send_not_acceptable'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to send location again + button_question_create::location($context); + }); + } + } else { + // Not initialized the new location + + // Sending the message + $context->sendMessage('📄 *' . $localization[static::PROCESS . '_location_send_not_acceptable'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to send locaztion again + button_question_create::location($context); + }); + } + } else { + // Not found started distribution declaratoin process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } } diff --git a/mirzaev/deeproots/system/models/telegram/processes/question/search.php b/mirzaev/deeproots/system/models/telegram/processes/question/search.php index 659851d..4448e4f 100755 --- a/mirzaev/deeproots/system/models/telegram/processes/question/search.php +++ b/mirzaev/deeproots/system/models/telegram/processes/question/search.php @@ -6,26 +6,26 @@ namespace mirzaev\deeproots\models\telegram\processes\question; // Files of the project use mirzaev\deeproots\models\core, - mirzaev\deeproots\models\question, - mirzaev\deeproots\models\question\localization as question_localization, - mirzaev\deeproots\models\answer, - mirzaev\deeproots\models\enumerations\language, - mirzaev\deeproots\models\telegram\commands, - mirzaev\deeproots\models\telegram\buttons\question\search as buttons_question_search, - mirzaev\deeproots\models\telegram\traits\escape; + mirzaev\deeproots\models\question, + mirzaev\deeproots\models\question\localization as question_localization, + mirzaev\deeproots\models\answer, + mirzaev\deeproots\models\enumerations\language, + mirzaev\deeproots\models\telegram\commands, + mirzaev\deeproots\models\telegram\buttons\question\search as buttons_question_search, + mirzaev\deeproots\models\telegram\traits\escape; // Baza database use mirzaev\baza\record; // Framework for Telegram use Zanzara\Context as context, - Zanzara\Telegram\Type\Message as message; + Zanzara\Telegram\Type\Message as message; // Event-driven library for PHP use function React\Async\await; /** - * Question create (system) + * Question create (system) * * @package mirzaev\deeproots\models\telegram\processes\question * @@ -34,2193 +34,2193 @@ use function React\Async\await; */ final class search extends core { - use escape; - - /** - * Process - * - * @var const string PROCESS Name of the process in the telegram user buffer - */ - public const string PROCESS = 'system_questions_search'; - - /** - * Start - * - * Starting the search process - * - * @param context $context Request data from Telegram - * @param int|null $identifier Identifier of the question - * - * @return void - */ - public static function start(context $context, ?int $identifier = null): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing language - $language = $context->get('language'); - - if ($language instanceof language) { - // Initialized language - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function (?array $search) use ($context, $account, $language, $localization, $identifier) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Sending the message - $context->sendMessage('🗂 *' . $localization[static::PROCESS . '_continued'] . '*') - ->then(function (message $message) use ($context, $account, $language, $localization) { - // Sended the message - - // Searching - static::search($context); - }); - } else { - // Not found started search process - - // Initializing the question search buffer - $search = [ - 'identifier' => $identifier, - 'text' => null, - 'A' => null, - 'B' => null, - 'C' => null, - 'D' => null, - 'page' => 0 - ]; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $account, $localization) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('🗂 *' . $localization[static::PROCESS . '_started'] . '*') - ->then(function (message $message) use ($context, $account, $localization) { - // Sended the message - - // Searching - static::search($context); - }); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized language - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize language*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * End - * - * Ending the search process - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function end(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function (?array $search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Deleting from the telegram user buffer - $context->deleteUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $search, $localization) { - // Deleted from the telegram user buffer - - // Sending the message - $context->sendMessage('🗂 *' . $localization[static::PROCESS . '_ended'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - }); - } else { - // Not found started search process - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Search - * - * Sends the list of found questions and menu with parameters - * - * @param context $context Request data from Telegram - * - * @return void - */ - protected static function search(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing language - $language = $context->get('language'); - - if ($language) { - // Initialized language - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function (?array $search) use ($context, $account, $language, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Initializing the buffer of generated keyboard with languages - $keyboard = [ - [ - [ - 'text' => empty($search['identifier']) ? '🔴 ' . $localization[static::PROCESS . '_button_identifier'] : '🟢 ' . $localization[static::PROCESS . '_button_identifier'] . ': ' . $search['identifier'], - 'callback_data' => static::PROCESS . '_identifier' - ] - ], - [ - [ - 'text' => empty($search['text']) ? '🔴 ' . $localization[static::PROCESS . '_button_text'] : '🟢 ' . $localization[static::PROCESS . '_button_text'] . ': ' . $search['text'], - 'callback_data' => static::PROCESS . '_text' - ] - ], - [ - [ - 'text' => empty($search['A']) ? '🔴 ' . $localization[static::PROCESS . '_button_a'] : '🟢 ' . $localization[static::PROCESS . '_button_a'] . ': ' . $search['A'], - 'callback_data' => static::PROCESS . '_a' - ] - ], - [ - [ - 'text' => empty($search['B']) ? '🔴 ' . $localization[static::PROCESS . '_button_b'] : '🟢 ' . $localization[static::PROCESS . '_button_b'] . ': ' . $search['B'], - 'callback_data' => static::PROCESS . '_b' - ] - ], - [ - [ - 'text' => empty($search['C']) ? '🔴 ' . $localization[static::PROCESS . '_button_c'] : '🟢 ' . $localization[static::PROCESS . '_button_c'] . ': ' . $search['C'], - 'callback_data' => static::PROCESS . '_c' - ] - ], - [ - [ - 'text' => empty($search['D']) ? '🔴 ' . $localization[static::PROCESS . '_button_d'] : '🟢 ' . $localization[static::PROCESS . '_button_d'] . ': ' . $search['D'], - 'callback_data' => static::PROCESS . '_d' - ] - ] - ]; - - // Ending the conversation process - $context->endConversation() - ->then(function () use ($context, $account, $language, $localization, $search, $keyboard) { - // Deinitialized the conversation process - - // Initializing the question model - $model_question = new question; - - // Initializing amount of questions for reading per page - $page = SYSTEM_QUESTIONS_SEARCH_PAGE; - - if ( - empty($search['identifier']) && - empty($search['text']) && - empty($search['A']) && - empty($search['B']) && - empty($search['C']) && - empty($search['D']) - ) { - // Each parameter is empty - - // Search for questions - $questions = $model_question->database->read( - amount: $page + 1, - offset: $search['page'] < 1 ? 0 : $page * $search['page'] - ); - } else { - // The search buffer has at least one parameter - - // Search for questions - $questions = $model_question->database->read( - filter: function (record $question) use ($search) { - // Initializing the matched buffer - $matched = false; - - if (!empty($search['identifier'])) { - // Requested search by identifier - - if ($question->identifier === $search['identifier']) { - // Identifier matched - - // Reinitializing the matched buffer - $matched = true; - } else { - // Identifier not matched - - // Exit (success) - return false; - } - } - - if ( - !empty($search['text']) || - !empty($search['A']) || - !empty($search['B']) || - !empty($search['C']) || - !empty($search['D']) - ) { - // Requested search with localizations - - // Initializing the buffer of result for localizations matchings process - $result = false; - - foreach (language::cases() as $case) { - // Iterating over languages - - // Initializing the question localization model - $model_question_localization = new question_localization($case); - - // Initializing localization - $localization = $model_question_localization->database->read( - filter: fn(record $localization) => $localization->identifier === $question->identifier, - amount: 1 - )[0] ?? null; - - if ($localization instanceof record) { - // Initialized the question localization - - if (!empty($search['text'])) { - // Requested search by localizations text - - // Splitting the localization text into parts - $parts = preg_split('/[\s]/', $localization->text); - - foreach ($parts as $part) { - // Iterating over localization text parts - - if (levenshtein($part, $search['text']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_TEXT_LEVENSHTEIN_DISTANCE) { - // Text matched by Levenshtein function - - // Reinitializing the matched buffer - $result = true; - - // Exit (success) - break 1; - } - } + use escape; + + /** + * Process + * + * @var const string PROCESS Name of the process in the telegram user buffer + */ + public const string PROCESS = 'system_questions_search'; + + /** + * Start + * + * Starting the search process + * + * @param context $context Request data from Telegram + * @param int|null $identifier Identifier of the question + * + * @return void + */ + public static function start(context $context, ?int $identifier = null): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing language + $language = $context->get('language'); + + if ($language instanceof language) { + // Initialized language + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function (?array $search) use ($context, $account, $language, $localization, $identifier) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Sending the message + $context->sendMessage('🗂 *' . $localization[static::PROCESS . '_continued'] . '*') + ->then(function (message $message) use ($context, $account, $language, $localization) { + // Sended the message + + // Searching + static::search($context); + }); + } else { + // Not found started search process + + // Initializing the question search buffer + $search = [ + 'identifier' => $identifier, + 'text' => null, + 'A' => null, + 'B' => null, + 'C' => null, + 'D' => null, + 'page' => 0 + ]; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $account, $localization) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('🗂 *' . $localization[static::PROCESS . '_started'] . '*') + ->then(function (message $message) use ($context, $account, $localization) { + // Sended the message + + // Searching + static::search($context); + }); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized language + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize language*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * End + * + * Ending the search process + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function end(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function (?array $search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Deleting from the telegram user buffer + $context->deleteUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $search, $localization) { + // Deleted from the telegram user buffer + + // Sending the message + $context->sendMessage('🗂 *' . $localization[static::PROCESS . '_ended'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + }); + } else { + // Not found started search process + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Search + * + * Sends the list of found questions and menu with parameters + * + * @param context $context Request data from Telegram + * + * @return void + */ + protected static function search(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing language + $language = $context->get('language'); + + if ($language) { + // Initialized language + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function (?array $search) use ($context, $account, $language, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Initializing the buffer of generated keyboard with languages + $keyboard = [ + [ + [ + 'text' => empty($search['identifier']) ? '🔴 ' . $localization[static::PROCESS . '_button_identifier'] : '🟢 ' . $localization[static::PROCESS . '_button_identifier'] . ': ' . $search['identifier'], + 'callback_data' => static::PROCESS . '_identifier' + ] + ], + [ + [ + 'text' => empty($search['text']) ? '🔴 ' . $localization[static::PROCESS . '_button_text'] : '🟢 ' . $localization[static::PROCESS . '_button_text'] . ': ' . $search['text'], + 'callback_data' => static::PROCESS . '_text' + ] + ], + [ + [ + 'text' => empty($search['A']) ? '🔴 ' . $localization[static::PROCESS . '_button_a'] : '🟢 ' . $localization[static::PROCESS . '_button_a'] . ': ' . $search['A'], + 'callback_data' => static::PROCESS . '_a' + ] + ], + [ + [ + 'text' => empty($search['B']) ? '🔴 ' . $localization[static::PROCESS . '_button_b'] : '🟢 ' . $localization[static::PROCESS . '_button_b'] . ': ' . $search['B'], + 'callback_data' => static::PROCESS . '_b' + ] + ], + [ + [ + 'text' => empty($search['C']) ? '🔴 ' . $localization[static::PROCESS . '_button_c'] : '🟢 ' . $localization[static::PROCESS . '_button_c'] . ': ' . $search['C'], + 'callback_data' => static::PROCESS . '_c' + ] + ], + [ + [ + 'text' => empty($search['D']) ? '🔴 ' . $localization[static::PROCESS . '_button_d'] : '🟢 ' . $localization[static::PROCESS . '_button_d'] . ': ' . $search['D'], + 'callback_data' => static::PROCESS . '_d' + ] + ] + ]; + + // Ending the conversation process + $context->endConversation() + ->then(function () use ($context, $account, $language, $localization, $search, $keyboard) { + // Deinitialized the conversation process + + // Initializing the question model + $model_question = new question; + + // Initializing amount of questions for reading per page + $page = SYSTEM_QUESTIONS_SEARCH_PAGE; + + if ( + empty($search['identifier']) && + empty($search['text']) && + empty($search['A']) && + empty($search['B']) && + empty($search['C']) && + empty($search['D']) + ) { + // Each parameter is empty + + // Search for questions + $questions = $model_question->database->read( + amount: $page + 1, + offset: $search['page'] < 1 ? 0 : $page * $search['page'] + ); + } else { + // The search buffer has at least one parameter + + // Search for questions + $questions = $model_question->database->read( + filter: function (record $question) use ($search) { + // Initializing the matched buffer + $matched = false; + + if (!empty($search['identifier'])) { + // Requested search by identifier + + if ($question->identifier === $search['identifier']) { + // Identifier matched + + // Reinitializing the matched buffer + $matched = true; + } else { + // Identifier not matched + + // Exit (success) + return false; + } + } + + if ( + !empty($search['text']) || + !empty($search['A']) || + !empty($search['B']) || + !empty($search['C']) || + !empty($search['D']) + ) { + // Requested search with localizations + + // Initializing the buffer of result for localizations matchings process + $result = false; + + foreach (language::cases() as $case) { + // Iterating over languages + + // Initializing the question localization model + $model_question_localization = new question_localization($case); + + // Initializing localization + $localization = $model_question_localization->database->read( + filter: fn(record $localization) => $localization->identifier === $question->identifier, + amount: 1 + )[0] ?? null; + + if ($localization instanceof record) { + // Initialized the question localization + + if (!empty($search['text'])) { + // Requested search by localizations text + + // Splitting the localization text into parts + $parts = preg_split('/[\s]/', $localization->text); + + foreach ($parts as $part) { + // Iterating over localization text parts + + if (levenshtein($part, $search['text']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_TEXT_LEVENSHTEIN_DISTANCE) { + // Text matched by Levenshtein function + + // Reinitializing the matched buffer + $result = true; + + // Exit (success) + break 1; + } + } - if ($result) { - // Text matched by Levenshtein function + if ($result) { + // Text matched by Levenshtein function - // Reinitializing the matched buffer - $matched = true; - } else { - // Text not matched by Levenshtein function + // Reinitializing the matched buffer + $matched = true; + } else { + // Text not matched by Levenshtein function - // Exit (success) - return false; - } - } + // Exit (success) + return false; + } + } - if (!empty($search['A'])) { - // Requested search by localizations A + if (!empty($search['A'])) { + // Requested search by localizations A - // Initializing the result status - $result = false; + // Initializing the result status + $result = false; - // Splitting the localization A into parts - $parts = preg_split('/[\s]/', $localization->A); + // Splitting the localization A into parts + $parts = preg_split('/[\s]/', $localization->A); - foreach ($parts as $part) { - // Iterating over localization A parts + foreach ($parts as $part) { + // Iterating over localization A parts - if (levenshtein($part, $search['A']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_A_LEVENSHTEIN_DISTANCE) { - // A matched by Levenshtein function + if (levenshtein($part, $search['A']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_A_LEVENSHTEIN_DISTANCE) { + // A matched by Levenshtein function - // Reinitializing the matched buffer - $result = true; + // Reinitializing the matched buffer + $result = true; - // Exit (success) - break 1; - } - } + // Exit (success) + break 1; + } + } - if ($result) { - // A matched by Levenshtein function + if ($result) { + // A matched by Levenshtein function - // Reinitializing the matched buffer - $matched = true; - } else { - // A not matched by Levenshtein function + // Reinitializing the matched buffer + $matched = true; + } else { + // A not matched by Levenshtein function - // Exit (success) - return false; - } - } + // Exit (success) + return false; + } + } - if (!empty($search['B'])) { - // Requested search by localizations B + if (!empty($search['B'])) { + // Requested search by localizations B - // Initializing the result status - $result = false; + // Initializing the result status + $result = false; - // Splitting the localization B into parts - $parts = preg_split('/[\s]/', $localization->B); + // Splitting the localization B into parts + $parts = preg_split('/[\s]/', $localization->B); - foreach ($parts as $part) { - // Iterating over localization B parts + foreach ($parts as $part) { + // Iterating over localization B parts - if (levenshtein($part, $search['B']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_B_LEVENSHTEIN_DISTANCE) { - // B matched by Levenshtein function + if (levenshtein($part, $search['B']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_B_LEVENSHTEIN_DISTANCE) { + // B matched by Levenshtein function - // Reinitializing the matched buffer - $result = true; + // Reinitializing the matched buffer + $result = true; - // Exit (success) - break 1; - } - } + // Exit (success) + break 1; + } + } - if ($result) { - // B matched by Levenshtein function + if ($result) { + // B matched by Levenshtein function - // Reinitializing the matched buffer - $matched = true; - } else { - // B not matched by Levenshtein function + // Reinitializing the matched buffer + $matched = true; + } else { + // B not matched by Levenshtein function - // Exit (success) - return false; - } - } + // Exit (success) + return false; + } + } - if (!empty($search['C'])) { - // Requested search by localizations C + if (!empty($search['C'])) { + // Requested search by localizations C - // Initializing the result status - $result = false; + // Initializing the result status + $result = false; - // Splitting the localization C into parts - $parts = preg_split('/[\s]/', $localization->C); + // Splitting the localization C into parts + $parts = preg_split('/[\s]/', $localization->C); - foreach ($parts as $part) { - // Iterating over localization C parts + foreach ($parts as $part) { + // Iterating over localization C parts - if (levenshtein($part, $search['C']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_C_LEVENSHTEIN_DISTANCE) { - // C matched by Levenshtein function + if (levenshtein($part, $search['C']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_C_LEVENSHTEIN_DISTANCE) { + // C matched by Levenshtein function - // Reinitializing the matched buffer - $result = true; + // Reinitializing the matched buffer + $result = true; - // Exit (success) - break 1; - } - } + // Exit (success) + break 1; + } + } - if ($result) { - // C matched by Levenshtein function + if ($result) { + // C matched by Levenshtein function - // Reinitializing the matched buffer - $matched = true; - } else { - // C not matched by Levenshtein function + // Reinitializing the matched buffer + $matched = true; + } else { + // C not matched by Levenshtein function - // Exit (success) - return false; - } - } + // Exit (success) + return false; + } + } - if (!empty($search['D'])) { - // Requested search by localizations D + if (!empty($search['D'])) { + // Requested search by localizations D - // Initializing the result status - $result = false; + // Initializing the result status + $result = false; - // Splitting the localization D into parts - $parts = preg_split('/[\s]/', $localization->D); + // Splitting the localization D into parts + $parts = preg_split('/[\s]/', $localization->D); - foreach ($parts as $part) { - // Iterating over localization D parts - - if (levenshtein($part, $search['D']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_D_LEVENSHTEIN_DISTANCE) { - // D matched by Levenshtein function + foreach ($parts as $part) { + // Iterating over localization D parts + + if (levenshtein($part, $search['D']) <= SYSTEM_QUESTIONS_SEARCH_QUESTION_D_LEVENSHTEIN_DISTANCE) { + // D matched by Levenshtein function - // Reinitializing the matched buffer - $result = true; - - // Exit (success) - break 1; - } - } - - if ($result) { - // D matched by Levenshtein function - - // Reinitializing the matched buffer - $matched = true; - } else { - // D not matched by Levenshtein function - - // Exit (success) - return false; - } - } - } - } - - // Reinitializing the matched buffer - $matched = $result; - } - - // Exit (success) - return $matched; - }, - amount: $page + 1, - offset: $search['page'] < 1 ? 0 : $page * $search['page'] - ); - } - - // Initializing the next page existence status - $next = count($questions) > $page; - - // Deleting the additional readed questions - unset($questions[$page]); - - // Sending the message - $context->sendMessage( - '🔍 *' . $localization[static::PROCESS . '_title'] . '*', - [ - 'reply_markup' => [ - 'inline_keyboard' => $keyboard, - 'disable_notification' => true, - 'remove_keyboard' => true - ], - ] - )->then(function (message $message) use ($context, $account, $language, $localization, $search, $page, $next, $questions) { - // Sended the message - - if (count($questions) > 0) { - // Initialized questions - - foreach ($questions as $question) { - // Iterating over found questions - - /* // Initializing the question localization model by the account language - $model_question_localization = new question_localization(language::{$account->language ?? LANGUAGE_DEFAULT} ?? language::{LANGUAGE_DEFAULT}); - - // Initializing the question localization - $question_localization = $model_question_localization->database->read( - filter: fn(record $localization) => $localization->identifier === $question->identifier, - amount: 1 - )[0] ?? null; - - if (is_null($question_localization)) { - // Failed to initialize the question localization by the account language - - // Reinitializing the question localization model by the default language - $model_question_localization = new question_localization(language::{LANGUAGE_DEFAULT}); - - // Initializing the question localization - $question_localization = $model_question_localization->database->read( - filter: fn(record $localization) => $localization->identifier === $question->identifier, - amount: 1 - )[0] ?? null; - - if (is_null($question_localization)) { - // Failed to initialize the question localization by the default language - - // Sending the message - await($context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_localized'] . '* \(' . $question->identifier . '\)') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - })); - - // Processing the next question - continue; - } - } */ - - // Initializing the message text - $text = static::message( - question: $question, - localization: $localization - ); - - // Initializing the message keyboard - $keyboard = static::keyboard( - question: $question, - localization: $localization - ); - - // Sending the message - await($context->sendMessage( - $text, - [ - 'reply_markup' => [ - 'inline_keyboard' => $keyboard, - 'disable_notification' => true, - 'remove_keyboard' => true - ], - ] - )); - } - - if ($next) { - // Exists the next page - - // Sending the message - $context->sendMessage( - '🔎 *' . $localization[static::PROCESS . '_page_next_exists'] . '*', - [ - 'reply_markup' => [ - 'inline_keyboard' => [ - [ - [ - 'text' => '🔒 ' . $localization[static::PROCESS . '_button_end'], - 'callback_data' => static::PROCESS . '_end' - ] - ], - [ - [ - 'text' => '📤 ' . $localization[static::PROCESS . '_button_page_next'] . ': ' . ++$search['page'], - 'callback_data' => static::PROCESS . '_next' - ] - ] - ], - 'disable_notification' => true, - 'remove_keyboard' => true - ], - ] - )->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } else { - // Not exists the next page - - // Sending the message - $context->sendMessage( - '🔎 *' . $localization[static::PROCESS . '_page_next_not_exists'] . '*', - [ - 'reply_markup' => [ - 'inline_keyboard' => [ - [ - [ - 'text' => '🔒 ' . $localization[static::PROCESS . '_button_end'], - 'callback_data' => static::PROCESS . '_end' - ] - ] - ], - 'disable_notification' => true, - 'remove_keyboard' => true - ], - ] - )->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized questions - - // Sending the message - $context->sendMessage( - '⚠️ *' . $localization[static::PROCESS . '_empty'] . '*', - [ - 'reply_markup' => [ - 'inline_keyboard' => [ - [ - [ - 'text' => '🔒 ' . $localization[static::PROCESS . '_button_end'], - 'callback_data' => static::PROCESS . '_end' - ] - ] - ], - 'disable_notification' => true, - 'remove_keyboard' => true - ], - ] - ) - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - }); - }); - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized language - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize language*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Next - * - * Write actual page + 1 into the question search buffer - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function next(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function ($search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Writing into the question search process buffer - ++$search['page']; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context) { - // Writed to the telegram user buffer - - // Searching - static::search($context); - }); - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Identifier - * - * Write identifier into the question search buffer - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function identifier(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function ($search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Initializing the button - $button = $context->getCallbackQuery()?->getData(); - - if ($button === 'cancel') { - // Cancel - - // Sending the message - $context->sendMessage('❎ *' . $localization[static::PROCESS . '_identifier_cancel_success'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Searching - static::search($context); - }); - } else if ($button === 'delete') { - // Delete - - // Writing into the question search process buffer - $search['identifier'] = null; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $localization) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_identifier_delete_success'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Searching - static::search($context); - }); - }); - } else { - // Write - - // Initializing the new identifier - $new = $context->getMessage()->getText(); - - if (!empty($new)) { - // Initialized the new identifier - - if (mb_strlen($new) >= 1) { - // Passed minimum length check - - if (mb_strlen($new) <= 12) { - // Passed maximum length check - - // Search for restricted characters - preg_match_all('/[^\d]/u', $new, $matches); - - // Declaring the buffer of found restricted characters - $characters = []; - - foreach ($matches[0] as $match) { - // Iterating over found restricted characters - - // Writing into the buffer of found restricted characers - $characters[] = $match; - } - - if (empty($characters)) { - // Not found restricted characters - - // Initializing the old identifier - $old = empty($search['identifier']) ? '_' . $localization['empty'] . '_' : $search['identifier']; - - // Writing into the question search process buffer - $search['identifier'] = (int) $new; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $localization, $new, $old) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('✅ *' . $localization[static::PROCESS . '_identifier_update_success'] . "* $old → *$new*") - ->then(function (message $message) use ($context) { - // Sended the message - - // Searching - static::search($context); - }); - }); - } else { - // Found restricted characters - - // Initializing title of the message - $title = '⚠️ *' . $localization[static::PROCESS . '_identifier_request_restricted_characters_title'] . '*'; - - // Initializing description of the message - $description = '*' . $localization[static::PROCESS . '_identifier_request_restricted_characters_description'] . '* \\' . implode(', \\', $characters); - - // Sending the message - $context->sendMessage( - <<then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter identifier again - buttons_question_search::identifier($context); - }); - } - } else { - // Not passed maximum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_identifier_request_too_long'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter identifier again - buttons_question_search::identifier($context); - }); - } - } else { - // Not passed minimum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_identifier_request_too_short'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter identifier again - buttons_question_search::identifier($context); - }); - } - } else { - // Failed to initialize the new identifier - - // Sending the message - $context->sendMessage('📄 *' . $localization[static::PROCESS . '_identifier_request_not_acceptable'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter identifier again - buttons_question_search::identifier($context); - }); - } - } - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Text - * - * Write text into the question search buffer - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function text(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function ($search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Initializing the button - $button = $context->getCallbackQuery()?->getData(); - - if ($button === 'cancel') { - // Cancel - - // Sending the message - $context->sendMessage('❎ *' . $localization[static::PROCESS . '_text_cancel_success'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Searching - static::search($context); - }); - } else if ($button === 'delete') { - // Delete - - // Writing into the question search process buffer - $search['text'] = null; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $localization) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_text_delete_success'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Searching - static::search($context); - }); - }); - } else { - // Write - - // Initializing the new text - $new = $context->getMessage()->getText(); - - if (!empty($new)) { - // Initialized the new text - - if (mb_strlen($new) >= 3) { - // Passed minimum length check - - if (mb_strlen($new) <= 256) { - // Passed maximum length check - - // Initializing the old text - $old = empty($search['text']) ? '_' . $localization['empty'] . '_' : $search['text']; - - // Writing into the question search process buffer - $search['text'] = $new; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $localization, $new, $old) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('✅ *' . $localization[static::PROCESS . '_text_update_success'] . "* $old → *" . escape::markdown($new) . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Searching - static::search($context); - }); - }); - } else { - // Not passed maximum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_text_request_too_long'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter text again - buttons_question_search::text($context); - }); - } - } else { - // Not passed minimum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_text_request_too_short'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter text again - buttons_question_search::text($context); - }); - } - } else { - // Failed to initialize the new text - - // Sending the message - $context->sendMessage('📄 *' . $localization[static::PROCESS . '_text_request_not_acceptable'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter text again - buttons_question_search::text($context); - }); - } - } - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - /** - * A - * - * Write A-answer into the question search buffer - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function a(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function ($search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Initializing the button - $button = $context->getCallbackQuery()?->getData(); - - if ($button === 'cancel') { - // Cancel - - // Sending the message - $context->sendMessage('❎ *' . $localization[static::PROCESS . '_a_cancel_success'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Searching - static::search($context); - }); - } else if ($button === 'delete') { - // Delete - - // Writing into the question search process buffer - $search['A'] = null; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $localization) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_a_delete_success'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Searching - static::search($context); - }); - }); - } else { - // Write - - // Initializing the new A-answer - $new = $context->getMessage()->getText(); - - if (!empty($new)) { - // Initialized the new A-answer - - if (mb_strlen($new) >= 3) { - // Passed minimum length check - - if (mb_strlen($new) <= 128) { - // Passed maximum length check - - // Initializing the old A-answer - $old = empty($search['A']) ? '_' . $localization['empty'] . '_' : $search['A']; - - // Writing into the question search process buffer - $search['A'] = $new; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $localization, $new, $old) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('✅ *' . $localization[static::PROCESS . '_a_update_success'] . "* $old → *" . escape::markdown($new) . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Searching - static::search($context); - }); - }); - } else { - // Not passed maximum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_a_request_too_long'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter A-answer again - buttons_question_search::a($context); - }); - } - } else { - // Not passed minimum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_a_request_too_short'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter A-answer again - buttons_question_search::a($context); - }); - } - } else { - // Failed to initialize the new A-answer - - // Sending the message - $context->sendMessage('📄 *' . $localization[static::PROCESS . '_a_request_not_acceptable'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter A-answer again - buttons_question_search::a($context); - }); - } - } - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - - /** - * B - * - * Write B-answer into the question search buffer - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function b(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function ($search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Initializing the button - $button = $context->getCallbackQuery()?->getData(); - - if ($button === 'cancel') { - // Cancel - - // Sending the message - $context->sendMessage('❎ *' . $localization[static::PROCESS . '_b_cancel_success'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Searching - static::search($context); - }); - } else if ($button === 'delete') { - // Delete - - // Writing into the question search process buffer - $search['B'] = null; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $localization) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_b_delete_success'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Searching - static::search($context); - }); - }); - } else { - // Write - - // Initializing the new B-answer - $new = $context->getMessage()->getText(); - - if (!empty($new)) { - // Initialized the new B-snswer - - if (mb_strlen($new) >= 3) { - // Passed minimum length check - - if (mb_strlen($new) <= 128) { - // Passed maximum length check - - // Initializing the old B-answer - $old = empty($search['B']) ? '_' . $localization['empty'] . '_' : $search['B']; - - // Writing into the question search process buffer - $search['B'] = $new; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $localization, $new, $old) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('✅ *' . $localization[static::PROCESS . '_b_update_success'] . "* $old → *" . escape::markdown($new) . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Searching - static::search($context); - }); - }); - } else { - // Not passed maximum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_b_request_too_long'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter B-answer again - buttons_question_search::b($context); - }); - } - } else { - // Not passed minimum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_b_request_too_short'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter B-answer again - buttons_question_search::b($context); - }); - } - } else { - // Failed to initialize the new B-answer - - // Sending the message - $context->sendMessage('📄 *' . $localization[static::PROCESS . '_b_request_not_acceptable'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter B-answer again - buttons_question_search::b($context); - }); - } - } - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * C - * - * Write C-answer into the question search buffer - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function c(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function ($search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Initializing the button - $button = $context->getCallbackQuery()?->getData(); - - if ($button === 'cancel') { - // Cancel - - // Sending the message - $context->sendMessage('❎ *' . $localization[static::PROCESS . '_c_cancel_success'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Searching - static::search($context); - }); - } else if ($button === 'delete') { - // Delete - - // Writing into the question search process buffer - $search['C'] = null; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $localization) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_c_delete_success'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Searching - static::search($context); - }); - }); - } else { - // Write - - // Initializing the new C-answer - $new = $context->getMessage()->getText(); - - if (!empty($new)) { - // Initialized the new C-answer - - if (mb_strlen($new) >= 3) { - // Passed minimum length check - - if (mb_strlen($new) <= 128) { - // Passed maximum length check - - // Initializing the old C-answer - $old = empty($search['C']) ? '_' . $localization['empty'] . '_' : $search['C']; - - // Writing into the question search process buffer - $search['C'] = $new; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $localization, $new, $old) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('✅ *' . $localization[static::PROCESS . '_c_update_success'] . "* $old → *" . escape::markdown($new) . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Searching - static::search($context); - }); - }); - } else { - // Not passed maximum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_c_request_too_long'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter C-answer again - buttons_question_search::c($context); - }); - } - } else { - // Not passed minimum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_c_request_too_short'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter C-answer again - buttons_question_search::c($context); - }); - } - } else { - // Failed to initialize the new text - - // Sending the message - $context->sendMessage('📄 *' . $localization[static::PROCESS . '_c_request_not_acceptable'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter C-answer again - buttons_question_search::c($context); - }); - } - } - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * D - * - * Write D-answer into the question search buffer - * - * @param context $context Request data from Telegram - * - * @return void - */ - public static function d(context $context): void - { - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Reading from the telegram user buffer - $context->getUserDataItem(static::PROCESS) - ->then(function ($search) use ($context, $localization) { - // Readed from the telegram user buffer - - if ($search) { - // Found started search process - - // Initializing the button - $button = $context->getCallbackQuery()?->getData(); - - if ($button === 'cancel') { - // Cancel - - // Sending the message - $context->sendMessage('❎ *' . $localization[static::PROCESS . '_d_cancel_success'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Searching - static::search($context); - }); - } else if ($button === 'delete') { - // Delete - - // Writing into the question search process buffer - $search['D'] = null; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $localization) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_d_delete_success'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Searching - static::search($context); - }); - }); - } else { - // Write - - // Initializing the new D-answer - $new = $context->getMessage()->getText(); - - if (!empty($new)) { - // Initialized the new D-answer - - if (mb_strlen($new) >= 3) { - // Passed minimum length check - - if (mb_strlen($new) <= 128) { - // Passed maximum length check - - // Initializing the old D-answer - $old = empty($search['D']) ? '_' . $localization['empty'] . '_' : $search['D']; - - // Writing into the question search process buffer - $search['D'] = $new; - - // Writing to the telegram user buffer - $context->setUserDataItem(static::PROCESS, $search) - ->then(function () use ($context, $localization, $new, $old) { - // Writed to the telegram user buffer - - // Sending the message - $context->sendMessage('✅ *' . $localization[static::PROCESS . '_d_update_success'] . "* $old → *" . escape::markdown($new) . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Searching - static::search($context); - }); - }); - } else { - // Not passed maximum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_d_request_too_long'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter D-answer again - buttons_question_search::d($context); - }); - } - } else { - // Not passed minimum length check - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_d_request_too_short'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter D-answer again - buttons_question_search::d($context); - }); - } - } else { - // Failed to initialize the new D-answer - - // Sending the message - $context->sendMessage('📄 *' . $localization[static::PROCESS . '_d_request_not_acceptable'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Requesting to enter D-answer again - buttons_question_search::d($context); - }); - } - } - } else { - // Not found started search process - - // Sending the message - $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - - // Sending the system questions menu - commands::system_questions($context); - }); - } - }); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Keyboard - * - * Generate inline keyboard - * - * @param record $question The question - * @param array $localization The account localization - * - * @return array Generated inline keyboard - */ - public static function keyboard(record $question, array $localization): array - { - // Declaring the toggle button - $toggle = []; - - if ($question->active) { - // Active - - // Initializing the toggle button - $toggle = [ - 'text' => '🟢 ' . $localization[static::PROCESS . '_button_active'], - 'callback_data' => static::PROCESS . '_deactivate' - ]; - } else { - // Inactive - - // Initializing the toggle button - $toggle = [ - 'text' => '🔴 ' . $localization[static::PROCESS . '_button_inactive'], - 'callback_data' => static::PROCESS . '_activate' - ]; - } - - // Exit (success) - return [ - [ - [ - 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], - 'callback_data' => static::PROCESS . '_delete' - ], - [ - 'text' => '🐣 ' . $localization[static::PROCESS . '_button_author'], - 'callback_data' => static::PROCESS . '_author' - ], - $toggle - ], - [ - [ - 'text' => '🔏 ' . $localization[static::PROCESS . '_button_answer'], - 'callback_data' => static::PROCESS . '_answer' - ], - [ - 'text' => '🌏 ' . $localization[static::PROCESS . '_button_localizations'], - 'callback_data' => static::PROCESS . '_localizations' - ], - ] - ]; - } - - /** - * Message text - * - * Generate text - * - * @param record $question The question - * @param array $localization The account localization - * - * @return string Generated text - */ - public static function message(record $question, array $localization): string - { - // Initializing the answer model - $model_answer = new answer(); - - // Initializing the answer - $answer = $model_answer->database->read( - filter: fn(record $record) => $record->identifier === $question->identifier, - amount: 1 - )[0] ?? null; - - // Declaring the questions list - $list = ''; - - foreach (language::cases() as $case) { - // Iterating over language - - // Initializing the localization model by the language - $model_question_localization = new question_localization(language: $case); - - // Initializing the localization - $_localization = $model_question_localization->database->read( - filter: fn(record $record) => $record->identifier === $question->identifier, - amount: 1 - )[0] ?? null; - - // Writing into the questions list - $list .= PHP_EOL . $case->flag() . ' *' . $case->label(language::{$account->language ?? 'en'} ?? language::en) . ':* ' . ($localization[$_localization instanceof record ? 'yes' : 'no']); - } - - // Deinitializing unnecessary variables - unset($case, $model_question, $model_question_localization, $model_answer, $amount); // Exit (success) - return sprintf( - <<identifier, - $localization[static::PROCESS . '_question_answer'], - $answer instanceof record ? "A:$answer->a B:$answer->b C:$answer->c D:$answer->d" : $localization['empty'], - $list - ); - } + // Reinitializing the matched buffer + $result = true; + + // Exit (success) + break 1; + } + } + + if ($result) { + // D matched by Levenshtein function + + // Reinitializing the matched buffer + $matched = true; + } else { + // D not matched by Levenshtein function + + // Exit (success) + return false; + } + } + } + } + + // Reinitializing the matched buffer + $matched = $result; + } + + // Exit (success) + return $matched; + }, + amount: $page + 1, + offset: $search['page'] < 1 ? 0 : $page * $search['page'] + ); + } + + // Initializing the next page existence status + $next = count($questions) > $page; + + // Deleting the additional readed questions + unset($questions[$page]); + + // Sending the message + $context->sendMessage( + '🔍 *' . $localization[static::PROCESS . '_title'] . '*', + [ + 'reply_markup' => [ + 'inline_keyboard' => $keyboard, + 'disable_notification' => true, + 'remove_keyboard' => true + ], + ] + )->then(function (message $message) use ($context, $account, $language, $localization, $search, $page, $next, $questions) { + // Sended the message + + if (count($questions) > 0) { + // Initialized questions + + foreach ($questions as $question) { + // Iterating over found questions + + /* // Initializing the question localization model by the account language + $model_question_localization = new question_localization(language::{$account->language ?? LANGUAGE_DEFAULT} ?? language::{LANGUAGE_DEFAULT}); + + // Initializing the question localization + $question_localization = $model_question_localization->database->read( + filter: fn(record $localization) => $localization->identifier === $question->identifier, + amount: 1 + )[0] ?? null; + + if (is_null($question_localization)) { + // Failed to initialize the question localization by the account language + + // Reinitializing the question localization model by the default language + $model_question_localization = new question_localization(language::{LANGUAGE_DEFAULT}); + + // Initializing the question localization + $question_localization = $model_question_localization->database->read( + filter: fn(record $localization) => $localization->identifier === $question->identifier, + amount: 1 + )[0] ?? null; + + if (is_null($question_localization)) { + // Failed to initialize the question localization by the default language + + // Sending the message + await($context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_localized'] . '* \(' . $question->identifier . '\)') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + })); + + // Processing the next question + continue; + } + } */ + + // Initializing the message text + $text = static::message( + question: $question, + localization: $localization + ); + + // Initializing the message keyboard + $keyboard = static::keyboard( + question: $question, + localization: $localization + ); + + // Sending the message + await($context->sendMessage( + $text, + [ + 'reply_markup' => [ + 'inline_keyboard' => $keyboard, + 'disable_notification' => true, + 'remove_keyboard' => true + ], + ] + )); + } + + if ($next) { + // Exists the next page + + // Sending the message + $context->sendMessage( + '🔎 *' . $localization[static::PROCESS . '_page_next_exists'] . '*', + [ + 'reply_markup' => [ + 'inline_keyboard' => [ + [ + [ + 'text' => '🔒 ' . $localization[static::PROCESS . '_button_end'], + 'callback_data' => static::PROCESS . '_end' + ] + ], + [ + [ + 'text' => '📤 ' . $localization[static::PROCESS . '_button_page_next'] . ': ' . ++$search['page'], + 'callback_data' => static::PROCESS . '_next' + ] + ] + ], + 'disable_notification' => true, + 'remove_keyboard' => true + ], + ] + )->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } else { + // Not exists the next page + + // Sending the message + $context->sendMessage( + '🔎 *' . $localization[static::PROCESS . '_page_next_not_exists'] . '*', + [ + 'reply_markup' => [ + 'inline_keyboard' => [ + [ + [ + 'text' => '🔒 ' . $localization[static::PROCESS . '_button_end'], + 'callback_data' => static::PROCESS . '_end' + ] + ] + ], + 'disable_notification' => true, + 'remove_keyboard' => true + ], + ] + )->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized questions + + // Sending the message + $context->sendMessage( + '⚠️ *' . $localization[static::PROCESS . '_empty'] . '*', + [ + 'reply_markup' => [ + 'inline_keyboard' => [ + [ + [ + 'text' => '🔒 ' . $localization[static::PROCESS . '_button_end'], + 'callback_data' => static::PROCESS . '_end' + ] + ] + ], + 'disable_notification' => true, + 'remove_keyboard' => true + ], + ] + ) + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + }); + }); + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized language + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize language*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Next + * + * Write actual page + 1 into the question search buffer + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function next(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function ($search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Writing into the question search process buffer + ++$search['page']; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context) { + // Writed to the telegram user buffer + + // Searching + static::search($context); + }); + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Identifier + * + * Write identifier into the question search buffer + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function identifier(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function ($search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Initializing the button + $button = $context->getCallbackQuery()?->getData(); + + if ($button === 'cancel') { + // Cancel + + // Sending the message + $context->sendMessage('❎ *' . $localization[static::PROCESS . '_identifier_cancel_success'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Searching + static::search($context); + }); + } else if ($button === 'delete') { + // Delete + + // Writing into the question search process buffer + $search['identifier'] = null; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $localization) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_identifier_delete_success'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Searching + static::search($context); + }); + }); + } else { + // Write + + // Initializing the new identifier + $new = $context->getMessage()->getText(); + + if (!empty($new)) { + // Initialized the new identifier + + if (mb_strlen($new) >= 1) { + // Passed minimum length check + + if (mb_strlen($new) <= 12) { + // Passed maximum length check + + // Search for restricted characters + preg_match_all('/[^\d]/u', $new, $matches); + + // Declaring the buffer of found restricted characters + $characters = []; + + foreach ($matches[0] as $match) { + // Iterating over found restricted characters + + // Writing into the buffer of found restricted characers + $characters[] = $match; + } + + if (empty($characters)) { + // Not found restricted characters + + // Initializing the old identifier + $old = empty($search['identifier']) ? '_' . $localization['empty'] . '_' : $search['identifier']; + + // Writing into the question search process buffer + $search['identifier'] = (int) $new; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $localization, $new, $old) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('✅ *' . $localization[static::PROCESS . '_identifier_update_success'] . "* $old → *$new*") + ->then(function (message $message) use ($context) { + // Sended the message + + // Searching + static::search($context); + }); + }); + } else { + // Found restricted characters + + // Initializing title of the message + $title = '⚠️ *' . $localization[static::PROCESS . '_identifier_request_restricted_characters_title'] . '*'; + + // Initializing description of the message + $description = '*' . $localization[static::PROCESS . '_identifier_request_restricted_characters_description'] . '* \\' . implode(', \\', $characters); + + // Sending the message + $context->sendMessage( + <<then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter identifier again + buttons_question_search::identifier($context); + }); + } + } else { + // Not passed maximum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_identifier_request_too_long'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter identifier again + buttons_question_search::identifier($context); + }); + } + } else { + // Not passed minimum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_identifier_request_too_short'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter identifier again + buttons_question_search::identifier($context); + }); + } + } else { + // Failed to initialize the new identifier + + // Sending the message + $context->sendMessage('📄 *' . $localization[static::PROCESS . '_identifier_request_not_acceptable'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter identifier again + buttons_question_search::identifier($context); + }); + } + } + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Text + * + * Write text into the question search buffer + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function text(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function ($search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Initializing the button + $button = $context->getCallbackQuery()?->getData(); + + if ($button === 'cancel') { + // Cancel + + // Sending the message + $context->sendMessage('❎ *' . $localization[static::PROCESS . '_text_cancel_success'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Searching + static::search($context); + }); + } else if ($button === 'delete') { + // Delete + + // Writing into the question search process buffer + $search['text'] = null; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $localization) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_text_delete_success'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Searching + static::search($context); + }); + }); + } else { + // Write + + // Initializing the new text + $new = $context->getMessage()->getText(); + + if (!empty($new)) { + // Initialized the new text + + if (mb_strlen($new) >= 3) { + // Passed minimum length check + + if (mb_strlen($new) <= 256) { + // Passed maximum length check + + // Initializing the old text + $old = empty($search['text']) ? '_' . $localization['empty'] . '_' : $search['text']; + + // Writing into the question search process buffer + $search['text'] = $new; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $localization, $new, $old) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('✅ *' . $localization[static::PROCESS . '_text_update_success'] . "* $old → *" . escape::markdown($new) . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Searching + static::search($context); + }); + }); + } else { + // Not passed maximum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_text_request_too_long'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter text again + buttons_question_search::text($context); + }); + } + } else { + // Not passed minimum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_text_request_too_short'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter text again + buttons_question_search::text($context); + }); + } + } else { + // Failed to initialize the new text + + // Sending the message + $context->sendMessage('📄 *' . $localization[static::PROCESS . '_text_request_not_acceptable'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter text again + buttons_question_search::text($context); + }); + } + } + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + /** + * A + * + * Write A-answer into the question search buffer + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function a(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function ($search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Initializing the button + $button = $context->getCallbackQuery()?->getData(); + + if ($button === 'cancel') { + // Cancel + + // Sending the message + $context->sendMessage('❎ *' . $localization[static::PROCESS . '_a_cancel_success'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Searching + static::search($context); + }); + } else if ($button === 'delete') { + // Delete + + // Writing into the question search process buffer + $search['A'] = null; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $localization) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_a_delete_success'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Searching + static::search($context); + }); + }); + } else { + // Write + + // Initializing the new A-answer + $new = $context->getMessage()->getText(); + + if (!empty($new)) { + // Initialized the new A-answer + + if (mb_strlen($new) >= 3) { + // Passed minimum length check + + if (mb_strlen($new) <= 128) { + // Passed maximum length check + + // Initializing the old A-answer + $old = empty($search['A']) ? '_' . $localization['empty'] . '_' : $search['A']; + + // Writing into the question search process buffer + $search['A'] = $new; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $localization, $new, $old) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('✅ *' . $localization[static::PROCESS . '_a_update_success'] . "* $old → *" . escape::markdown($new) . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Searching + static::search($context); + }); + }); + } else { + // Not passed maximum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_a_request_too_long'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter A-answer again + buttons_question_search::a($context); + }); + } + } else { + // Not passed minimum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_a_request_too_short'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter A-answer again + buttons_question_search::a($context); + }); + } + } else { + // Failed to initialize the new A-answer + + // Sending the message + $context->sendMessage('📄 *' . $localization[static::PROCESS . '_a_request_not_acceptable'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter A-answer again + buttons_question_search::a($context); + }); + } + } + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + + /** + * B + * + * Write B-answer into the question search buffer + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function b(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function ($search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Initializing the button + $button = $context->getCallbackQuery()?->getData(); + + if ($button === 'cancel') { + // Cancel + + // Sending the message + $context->sendMessage('❎ *' . $localization[static::PROCESS . '_b_cancel_success'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Searching + static::search($context); + }); + } else if ($button === 'delete') { + // Delete + + // Writing into the question search process buffer + $search['B'] = null; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $localization) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_b_delete_success'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Searching + static::search($context); + }); + }); + } else { + // Write + + // Initializing the new B-answer + $new = $context->getMessage()->getText(); + + if (!empty($new)) { + // Initialized the new B-snswer + + if (mb_strlen($new) >= 3) { + // Passed minimum length check + + if (mb_strlen($new) <= 128) { + // Passed maximum length check + + // Initializing the old B-answer + $old = empty($search['B']) ? '_' . $localization['empty'] . '_' : $search['B']; + + // Writing into the question search process buffer + $search['B'] = $new; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $localization, $new, $old) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('✅ *' . $localization[static::PROCESS . '_b_update_success'] . "* $old → *" . escape::markdown($new) . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Searching + static::search($context); + }); + }); + } else { + // Not passed maximum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_b_request_too_long'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter B-answer again + buttons_question_search::b($context); + }); + } + } else { + // Not passed minimum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_b_request_too_short'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter B-answer again + buttons_question_search::b($context); + }); + } + } else { + // Failed to initialize the new B-answer + + // Sending the message + $context->sendMessage('📄 *' . $localization[static::PROCESS . '_b_request_not_acceptable'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter B-answer again + buttons_question_search::b($context); + }); + } + } + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * C + * + * Write C-answer into the question search buffer + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function c(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function ($search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Initializing the button + $button = $context->getCallbackQuery()?->getData(); + + if ($button === 'cancel') { + // Cancel + + // Sending the message + $context->sendMessage('❎ *' . $localization[static::PROCESS . '_c_cancel_success'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Searching + static::search($context); + }); + } else if ($button === 'delete') { + // Delete + + // Writing into the question search process buffer + $search['C'] = null; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $localization) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_c_delete_success'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Searching + static::search($context); + }); + }); + } else { + // Write + + // Initializing the new C-answer + $new = $context->getMessage()->getText(); + + if (!empty($new)) { + // Initialized the new C-answer + + if (mb_strlen($new) >= 3) { + // Passed minimum length check + + if (mb_strlen($new) <= 128) { + // Passed maximum length check + + // Initializing the old C-answer + $old = empty($search['C']) ? '_' . $localization['empty'] . '_' : $search['C']; + + // Writing into the question search process buffer + $search['C'] = $new; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $localization, $new, $old) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('✅ *' . $localization[static::PROCESS . '_c_update_success'] . "* $old → *" . escape::markdown($new) . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Searching + static::search($context); + }); + }); + } else { + // Not passed maximum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_c_request_too_long'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter C-answer again + buttons_question_search::c($context); + }); + } + } else { + // Not passed minimum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_c_request_too_short'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter C-answer again + buttons_question_search::c($context); + }); + } + } else { + // Failed to initialize the new text + + // Sending the message + $context->sendMessage('📄 *' . $localization[static::PROCESS . '_c_request_not_acceptable'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter C-answer again + buttons_question_search::c($context); + }); + } + } + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * D + * + * Write D-answer into the question search buffer + * + * @param context $context Request data from Telegram + * + * @return void + */ + public static function d(context $context): void + { + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Reading from the telegram user buffer + $context->getUserDataItem(static::PROCESS) + ->then(function ($search) use ($context, $localization) { + // Readed from the telegram user buffer + + if ($search) { + // Found started search process + + // Initializing the button + $button = $context->getCallbackQuery()?->getData(); + + if ($button === 'cancel') { + // Cancel + + // Sending the message + $context->sendMessage('❎ *' . $localization[static::PROCESS . '_d_cancel_success'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Searching + static::search($context); + }); + } else if ($button === 'delete') { + // Delete + + // Writing into the question search process buffer + $search['D'] = null; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $localization) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('🗑 *' . $localization[static::PROCESS . '_d_delete_success'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Searching + static::search($context); + }); + }); + } else { + // Write + + // Initializing the new D-answer + $new = $context->getMessage()->getText(); + + if (!empty($new)) { + // Initialized the new D-answer + + if (mb_strlen($new) >= 3) { + // Passed minimum length check + + if (mb_strlen($new) <= 128) { + // Passed maximum length check + + // Initializing the old D-answer + $old = empty($search['D']) ? '_' . $localization['empty'] . '_' : $search['D']; + + // Writing into the question search process buffer + $search['D'] = $new; + + // Writing to the telegram user buffer + $context->setUserDataItem(static::PROCESS, $search) + ->then(function () use ($context, $localization, $new, $old) { + // Writed to the telegram user buffer + + // Sending the message + $context->sendMessage('✅ *' . $localization[static::PROCESS . '_d_update_success'] . "* $old → *" . escape::markdown($new) . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Searching + static::search($context); + }); + }); + } else { + // Not passed maximum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_d_request_too_long'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter D-answer again + buttons_question_search::d($context); + }); + } + } else { + // Not passed minimum length check + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_d_request_too_short'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter D-answer again + buttons_question_search::d($context); + }); + } + } else { + // Failed to initialize the new D-answer + + // Sending the message + $context->sendMessage('📄 *' . $localization[static::PROCESS . '_d_request_not_acceptable'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Requesting to enter D-answer again + buttons_question_search::d($context); + }); + } + } + } else { + // Not found started search process + + // Sending the message + $context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + + // Sending the system questions menu + commands::system_questions($context); + }); + } + }); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize your Telegram account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Keyboard + * + * Generate inline keyboard + * + * @param record $question The question + * @param array $localization The account localization + * + * @return array Generated inline keyboard + */ + public static function keyboard(record $question, array $localization): array + { + // Declaring the toggle button + $toggle = []; + + if ($question->active) { + // Active + + // Initializing the toggle button + $toggle = [ + 'text' => '🟢 ' . $localization[static::PROCESS . '_button_active'], + 'callback_data' => static::PROCESS . '_deactivate' + ]; + } else { + // Inactive + + // Initializing the toggle button + $toggle = [ + 'text' => '🔴 ' . $localization[static::PROCESS . '_button_inactive'], + 'callback_data' => static::PROCESS . '_activate' + ]; + } + + // Exit (success) + return [ + [ + [ + 'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'], + 'callback_data' => static::PROCESS . '_delete' + ], + [ + 'text' => '🐣 ' . $localization[static::PROCESS . '_button_author'], + 'callback_data' => static::PROCESS . '_author' + ], + $toggle + ], + [ + [ + 'text' => '🔏 ' . $localization[static::PROCESS . '_button_answer'], + 'callback_data' => static::PROCESS . '_answer' + ], + [ + 'text' => '🌏 ' . $localization[static::PROCESS . '_button_localizations'], + 'callback_data' => static::PROCESS . '_localizations' + ], + ] + ]; + } + + /** + * Message text + * + * Generate text + * + * @param record $question The question + * @param array $localization The account localization + * + * @return string Generated text + */ + public static function message(record $question, array $localization): string + { + // Initializing the answer model + $model_answer = new answer(); + + // Initializing the answer + $answer = $model_answer->database->read( + filter: fn(record $record) => $record->identifier === $question->identifier, + amount: 1 + )[0] ?? null; + + // Declaring the questions list + $list = ''; + + foreach (language::cases() as $case) { + // Iterating over language + + // Initializing the localization model by the language + $model_question_localization = new question_localization(language: $case); + + // Initializing the localization + $_localization = $model_question_localization->database->read( + filter: fn(record $record) => $record->identifier === $question->identifier, + amount: 1 + )[0] ?? null; + + // Writing into the questions list + $list .= PHP_EOL . $case->flag() . ' *' . $case->label(language::{$account->language ?? 'en'} ?? language::en) . ':* ' . ($localization[$_localization instanceof record ? 'yes' : 'no']); + } + + // Deinitializing unnecessary variables + unset($case, $model_question, $model_question_localization, $model_answer, $amount); // Exit (success) + return sprintf( + <<identifier, + $localization[static::PROCESS . '_question_answer'], + $answer instanceof record ? "A:$answer->a B:$answer->b C:$answer->c D:$answer->d" : $localization['empty'], + $list + ); + } } diff --git a/mirzaev/deeproots/system/models/telegram/settings.php b/mirzaev/deeproots/system/models/telegram/settings.php index 72baa1e..fc43b30 100755 --- a/mirzaev/deeproots/system/models/telegram/settings.php +++ b/mirzaev/deeproots/system/models/telegram/settings.php @@ -6,15 +6,15 @@ namespace mirzaev\deeproots\models\telegram; // Files of the project use mirzaev\deeproots\models\core, - mirzaev\deeproots\models\account, - mirzaev\deeproots\models\enumerations\language, - mirzaev\deeproots\models\telegram\middlewares; + mirzaev\deeproots\models\account, + mirzaev\deeproots\models\enumerations\language, + mirzaev\deeproots\models\telegram\middlewares; // Framework for Telegram use Zanzara\Zanzara, - Zanzara\Context as context, - Zanzara\Telegram\Type\Message as message, - Zanzara\Middleware\MiddlewareNode as node; + Zanzara\Context as context, + Zanzara\Telegram\Type\Message as message, + Zanzara\Middleware\MiddlewareNode as node; // Baza database use mirzaev\baza\record; @@ -32,125 +32,125 @@ use Error as error; */ final class settings extends core { - /** - * Language - * - * Write language into the account record - * - * @param context $context Request data from Telegram - * @param language $language The language - * - * @return void - */ - public static function language(context $context, language $language): void - { - // Initializing the account - $account = $context->get('account'); + /** + * Language + * + * Write language into the account record + * + * @param context $context Request data from Telegram + * @param language $language The language + * + * @return void + */ + public static function language(context $context, language $language): void + { + // Initializing the account + $account = $context->get('account'); - if ($account instanceof record) { - // Initialized the account + if ($account instanceof record) { + // Initialized the account - // Initializing localization - $localization = $context->get('localization'); + // Initializing localization + $localization = $context->get('localization'); - if ($localization) { - // Initialized localization - - // Initializing the account model - $model = new account(); + if ($localization) { + // Initialized localization - // Updating the account in the database - $updated = $model->database->read( - filter: fn(record $record) => $record->identifier === $account->identifier, - update: function (record &$record) use ($language) { - // Writing new language value into the record - $record->language = $language->name; - }, - amount: 1 - )[0] ?? null; + // Initializing the account model + $model = new account(); - if ($updated instanceof record) { - // Updated the account in the database + // Updating the account in the database + $updated = $model->database->read( + filter: fn(record $record) => $record->identifier === $account->identifier, + update: function (record &$record) use ($language) { + // Writing new language value into the record + $record->language = $language->name; + }, + amount: 1 + )[0] ?? null; - // Writing the updated account into the context variable - $context->set('account', $updated); + if ($updated instanceof record) { + // Updated the account in the database - middlewares::language($context, new node(function (context $context) use ($account, $updated) { - // Updated language + // Writing the updated account into the context variable + $context->set('account', $updated); - middlewares::localization($context, new node(function (context $context) use ($account, $updated) { - // Updated localization + middlewares::language($context, new node(function (context $context) use ($account, $updated) { + // Updated language - // Initializing localization - $localization = $context->get('localization'); + middlewares::localization($context, new node(function (context $context) use ($account, $updated) { + // Updated localization - if ($localization) { - // Initialized localization + // Initializing localization + $localization = $context->get('localization'); - try { - // Initializing the old language - $old = language::{$account->language}; + if ($localization) { + // Initialized localization - // Initializing the new language - $new = language::{$updated->language}; + try { + // Initializing the old language + $old = language::{$account->language}; - // Sending the message - $context->sendMessage('✅ *' . $localization['settings_language_update_success'] . '* ' . ($old->flag() ? $old->flag() . ' ' : '') . $old->label($new) . ' → *' . ($new->flag() ? $new->flag() . ' ' : '') . $new->label($new) . '*') - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } catch (error $error) { - // Failed to send the message about language update + // Initializing the new language + $new = language::{$updated->language}; - // Sending the message - $context->sendMessage('❎ *' . $localization['settings_language_update_fail']) - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized localization + // Sending the message + $context->sendMessage('✅ *' . $localization['settings_language_update_success'] . '* ' . ($old->flag() ? $old->flag() . ' ' : '') . $old->label($new) . ' → *' . ($new->flag() ? $new->flag() . ' ' : '') . $new->label($new) . '*') + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } catch (error $error) { + // Failed to send the message about language update - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - })); - })); - } else { - // Not updated the account in the database + // Sending the message + $context->sendMessage('❎ *' . $localization['settings_language_update_fail']) + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized localization - // Sending the message - $context->sendMessage('❎ *' . $localization['settings_language_update_fail']) - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized localization + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + })); + })); + } else { + // Not updated the account in the database - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account + // Sending the message + $context->sendMessage('❎ *' . $localization['settings_language_update_fail']) + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized localization - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Ending the conversation process - $context->endConversation(); - }); - } - } + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Ending the conversation process + $context->endConversation(); + }); + } + } } diff --git a/mirzaev/deeproots/system/models/telegram/traits/escape.php b/mirzaev/deeproots/system/models/telegram/traits/escape.php index a9dcf87..93625ce 100644 --- a/mirzaev/deeproots/system/models/telegram/traits/escape.php +++ b/mirzaev/deeproots/system/models/telegram/traits/escape.php @@ -14,44 +14,44 @@ namespace mirzaev\deeproots\models\telegram\traits; */ trait escape { - /** - * Markdown - * - * Escaping for markdown - * - * @param string $text Text - * @param array $exception Symbols excluded from escaping - * - * @return string Escaped text - */ - public static function markdown(string $text, array $exceptions = []): string - { - // Initializing the registry of symbols for escaping - $from = array_diff( - [ - '#', - '*', - '_', - '=', - '.', - '[', - ']', - '(', - ')', - '-', - '>', - '<', - '!', - '`' - ], - $exceptions - ); + /** + * Markdown + * + * Escaping for markdown + * + * @param string $text Text + * @param array $exception Symbols excluded from escaping + * + * @return string Escaped text + */ + public static function markdown(string $text, array $exceptions = []): string + { + // Initializing the registry of symbols for escaping + $from = array_diff( + [ + '#', + '*', + '_', + '=', + '.', + '[', + ']', + '(', + ')', + '-', + '>', + '<', + '!', + '`' + ], + $exceptions + ); - // Initializing the registry of targets for escaping - $to = []; - foreach ($from as $symbol) $to[] = "\\$symbol"; + // Initializing the registry of targets for escaping + $to = []; + foreach ($from as $symbol) $to[] = "\\$symbol"; - // Escaping and exit (success) - return str_replace($from, $to, $text); - } + // Escaping and exit (success) + return str_replace($from, $to, $text); + } } diff --git a/mirzaev/deeproots/system/public/telegram.php b/mirzaev/deeproots/system/public/telegram.php index dea0ab0..dfe51b1 100755 --- a/mirzaev/deeproots/system/public/telegram.php +++ b/mirzaev/deeproots/system/public/telegram.php @@ -78,7 +78,7 @@ $robot->onCommand('repository', [commands::class, 'repository']); /* $robot->onCommand('projects', [commands::class, 'projects']); */ $robot->onCommand('author', [commands::class, 'author']); $robot->onCommand('society', [commands::class, 'society']); -/* $robot->onCommand('system_settings', [commands::class, 'system_settings'])->middleware([middlewares::class, 'system_settings']); */ +// $robot->onCommand('system_settings', [commands::class, 'system_settings'])->middleware([middlewares::class, 'system']); // Initializing the robot settings language buttons handlers foreach (language::cases() as $language) { diff --git a/mirzaev/deeproots/system/views/templater.php b/mirzaev/deeproots/system/views/templater.php index 1052abe..cafaa3e 100755 --- a/mirzaev/deeproots/system/views/templater.php +++ b/mirzaev/deeproots/system/views/templater.php @@ -12,14 +12,14 @@ use mirzaev\minimal\controller; // Templater of views use Twig\Loader\FilesystemLoader, - Twig\Environment as twig, - Twig\Extra\Intl\IntlExtension as intl, - Twig\TwigFilter, - Twig\TwigFunction; + Twig\Environment as twig, + Twig\Extra\Intl\IntlExtension as intl, + Twig\TwigFilter, + Twig\TwigFunction; // Built-in libraries use ArrayAccess as array_access, - Error as error; + Error as error; /** * Templater @@ -38,174 +38,173 @@ use ArrayAccess as array_access, */ final class templater extends controller implements array_access { - /** - * Twig - * - * @var twig $twig Instance of the twig templater - */ - readonly public twig $twig; + /** + * Twig + * + * @var twig $twig Instance of the twig templater + */ + readonly public twig $twig; - /** - * Variables - * - * @var array $variables Registry of view global variables - */ - public array $variables = []; + /** + * Variables + * + * @var array $variables Registry of view global variables + */ + public array $variables = []; - /** - * Constructor of an instance - * - * @return void - */ - public function __construct() - { - // Initializing the Twig instance - $this->twig = new twig(new FilesystemLoader(VIEWS)); + /** + * Constructor of an instance + * + * @return void + */ + public function __construct() + { + // Initializing the Twig instance + $this->twig = new twig(new FilesystemLoader(VIEWS)); - // Initializing global variables - $this->twig->addGlobal('theme', 'default'); - $this->twig->addGlobal('server', $_SERVER); - $this->twig->addGlobal('cookies', $_COOKIE); - $this->twig->addGlobal('language', $language = $session?->buffer['language'] ?? language::en); - } + // Initializing global variables + $this->twig->addGlobal('theme', 'default'); + $this->twig->addGlobal('server', $_SERVER); + $this->twig->addGlobal('cookies', $_COOKIE); + $this->twig->addGlobal('language', $language = $session?->buffer['language'] ?? language::en); + } - /** - * Render - * - * Render the HTML-document - * - * @param string $file Related path to a HTML-document - * @param array $variables Registry of variables to push into registry of global variables - * - * @return ?string HTML-document - */ - public function render(string $file, array $variables = []): ?string - { - // Generation and exit (success) - return $this->twig->render('themes' . DIRECTORY_SEPARATOR . $this->twig->getGlobals()['theme'] . DIRECTORY_SEPARATOR . $file, $variables + $this->variables); + /** + * Render + * + * Render the HTML-document + * + * @param string $file Related path to a HTML-document + * @param array $variables Registry of variables to push into registry of global variables + * + * @return ?string HTML-document + */ + public function render(string $file, array $variables = []): ?string + { + // Generation and exit (success) + return $this->twig->render('themes' . DIRECTORY_SEPARATOR . $this->twig->getGlobals()['theme'] . DIRECTORY_SEPARATOR . $file, $variables + $this->variables); - } + } - /** - * Write - * - * Write the variable into the registry of the view global variables - * - * @param string $name Name of the variable - * @param mixed $value Value of the variable - * - * @return void - */ - public function __set(string $name, mixed $value = null): void - { - // Write the variable and exit (success) - $this->variables[$name] = $value; - } + /** + * Write + * + * Write the variable into the registry of the view global variables + * + * @param string $name Name of the variable + * @param mixed $value Value of the variable + * + * @return void + */ + public function __set(string $name, mixed $value = null): void + { + // Write the variable and exit (success) + $this->variables[$name] = $value; + } - /** - * Read - * - * Read the variable from the registry of the view global variables - * - * @param string $name Name of the variable - * - * @return mixed Content of the variable, if they are found - */ - public function __get(string $name): mixed - { - // Read the variable and exit (success) - return $this->variables[$name]; - } + /** + * Read + * + * Read the variable from the registry of the view global variables + * + * @param string $name Name of the variable + * + * @return mixed Content of the variable, if they are found + */ + public function __get(string $name): mixed + { + // Read the variable and exit (success) + return $this->variables[$name]; + } - /** - * Delete - * - * Delete the variable from the registry of the view global variables - * - * @param string $name Name of the variable - * - * @return void - */ - public function __unset(string $name): void - { - // Delete the variable and exit (success) - unset($this->variables[$name]); - } + /** + * Delete + * + * Delete the variable from the registry of the view global variables + * + * @param string $name Name of the variable + * + * @return void + */ + public function __unset(string $name): void + { + // Delete the variable and exit (success) + unset($this->variables[$name]); + } - /** - * Check of initialization - * - * Check of initialization in the registry of the view global variables - * - * @param string $name Name of the variable - * - * @return bool The variable is initialized? - */ - public function __isset(string $name): bool - { - // Check of initialization of the variable and exit (success) - return isset($this->variables[$name]); - } + /** + * Check of initialization + * + * Check of initialization in the registry of the view global variables + * + * @param string $name Name of the variable + * + * @return bool The variable is initialized? + */ + public function __isset(string $name): bool + { + // Check of initialization of the variable and exit (success) + return isset($this->variables[$name]); + } - /** - * Write - * - * Write the variable into the registry of the view global variables - * - * @param mixed $name Name of an offset of the variable - * @param mixed $value Value of the variable - * - * @return void - */ - public function offsetSet(mixed $name, mixed $value): void - { - // Write the variable and exit (success) - $this->variables[$name] = $value; - } + /** + * Write + * + * Write the variable into the registry of the view global variables + * + * @param mixed $name Name of an offset of the variable + * @param mixed $value Value of the variable + * + * @return void + */ + public function offsetSet(mixed $name, mixed $value): void + { + // Write the variable and exit (success) + $this->variables[$name] = $value; + } - /** - * Read - * - * Read the variable from the registry of the view global variables - * - * @param mixed $name Name of the variable - * - * @return mixed Content of the variable, if they are found - */ - public function offsetGet(mixed $name): mixed - { - // Read the variable and exit (success) - return $this->variables[$name]; - } + /** + * Read + * + * Read the variable from the registry of the view global variables + * + * @param mixed $name Name of the variable + * + * @return mixed Content of the variable, if they are found + */ + public function offsetGet(mixed $name): mixed + { + // Read the variable and exit (success) + return $this->variables[$name]; + } - /** - * Delete - * - * Delete the variable from the registry of the view global variables - * - * @param mixed $name Name of the variable - * - * @return void - */ - public function offsetUnset(mixed $name): void - { - // Delete the variable and exit (success) - unset($this->variables[$name]); - } + /** + * Delete + * + * Delete the variable from the registry of the view global variables + * + * @param mixed $name Name of the variable + * + * @return void + */ + public function offsetUnset(mixed $name): void + { + // Delete the variable and exit (success) + unset($this->variables[$name]); + } - /** - * Check of initialization - * - * Check of initialization in the registry of the view global variables - * - * @param mixed $name Name of the variable - * - * @return bool The variable is initialized? - */ - public function offsetExists(mixed $name): bool - { - // Check of initialization of the variable and exit (success) - return isset($this->variables[$name]); - } + /** + * Check of initialization + * + * Check of initialization in the registry of the view global variables + * + * @param mixed $name Name of the variable + * + * @return bool The variable is initialized? + */ + public function offsetExists(mixed $name): bool + { + // Check of initialization of the variable and exit (success) + return isset($this->variables[$name]); + } } - diff --git a/mirzaev/deeproots/system/views/themes/default/aside.html b/mirzaev/deeproots/system/views/themes/default/aside.html index afb2aa1..5490d9f 100644 --- a/mirzaev/deeproots/system/views/themes/default/aside.html +++ b/mirzaev/deeproots/system/views/themes/default/aside.html @@ -7,4 +7,4 @@ {% endblock %} {% block js %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/mirzaev/deeproots/system/views/themes/default/core.html b/mirzaev/deeproots/system/views/themes/default/core.html index 1bb43a7..6e9357a 100755 --- a/mirzaev/deeproots/system/views/themes/default/core.html +++ b/mirzaev/deeproots/system/views/themes/default/core.html @@ -2,30 +2,29 @@ - - {% use '/themes/default/head.html' with title as head_title, meta as head_meta, css as head_css %} + + {% use '/themes/default/head.html' with title as head_title, meta as head_meta, css as head_css %} - {% block title %} - {{ block('head_title') }} - {% endblock %} + {% block title %} + {{ block('head_title') }} + {% endblock %} - {% block meta %} - {{ block('head_meta') }} - {% endblock %} + {% block meta %} + {{ block('head_meta') }} + {% endblock %} - {{ block('head_css') }} - {% block css %} - {% endblock %} - + {{ block('head_css') }} + {% block css %} + {% endblock %} + - - {% block body %} - {% endblock %} + + {% block body %} + {% endblock %} - {% include '/themes/default/js.html' %} - {% block js %} - {% endblock %} - + {% include '/themes/default/js.html' %} + {% block js %} + {% endblock %} + - diff --git a/mirzaev/deeproots/system/views/themes/default/index.html b/mirzaev/deeproots/system/views/themes/default/index.html index 474fd75..5413f93 100755 --- a/mirzaev/deeproots/system/views/themes/default/index.html +++ b/mirzaev/deeproots/system/views/themes/default/index.html @@ -14,9 +14,9 @@ {{ block('header') }} {{ block('aside') }}
- {% block main %} - {{ main|raw }} - {% endblock %} + {% block main %} + {{ main|raw }} + {% endblock %}
{{ block('footer') }} {% endblock %}