generated from mirzaev/pot-php-telegram
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f1f73564a0 | |||
| 4757a81d95 | |||
| 4fdcae74be | |||
| 4839f950e5 | |||
| 3fa8e067a1 | |||
| 74d2eaa62b | |||
| 0692db9c80 | |||
| ebba2a970e |
@@ -23,28 +23,22 @@
|
||||
},
|
||||
"require": {
|
||||
"php": "^8.5",
|
||||
"mirzaev/minimal": "^3.7",
|
||||
"mirzaev/baza": "^3.4",
|
||||
"mirzaev/record": "^1.0",
|
||||
"mirzaev/minimal": "^3",
|
||||
"mirzaev/baza": "^3",
|
||||
"mirzaev/record": "^2.0",
|
||||
"mirzaev/languages": "^1.0",
|
||||
"mirzaev/currencies": "^2.0",
|
||||
"mirzaev/unmarkdown": "^1.0",
|
||||
"svoboda/time": "^1.0",
|
||||
"badfarm/zanzara": "^0.9.1",
|
||||
"twig/twig": "^3.2",
|
||||
"twig/extra-bundle": "^3.7",
|
||||
"twig/intl-extra": "^3.10",
|
||||
"react/filesystem": "^0.1.2",
|
||||
"nyholm/psr7": "^1.8",
|
||||
"irazasyed/telegram-bot-sdk": "^3.15",
|
||||
"nutgram/nutgram": "^4.40",
|
||||
"nutgram/nutgram": "^4.42",
|
||||
"psr/simple-cache": "^3.0",
|
||||
"symfony/cache": "^8.0"
|
||||
},
|
||||
"suggest": {
|
||||
"mirzaev/files": "Easy working with files",
|
||||
"mirzaev/currencies": "Easy currencies integration"
|
||||
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
||||
4342
composer.lock
generated
4342
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace kodorvan\constructor;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\account,
|
||||
kodorvan\constructor\models\authorizations,
|
||||
kodorvan\constructor\models\chat,
|
||||
kodorvan\constructor\models\tariff;
|
||||
|
||||
// Svoboda time
|
||||
use svoboda\time\statement as svoboda;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\record;
|
||||
|
||||
// Enabling debugging
|
||||
/* ini_set('error_reporting', E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1); */
|
||||
|
||||
// Initializing path to the public directory
|
||||
define('INDEX', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'public');
|
||||
|
||||
// Initializing path to the root directory
|
||||
define('ROOT', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
|
||||
|
||||
// Initializing path to the settings directory
|
||||
define('SETTINGS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'settings');
|
||||
|
||||
// Initializing path to the storage directory
|
||||
define('STORAGE', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage');
|
||||
|
||||
// Initializing path to the databases directory
|
||||
define('DATABASES', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'databases');
|
||||
|
||||
// Initializing path to the localizations directory
|
||||
define('LOCALIZATIONS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'localizations');
|
||||
|
||||
// Initiailizing telegram data
|
||||
require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php');
|
||||
|
||||
// Initializing dependencies
|
||||
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
|
||||
// Initializing the account model
|
||||
$account_model = new account();
|
||||
|
||||
// Searching for the account
|
||||
$account = $account_model->database->read(
|
||||
filter: fn(record $record) => $record->domain === 'buddy_volkodav',
|
||||
amount: 1,
|
||||
offset: 0
|
||||
)[0] ?? null;
|
||||
|
||||
var_dump($account);
|
||||
|
||||
// Initializing the account authorizations model
|
||||
$authorizations_model = new authorizations();
|
||||
|
||||
// Searching for the account authorizations
|
||||
$authorizations = $authorizations_model->database->read(
|
||||
filter: fn(record $record) => $record->account === $account->identifier,
|
||||
update: function (record $record) {
|
||||
$record->system_settings = 1;
|
||||
$record->system_deals = 1;
|
||||
$record->system_projects = 1;
|
||||
$record->system_invoices = 1;
|
||||
$record->updated = svoboda::timestamp();
|
||||
},
|
||||
amount: 1,
|
||||
offset: 0
|
||||
)[0] ?? null;
|
||||
|
||||
var_dump($authorizations);
|
||||
75
kodorvan/constructor/system/databases/scripts/workers.php
Normal file
75
kodorvan/constructor/system/databases/scripts/workers.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace kodorvan\constructor;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\account,
|
||||
kodorvan\constructor\models\authorizations,
|
||||
kodorvan\constructor\models\worker,
|
||||
kodorvan\constructor\models\tariff;
|
||||
|
||||
// The library for currencies support
|
||||
use mirzaev\currencies\currency;
|
||||
|
||||
// Svoboda time
|
||||
use svoboda\time\statement as svoboda;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\record;
|
||||
|
||||
// Enabling debugging
|
||||
/* ini_set('error_reporting', E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1); */
|
||||
|
||||
// Initializing path to the public directory
|
||||
define('INDEX', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'public');
|
||||
|
||||
// Initializing path to the root directory
|
||||
define('ROOT', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
|
||||
|
||||
// Initializing path to the settings directory
|
||||
define('SETTINGS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'settings');
|
||||
|
||||
// Initializing path to the storage directory
|
||||
define('STORAGE', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage');
|
||||
|
||||
// Initializing path to the databases directory
|
||||
define('DATABASES', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'databases');
|
||||
|
||||
// Initializing path to the localizations directory
|
||||
define('LOCALIZATIONS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'localizations');
|
||||
|
||||
// Initiailizing telegram data
|
||||
require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php');
|
||||
|
||||
// Initializing dependencies
|
||||
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
|
||||
// Initializing the account model
|
||||
$account_model = new account();
|
||||
|
||||
// Searching for the account
|
||||
$account = $account_model->read(
|
||||
filter: fn(record $record) => $record->domain === 'buddy_volkodav',
|
||||
);
|
||||
|
||||
var_dump($account);
|
||||
|
||||
// Searching for the account authorizations
|
||||
$authorizations = $account->authorizations();
|
||||
|
||||
var_dump($authorizations);
|
||||
|
||||
// Creating the worker
|
||||
$worker = new worker()->write(
|
||||
account: $account->identifier,
|
||||
hour: 2000,
|
||||
currency: currency::rub,
|
||||
active: true
|
||||
);
|
||||
|
||||
var_dump($worker);
|
||||
|
||||
@@ -10,7 +10,8 @@ return [
|
||||
// Главное меню
|
||||
'menu_title' => 'Главное меню',
|
||||
'menu_description_guest' => "🔥 *Создайте ваш первый проект* и получите *ориентировочную стоимость* всего за 2 минуты",
|
||||
'menu_description_partner' => "*Благодарю за выбор нашей команды*. Теперь Вы один из наших %d партнёров!",
|
||||
'menu_description_partner' => 'Благодарим за выбор нашей команды',
|
||||
'menu_cooperation' => '_Стараемся, чтобы сотрудничество с нами было максимально *комфортным* и *эффективным*_',
|
||||
'menu_update' => 'Последнее обновление',
|
||||
'menu_button_project_new' => 'Создать',
|
||||
'menu_button_projects' => 'Проекты',
|
||||
@@ -23,37 +24,96 @@ return [
|
||||
'account_authorized_system_settings' => 'Системный доступ к системным настройкам',
|
||||
|
||||
// Проект: создание
|
||||
'project_create_title' => 'Создание проекта',
|
||||
'project_create_description' => 'Получите ориентировочную стоимость всего за 2 минуты\!',
|
||||
'project_create_cost' => 'Стоимость',
|
||||
'project_create_button_request' => 'Заказать',
|
||||
'project_title' => 'Создание проекта',
|
||||
/* 'project_description' => "Расчитайте ориентировочное время разработки, затем выберите разработчиков и получите стоимость\n\nПосле расчётов можно будет отправить проект в заказ разработчикам и приложить ТЗ, либо краткое описание задачи\n\nМы погружаемся в проекты полностью, поэтому стараемся не распыляться - от степени нагрузки меняется коэффициент стоимости!", */
|
||||
'project_description' => "Установите параметры и получите ориентировочное время разработки\n\n_После расчётов можно отправить проект в заказ приложив ТЗ, либо описание задачи_",
|
||||
'project_warning_cost' => "Стоимость и сроки выполнения предоставлены для планирования и *не являются публичной офертой*",
|
||||
'project_team_warning' => "",
|
||||
'project_time' => 'Время',
|
||||
'project_time_hours' => 'ч',
|
||||
'project_time_hours_from' => 'от',
|
||||
'project_time_days' => 'дн',
|
||||
'project_cost' => 'Стоимость',
|
||||
'project_cost_prepayment' => 'Предоплата',
|
||||
'project_team_title' => 'Сбор команды',
|
||||
'project_team_description' => '_Вы можете *убрать* или *добавить* специалистов, создавая максимально удобное сотрудничество под вашу систему_',
|
||||
'project_team_warning_cost' => '_*Не влияет на время разработки*_',
|
||||
'project_team_button_programmers' => 'Программисты: %d%s',
|
||||
'project_team_button_designers' => 'Дизайнеры: %d%s',
|
||||
'project_team_button_boosters' => 'Бустеры: %d%s',
|
||||
'project_team_programmers_title' => 'Количество программистов',
|
||||
'project_team_programmers_description' => 'Никаких копий по шаблонам и конструкторов, только *чистый код с нуля* и наши *уникальные технологии* с *многолетней кодовой базой*',
|
||||
'project_team_programmers_request' => '_Отправьте предложение по *количеству программистов*_',
|
||||
'project_team_programmers_error_amount' => 'Мы можем предоставить до %d программистов',
|
||||
'project_team_designers_title' => 'Количество дизайнеров',
|
||||
'project_team_designers_description' => 'У каждого дизайнера своё *уникальное видение*, поэтому мы стараемся находить максимально подходящих под проект, но зачастую мы привлекаем сторонних дизайнеров\. Если у заказчика имеются свои проверенные дизайнеры, то мы готовы с ними сотрудничать',
|
||||
'project_team_designers_request' => '_Отправьте предложение по *количеству дизайнеров*_',
|
||||
'project_team_designers_error_amount' => 'Мы можем предоставить до %d дизайнеров',
|
||||
'project_team_boosters_title' => 'Количество бустеров',
|
||||
'project_team_boosters_description' => '*Бустер* \- обобщение для специалистов которые занимаются *маркетингом*, *рекламными кабинетами*, дошлифовкой интерфейса, *user\-experience*, А\/Б тестированием, сбором фокус\-группы, развитием сообщества и в целом *SMM*',
|
||||
'project_team_boosters_request' => '_Отправьте предложение по *количеству бустеров*_',
|
||||
'project_team_boosters_error_amount' => 'Мы можем предоставить до %d бустеров',
|
||||
'project_team_error_not_a_number' => 'Значение должно быть числом',
|
||||
'project_cost_title' => 'Стоимость разработки',
|
||||
'project_cost_description' => '*`%d%s`* \- средняя стоимость с учётом *компетенции*, совокупного опыта, *уникальных* разработок\. Цена уже включает\: *наши сервера*, документирование кода, *передачу кода*, ведение репозитория, *техподдержку* и репутационные гарантии',
|
||||
'project_cost_request' => '_Отправьте предложение по *оплате за 1 час* разработки_',
|
||||
'project_cost_warning' => '_Если цена окажется *недостаточной*, мы выставим *справедливое* и *конкурентное* встречное предложение_',
|
||||
'project_cost_error_distance' => 'Длина сообщения должна быть от %d и до %d символов',
|
||||
'project_cost_error_not_a_number' => 'Значение должно быть числом',
|
||||
'project_button_back' => 'Назад',
|
||||
'project_button_cost_per_hour' => 'Час',
|
||||
'project_button_request' => 'Заказать',
|
||||
|
||||
'project_create_types_title' => 'Выбор типа проекта',
|
||||
'project_create_types_description' => 'Каждый тип имеет уникальные параметры и коэффициент',
|
||||
'project_create_button_type' => 'Тип проекта',
|
||||
'project_create_button_type_selected' => 'Тип',
|
||||
'project_architectures_title' => 'Выбор архитектуры проекта',
|
||||
'project_architectures_description' => 'Каждая архитектура имеет уникальные параметры и коэффициенты \- это основа дальнейших расчётов\!',
|
||||
'project_button_architecture' => 'Архитектура',
|
||||
'project_button_architecture_selected' => 'Архитектура',
|
||||
|
||||
'project_create_purposes_title' => 'Выбор назначения',
|
||||
'project_create_purposes_description' => 'Вектор разработки, основание проекта',
|
||||
'project_create_button_purpose' => 'Назначение',
|
||||
'project_create_button_purpose_selected' => 'Назнач.',
|
||||
'project_purposes_title' => 'Выбор назначения',
|
||||
'project_purposes_description' => 'Вектор разработки, основание проекта',
|
||||
'project_button_purpose' => 'Назначение',
|
||||
'project_button_purpose_selected' => 'Назнач.',
|
||||
|
||||
'project_create_integrations_title' => 'Выбор интеграций',
|
||||
'project_create_integrations_description' => 'Синхронизация, скачивание, загрузка, запись...',
|
||||
'project_create_button_integrations' => 'Интеграции',
|
||||
'project_create_button_integrations_selected' => 'Интеграции',
|
||||
|
||||
'project_create_requested' => 'Проект создан и отправлен оператору',
|
||||
'project_create_cancelled' => 'Создание проекта отменено',
|
||||
'project_integrations_title' => 'Выбор интеграций',
|
||||
'project_integrations_description' => "Синхронизация заказов, товаров, публикаций и прочего в реальном времени, скачивание, загрузка, админ\-панель, рассылка сообщений, подключение аккаунтов\.\.\.\n\n_Отправка запросов в *API*, генерация и перехват *HTTP\-сообщений*, *эмуляция действий пользователя*_",
|
||||
'project_button_integrations' => 'Интеграции',
|
||||
'project_button_integrations_selected' => 'Интеграции',
|
||||
'project_button_team' => 'Команда: %d%s',
|
||||
'project_peoples' => '',
|
||||
'project_cancelled' => 'Создание проекта отменено',
|
||||
'project_deal_requested' => 'Проект создан и отправлен оператору',
|
||||
'project_deal_title' => 'Заказ #%d',
|
||||
'project_deal_architecture' => 'Архитектура',
|
||||
'project_deal_purpose' => 'Назначение',
|
||||
'project_deal_time' => 'Время',
|
||||
'project_deal_time_hours' => 'ч',
|
||||
'project_deal_time_hours_from' => 'от',
|
||||
'project_deal_time_days' => 'дн',
|
||||
'project_deal_cost' => 'Стоимость',
|
||||
'project_deal_team' => 'Команда',
|
||||
'project_deal_empty' => 'Пусто',
|
||||
'project_deal_button_accept' => 'Принять',
|
||||
'project_deal_button_refuse' => 'Отказать',
|
||||
'project_deal_button_edit' => 'Редактировать',
|
||||
'project_deal_button_chat' => 'Чат с заказчиком',
|
||||
'project_accepted_deal_not_found' => 'Не удалось найти заявку',
|
||||
'project_accepted_project_not_found' => 'Не удалось найти проект',
|
||||
'project_accepted_already_confirmed' => 'Сделка уже проведена',
|
||||
'project_accepted_title' => 'Заказ подтверждён\!',
|
||||
'project_accepted_description' => 'Мы изучили предложение и *согласились* на условия',
|
||||
'project_accepted_prepayment' => 'Предоплата',
|
||||
'project_accepted_documents' => '_При желании оформить договор о неразглашении и передаче прав, *обратитесь к оператору*_',
|
||||
'project_accepted_confirmed' => 'Подтверждено',
|
||||
'project_accepted_button_prepayment' => 'Оплатить через СБП',
|
||||
|
||||
// Проект: типы
|
||||
'project_type_chat_robot' => 'Чат-робот',
|
||||
'project_type_parser' => 'Парсер',
|
||||
'project_type_calculator' => 'Калькулятор',
|
||||
'project_type_crm' => 'CRM',
|
||||
'project_type_site' => 'Сайт',
|
||||
'project_type_program' => 'Программа',
|
||||
'project_type_complex' => 'Нестандартный',
|
||||
'project_architecture_chat_robot' => 'Чат-робот',
|
||||
'project_architecture_parser' => 'Парсер',
|
||||
'project_architecture_calculator' => 'Калькулятор',
|
||||
'project_architecture_crm' => 'CRM',
|
||||
'project_architecture_site' => 'Сайт',
|
||||
'project_architecture_program' => 'Программа',
|
||||
'project_architecture_complex' => 'Нестандартная',
|
||||
|
||||
// Проект: назначение
|
||||
'project_purpose_funnel' => 'Воронка',
|
||||
@@ -65,12 +125,21 @@ return [
|
||||
'project_purpose_marketplace' => 'Маркетплейс',
|
||||
'project_purpose_charity' => 'Благотворительность',
|
||||
'project_purpose_search' => 'Поиск',
|
||||
'project_purpose_calculate' => 'Расчёт',
|
||||
'project_purpose_calcul+ate' => 'Расчёт',
|
||||
'project_purpose_tools' => 'Инструменты',
|
||||
'project_purpose_workers' => 'Рабочие',
|
||||
'project_purpose_objects' => 'Предметы',
|
||||
'project_purpose_events' => 'События',
|
||||
'project_purpose_special' => 'Особенный',
|
||||
'project_purpose_special' => 'Особенное',
|
||||
|
||||
// Проект: интеграции
|
||||
'project_integration_one_c' => '1C',
|
||||
'project_integration_bitrix24' => 'Битрикс 24',
|
||||
'project_integration_moy_sklad' => 'Мой Склад',
|
||||
'project_integration_telegram' => 'Телеграм',
|
||||
'project_integration_mail' => 'Почта',
|
||||
'project_integration_excel' => 'Excel',
|
||||
/* 'project_integration_' => '', */
|
||||
|
||||
// Настройки: язык
|
||||
'settings_language_title' => 'Выбери язык',
|
||||
@@ -82,14 +151,24 @@ return [
|
||||
// Авторизация
|
||||
'authorization_system' => 'Система',
|
||||
'authorization_settings' => 'Настройки',
|
||||
'not_authorized_system' => 'У тебя нет доступа к системе',
|
||||
'not_authorized_settings' => 'У тебя нет доступа к настройкам',
|
||||
'not_authorized_system_settings' => 'У тебя нет доступа к системным настройкам',
|
||||
'not_authorized_system' => 'Запрещён доступ к системе',
|
||||
'not_authorized_settings' => 'Запрещён доступ к настройкам',
|
||||
'not_authorized_system_settings' => 'Запрещён системный доступ к настройкам',
|
||||
'not_authorized_system_deals' => 'Запрещён системный доступ к сделкам',
|
||||
'not_authorized_system_projects' => 'Запрещён системный доступ к проектам ',
|
||||
'not_authorized_system_invoices' => 'Запрещён системный доступ к счетам',
|
||||
|
||||
// Сообщения
|
||||
'message_initialization_fail' => 'Не удалось инициализировать сообщение Телеграм',
|
||||
'message_text_initialization_fail' => 'Не удалось инициализировать текст сообщения Телеграм',
|
||||
|
||||
'error_title' => 'Перегрузка\!',
|
||||
'error_description' => 'Чат\-робот обрабатывает *длинную очередь* запросов',
|
||||
'error_repeat' => 'Если не заработает *через 30 минут*, пишите оператору',
|
||||
'error_account' => 'Аккаунт',
|
||||
'error_button_chat_user' => 'Чат с пользователем',
|
||||
'error_button_chat_operator' => 'Чат с оператором',
|
||||
|
||||
// Прочее
|
||||
'why_so_shroomious' => 'почему такой грибъёзный'
|
||||
];
|
||||
|
||||
@@ -8,8 +8,9 @@ namespace kodorvan\constructor\models;
|
||||
use kodorvan\constructor\models\core,
|
||||
kodorvan\constructor\models\authorizations,
|
||||
kodorvan\constructor\models\settings,
|
||||
kodorvan\constructor\models\worker,
|
||||
kodorvan\constructor\models\project,
|
||||
kodorvan\constructor\models\project\enumerations\type as project_type,
|
||||
kodorvan\constructor\models\project\enumerations\architecture as project_architecture,
|
||||
kodorvan\constructor\models\project\enumerations\status as project_status;
|
||||
|
||||
// The library for languages support
|
||||
@@ -65,6 +66,13 @@ final class account extends core implements record_interface
|
||||
*/
|
||||
public protected(set) database $database;
|
||||
|
||||
/**
|
||||
* Serialized
|
||||
*
|
||||
* @var bool $serialized Is the implementator object serialized?
|
||||
*/
|
||||
private bool $serialized = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -84,6 +92,7 @@ final class account extends core implements record_interface
|
||||
new column('name_first', type::string, ['length' => 64]),
|
||||
new column('name_second', type::string, ['length' => 64]),
|
||||
new column('language', type::string, ['length' => 2]),
|
||||
new column('currency', type::string, ['length' => 3]),
|
||||
new column('robot', type::char),
|
||||
/* new column('', type::), */
|
||||
new column('active', type::char),
|
||||
@@ -141,7 +150,7 @@ final class account extends core implements record_interface
|
||||
// Writing the updated record into the account object
|
||||
$this->record = $updated;
|
||||
|
||||
// Deserializing parameters
|
||||
// Deserializing the record
|
||||
$this->deserialize();
|
||||
|
||||
// Exit (success)
|
||||
@@ -157,7 +166,7 @@ final class account extends core implements record_interface
|
||||
// Writing the found record into the account object
|
||||
$this->record = $account;
|
||||
|
||||
// Deserializing parameters
|
||||
// Deserializing the record
|
||||
$this->deserialize();
|
||||
|
||||
// Exit (success)
|
||||
@@ -215,6 +224,7 @@ final class account extends core implements record_interface
|
||||
name_second: (string) $telegram->last_name,
|
||||
domain: (string) $telegram->username,
|
||||
language: (string) $telegram->language_code,
|
||||
currency: CURRENCY_DEFAULT,
|
||||
robot: (bool) $telegram->is_bot
|
||||
);
|
||||
|
||||
@@ -256,6 +266,7 @@ final class account extends core implements record_interface
|
||||
* @param string $name_second
|
||||
* @param string $domain
|
||||
* @param language|string $language
|
||||
* @param currency|string $currency
|
||||
* @param bool $robot Is a robot?
|
||||
* @param bool $active Is the record active?
|
||||
*
|
||||
@@ -267,6 +278,7 @@ final class account extends core implements record_interface
|
||||
string $name_first = '',
|
||||
string $name_second = '',
|
||||
language|string $language = LANGUAGE_DEFAULT ?? language::en,
|
||||
currency|string $currency = CURRENCY_DEFAULT ?? currency::usd,
|
||||
bool $robot = false,
|
||||
bool $active = true,
|
||||
): record|false {
|
||||
@@ -278,6 +290,7 @@ final class account extends core implements record_interface
|
||||
$name_first,
|
||||
$name_second,
|
||||
$language instanceof language ? $language->name : (string) $language,
|
||||
$currency instanceof currency ? $currency->name : (string) $currency,
|
||||
(int) $robot,
|
||||
/* */
|
||||
(int) $active,
|
||||
@@ -299,11 +312,22 @@ final class account extends core implements record_interface
|
||||
*/
|
||||
public function serialize(): self
|
||||
{
|
||||
if ($this->serialized) {
|
||||
// The record implementor is serialized
|
||||
|
||||
// Exit (fail)
|
||||
throw new exception_runtime('The record implementor is already serialized');
|
||||
}
|
||||
|
||||
// Serializing the record parameters
|
||||
$this->record->language = $this->record->language->name;
|
||||
$this->record->currency = $this->record->currency->name;
|
||||
$this->record->robot = (int) $this->record->robot;
|
||||
$this->record->active = (int) $this->record->active;
|
||||
|
||||
// Writing the status of serializing
|
||||
$this->serialized = true;
|
||||
|
||||
// Exit (success)
|
||||
return $this;
|
||||
}
|
||||
@@ -315,11 +339,22 @@ final class account extends core implements record_interface
|
||||
*/
|
||||
public function deserialize(): self
|
||||
{
|
||||
if (!$this->serialized) {
|
||||
// The record implementor is deserialized
|
||||
|
||||
// Exit (fail)
|
||||
throw new exception_runtime('The record implementor is already deserialized');
|
||||
}
|
||||
|
||||
// Deserializing the record parameters
|
||||
$this->record->language = language::{$this->record->language} ?? LANGUAGE_DEFAULT ?? language::en;
|
||||
$this->record->currency = currency::{$this->record->currency} ?? CURRENCY_DEFAULT ?? currency::usd;
|
||||
$this->record->robot = (bool) $this->record->robot;
|
||||
$this->record->active = (bool) $this->record->active;
|
||||
|
||||
// Writing the status of serializing
|
||||
$this->serialized = false;
|
||||
|
||||
// Exit (success)
|
||||
return $this;
|
||||
}
|
||||
@@ -339,6 +374,9 @@ final class account extends core implements record_interface
|
||||
if ($authorizations instanceof authorizations) {
|
||||
// Found the account authorizations
|
||||
|
||||
// Deserializing the record
|
||||
$authorizations->deserialize();
|
||||
|
||||
// Exit (success)
|
||||
return $authorizations;
|
||||
}
|
||||
@@ -347,6 +385,32 @@ final class account extends core implements record_interface
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Worker
|
||||
*
|
||||
* Search for the account worker
|
||||
*
|
||||
* @return worker|null The account worker
|
||||
*/
|
||||
public function worker(): ?worker
|
||||
{
|
||||
// Search for the account worker
|
||||
$worker = new worker()->read(filter: fn(record $record) => $record->active === 1 && $record->account === $this->identifier);
|
||||
|
||||
if ($worker instanceof worker) {
|
||||
// Found the account worker
|
||||
|
||||
// Deserializing the record
|
||||
$worker->deserialize();
|
||||
|
||||
// Exit (success)
|
||||
return $worker;
|
||||
}
|
||||
|
||||
// Exit (fail)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings
|
||||
*
|
||||
@@ -362,6 +426,9 @@ final class account extends core implements record_interface
|
||||
if ($settings instanceof settings) {
|
||||
// Found the account settings
|
||||
|
||||
// Deserializing the record
|
||||
$settings->deserialize();
|
||||
|
||||
// Exit (success)
|
||||
return $settings;
|
||||
}
|
||||
@@ -375,23 +442,23 @@ final class account extends core implements record_interface
|
||||
*
|
||||
* Search for the account projects
|
||||
*
|
||||
* @param project_type|null $type Type of the project
|
||||
* @param project_architecture|null $architecture architecture of the project
|
||||
* @param project_status|null $status Status of the project
|
||||
* @param int $amount Maximum amount
|
||||
*
|
||||
* @return array The account projects
|
||||
*/
|
||||
public function projects(
|
||||
?project_type $type = null,
|
||||
?project_architecture $architecture = null,
|
||||
?project_status $status = null,
|
||||
int $amount = 20
|
||||
int $amount = 1000
|
||||
): array {
|
||||
// Search for the account projects
|
||||
$projects = new project()->database->read(
|
||||
filter: fn(record $record) =>
|
||||
$record->active === 1
|
||||
&& $record->account === $this->identifier
|
||||
&& ($type === null || $record->type === $type->name)
|
||||
&& ($architecture === null || $record->architecture === $architecture->name)
|
||||
&& ($status === null || $record->status === $status->name),
|
||||
amount: $amount
|
||||
);
|
||||
@@ -417,7 +484,7 @@ final class account extends core implements record_interface
|
||||
filter: fn(record $record) =>
|
||||
$record->active === 1
|
||||
&& match (project_status::{$record->status}) {
|
||||
project_status::developing, project_status::developed, project_status::launched => true,
|
||||
project_status::developing, project_status::launched => true,
|
||||
default => false
|
||||
},
|
||||
amount: $amount
|
||||
|
||||
@@ -51,6 +51,13 @@ final class authorizations extends core implements record_interface
|
||||
*/
|
||||
public protected(set) database $database;
|
||||
|
||||
/**
|
||||
* Serialized
|
||||
*
|
||||
* @var bool $serialized Is the implementator object serialized?
|
||||
*/
|
||||
private bool $serialized = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -68,8 +75,10 @@ final class authorizations extends core implements record_interface
|
||||
new column('account', type::long_long_unsigned),
|
||||
new column('system', type::char),
|
||||
new column('settings', type::char),
|
||||
/* new column('', type::char), */
|
||||
new column('system_settings', type::char),
|
||||
new column('system_deals', type::char),
|
||||
new column('system_invoices', type::char),
|
||||
new column('system_projects', type::char),
|
||||
new column('active', type::char),
|
||||
new column('updated', type::integer_unsigned),
|
||||
new column('created', type::integer_unsigned)
|
||||
@@ -87,6 +96,9 @@ final class authorizations extends core implements record_interface
|
||||
* @param bool $system
|
||||
* @param bool $settings
|
||||
* @param bool $system_settings
|
||||
* @param bool $system_deals
|
||||
* @param bool $system_projects
|
||||
* @param bool $system_invoices
|
||||
* @param bool $active Is the record active?
|
||||
*
|
||||
* @return int|false The record, if created
|
||||
@@ -96,6 +108,9 @@ final class authorizations extends core implements record_interface
|
||||
bool $system = true,
|
||||
bool $settings = true,
|
||||
bool $system_settings = false,
|
||||
bool $system_deals = false,
|
||||
bool $system_projects = false,
|
||||
bool $system_invoices = false,
|
||||
bool $active = true,
|
||||
): record|false
|
||||
{
|
||||
@@ -105,6 +120,9 @@ final class authorizations extends core implements record_interface
|
||||
(int) $system,
|
||||
(int) $settings,
|
||||
(int) $system_settings,
|
||||
(int) $system_deals,
|
||||
(int) $system_projects,
|
||||
(int) $system_invoices,
|
||||
(int) $active,
|
||||
svoboda::timestamp(),
|
||||
svoboda::timestamp()
|
||||
@@ -124,12 +142,25 @@ final class authorizations extends core implements record_interface
|
||||
*/
|
||||
public function serialize(): self
|
||||
{
|
||||
if ($this->serialized) {
|
||||
// The record implementor is serialized
|
||||
|
||||
// Exit (fail)
|
||||
throw new exception_runtime('The record implementor is already serialized');
|
||||
}
|
||||
|
||||
// Serializing the record parameters
|
||||
$this->record->system = (int) $this->record->system;
|
||||
$this->record->settings = (int) $this->record->settings;
|
||||
$this->record->system_settings = (int) $this->record->system_settings;
|
||||
$this->record->system_deals = (int) $this->record->system_deals;
|
||||
$this->record->system_projects = (int) $this->record->system_projects;
|
||||
$this->record->system_invoices = (int) $this->record->system_invoices;
|
||||
$this->record->active = (int) $this->record->active;
|
||||
|
||||
// Writing the status of serializing
|
||||
$this->serialized = true;
|
||||
|
||||
// Exit (success)
|
||||
return $this;
|
||||
}
|
||||
@@ -141,12 +172,25 @@ final class authorizations extends core implements record_interface
|
||||
*/
|
||||
public function deserialize(): self
|
||||
{
|
||||
if (!$this->serialized) {
|
||||
// The record implementor is deserialized
|
||||
|
||||
// Exit (fail)
|
||||
throw new exception_runtime('The record implementor is already deserialized');
|
||||
}
|
||||
|
||||
// Deserializing the record parameters
|
||||
$this->record->system = (bool) $this->record->system;
|
||||
$this->record->settings = (bool) $this->record->settings;
|
||||
$this->record->system_settings = (bool) $this->record->system_settings;
|
||||
$this->record->system_deals = (bool) $this->record->system_deals;
|
||||
$this->record->system_projects = (bool) $this->record->system_projects;
|
||||
$this->record->system_invoices = (bool) $this->record->system_invoices;
|
||||
$this->record->active = (bool) $this->record->active;
|
||||
|
||||
// Writing the status of serializing
|
||||
$this->serialized = false;
|
||||
|
||||
// Exit (success)
|
||||
return $this;
|
||||
}
|
||||
|
||||
240
kodorvan/constructor/system/models/deal.php
Normal file
240
kodorvan/constructor/system/models/deal.php
Normal file
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace kodorvan\constructor\models;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\core,
|
||||
kodorvan\constructor\models\deal\enumerations\direction as deal_direction,
|
||||
kodorvan\constructor\models\project\enumerations\status as project_status,
|
||||
kodorvan\constructor\models\project\enumerations\architecture as project_architecture,
|
||||
kodorvan\constructor\models\project\enumerations\purpose as project_purpose,
|
||||
kodorvan\constructor\models\project\enumerations\integration as project_integration,
|
||||
kodorvan\constructor\models\worker\enumerations\type as worker_type;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\database,
|
||||
mirzaev\baza\column,
|
||||
mirzaev\baza\record,
|
||||
mirzaev\baza\enumerations\encoding,
|
||||
mirzaev\baza\enumerations\type;
|
||||
|
||||
// Active Record pattern
|
||||
use mirzaev\record\interfaces\record as record_interface,
|
||||
mirzaev\record\traits\record as record_trait;
|
||||
|
||||
// Svoboda time
|
||||
use svoboda\time\statement as svoboda;
|
||||
|
||||
// Built-in libraries
|
||||
use Exception as exception,
|
||||
LogicException as exception_logic,
|
||||
RuntimeException as exception_runtime;
|
||||
|
||||
/**
|
||||
* Deal
|
||||
*
|
||||
* @package kodorvan\constructor\models
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class deal extends core implements record_interface
|
||||
{
|
||||
use record_trait;
|
||||
|
||||
/**
|
||||
* File
|
||||
*
|
||||
* @var string $file Path to the database file
|
||||
*/
|
||||
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'projects' . DIRECTORY_SEPARATOR . 'deals.baza';
|
||||
|
||||
/**
|
||||
* Database
|
||||
*
|
||||
* @var database $database The database
|
||||
*/
|
||||
public protected(set) database $database;
|
||||
|
||||
/**
|
||||
* Serialized
|
||||
*
|
||||
* @var bool $serialized Is the implementator object serialized?
|
||||
*/
|
||||
private bool $serialized = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @method record|null $record The record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(?record $record = null)
|
||||
{
|
||||
// Initializing the database
|
||||
$this->database = new database()
|
||||
->encoding(encoding::utf8)
|
||||
->columns(
|
||||
new column('identifier', type::long_long_unsigned),
|
||||
new column('account', type::long_long_unsigned),
|
||||
new column('project', type::long_long_unsigned),
|
||||
new column('direction', type::char),
|
||||
new column('description', type::string, ['length' => 512]),
|
||||
new column('hours', type::integer_unsigned),
|
||||
new column('cost', type::float),
|
||||
new column('payment', type::float),
|
||||
new column('prepayment', type::float),
|
||||
new column('programmers', type::integer_unsigned),
|
||||
new column('designers', type::integer_unsigned),
|
||||
new column('boosters', type::integer_unsigned),
|
||||
new column('active', type::char),
|
||||
new column('confirmed', type::integer_unsigned),
|
||||
new column('updated', type::integer_unsigned),
|
||||
new column('created', type::integer_unsigned)
|
||||
)
|
||||
->connect($this->file);
|
||||
|
||||
// Initializing the record
|
||||
$record instanceof record and $this->record = $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write
|
||||
*
|
||||
* @throws exception_logic when failed to process project integration
|
||||
*
|
||||
* @param int $account The account identifier
|
||||
* @param int $project The project identifier
|
||||
* @param deal_direction $direction Direction of the deal
|
||||
* @param string|null $description Description of the project
|
||||
* @param int $hours Hours of the project development
|
||||
* @param int|float $cost Cost per hour of the project development
|
||||
* @param int|float $payment Payment of the project development
|
||||
* @param int|float $prepayment Prepayment of the project development
|
||||
* @param int $programmers Programmers of the project
|
||||
* @param int $designers Designers of the project
|
||||
* @param int $boosters Boosters of the project
|
||||
* @param int $active Is the record active?
|
||||
*
|
||||
* @return record|false The record, if created
|
||||
*/
|
||||
public function write(
|
||||
int $account,
|
||||
int $project,
|
||||
deal_direction $direction,
|
||||
?string $description = null,
|
||||
int $hours = PROJECT_HOURS_MINIMAL,
|
||||
int|float $cost = PROJECT_COST_HOUR_DEFAULT,
|
||||
int|float $payment,
|
||||
int|float $prepayment,
|
||||
int $programmers = 0,
|
||||
int $designers = 0,
|
||||
int $boosters = 0,
|
||||
bool $active = true,
|
||||
): record|false {
|
||||
// Initializing the record
|
||||
$record = $this->database->record(
|
||||
$this->database->count() + 1,
|
||||
$account,
|
||||
$project,
|
||||
$direction->value,
|
||||
$description,
|
||||
$hours,
|
||||
(float) $cost,
|
||||
(float) $payment,
|
||||
(float) $prepayment,
|
||||
$programmers,
|
||||
$designers,
|
||||
$boosters,
|
||||
(int) $active,
|
||||
0,
|
||||
svoboda::timestamp(),
|
||||
svoboda::timestamp()
|
||||
);
|
||||
|
||||
// Writing the record into the database
|
||||
$created = $this->database->write($record);
|
||||
|
||||
// Exit (success)
|
||||
return $created ? $record : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize
|
||||
*
|
||||
* @return self The instance from which the method was called (fluent interface)
|
||||
*/
|
||||
public function serialize(): self
|
||||
{
|
||||
if ($this->serialized) {
|
||||
// The record implementor is serialized
|
||||
|
||||
// Exit (fail)
|
||||
throw new exception_runtime('The record implementor is already serialized');
|
||||
}
|
||||
|
||||
// Serializing the record parameters
|
||||
$this->record->direction = $this->record->direction->value;
|
||||
$this->record->active = (int) $this->record->active;
|
||||
|
||||
// Writing the status of serializing
|
||||
$this->serialized = true;
|
||||
|
||||
// Exit (success)
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize
|
||||
*
|
||||
* @return self The instance from which the method was called (fluent interface)
|
||||
*/
|
||||
public function deserialize(): self
|
||||
{
|
||||
if (!$this->serialized) {
|
||||
// The record implementor is deserialized
|
||||
|
||||
// Exit (fail)
|
||||
throw new exception_runtime('The record implementor is already deserialized');
|
||||
}
|
||||
|
||||
// Deserializing the record parameters
|
||||
$this->record->direction = deal_direction::from($this->record->direction);
|
||||
$this->record->active = (bool) $this->record->active;
|
||||
|
||||
// Writing the status of serializing
|
||||
$this->serialized = false;
|
||||
|
||||
// Exit (success)
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Project
|
||||
*
|
||||
* Search for the project
|
||||
*
|
||||
* @return project|null The project
|
||||
*/
|
||||
public function project(): ?project
|
||||
{
|
||||
// Search for the account project
|
||||
$project = new project()->read(filter: fn(record $record) => $record->identifier === $this->project && $record->active === 1);
|
||||
|
||||
if ($project instanceof project) {
|
||||
// Found the account project
|
||||
|
||||
// Deserializing the project
|
||||
$project->deserialize();
|
||||
|
||||
// Exit (success)
|
||||
return $project;
|
||||
}
|
||||
|
||||
// Exit (fail)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace kodorvan\constructor\models\deal\enumerations;
|
||||
|
||||
// Built-in libraries
|
||||
use InvalidArgumentException as exception_argument,
|
||||
DomainException as exception_domain;
|
||||
|
||||
/**
|
||||
* Direction
|
||||
*
|
||||
* @package kodorvan\neurobot\models\deal\enumerations
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
enum direction: int
|
||||
{
|
||||
case inbound = 0;
|
||||
case outbound = 1;
|
||||
}
|
||||
@@ -7,7 +7,10 @@ namespace kodorvan\constructor\models;
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\core,
|
||||
kodorvan\constructor\models\project\enumerations\status as project_status,
|
||||
kodorvan\constructor\models\project\enumerations\status as project_type;
|
||||
kodorvan\constructor\models\project\enumerations\architecture as project_architecture,
|
||||
kodorvan\constructor\models\project\enumerations\purpose as project_purpose,
|
||||
kodorvan\constructor\models\project\enumerations\integration as project_integration,
|
||||
kodorvan\constructor\models\worker\enumerations\type as worker_type;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\database,
|
||||
@@ -25,6 +28,7 @@ use svoboda\time\statement as svoboda;
|
||||
|
||||
// Built-in libraries
|
||||
use Exception as exception,
|
||||
LogicException as exception_logic,
|
||||
RuntimeException as exception_runtime;
|
||||
|
||||
/**
|
||||
@@ -44,7 +48,7 @@ final class project extends core implements record_interface
|
||||
*
|
||||
* @var string $file Path to the database file
|
||||
*/
|
||||
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'project.baza';
|
||||
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'projects.baza';
|
||||
|
||||
/**
|
||||
* Database
|
||||
@@ -53,6 +57,13 @@ final class project extends core implements record_interface
|
||||
*/
|
||||
public protected(set) database $database;
|
||||
|
||||
/**
|
||||
* Serialized
|
||||
*
|
||||
* @var bool $serialized Is the implementator object serialized?
|
||||
*/
|
||||
private bool $serialized = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -68,9 +79,15 @@ final class project extends core implements record_interface
|
||||
->columns(
|
||||
new column('identifier', type::long_long_unsigned),
|
||||
new column('account', type::long_long_unsigned),
|
||||
new column('status', type::string, ['length' => 16]),
|
||||
new column('type', type::string, ['length' => 32]),
|
||||
new column('deal', type::long_long_unsigned),
|
||||
new column('name', type::string, ['length' => 64]),
|
||||
new column('status', type::string, ['length' => 16]),
|
||||
new column('architecture', type::string, ['length' => 32]),
|
||||
new column('purpose', type::string, ['length' => 32]),
|
||||
new column('integrations', type::integer_unsigned),
|
||||
/* new column('programmers', type::integer_unsigned),
|
||||
new column('designers', type::integer_unsigned),
|
||||
new column('boosters', type::integer_unsigned), */
|
||||
/* new column('', type::), */
|
||||
new column('active', type::char),
|
||||
new column('updated', type::integer_unsigned),
|
||||
@@ -85,34 +102,85 @@ final class project extends core implements record_interface
|
||||
/**
|
||||
* Write
|
||||
*
|
||||
* @throws exception_logic when failed to process project integration
|
||||
*
|
||||
* @param int $account The account identifier
|
||||
* @param int|null $deal The deal identifier
|
||||
* @param project_status $status Status of the project
|
||||
* @param project_type $status Type of the project
|
||||
* @param string|null $name Name of the project
|
||||
* @param project_architecture|null $architecture Architecture of the project
|
||||
* @param project_purpose|null $purpose Purpose of the project
|
||||
* @param int|array $Inegrations Integrations of the project
|
||||
|
||||
* @param int $programmers Programmers of the project
|
||||
* @param int $designers Designers of the project
|
||||
* @param int $boosters Boosters of the project
|
||||
|
||||
* @param int $active Is the record active?
|
||||
*
|
||||
* @return record|false The record, if created
|
||||
*/
|
||||
public function write(
|
||||
int $account,
|
||||
project_status $status = project_status::creating,
|
||||
project_type $type = project_type::special,
|
||||
?int $deal = null,
|
||||
?string $name = null,
|
||||
project_status $status = project_status::creating,
|
||||
?project_architecture $architecture = null,
|
||||
?project_purpose $purpose = null,
|
||||
int|array $integrations = 0b000000,
|
||||
/* int $programmers = 0,
|
||||
int $designers = 0,
|
||||
int $boosters = 0, */
|
||||
bool $active = true,
|
||||
): record|false {
|
||||
if (empty($name)) {
|
||||
// Not received the project name
|
||||
|
||||
// Generating the project name
|
||||
$name = 'Project №' . count(new account()->read(filter: fn(record $record) => $record->active === 1 && $record->account === $account)?->projects() ?? []);
|
||||
$name = 'Project №' . count(new account()->read(filter: fn(record $record) => $record->active === 1 && $record->identifier === $account)?->projects() ?? []);
|
||||
}
|
||||
|
||||
if (is_array($integrations)) {
|
||||
// Received integrations in array format
|
||||
|
||||
// Initializing the project integrations buffer
|
||||
$buffer = 0b000000;
|
||||
|
||||
foreach ($integrations as $integration) {
|
||||
// Iterating over integrations
|
||||
|
||||
if ($integration instanceof project_integration) {
|
||||
// Project integration
|
||||
|
||||
// Writing the project integration into the project integrations buffer
|
||||
$buffer |= $integration->value;
|
||||
} else {
|
||||
// Not project integration
|
||||
|
||||
throw new exception_logic('Failed to process project integration');
|
||||
}
|
||||
}
|
||||
|
||||
// Reinitializing the project integrations
|
||||
$integrations = $buffer;
|
||||
|
||||
// Deinitializing the project integrations buffer
|
||||
unset($buffer);
|
||||
}
|
||||
|
||||
// Initializing the record
|
||||
$record = $this->database->record(
|
||||
$this->database->count() + 1,
|
||||
$account,
|
||||
$status->name,
|
||||
$type->name,
|
||||
(int) $deal,
|
||||
$name,
|
||||
$status->name,
|
||||
$architecture?->name ?? '',
|
||||
$purpose?->name ?? '',
|
||||
$integrations,
|
||||
/* $programmers,
|
||||
$designers,
|
||||
$boosters, */
|
||||
(int) $active,
|
||||
svoboda::timestamp(),
|
||||
svoboda::timestamp()
|
||||
@@ -140,9 +208,11 @@ final class project extends core implements record_interface
|
||||
}
|
||||
|
||||
// Serializing the record parameters
|
||||
$this->record->active = (int) $this->record->active;
|
||||
$this->record->status = $this->record->status->name;
|
||||
$this->record->type = $this->record->type->name;
|
||||
$this->record->architecture = $this->record->architecture?->name ?? '';
|
||||
$this->record->purpose = $this->record->purpose?->name ?? '';
|
||||
$this->record->integrations = project_integration::encode($this->record->integrations);
|
||||
$this->record->active = (int) $this->record->active;
|
||||
|
||||
// Writing the status of serializing
|
||||
$this->serialized = true;
|
||||
@@ -166,9 +236,15 @@ final class project extends core implements record_interface
|
||||
}
|
||||
|
||||
// Deserializing the record parameters
|
||||
$this->record->active = (bool) $this->record->active;
|
||||
$this->record->status = project_status::{$this->record->status};
|
||||
$this->record->type = project_status::{$this->record->type};
|
||||
$this->record->architecture = $this->architecture instanceof project_architecture
|
||||
? project_architecture::{$this->architecture->type}
|
||||
: null;
|
||||
$this->record->purpose = $this->purpose instanceof project_purpose
|
||||
? project_purpose::{$this->purpose->type}
|
||||
: null;
|
||||
$this->record->integrations = project_integration::decode($this->record->integrations);
|
||||
$this->record->active = (bool) $this->record->active;
|
||||
|
||||
// Writing the status of serializing
|
||||
$this->serialized = false;
|
||||
@@ -178,32 +254,205 @@ final class project extends core implements record_interface
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters
|
||||
* Account
|
||||
*
|
||||
* Search for all the project properties
|
||||
* Search for the account
|
||||
*
|
||||
* @return self The instance from which the method was called (fluent interface)
|
||||
* @return account|null The account
|
||||
*/
|
||||
public function parameters(): self
|
||||
public function account(): ?account
|
||||
{
|
||||
// Deserializing the record parameters
|
||||
$this->record->active = (bool) $this->record->active;
|
||||
$this->record->status = project_status::{$this->record->status};
|
||||
// Search for the account account
|
||||
$account = new account()->read(filter: fn(record $record) => $record->identifier === $this->account && $record->active === 1);
|
||||
|
||||
if (!$this->serialized) {
|
||||
// Not serialized
|
||||
if ($account instanceof account) {
|
||||
// Found the account account
|
||||
|
||||
// Deserializing the record
|
||||
$account->deserialize();
|
||||
|
||||
} else {
|
||||
// Serialized
|
||||
|
||||
// Exit (fail)
|
||||
throw new exception('The project implementator is serialized');
|
||||
// Exit (success)
|
||||
return $account;
|
||||
}
|
||||
/* if ($this->record->type === '') */
|
||||
|
||||
// Exit (fail)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hours
|
||||
*
|
||||
* Calculate the project development hours
|
||||
*
|
||||
* @throws exception_runtime The record is not deserialized
|
||||
*
|
||||
* @param bool $absolute Summary all coefficients and then multiply?
|
||||
*
|
||||
* @return int|float The project development hours
|
||||
*/
|
||||
public function hours(bool $absolute = false): int
|
||||
{
|
||||
if ($this->serialized) {
|
||||
// The record is serialized
|
||||
|
||||
throw new exception_runtime('The record is not deserialized');
|
||||
}
|
||||
|
||||
// Initializing start hours
|
||||
$start = PROJECT_START_HOURS ?? 1;
|
||||
$start < 1 and $start = 1;
|
||||
|
||||
// Initializing additional hours
|
||||
$additional = PROJECT_HOURS_ADDITIONAL ?? 0;
|
||||
|
||||
if ($absolute) {
|
||||
// The absolute coefficient
|
||||
|
||||
// Declaring coefficient
|
||||
$coefficient = PROJECT_START_COEFFICIENT ?? 0;
|
||||
|
||||
if (isset($this->architecture)) {
|
||||
// Initialized the project architecture
|
||||
|
||||
// Adding into the coefficient
|
||||
$coefficient += $this->architecture->coefficient() ?? 0;
|
||||
}
|
||||
|
||||
if (isset($this->purpose)) {
|
||||
// Initialized the project purpose
|
||||
|
||||
// Adding into the coefficient
|
||||
$coefficient += $this->purpose->coefficient() ?? 0;
|
||||
}
|
||||
|
||||
if (!empty($this->integrations)) {
|
||||
// Initialized the project integrations
|
||||
|
||||
foreach ($this->integrations as $integration) {
|
||||
// Iterating over the project integrations
|
||||
|
||||
// Adding into the coefficient
|
||||
$coefficient += $integration->coefficient() ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculating the development hours
|
||||
$hours = $start * $coefficient + $additional;
|
||||
|
||||
// Calculating and exit (success)
|
||||
return (int) ceil(max($hours, PROJECT_HOURS_MINIMAL));
|
||||
} else {
|
||||
// The relative coefficient
|
||||
|
||||
// Initializing the development hours
|
||||
$hours = $start;
|
||||
|
||||
if (isset($this->architecture)) {
|
||||
// Initialized the project architecture
|
||||
|
||||
// Adding into the coefficient
|
||||
$hours *= $this->architecture->coefficient() ?? 1;
|
||||
}
|
||||
|
||||
if (isset($this->purpose)) {
|
||||
// Initialized the project purpose
|
||||
|
||||
// Adding into the coefficient
|
||||
$hours *= $this->purpose->coefficient() ?? 1;
|
||||
}
|
||||
|
||||
if (!empty($this->integrations)) {
|
||||
// Initialized the project integrations
|
||||
|
||||
foreach ($this->integrations as $integration) {
|
||||
// Iterating over the project integrations
|
||||
|
||||
// Adding into the coefficient
|
||||
$hours *= $integration->coefficient() ?? 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculating with additional hours
|
||||
$hours += $additional;
|
||||
|
||||
// Calculating and exit (success)
|
||||
return (int) ceil(max($hours, PROJECT_HOURS_MINIMAL));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment
|
||||
*
|
||||
* Calculate the project development payment
|
||||
*
|
||||
* @param int|float $cost Cost per hour
|
||||
* @param int $hours The project development hours
|
||||
* @param int $programmers Programmers
|
||||
* @param int $designers Designers
|
||||
* @param int $boosters Boosters
|
||||
*
|
||||
* @return array ['full' => int|float, 'prepayment' => int|float]
|
||||
*/
|
||||
public function payment(
|
||||
int|float $cost = PROJECT_COST_HOUR_DEFAULT,
|
||||
int $hours = PROJECT_HOURS_MINIMAL,
|
||||
int $programmers = 0,
|
||||
int $designers = 0,
|
||||
int $boosters = 0
|
||||
): array {
|
||||
// Initializing costs
|
||||
$costs = [
|
||||
'full' => ceil($hours * $cost),
|
||||
'prepayment' => null
|
||||
];
|
||||
|
||||
// Initializing default workers amounts
|
||||
$default = [
|
||||
'programmers' => $this->architecture?->workers()[worker_type::programmer->name] ?? 0,
|
||||
'designers' => $this->architecture?->workers()[worker_type::designer->name] ?? 0,
|
||||
'boosters' => $this->architecture?->workers()[worker_type::booster->name] ?? 0
|
||||
];
|
||||
|
||||
if ($programmers > $default['programmers']) {
|
||||
// Programmers amount more than default
|
||||
|
||||
// Calculating the full cost
|
||||
$costs['full'] *= $programmers * PROJECT_WORKERS_PROGRAMMERS_COEFFICIENT;
|
||||
} else if ($programmers < $default['programmers']) {
|
||||
// Programmers amount less than default
|
||||
|
||||
// Calculating the full cost
|
||||
$costs['full'] /= max($programmers, 1) * PROJECT_WORKERS_PROGRAMMERS_COEFFICIENT;
|
||||
}
|
||||
|
||||
if ($designers > $default['designers']) {
|
||||
// Designers amount more than default
|
||||
|
||||
// Calculating the full cost
|
||||
$costs['full'] *= $designers * PROJECT_WORKERS_DESIGNERS_COEFFICIENT;
|
||||
} else if ($designers < $default['designers']) {
|
||||
// Designers amount less than default
|
||||
|
||||
// Calculating the full cost
|
||||
$costs['full'] /= max($designers, 1) * PROJECT_WORKERS_DESIGNERS_COEFFICIENT;
|
||||
}
|
||||
|
||||
if ($boosters > $default['boosters']) {
|
||||
// Boosters amount more than default
|
||||
|
||||
// Calculating the full cost
|
||||
$costs['full'] *= $boosters * PROJECT_WORKERS_BOOSTERS_COEFFICIENT;
|
||||
} else if ($boosters < $default['boosters']) {
|
||||
// Boosters amount less than default
|
||||
|
||||
// Calculating the full cost
|
||||
$costs['full'] /= max($boosters, 1) * PROJECT_WORKERS_BOOSTERS_COEFFICIENT;
|
||||
}
|
||||
|
||||
// Calculating the prepayment
|
||||
$costs['prepayment'] = ceil($costs['full'] * (PROJECT_COST_PREPAYMENT_PERCENTS / 100));
|
||||
|
||||
// Exit (success)
|
||||
return $this;
|
||||
return $costs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ declare(strict_types=1);
|
||||
namespace kodorvan\constructor\models\project\enumerations;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\project\enumerations\purpose;
|
||||
use kodorvan\constructor\models\project\enumerations\purpose,
|
||||
kodorvan\constructor\models\project\enumerations\integration,
|
||||
kodorvan\constructor\models\worker\enumerations\type as worker_type;
|
||||
|
||||
// The library for languages support
|
||||
use mirzaev\languages\language;
|
||||
@@ -18,20 +20,18 @@ use InvalidArgumentException as exception_argument,
|
||||
DomainException as exception_domain;
|
||||
|
||||
/**
|
||||
* Type
|
||||
* Architecture
|
||||
*
|
||||
* @package kodorvan\neurobot\models\project\enumerations
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
enum type
|
||||
enum architecture
|
||||
{
|
||||
case chat_robot;
|
||||
case parser;
|
||||
case calculator;
|
||||
case crm;
|
||||
/* case marketplace; */
|
||||
case script;
|
||||
case site;
|
||||
case program;
|
||||
|
||||
@@ -42,7 +42,7 @@ enum type
|
||||
*
|
||||
* @param language $language The language
|
||||
*
|
||||
* @return string The project type label
|
||||
* @return string The project architecture label
|
||||
*/
|
||||
public function label(language $language = LANGUAGE_DEFAULT): string
|
||||
{
|
||||
@@ -56,17 +56,10 @@ enum type
|
||||
language::en => 'Parser',
|
||||
language::ru => 'Парсер'
|
||||
},
|
||||
static::calculator => match ($language) {
|
||||
language::en => 'Calculator',
|
||||
language::ru => 'Калькулятор'
|
||||
static::script => match ($language) {
|
||||
language::en => 'Script',
|
||||
language::ru => 'Скрипт'
|
||||
},
|
||||
static::crm => match ($language) {
|
||||
default => 'CRM'
|
||||
},
|
||||
/* static::marketplace => match ($language) {
|
||||
language::en => 'Marketplace',
|
||||
language::ru => 'Маркетплейс'
|
||||
}, */
|
||||
static::site => match ($language) {
|
||||
language::en => 'Site',
|
||||
language::ru => 'Сайт'
|
||||
@@ -93,12 +86,10 @@ enum type
|
||||
return match ($this) {
|
||||
static::chat_robot => 2,
|
||||
static::parser => 1,
|
||||
static::calculator => 2,
|
||||
static::crm => 1,
|
||||
/* static::marketplace => 4, */
|
||||
static::site => 1,
|
||||
static::program => 1,
|
||||
static::complex => 2,
|
||||
static::script => 1,
|
||||
static::site => 2,
|
||||
static::program => 2,
|
||||
static::complex => 4,
|
||||
default => 1
|
||||
};
|
||||
}
|
||||
@@ -110,6 +101,13 @@ enum type
|
||||
*/
|
||||
public function purposes(): array
|
||||
{
|
||||
// Initializing purposes
|
||||
$purposes = purpose::cases();
|
||||
|
||||
// Deleting the special purpose
|
||||
$indexes = array_keys($purposes, purpose::special);
|
||||
foreach ($indexes as $index) unset($purposes[$index]);
|
||||
|
||||
// Exit (success)
|
||||
return match ($this) {
|
||||
static::chat_robot => [
|
||||
@@ -119,22 +117,15 @@ enum type
|
||||
purpose::game,
|
||||
purpose::gallery,
|
||||
purpose::crm,
|
||||
purpose::calculate,
|
||||
purpose::landing,
|
||||
purpose::marketplace,
|
||||
purpose::events,
|
||||
purpose::charity
|
||||
],
|
||||
static::parser => [
|
||||
purpose::search
|
||||
],
|
||||
static::calculator => [
|
||||
purpose::calculate
|
||||
],
|
||||
static::crm => [
|
||||
purpose::workers,
|
||||
purpose::tools,
|
||||
purpose::objects,
|
||||
purpose::events
|
||||
static::script => [
|
||||
purpose::logic
|
||||
],
|
||||
static::site => [
|
||||
purpose::funnel,
|
||||
@@ -142,23 +133,15 @@ enum type
|
||||
purpose::neural_network,
|
||||
purpose::gallery,
|
||||
purpose::crm,
|
||||
purpose::calculate,
|
||||
purpose::landing,
|
||||
purpose::marketplace,
|
||||
purpose::workers,
|
||||
purpose::tools,
|
||||
purpose::objects,
|
||||
purpose::events,
|
||||
purpose::charity
|
||||
],
|
||||
static::program => [
|
||||
purpose::neural_network,
|
||||
purpose::crm,
|
||||
purpose::calculate,
|
||||
purpose::marketplace,
|
||||
purpose::workers,
|
||||
purpose::tools,
|
||||
purpose::objects,
|
||||
purpose::events,
|
||||
purpose::charity
|
||||
],
|
||||
default => []
|
||||
};
|
||||
@@ -168,6 +151,8 @@ enum type
|
||||
* Cost
|
||||
*
|
||||
* @return int|float The minimal cost of the project development
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function cost(currency $currency = CURRENCY_DEFAULT): int|float
|
||||
{
|
||||
@@ -181,13 +166,9 @@ enum type
|
||||
currency::usd => 35,
|
||||
currency::rub => 3500
|
||||
},
|
||||
static::calculator => match ($currency) {
|
||||
currency::usd => 40,
|
||||
currency::rub => 4000
|
||||
},
|
||||
static::crm => match ($currency) {
|
||||
currency::usd => 100,
|
||||
currency::rub => 8000
|
||||
static::script => match ($currency) {
|
||||
currency::usd => 10,
|
||||
currency::rub => 1000
|
||||
},
|
||||
static::site => match ($currency) {
|
||||
currency::usd => 50,
|
||||
@@ -203,4 +184,60 @@ enum type
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Coefficient
|
||||
*
|
||||
* @return int The project development hours
|
||||
*/
|
||||
public function coefficient(): int|float
|
||||
{
|
||||
// Exit (success)
|
||||
return (int) match ($this) {
|
||||
static::chat_robot => 3,
|
||||
static::parser => 2,
|
||||
static::script => 1,
|
||||
static::site => 3,
|
||||
static::program => 4,
|
||||
static::complex => 5,
|
||||
default => 5
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Workers
|
||||
*
|
||||
* @return array Workers
|
||||
*/
|
||||
public function workers(): array
|
||||
{
|
||||
// Exit (success)
|
||||
return match ($this) {
|
||||
static::chat_robot => [
|
||||
worker_type::programmer->name => 1,
|
||||
worker_type::booster->name => 1
|
||||
],
|
||||
static::parser => [
|
||||
worker_type::programmer->name => 1
|
||||
],
|
||||
static::script => [
|
||||
worker_type::programmer->name => 1
|
||||
],
|
||||
static::site => [
|
||||
worker_type::programmer->name => 1,
|
||||
worker_type::designer->name => 1,
|
||||
worker_type::booster->name => 1
|
||||
],
|
||||
static::program => [
|
||||
worker_type::programmer->name => 1,
|
||||
worker_type::designer->name => 1
|
||||
],
|
||||
static::complex => [
|
||||
worker_type::programmer->name => 1
|
||||
],
|
||||
default => [
|
||||
worker_type::programmer->name => 1
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace kodorvan\constructor\models\project\enumerations;
|
||||
|
||||
// The library for languages support
|
||||
use mirzaev\languages\language;
|
||||
|
||||
// Built-in libraries
|
||||
use InvalidArgumentException as exception_argument,
|
||||
DomainException as exception_domain;
|
||||
|
||||
/**
|
||||
* Integration
|
||||
*
|
||||
* @package kodorvan\neurobot\models\project\enumerations
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
enum integration: int
|
||||
{
|
||||
case one_c = 0b000001;
|
||||
case bitrix24 = 0b000010;
|
||||
case moy_sklad = 0b000100;
|
||||
case telegram = 0b001000;
|
||||
case mail = 0b010000;
|
||||
case excel = 0b100000;
|
||||
|
||||
/**
|
||||
* Label
|
||||
*
|
||||
* @param language $language The language
|
||||
*
|
||||
* @return string The project form label
|
||||
*/
|
||||
public function label(language $language = LANGUAGE_DEFAULT): string
|
||||
{
|
||||
// Exit (success)
|
||||
return match ($this) {
|
||||
static::one_c => '1C',
|
||||
static::bitrix24 => match ($language) {
|
||||
language::en => 'Bitrix 24',
|
||||
language::ru => 'Битрикс 24'
|
||||
},
|
||||
static::moy_sklad => match ($language) {
|
||||
language::en => 'Moy Sklad',
|
||||
language::ru => 'Мой Склад'
|
||||
},
|
||||
static::telegram => match ($language) {
|
||||
language::en => 'Telegram',
|
||||
language::ru => 'Телеграм'
|
||||
},
|
||||
static::mail => match ($language) {
|
||||
language::en => 'Mail',
|
||||
language::ru => 'Почта'
|
||||
},
|
||||
static::excel => 'Excel'
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Length
|
||||
*
|
||||
* @return int Amount of buttons cells length
|
||||
*/
|
||||
public function length(): int
|
||||
{
|
||||
// Exit (success)
|
||||
return match ($this) {
|
||||
static::one_c => 1,
|
||||
static::bitrix24 => 2,
|
||||
static::moy_sklad => 2,
|
||||
static::telegram => 2,
|
||||
static::mail => 1,
|
||||
static::excel => 1,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Coefficient
|
||||
*
|
||||
* @return int|float Coefficient to the project development hours
|
||||
*/
|
||||
public function coefficient(): int|float
|
||||
{
|
||||
// Exit (success)
|
||||
return match ($this) {
|
||||
static::one_c => 3,
|
||||
static::bitrix24 => 3.5,
|
||||
static::moy_sklad => 3,
|
||||
static::telegram => 2,
|
||||
static::mail => 1.2,
|
||||
static::excel => 1.5,
|
||||
default => 2
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode
|
||||
*
|
||||
* @param int $bitmask The encoded cases
|
||||
*
|
||||
* @return array Decoded cases
|
||||
*/
|
||||
public static function decode(int $bitmask): array
|
||||
{
|
||||
// Initializing the registry of decoded cases
|
||||
$decoded = [];
|
||||
|
||||
foreach (static::cases() as $case) {
|
||||
// Iterating over cases
|
||||
|
||||
if ($bitmask & $case->value) {
|
||||
// Decoded the case
|
||||
|
||||
// Decoding the case and writing into the registry of decoded cases
|
||||
$decoded[] = $case;
|
||||
}
|
||||
}
|
||||
|
||||
// Exit (success)
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode
|
||||
*
|
||||
* @param array $cases The decoded cases
|
||||
*
|
||||
* @return int Encoded cases bitmask
|
||||
*/
|
||||
public static function encode(array $cases):int
|
||||
{
|
||||
// Initializing the registry of encoded cases
|
||||
$encoded = 0b000000;
|
||||
|
||||
foreach ($cases as $case) {
|
||||
// Iterating over cases
|
||||
|
||||
// Encoding the case and writing into the registry of encoded cases
|
||||
$encoded |= $case->value;
|
||||
}
|
||||
|
||||
// Exit (success)
|
||||
return $encoded;
|
||||
}
|
||||
}
|
||||
@@ -28,15 +28,16 @@ enum purpose
|
||||
case crm;
|
||||
case landing;
|
||||
case marketplace;
|
||||
case charity;
|
||||
/* case charity; */
|
||||
case search;
|
||||
case calculate;
|
||||
case logic;
|
||||
case game;
|
||||
|
||||
case workers;
|
||||
/* case workers;
|
||||
case tools;
|
||||
case objects;
|
||||
case events;
|
||||
case events; */
|
||||
|
||||
case special;
|
||||
|
||||
@@ -45,7 +46,7 @@ enum purpose
|
||||
*
|
||||
* @param language $language The language
|
||||
*
|
||||
* @return string The project type label
|
||||
* @return string The project form label
|
||||
*/
|
||||
public function label(language $language = LANGUAGE_DEFAULT): string
|
||||
{
|
||||
@@ -61,7 +62,7 @@ enum purpose
|
||||
},
|
||||
static::neural_network => match ($language) {
|
||||
language::en => 'Neural network',
|
||||
language::ru => 'Нейросети'
|
||||
language::ru => 'Нейросеть'
|
||||
},
|
||||
static::game => match ($language) {
|
||||
language::en => 'Game',
|
||||
@@ -82,10 +83,10 @@ enum purpose
|
||||
language::en => 'Marketplace',
|
||||
language::ru => 'Маркетплейс'
|
||||
},
|
||||
static::charity => match ($language) {
|
||||
/* static::charity => match ($language) {
|
||||
language::en => 'Charity',
|
||||
language::ru => 'Благотворительность'
|
||||
},
|
||||
}, */
|
||||
static::search => match ($language) {
|
||||
language::en => 'Search',
|
||||
language::ru => 'Поиск'
|
||||
@@ -94,11 +95,15 @@ enum purpose
|
||||
language::en => 'Calculate',
|
||||
language::ru => 'Расчёты'
|
||||
},
|
||||
static::logic => match ($language) {
|
||||
language::en => 'Logic',
|
||||
language::ru => 'Логика'
|
||||
},
|
||||
static::game => match ($language) {
|
||||
language::en => 'Game',
|
||||
language::ru => 'Игра'
|
||||
},
|
||||
static::workers => match ($language) {
|
||||
/* static::workers => match ($language) {
|
||||
language::en => 'Workes',
|
||||
language::ru => 'Рабочие'
|
||||
},
|
||||
@@ -113,14 +118,93 @@ enum purpose
|
||||
static::events => match ($language) {
|
||||
language::en => 'Events',
|
||||
language::ru => 'События'
|
||||
},
|
||||
}, */
|
||||
static::special => match ($language) {
|
||||
language::en => 'Special',
|
||||
language::ru => 'Особенный'
|
||||
language::ru => 'Особенное'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Integrations
|
||||
*
|
||||
* @return array Integrations
|
||||
*/
|
||||
public function integrations(): array
|
||||
{
|
||||
// Exit (success)
|
||||
return match ($this) {
|
||||
static::funnel => [
|
||||
integration::telegram,
|
||||
integration::mail,
|
||||
integration::bitrix24
|
||||
],
|
||||
static::contact => [
|
||||
integration::mail,
|
||||
integration::bitrix24
|
||||
],
|
||||
static::neural_network => [
|
||||
integration::telegram
|
||||
],
|
||||
static::game => [
|
||||
integration::telegram
|
||||
],
|
||||
static::gallery => [],
|
||||
static::crm => [
|
||||
integration::one_c,
|
||||
integration::moy_sklad,
|
||||
integration::excel
|
||||
],
|
||||
static::landing => [
|
||||
integration::telegram
|
||||
],
|
||||
static::marketplace => [
|
||||
integration::one_c,
|
||||
integration::moy_sklad,
|
||||
integration::excel
|
||||
],
|
||||
/* static::charity => [
|
||||
integration::one_c,
|
||||
integration::moy_sklad,
|
||||
integration::excel
|
||||
], */
|
||||
static::search => [],
|
||||
static::calculate => [
|
||||
integration::one_c,
|
||||
integration::moy_sklad,
|
||||
integration::excel
|
||||
],
|
||||
/* static::logic => [],
|
||||
static::tools => [
|
||||
integration::one_c,
|
||||
integration::moy_sklad,
|
||||
integration::excel
|
||||
],
|
||||
static::workers => [
|
||||
integration::one_c,
|
||||
integration::moy_sklad,
|
||||
integration::excel
|
||||
],
|
||||
static::objects => [
|
||||
integration::one_c,
|
||||
integration::moy_sklad,
|
||||
integration::excel
|
||||
],
|
||||
static::events => [
|
||||
integration::one_c,
|
||||
integration::moy_sklad,
|
||||
integration::excel
|
||||
],
|
||||
static::special => [
|
||||
integration::one_c,
|
||||
integration::moy_sklad,
|
||||
integration::excel
|
||||
], */
|
||||
default => []
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Length
|
||||
*
|
||||
@@ -138,13 +222,14 @@ enum purpose
|
||||
static::crm => 1,
|
||||
static::landing => 1,
|
||||
static::marketplace => 2,
|
||||
static::charity => 2,
|
||||
/* static::charity => 2, */
|
||||
static::search => 2,
|
||||
static::calculate => 2,
|
||||
/* static::logic => 1,
|
||||
static::tools => 1,
|
||||
static::workers => 1,
|
||||
static::objects => 1,
|
||||
static::events => 1,
|
||||
static::events => 1, */
|
||||
static::special => 4,
|
||||
default => 1
|
||||
};
|
||||
@@ -153,27 +238,28 @@ enum purpose
|
||||
/**
|
||||
* Coefficient
|
||||
*
|
||||
* @return int|float Coefficient to the project development cost
|
||||
* @return int|float Coefficient to the project development hours
|
||||
*/
|
||||
public function coefficient(): int|float
|
||||
{
|
||||
// Exit (success)
|
||||
return match ($this) {
|
||||
static::funnel => 1.4,
|
||||
static::funnel => 2,
|
||||
static::contact => 1.1,
|
||||
static::neural_network => 2,
|
||||
static::neural_network => 4,
|
||||
static::game => 3,
|
||||
static::gallery => 1,
|
||||
static::crm => 3,
|
||||
static::landing => 1.2,
|
||||
static::marketplace => 2,
|
||||
static::charity => 0.8,
|
||||
static::crm => 6,
|
||||
static::landing => 1.5,
|
||||
static::marketplace => 8,
|
||||
/* static::charity => 0.8, */
|
||||
static::search => 1,
|
||||
static::calculate => 1.1,
|
||||
static::calculate => 2,
|
||||
/* static::logic => 1,
|
||||
static::tools => 1,
|
||||
static::workers => 1.2,
|
||||
static::objects => 1,
|
||||
static::events => 1.5,
|
||||
static::events => 1.5, */
|
||||
static::special => 2,
|
||||
default => 1
|
||||
};
|
||||
|
||||
@@ -19,12 +19,8 @@ use InvalidArgumentException as exception_argument,
|
||||
enum status
|
||||
{
|
||||
case creating;
|
||||
case calculated;
|
||||
case requested;
|
||||
|
||||
case invoiced;
|
||||
|
||||
case developing;
|
||||
case developed;
|
||||
case launched;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,13 @@ final class settings extends core implements record_interface
|
||||
*/
|
||||
public protected(set) database $database;
|
||||
|
||||
/**
|
||||
* Serialized
|
||||
*
|
||||
* @var bool $serialized Is the implementator object serialized?
|
||||
*/
|
||||
private bool $serialized = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -111,9 +118,19 @@ final class settings extends core implements record_interface
|
||||
*/
|
||||
public function serialize(): self
|
||||
{
|
||||
if ($this->serialized) {
|
||||
// The record implementor is serialized
|
||||
|
||||
// Exit (fail)
|
||||
throw new exception_runtime('The record implementor is already serialized');
|
||||
}
|
||||
|
||||
// Serializing the record parameters
|
||||
$this->record->active = (int) $this->record->active;
|
||||
|
||||
// Writing the status of serializing
|
||||
$this->serialized = true;
|
||||
|
||||
// Exit (success)
|
||||
return $this;
|
||||
}
|
||||
@@ -125,9 +142,19 @@ final class settings extends core implements record_interface
|
||||
*/
|
||||
public function deserialize(): self
|
||||
{
|
||||
if (!$this->serialized) {
|
||||
// The record implementor is deserialized
|
||||
|
||||
// Exit (fail)
|
||||
throw new exception_runtime('The record implementor is already deserialized');
|
||||
}
|
||||
|
||||
// Deserializing the record parameters
|
||||
$this->record->active = (bool) $this->record->active;
|
||||
|
||||
// Writing the status of serializing
|
||||
$this->serialized = false;
|
||||
|
||||
// Exit (success)
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -82,10 +82,6 @@ final class start extends command
|
||||
// Initializing the account
|
||||
$account = $robot->get('account');
|
||||
|
||||
// Initializing the message last update text
|
||||
exec(command: 'git log --oneline $(git describe --tags --abbrev=0 @^ --always)..@ -1 --format="%at" | xargs -I{} date -d @{} "+%Y.%m.%d %H:%M"', output: $git);
|
||||
$update = empty($git[0]) ? '' : "🔏 *$localization->menu_update:* " . unmarkdown($git[0]);
|
||||
|
||||
// Calculating amount of projects
|
||||
$projects = count($account->projects());
|
||||
|
||||
@@ -115,14 +111,42 @@ final class start extends command
|
||||
)
|
||||
);
|
||||
|
||||
// Title
|
||||
$title = "📋 *$localization->menu_title*";
|
||||
|
||||
// Declaring the message variables
|
||||
$welcome = $cooperation = null;
|
||||
|
||||
if ($projects > 0) {
|
||||
// The account have projects
|
||||
|
||||
// Welcome
|
||||
$welcome = "🤟 *$localization->menu_description_partner*";
|
||||
|
||||
// Cooperation
|
||||
$cooperation = $localization->menu_cooperation;
|
||||
} else {
|
||||
// The account have not projects
|
||||
|
||||
// Welcome
|
||||
$welcome = $localization->menu_description_guest;
|
||||
}
|
||||
|
||||
// Update
|
||||
/* exec(command: 'git log --oneline $(git describe --tags --abbrev=0 @^ --always)..@ -1 --format="%at" | xargs -I{} date -d @{} "+%Y\.%m\.%d %H:%M"', output: $git); // Formatted */
|
||||
exec(command: 'git log --oneline $(git describe --tags --abbrev=0 @^ --always)..@ -1 --format="%at"', output: $git);
|
||||
$update = empty($git[0]) ? '' : "🔏 *$localization->menu_update:* ![" . $git[0] . '](tg://time?unix=' . $git[0] . '&format=r)';
|
||||
|
||||
// Sending the message
|
||||
$robot->sendMessage(
|
||||
text: implode(
|
||||
"\n\n",
|
||||
[
|
||||
"📋 *$localization->menu_title*",
|
||||
$projects > 0 ? printf($localization->menu_description_partner, $partners) : $localization->menu_description_guest,
|
||||
array_filter([
|
||||
$title,
|
||||
$welcome,
|
||||
$cooperation,
|
||||
$update
|
||||
]
|
||||
])
|
||||
),
|
||||
parse_mode: mode::MARKDOWN,
|
||||
disable_notification: true,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,924 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace kodorvan\constructor\models\telegram\conversations\project;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\core,
|
||||
kodorvan\constructor\models\account,
|
||||
kodorvan\constructor\models\localization,
|
||||
kodorvan\constructor\models\settings,
|
||||
kodorvan\constructor\models\project\enumerations\type as project_type,
|
||||
kodorvan\constructor\models\project\enumerations\purpose as project_purpose,
|
||||
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
|
||||
|
||||
// Library for languages support
|
||||
use mirzaev\languages\language;
|
||||
|
||||
// The library for escaping all markdown symbols
|
||||
use function mirzaev\unmarkdown;
|
||||
|
||||
// Framework for Telegram
|
||||
use SergiX44\Nutgram\Nutgram as telegram,
|
||||
SergiX44\Nutgram\Conversations\InlineMenu as menu,
|
||||
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode,
|
||||
SergiX44\Nutgram\Handlers\Type\Command as command,
|
||||
SergiX44\Nutgram\Telegram\Types\Message\Message as message,
|
||||
SergiX44\Nutgram\Telegram\Types\Internal\InputFile as input,
|
||||
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup as keyboard,
|
||||
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardButton as button;
|
||||
|
||||
// Built-in libraries
|
||||
use Error as error;
|
||||
|
||||
/**
|
||||
* Telegram project
|
||||
*
|
||||
* @package kodorvan\constructor\models\telegram
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class create extends menu
|
||||
{
|
||||
/**
|
||||
* Text
|
||||
*
|
||||
* @var string $text The message text
|
||||
*/
|
||||
public string $text = '';
|
||||
|
||||
/**
|
||||
* Type
|
||||
*
|
||||
* @var project_type $type The project type
|
||||
*/
|
||||
public project_type $type;
|
||||
|
||||
/**
|
||||
* Purpose
|
||||
*
|
||||
* @var project_purpose $purpose The project purpose
|
||||
*/
|
||||
public project_purpose $purpose;
|
||||
|
||||
/**
|
||||
* Start
|
||||
*
|
||||
* Generate the project create menu and start the process
|
||||
*
|
||||
* @param telegram $robot The robot
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function start(telegram $robot): void
|
||||
{
|
||||
// Initializing the language
|
||||
$language = $robot->get('language') ?? LANGUAGE_DEFAULT;
|
||||
|
||||
// Initializing the menu message localization
|
||||
$localization = $robot->get('localization') ?? new localization($language);
|
||||
|
||||
// Initializing the account
|
||||
$account = $robot->get('account');
|
||||
|
||||
// Initializing the project development cost
|
||||
$cost = $this->cost();
|
||||
|
||||
// Generating the message text
|
||||
$text = implode(
|
||||
"\n\n",
|
||||
[
|
||||
"🏛 *$localization->project_create_title*",
|
||||
$cost > 0 ? "*$localization->project_create_cost:* " . $cost . ($account->currency?->symbol() ?? CURRENCY_DEFAULT->symbol()) : $localization->project_create_description
|
||||
]
|
||||
);
|
||||
|
||||
if ($this->text !== $text) {
|
||||
$this->menuText(
|
||||
text: $text,
|
||||
opt: [
|
||||
'parse_mode' => mode::MARKDOWN
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->type)) {
|
||||
// Initialized the project type
|
||||
|
||||
// Initializing the buffer for the first row
|
||||
$first = [];
|
||||
|
||||
// Writing the project type button into the buffer of the first row
|
||||
$first[0] = button::make(
|
||||
text: $localization['project_type_' . $this->type?->name] ?? $this->type?->label(language: $language),
|
||||
callback_data: '@types'
|
||||
);
|
||||
|
||||
if (isset($this->purpose) || $this->type === project_type::complex) {
|
||||
// Initialized the project purpose
|
||||
|
||||
// Writing the project purpose button into the buffer of the first row
|
||||
$first[1] = button::make(
|
||||
text: $localization['project_purpose_' . $this->purpose?->name] ?? $this->purpose?->label(language: $language),
|
||||
callback_data: '@purposes'
|
||||
);
|
||||
|
||||
// Writing the project buttons first row
|
||||
$this->addButtonRow(...$first);
|
||||
|
||||
// Initializing the row
|
||||
$row = [];
|
||||
|
||||
// Initializing the maximum amount of buttons in a row
|
||||
$break = 2;
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::chat_robot,
|
||||
project_type::parser,
|
||||
project_type::calculator,
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::program,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Integrations
|
||||
|
||||
if (isset($this->integrations)) {
|
||||
// Initialized the project integrations
|
||||
|
||||
} else {
|
||||
// Not initialized the project integrations
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::chat_robot,
|
||||
project_type::parser,
|
||||
project_type::calculator,
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::program,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Server
|
||||
|
||||
if (isset($this->server)) {
|
||||
// Initialized the project server
|
||||
|
||||
} else {
|
||||
// Not initialized the project server
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::calculator,
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::program,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Interface
|
||||
|
||||
if (isset($this->interface)) {
|
||||
// Initialized the project interface
|
||||
|
||||
if ($this->type === project_type::calculator) {
|
||||
// Calculator
|
||||
|
||||
// site, mobile or desktop program
|
||||
} else if ($this->type === project_type::crm) {
|
||||
// CRM
|
||||
|
||||
// site, mobile or desktop program
|
||||
} else if ($this->type === project_type::program) {
|
||||
// Program
|
||||
|
||||
// mobile or desktop
|
||||
}
|
||||
} else {
|
||||
// Not initialized the project interface
|
||||
|
||||
if ($this->type === project_type::calculator) {
|
||||
// Calculator
|
||||
|
||||
// site, mobile or desktop program
|
||||
} else if ($this->type === project_type::crm) {
|
||||
// CRM
|
||||
|
||||
// site, mobile or desktop program
|
||||
} else if ($this->type === project_type::program) {
|
||||
// Program
|
||||
|
||||
// mobile or desktop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::chat_robot,
|
||||
project_type::parser,
|
||||
project_type::calculator,
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::program,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Repository
|
||||
|
||||
if (isset($this->repository)) {
|
||||
// Initialized the project repository
|
||||
|
||||
} else {
|
||||
// Not initialized the project repository
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::calculator,
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::program,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Testing
|
||||
|
||||
if (isset($this->testing)) {
|
||||
// Initialized the project testing
|
||||
|
||||
} else {
|
||||
// Not initialized the project testing
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::program,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Security
|
||||
|
||||
if (isset($this->security)) {
|
||||
// Initialized the project security
|
||||
|
||||
} else {
|
||||
// Not initialized the project security
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::chat_robot,
|
||||
project_type::parser,
|
||||
project_type::calculator,
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::program,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Documenting
|
||||
|
||||
if (isset($this->documenting)) {
|
||||
// Initialized the project documenting
|
||||
|
||||
} else {
|
||||
// Not initialized the project documenting
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::chat_robot,
|
||||
project_type::calculator,
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::program,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Localization
|
||||
|
||||
if (isset($this->localization)) {
|
||||
// Initialized the project localization
|
||||
|
||||
} else {
|
||||
// Not initialized the project localization
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::chat_robot,
|
||||
project_type::parser,
|
||||
project_type::calculator,
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Journal
|
||||
|
||||
if (isset($this->journal)) {
|
||||
// Initialized the project journal
|
||||
|
||||
} else {
|
||||
// Not initialized the project journal
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::chat_robot,
|
||||
project_type::calculator,
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::program,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Scalability
|
||||
|
||||
if (isset($this->scalability)) {
|
||||
// Initialized the project scalability
|
||||
|
||||
} else {
|
||||
// Not initialized the project scalability
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::chat_robot,
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Framework
|
||||
|
||||
if (isset($this->framework)) {
|
||||
// Initialized the project framework
|
||||
|
||||
} else {
|
||||
// Not initialized the project framework
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::chat_robot,
|
||||
project_type::parser,
|
||||
project_type::calculator,
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::program,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Database
|
||||
|
||||
if (isset($this->database)) {
|
||||
// Initialized the project database
|
||||
|
||||
} else {
|
||||
// Not initialized the project database
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::chat_robot,
|
||||
project_type::calculator,
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::program,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Depth of development
|
||||
|
||||
if (isset($this->depth)) {
|
||||
// Initialized the project depth of development
|
||||
|
||||
} else {
|
||||
// Not initialized the project depth of development
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (match ($this->type) {
|
||||
project_type::chat_robot,
|
||||
project_type::parser,
|
||||
project_type::calculator,
|
||||
project_type::crm,
|
||||
project_type::site,
|
||||
project_type::program,
|
||||
project_type::complex => true,
|
||||
default => false
|
||||
}) {
|
||||
// Form of cooperation
|
||||
|
||||
if (isset($this->cooperation)) {
|
||||
// Initialized the project cooperation
|
||||
|
||||
} else {
|
||||
// Not initialized the project cooperation
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Not initialized the project purpose
|
||||
|
||||
// Writing the project purpose button into the buffer of the first row
|
||||
$first[1] = button::make(
|
||||
text: "🔸 $localization->project_create_button_purpose",
|
||||
callback_data: '@purposes'
|
||||
);
|
||||
|
||||
// Writing the project buttons first row
|
||||
$this->addButtonRow(...$first);
|
||||
}
|
||||
} else {
|
||||
// Not initialized the project type
|
||||
|
||||
// Writing the project type button
|
||||
$this->addButtonRow(
|
||||
button::make(
|
||||
text: "🔸 $localization->project_create_button_type",
|
||||
callback_data: '@types'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($cost > 0) {
|
||||
// The project development cost was calculated
|
||||
|
||||
// Writing the project type button
|
||||
$this->addButtonRow(
|
||||
button::make(
|
||||
text: "☑️ $localization->project_create_button_request",
|
||||
callback_data: '@request'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Updating the message and saving its text
|
||||
$this->text = $this->orNext('stop')->showMenu()->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Types
|
||||
*
|
||||
* Generate the project type select menu
|
||||
*
|
||||
* @param telegram $robot The robot
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function types(telegram $robot): void
|
||||
{
|
||||
// Initializing the language
|
||||
$language = $robot->get('language') ?? LANGUAGE_DEFAULT;
|
||||
|
||||
// Initializing the menu message localization
|
||||
$localization = $robot->get('localization') ?? new localization($language);
|
||||
|
||||
// Initializing the account
|
||||
$account = $robot->get('account');
|
||||
|
||||
// Updating the message text
|
||||
$this->menuText(
|
||||
text: implode(
|
||||
"\n\n",
|
||||
[
|
||||
"⚙️ *$localization->project_create_types_title*",
|
||||
$localization->project_create_types_description,
|
||||
]
|
||||
),
|
||||
opt: [
|
||||
'parse_mode' => mode::MARKDOWN
|
||||
]
|
||||
);
|
||||
|
||||
// Deleting the message buttons
|
||||
$this->clearButtons();
|
||||
|
||||
// Initializing the row
|
||||
$row = [];
|
||||
|
||||
// Declaring the buffer of the row buttons length
|
||||
$length = 0;
|
||||
|
||||
// Initializing the maximum amount of buttons in a row
|
||||
$break = 4;
|
||||
|
||||
// Initializing buffer of types
|
||||
$types = project_type::cases();
|
||||
|
||||
if (isset($this->type)) {
|
||||
// Initialized the selected type
|
||||
|
||||
// Initializing the selected purpose index
|
||||
$selected = array_search($this->type ?? null, $types, strict: true);
|
||||
|
||||
if ($selected !== false) {
|
||||
// Found the selected type index
|
||||
|
||||
// Exclude the selected type from buffer of types
|
||||
unset($types[$selected]);
|
||||
}
|
||||
}
|
||||
|
||||
// Declaring the generated buttons registry
|
||||
$generated = [];
|
||||
|
||||
foreach ($types as $index => $type) {
|
||||
// Iterating over types
|
||||
|
||||
if (array_search($type, $generated)) {
|
||||
// The type button is already generated
|
||||
|
||||
// Skipping the iteration
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($length + $type->length() > $break && !empty($row)) {
|
||||
// Reached the limit of buttons in a row
|
||||
|
||||
// Writing the row into the menu
|
||||
$this->addButtonRow(...$row);
|
||||
|
||||
// Writing buttons into the generated buttons registry
|
||||
$generated += $row;
|
||||
|
||||
// Reinitializing the row buttons length
|
||||
/* $length -= $break; */
|
||||
$length = 0;
|
||||
|
||||
// Reinitializing the row
|
||||
$row = [];
|
||||
}
|
||||
|
||||
// Addition to row buttons length
|
||||
$length += $type->length();
|
||||
|
||||
// Writing the type button into the row
|
||||
$row[] = button::make(
|
||||
text: $localization['project_type_' . $type->name] ?? $type->label(language: $language),
|
||||
callback_data: "$type->name@type"
|
||||
);
|
||||
|
||||
// Initializing the next type
|
||||
$next = $types[$index + 1] ?? null;
|
||||
|
||||
if ($next?->length() >= $break) {
|
||||
// The next type is the full-length button
|
||||
|
||||
// Writing the row into the menu
|
||||
$this->addButtonRow(...$row);
|
||||
|
||||
// Writing buttons into the generated buttons registry
|
||||
$generated += $row;
|
||||
|
||||
// Reinitializing the row
|
||||
$row = [];
|
||||
|
||||
// Reinitializing the row buttons length
|
||||
$length = 0;
|
||||
|
||||
// Writing the button into the menu
|
||||
$this->addButtonRow(button::make(
|
||||
text: $localization['project_type_' . $next->name] ?? $next->label(language: $language),
|
||||
callback_data: "$next->name@type"
|
||||
));
|
||||
|
||||
// Writing the button into the generated buttons registry
|
||||
$generated[] = $next;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($row) > 0) {
|
||||
// The row was not writed
|
||||
|
||||
// Writing the row into the menu
|
||||
$this->addButtonRow(...$row);
|
||||
}
|
||||
|
||||
// Deinitializing deprecated variables
|
||||
unset($row, $limit, $length, $generated, $types, $type);
|
||||
|
||||
// Updating the message and saving its text
|
||||
$this->text = $this->showMenu()->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type
|
||||
*
|
||||
* Write the project type
|
||||
*
|
||||
* @param telegram $robot The robot
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function type(telegram $robot): void
|
||||
{
|
||||
// Initializing the project type
|
||||
$this->type = project_type::{$robot->callbackQuery()->data};
|
||||
|
||||
// Deinitializing the project purpose
|
||||
unset($this->purpose);
|
||||
|
||||
if (count($this->type->purposes()) === 1) {
|
||||
// The project type has only 1 purpose
|
||||
|
||||
// Initializing the project purpose
|
||||
$this->purpose = $this->type->purposes()[0];
|
||||
}
|
||||
|
||||
// Deleting the message buttons
|
||||
$this->clearButtons();
|
||||
|
||||
// Deleting the message buttons
|
||||
$this->start(robot: $robot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Purposes
|
||||
*
|
||||
* Generate the project purpose select menu
|
||||
*
|
||||
* @param telegram $robot The robot
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function purposes(telegram $robot): void
|
||||
{
|
||||
// Initializing the language
|
||||
$language = $robot->get('language') ?? LANGUAGE_DEFAULT;
|
||||
|
||||
// Initializing the menu message localization
|
||||
$localization = $robot->get('localization') ?? new localization($language);
|
||||
|
||||
// Initializing the account
|
||||
$account = $robot->get('account');
|
||||
|
||||
// Updating the message text
|
||||
$this->menuText(
|
||||
text: implode(
|
||||
"\n\n",
|
||||
[
|
||||
"🛠 *$localization->project_create_purposes_title*",
|
||||
$localization->project_create_purposes_description,
|
||||
]
|
||||
),
|
||||
opt: [
|
||||
'parse_mode' => mode::MARKDOWN
|
||||
]
|
||||
);
|
||||
|
||||
// Deleting the message buttons
|
||||
$this->clearButtons();
|
||||
|
||||
// Initializing the row
|
||||
$row = [];
|
||||
|
||||
// Declaring the buffer of the row buttons length
|
||||
$length = 0;
|
||||
|
||||
// Initializing the maximum amount of buttons in a row
|
||||
$break = 4;
|
||||
|
||||
// Initializing buffer of purposes
|
||||
$purposes = $this->type->purposes();
|
||||
|
||||
if (isset($this->purpose)) {
|
||||
// Initialized the selected purpose
|
||||
|
||||
// Initializing the selected purpose index
|
||||
$selected = array_search($this->purpose ?? null, $purposes, strict: true);
|
||||
|
||||
if ($selected !== false) {
|
||||
// Found the selected purpose index
|
||||
|
||||
// Exclude the selected purpose from buffer of purposes
|
||||
unset($purposes[$selected]);
|
||||
}
|
||||
}
|
||||
|
||||
// Declaring the generated buttons registry
|
||||
$generated = [];
|
||||
|
||||
foreach ($purposes as $index => $purpose) {
|
||||
// Iterating over purposes
|
||||
|
||||
if (array_search($purpose, $generated)) {
|
||||
// The purpose button is already generated
|
||||
|
||||
// Skipping the iteration
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($length + $purpose->length() > $break && !empty($row)) {
|
||||
// Reached the limit of buttons in a row
|
||||
|
||||
// Writing the row into the menu
|
||||
$this->addButtonRow(...$row);
|
||||
|
||||
// Writing buttons into the generated buttons registry
|
||||
$generated += $row;
|
||||
|
||||
// Reinitializing the row buttons length
|
||||
/* $length -= $break; */
|
||||
$length = 0;
|
||||
|
||||
// Reinitializing the row
|
||||
$row = [];
|
||||
}
|
||||
|
||||
// Addition to row buttons length
|
||||
$length += $purpose->length();
|
||||
|
||||
// Initializing the coefficient
|
||||
$coefficient = $purpose->coefficient();
|
||||
|
||||
// Writing the purpose button into the row
|
||||
$row[] = button::make(
|
||||
/* text: ($localization['project_purpose_' . $purpose->name] ?? $purpose->label(language: $language)) . (!empty($coefficient) ? ' x' . $coefficient : ''), */
|
||||
text: $localization['project_purpose_' . $purpose->name] ?? $purpose->label(language: $language),
|
||||
callback_data: "$purpose->name@purpose"
|
||||
);
|
||||
|
||||
// Initializing the next purpose
|
||||
$next = $purposes[$index + 1] ?? null;
|
||||
|
||||
if ($next?->length() >= $break) {
|
||||
// The next purpose is the full-length button
|
||||
|
||||
// Writing the row into the menu
|
||||
$this->addButtonRow(...$row);
|
||||
|
||||
// Writing buttons into the generated buttons registry
|
||||
$generated += $row;
|
||||
|
||||
// Reinitializing the row
|
||||
$row = [];
|
||||
|
||||
// Reinitializing the row buttons length
|
||||
$length = 0;
|
||||
|
||||
// Initializing the coefficient
|
||||
$coefficient = $next->coefficient();
|
||||
|
||||
// Writing the button into the menu
|
||||
$this->addButtonRow(button::make(
|
||||
/* text: ($localization['project_purpose_' . $next->name] ?? $next->label(language: $language)) . (!empty($coefficient) ? ' x' . $coefficient : ''), */
|
||||
text: $localization['project_purpose_' . $next->name] ?? $next->label(language: $language),
|
||||
callback_data: "$next->name@purpose"
|
||||
));
|
||||
|
||||
// Writing the button into the generated buttons registry
|
||||
$generated[] = $next;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($row) > 0) {
|
||||
// The row was not writed
|
||||
|
||||
// Writing the row into the menu
|
||||
$this->addButtonRow(...$row);
|
||||
}
|
||||
|
||||
// Writing the "special" button into the menu
|
||||
$this->addButtonRow(button::make(
|
||||
/* text: ($localization->project_purpose_special ?? project_purpose::special->label(language: $language)) . ' x' . project_purpose::special->coefficient(), */
|
||||
text: $localization->project_purpose_special ?? project_purpose::special->label(language: $language),
|
||||
callback_data: project_purpose::special->name . '@purpose'
|
||||
));
|
||||
|
||||
// Deinitializing deprecated variables
|
||||
unset($row, $limit, $length, $generated, $purposes, $purpose);
|
||||
|
||||
// Updating the message and saving its text
|
||||
$this->text = $this->showMenu()->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose
|
||||
*
|
||||
* Write the project purpose
|
||||
*
|
||||
* @param telegram $robot The robot
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function purpose(telegram $robot): void
|
||||
{
|
||||
// Initializing the project purpose
|
||||
$this->purpose = project_purpose::{$robot->callbackQuery()->data};
|
||||
|
||||
// Deleting the message buttons
|
||||
$this->clearButtons();
|
||||
|
||||
// Deleting the message buttons
|
||||
$this->start(robot: $robot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cost
|
||||
*
|
||||
* Calculate the project development cost
|
||||
*
|
||||
* @return int|float The project development cost
|
||||
*/
|
||||
public function cost(): int|float
|
||||
{
|
||||
// Declaring the project development cost
|
||||
$cost = 0;
|
||||
|
||||
if (isset($this->type)) {
|
||||
// Initialized the project type
|
||||
|
||||
// Calculating the project development cost
|
||||
$cost = $this->type->cost();
|
||||
}
|
||||
|
||||
if (isset($this->purpose)) {
|
||||
// Initialized the project purpose
|
||||
|
||||
// Calculating the project development cost
|
||||
$cost *= $this->purpose->coefficient();
|
||||
}
|
||||
|
||||
// Exit (success)
|
||||
return $cost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param telegram $robot The robot
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function request(telegram $robot): void
|
||||
{
|
||||
// Initializing the language
|
||||
$language = $robot->get('language') ?? LANGUAGE_DEFAULT;
|
||||
|
||||
// Initializing the menu message localization
|
||||
$localization = $robot->get('localization') ?? new localization($language);
|
||||
|
||||
// Sending the message
|
||||
$robot->sendMessage(
|
||||
text: "✅ *$localization->project_create_requested*",
|
||||
parse_mode: mode::MARKDOWN,
|
||||
disable_notification: true
|
||||
);
|
||||
|
||||
// Stopping conversation
|
||||
$this->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop
|
||||
*
|
||||
* Delete the project create menu and terminating the process
|
||||
*
|
||||
* @param telegram $robot The robot
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function stop(telegram $robot): void
|
||||
{
|
||||
// Initializing the language
|
||||
$language = $robot->get('language') ?? LANGUAGE_DEFAULT;
|
||||
|
||||
// Initializing the menu message localization
|
||||
$localization = $robot->get('localization') ?? new localization($language);
|
||||
|
||||
// Sending the message
|
||||
$robot->sendMessage(
|
||||
text: "⚠️ *$localization->project_create_cancelled*",
|
||||
parse_mode: mode::MARKDOWN,
|
||||
disable_notification: true
|
||||
);
|
||||
|
||||
// Stopping conversation
|
||||
$this->end();
|
||||
}
|
||||
}
|
||||
48
kodorvan/constructor/system/models/telegram/exceptions.php
Normal file
48
kodorvan/constructor/system/models/telegram/exceptions.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace kodorvan\constructor\models\telegram;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\core,
|
||||
kodorvan\constructor\models\account,
|
||||
kodorvan\constructor\models\localization,
|
||||
kodorvan\constructor\models\settings as model,
|
||||
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
|
||||
|
||||
// Library for languages support
|
||||
use mirzaev\languages\language;
|
||||
|
||||
// The library for escaping all markdown symbols
|
||||
use function mirzaev\unmarkdown;
|
||||
|
||||
// Framework for Telegram
|
||||
use SergiX44\Nutgram\Nutgram as telegram,
|
||||
SergiX44\Nutgram\Telegram\Exceptions\TelegramException as telegram_exception,
|
||||
SergiX44\Nutgram\Exception\ApiException as telegram_api_exception;
|
||||
|
||||
// Built-in libraries
|
||||
use Error as error;
|
||||
|
||||
/**
|
||||
* Telegram exceptions
|
||||
*
|
||||
* @package kodorvan\constructor\models\telegram
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
final class exceptions extends telegram_api_exception
|
||||
{
|
||||
public static ?string $pattern = '.*';
|
||||
|
||||
public function __invoke(telegram $robot, telegram_exception $exception)
|
||||
{
|
||||
// override this method to change the default behaviour:
|
||||
$robot->sendMessage('robot zdox');
|
||||
throw new static($exception->getMessage(), $exception->getCode(), $exception);
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,7 @@ declare(strict_types=1);
|
||||
namespace kodorvan\constructor\models\telegram\middlewares;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\core,
|
||||
kodorvan\constructor\models\account as model,
|
||||
use kodorvan\constructor\models\account as model,
|
||||
kodorvan\constructor\models\authorizations;
|
||||
|
||||
// The library for languages support
|
||||
@@ -30,7 +29,7 @@ use Error as error;
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class account extends core
|
||||
final class account
|
||||
{
|
||||
/**
|
||||
* Account
|
||||
|
||||
@@ -5,8 +5,7 @@ declare(strict_types=1);
|
||||
namespace kodorvan\constructor\models\telegram\middlewares;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\core,
|
||||
kodorvan\constructor\models\account,
|
||||
use kodorvan\constructor\models\account,
|
||||
kodorvan\constructor\models\authorizations as model;
|
||||
|
||||
// The library for languages support
|
||||
@@ -30,7 +29,7 @@ use Error as error;
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class authorizations extends core
|
||||
final class authorizations
|
||||
{
|
||||
/**
|
||||
* Authorizations
|
||||
|
||||
@@ -5,8 +5,7 @@ declare(strict_types=1);
|
||||
namespace kodorvan\constructor\models\telegram\middlewares;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\core,
|
||||
kodorvan\constructor\models\account,
|
||||
use kodorvan\constructor\models\account,
|
||||
kodorvan\constructor\models\authorizations;
|
||||
|
||||
// The library for languages support
|
||||
@@ -30,7 +29,7 @@ use Error as error;
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class language extends core
|
||||
final class language
|
||||
{
|
||||
/**
|
||||
* Language
|
||||
|
||||
@@ -5,8 +5,7 @@ declare(strict_types=1);
|
||||
namespace kodorvan\constructor\models\telegram\middlewares;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\core,
|
||||
kodorvan\constructor\models\account,
|
||||
use kodorvan\constructor\models\account,
|
||||
kodorvan\constructor\models\localization as model,
|
||||
kodorvan\constructor\models\authorizations;
|
||||
|
||||
@@ -32,7 +31,7 @@ use Exception as exception,
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class localization extends core
|
||||
final class localization
|
||||
{
|
||||
/**
|
||||
* Localization
|
||||
|
||||
@@ -5,8 +5,7 @@ declare(strict_types=1);
|
||||
namespace kodorvan\constructor\models\telegram\middlewares;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\core,
|
||||
kodorvan\constructor\models\account,
|
||||
use kodorvan\constructor\models\account,
|
||||
kodorvan\constructor\models\authorizations;
|
||||
|
||||
// The library for languages support
|
||||
@@ -30,7 +29,7 @@ use Error as error;
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class settings extends core
|
||||
final class settings
|
||||
{
|
||||
/**
|
||||
* Settings
|
||||
@@ -75,7 +74,7 @@ final class settings extends core
|
||||
|
||||
// Sending the message
|
||||
$robot->sendMessage(
|
||||
text: '⛔ *' . $localization['not_authorized_settings'] . '*',
|
||||
text: "⛔ *$localization->not_authorized_settings*",
|
||||
parse_mode: mode::MARKDOWN
|
||||
);
|
||||
|
||||
|
||||
@@ -5,8 +5,7 @@ declare(strict_types=1);
|
||||
namespace kodorvan\constructor\models\telegram\middlewares\system;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\core,
|
||||
kodorvan\constructor\models\account,
|
||||
use kodorvan\constructor\models\account,
|
||||
kodorvan\constructor\models\authorizations;
|
||||
|
||||
// The library for languages support
|
||||
@@ -23,14 +22,14 @@ use SergiX44\Nutgram\Nutgram as telegram,
|
||||
use Error as error;
|
||||
|
||||
/**
|
||||
* Telegram middleware: language
|
||||
* Telegram middleware: system settings
|
||||
*
|
||||
* @package kodorvan\constructor\models\telegram\middlewares\system
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class settings extends core
|
||||
final class settings
|
||||
{
|
||||
/**
|
||||
* System settings (middleware)
|
||||
|
||||
@@ -8,8 +8,13 @@ namespace kodorvan\constructor\models\telegram;
|
||||
use kodorvan\constructor\models\core,
|
||||
kodorvan\constructor\models\account,
|
||||
kodorvan\constructor\models\localization,
|
||||
kodorvan\constructor\models\settings as model,
|
||||
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
|
||||
kodorvan\constructor\models\settings,
|
||||
kodorvan\constructor\models\deal,
|
||||
kodorvan\constructor\models\project as model,
|
||||
kodorvan\constructor\models\project\enumerations\status as project_status,
|
||||
kodorvan\constructor\models\worker\enumerations\type as worker_type,
|
||||
kodorvan\constructor\models\telegram\processes\language\select as process_language_select,
|
||||
kodorvan\constructor\models\telegram\conversations\project as conversation_project;
|
||||
|
||||
// Library for languages support
|
||||
use mirzaev\languages\language;
|
||||
@@ -17,6 +22,16 @@ use mirzaev\languages\language;
|
||||
// The library for escaping all markdown symbols
|
||||
use function mirzaev\unmarkdown;
|
||||
|
||||
// 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;
|
||||
|
||||
// Framework for Telegram
|
||||
use SergiX44\Nutgram\Nutgram as telegram,
|
||||
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode,
|
||||
@@ -27,7 +42,8 @@ use SergiX44\Nutgram\Nutgram as telegram,
|
||||
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardButton as button;
|
||||
|
||||
// Built-in libraries
|
||||
use Error as error;
|
||||
use DateTime as datetime,
|
||||
Error as error;
|
||||
|
||||
/**
|
||||
* Telegram project
|
||||
@@ -40,42 +56,260 @@ use Error as error;
|
||||
final class project extends core
|
||||
{
|
||||
/**
|
||||
* Language
|
||||
* Create
|
||||
*
|
||||
* Write the language into the account and the robot instance
|
||||
* Starting the project creating process
|
||||
*
|
||||
* @param telegram $robot The chat-robot instance
|
||||
* @param language $language The language
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function create(telegram $robot, language $language = LANGUAGE_DEFAULT): void
|
||||
public static function create(telegram $robot): void
|
||||
{
|
||||
/* // Initializing the account
|
||||
// Initializing the account
|
||||
$account = $robot->get('account');
|
||||
|
||||
if ($account instanceof account) {
|
||||
// Initialized the account
|
||||
// Initializing the project record
|
||||
$record = new model()->write(account: $account->identifier);
|
||||
|
||||
// Initializing the menu message localization
|
||||
$localization = new localization($language);
|
||||
// Initializing the project
|
||||
$project = new model(record: $record);
|
||||
|
||||
if ($localization instanceof localization) {
|
||||
// Initialized the localization
|
||||
// Deserializing the record
|
||||
$project->deserialize();
|
||||
|
||||
// Starting the project creating process
|
||||
conversation_project::begin(
|
||||
bot: $robot,
|
||||
userId: $robot->userId(),
|
||||
chatId: $robot->chatId(),
|
||||
data: ['instance' => $project]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept
|
||||
*
|
||||
* Accept the project and issue an invoice
|
||||
*
|
||||
* @param telegram $robot The robot
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function accept(telegram $robot): void
|
||||
{
|
||||
// Sending the "typing" action
|
||||
/* $robot->sendChatAction('typing'); */
|
||||
|
||||
// Initializing the account language
|
||||
$language = $robot->get('language') ?? LANGUAGE_DEFAULT;
|
||||
|
||||
// Initializing the account localization
|
||||
$localization = $robot->get('localization') ?? new localization($language);
|
||||
|
||||
// Initializing the account
|
||||
$account = $robot->get('account');
|
||||
|
||||
// Initializing the account authorizations
|
||||
$authorizations = $account->authorizations();
|
||||
|
||||
if ($authorizations->system_deals) {
|
||||
// Authorized to deals (system)
|
||||
|
||||
if ($authorizations->system_projects) {
|
||||
// Authorized to projects (system)
|
||||
|
||||
if ($authorizations->system_invoices) {
|
||||
// Authorized to invoices (system)
|
||||
|
||||
// The message
|
||||
$message = $robot->message();
|
||||
|
||||
// The message text
|
||||
$text = $message?->text;
|
||||
|
||||
// The project identifier
|
||||
preg_match('/^.*#(\d+)$/m', $text, $matches);
|
||||
$identifier = (int) $matches[1];
|
||||
unset($matches);
|
||||
|
||||
// The deal
|
||||
$deal = new deal()->read(filter: fn(record $record) => $record->identifier === $identifier && $record->active === 1);
|
||||
|
||||
// Deserializing the record
|
||||
$deal->deserialize();
|
||||
|
||||
if ($deal instanceof deal) {
|
||||
// Initialized the deal
|
||||
|
||||
// The project
|
||||
$project = $deal->project();
|
||||
|
||||
if ($project instanceof model) {
|
||||
// Initialized the project
|
||||
|
||||
if ($project->status === project_status::requested && $deal->confirmed === 0) {
|
||||
// The project deal is not confirmed
|
||||
|
||||
// Initializing the keyboard
|
||||
$keyboard = keyboard::make();
|
||||
|
||||
// Writing the row into the keyboard
|
||||
$keyboard->addRow(
|
||||
button::make(
|
||||
text: "🔏 $localization->project_accepted_button_prepayment",
|
||||
url: 'https://t.me/' . $robot->user()->username
|
||||
)
|
||||
);
|
||||
|
||||
// Initializing the receiver account
|
||||
$receiver = $project->account();
|
||||
|
||||
// Title
|
||||
$title = "🏗 *$localization->project_accepted_title*";
|
||||
|
||||
// Description
|
||||
$description = $localization->project_accepted_description;
|
||||
|
||||
// Prepayment
|
||||
$prepayment = "*$localization->project_accepted_prepayment:* $deal->prepayment" . $receiver->currency->symbol();
|
||||
|
||||
// Documents
|
||||
$documents = $localization->project_accepted_documents;
|
||||
|
||||
// Sending the message
|
||||
$robot->sendMessage(
|
||||
text: implode(
|
||||
"\n\n",
|
||||
array_filter([
|
||||
$title,
|
||||
$description,
|
||||
$documents,
|
||||
$prepayment
|
||||
])
|
||||
),
|
||||
chat_id: $receiver->identifier_telegram,
|
||||
parse_mode: mode::MARKDOWN,
|
||||
disable_notification: true,
|
||||
reply_markup: $keyboard
|
||||
);
|
||||
|
||||
// Ending the conversation
|
||||
$robot->endConversation();
|
||||
|
||||
// Writing the confirmation date
|
||||
$deal->confirmed = svoboda::timestamp();
|
||||
|
||||
// Serializing the record
|
||||
$deal->serialize();
|
||||
|
||||
// Updating the deal record
|
||||
$deal->update();
|
||||
|
||||
// Deserializing the record
|
||||
$deal->deserialize();
|
||||
|
||||
// Initializing the keyboard
|
||||
$keyboard = keyboard::make();
|
||||
|
||||
// Writing the row into the keyboard
|
||||
$keyboard->addRow(
|
||||
button::make(
|
||||
text: "✉️ $localization->project_deal_button_chat",
|
||||
url: 'https://t.me/' . $robot->user()->username
|
||||
)
|
||||
);
|
||||
|
||||
// Converting the confirmation to unixtime format
|
||||
$unixtime = $deal->confirmed + svoboda::datetime()->getTimestamp();
|
||||
|
||||
// Confirmed
|
||||
/* $confirmed = "*$localization->project_accepted_confirmed*: '; */
|
||||
$confirmed = "$localization->project_accepted_confirmed: ';
|
||||
|
||||
// Updating the message buttons
|
||||
$message->editText(
|
||||
text: implode(
|
||||
"\n\n",
|
||||
[
|
||||
$message->getText(),
|
||||
$confirmed
|
||||
]
|
||||
),
|
||||
/* parse_mode: mode::MARKDOWN, */
|
||||
reply_markup: $keyboard
|
||||
);
|
||||
} else {
|
||||
// The project deal is confirmed
|
||||
|
||||
// Sending the message
|
||||
$robot->sendMessage(
|
||||
text: "⚠️ *$localization->project_accepted_already_confirmed*",
|
||||
parse_mode: mode::MARKDOWN,
|
||||
);
|
||||
|
||||
// Ending the conversation
|
||||
$robot->endConversation();
|
||||
}
|
||||
} else {
|
||||
// Not initialized the project
|
||||
|
||||
// Sending the message
|
||||
$robot->sendMessage(
|
||||
text: "⚠️ *$localization->project_accepted_project_not_found*",
|
||||
parse_mode: mode::MARKDOWN,
|
||||
);
|
||||
|
||||
// Ending the conversation
|
||||
$robot->endConversation();
|
||||
}
|
||||
} else {
|
||||
// Not initialized the project
|
||||
|
||||
// Sending the message
|
||||
$robot->sendMessage(
|
||||
text: "⚠️ *$localization->project_accepted_deal_not_found*",
|
||||
parse_mode: mode::MARKDOWN,
|
||||
);
|
||||
|
||||
// Ending the conversation
|
||||
$robot->endConversation();
|
||||
}
|
||||
} else {
|
||||
// Not authorized to invoices (system)
|
||||
|
||||
// Sending the message
|
||||
$robot->sendMessage(
|
||||
text: "⛔ *$localization->not_authorized_system_invoices*",
|
||||
parse_mode: mode::MARKDOWN,
|
||||
);
|
||||
|
||||
// Ending the conversation
|
||||
$robot->endConversation();
|
||||
}
|
||||
} else {
|
||||
// Not authorized to projects (system)
|
||||
|
||||
// Sending the message
|
||||
$robot->sendMessage(
|
||||
text: "✅ *$localization->settings_language_update_success:* " . trim($from->flag() . ' ' . $from->label($to)) . ' → *' . trim($to->flag() . ' ' . $to->label($to)) . '*',
|
||||
text: "⛔ *$localization->not_authorized_system_projects*",
|
||||
parse_mode: mode::MARKDOWN,
|
||||
disable_notification: true
|
||||
);
|
||||
|
||||
// Sending the message
|
||||
$robot->answerCallbackQuery(
|
||||
text: $to->label($to),
|
||||
show_alert: false
|
||||
);
|
||||
// Ending the conversation
|
||||
$robot->endConversation();
|
||||
}
|
||||
} */
|
||||
} else {
|
||||
// Not authorized to deals (system)
|
||||
|
||||
// Sending the message
|
||||
$robot->sendMessage(
|
||||
text: "⛔ *$localization->not_authorized_system_deals*",
|
||||
parse_mode: mode::MARKDOWN,
|
||||
);
|
||||
|
||||
// Ending the conversation
|
||||
$robot->endConversation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
227
kodorvan/constructor/system/models/worker.php
Normal file
227
kodorvan/constructor/system/models/worker.php
Normal file
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace kodorvan\constructor\models;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\core,
|
||||
kodorvan\constructor\models\authorizations,
|
||||
kodorvan\constructor\models\settings,
|
||||
kodorvan\constructor\models\project,
|
||||
kodorvan\constructor\models\account,
|
||||
kodorvan\constructor\models\project\enumerations\type as project_type,
|
||||
kodorvan\constructor\models\project\enumerations\status as project_status;
|
||||
|
||||
// The library for languages support
|
||||
use mirzaev\languages\language;
|
||||
|
||||
// The library for currencies support
|
||||
use mirzaev\currencies\currency;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\database,
|
||||
mirzaev\baza\column,
|
||||
mirzaev\baza\record,
|
||||
mirzaev\baza\enumerations\encoding,
|
||||
mirzaev\baza\enumerations\type;
|
||||
|
||||
// Active Record pattern
|
||||
use mirzaev\record\interfaces\record as record_interface,
|
||||
mirzaev\record\traits\record as record_trait;
|
||||
|
||||
// Svoboda time
|
||||
use svoboda\time\statement as svoboda;
|
||||
|
||||
// Framework for Telegram
|
||||
use SergiX44\Nutgram\Telegram\Types\User\User as telegram_user;
|
||||
|
||||
// Built-in libraries
|
||||
use Exception as exception,
|
||||
RuntimeException as exception_runtime;
|
||||
|
||||
/**
|
||||
* Worker
|
||||
*
|
||||
* @package kodorvan\constructor\models
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class worker extends core implements record_interface
|
||||
{
|
||||
use record_trait;
|
||||
|
||||
/**
|
||||
* File
|
||||
*
|
||||
* @var string $file Path to the database file
|
||||
*/
|
||||
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'workers.baza';
|
||||
|
||||
/**
|
||||
* Database
|
||||
*
|
||||
* @var database $database The database
|
||||
*/
|
||||
public protected(set) database $database;
|
||||
|
||||
/**
|
||||
* Serialized
|
||||
*
|
||||
* @var bool $serialized Is the implementator object serialized?
|
||||
*/
|
||||
private bool $serialized = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @method record|null $record The record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(?record $record = null)
|
||||
{
|
||||
// Initializing the database
|
||||
$this->database = new database()
|
||||
->encoding(encoding::utf8)
|
||||
->columns(
|
||||
new column('identifier', type::long_long_unsigned),
|
||||
new column('account', type::long_long_unsigned),
|
||||
new column('hour', type::integer_unsigned),
|
||||
new column('currency', type::string, ['length' => 3]),
|
||||
new column('active', type::char),
|
||||
new column('updated', type::integer_unsigned),
|
||||
new column('created', type::integer_unsigned)
|
||||
)
|
||||
->connect($this->file);
|
||||
|
||||
// Initializing the record
|
||||
$record instanceof record and $this->record = $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write
|
||||
*
|
||||
* @param int $account The account identifier
|
||||
* @param int|float $hour Cost per hour
|
||||
* @param currency|string $currency Currency of cost per hour
|
||||
* @param bool $active Is the record active?
|
||||
*
|
||||
* @return record|false The record, if created
|
||||
*/
|
||||
public function write(
|
||||
int $account,
|
||||
int|float $hour,
|
||||
currency|string $currency = CURRENCY_DEFAULT ?? currency::usd,
|
||||
bool $active = true,
|
||||
): record|false {
|
||||
// Initializing the record
|
||||
$record = $this->database->record(
|
||||
$this->database->count() + 1,
|
||||
(int) $account,
|
||||
$hour,
|
||||
$currency instanceof currency ? $currency->name : (string) $currency,
|
||||
(int) $active,
|
||||
svoboda::timestamp(),
|
||||
svoboda::timestamp()
|
||||
);
|
||||
|
||||
// Writing the record into the database
|
||||
$created = $this->database->write($record);
|
||||
|
||||
// Exit (success)
|
||||
return $created ? $record : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Account
|
||||
*
|
||||
* Search for the worker account
|
||||
*
|
||||
* @return account|null The account worker
|
||||
*/
|
||||
public function account(): ?account
|
||||
{
|
||||
// Search for the worker account
|
||||
$account = new account()->read(filter: fn(record $record) => $record->active === 1 && $record->identifier === $this->account);
|
||||
|
||||
if ($account instanceof account) {
|
||||
// Found the worker account
|
||||
|
||||
// Exit (success)
|
||||
return $account;
|
||||
}
|
||||
|
||||
// Exit (fail)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Workers
|
||||
*
|
||||
* Search for workers
|
||||
*
|
||||
* @param int $amount Amount
|
||||
*
|
||||
* @return array Workers
|
||||
*/
|
||||
public static function workers(int $amount = 100): array
|
||||
{
|
||||
// Search for workers and exit (success/fail)
|
||||
return new static()->database->read(
|
||||
filter: fn(record $record) => $record->active === 1,
|
||||
amount: $amount
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize
|
||||
*
|
||||
* @return self The instance from which the method was called (fluent interface)
|
||||
*/
|
||||
public function serialize(): self
|
||||
{
|
||||
if ($this->serialized) {
|
||||
// The record implementor is serialized
|
||||
|
||||
// Exit (fail)
|
||||
throw new exception_runtime('The record implementor is already serialized');
|
||||
}
|
||||
|
||||
// Serializing the record parameters
|
||||
$this->record->currency = $this->record->currency->name;
|
||||
$this->record->active = (int) $this->record->active;
|
||||
|
||||
// Writing the status of serializing
|
||||
$this->serialized = true;
|
||||
|
||||
// Exit (success)
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize
|
||||
*
|
||||
* @return self The instance from which the method was called (fluent interface)
|
||||
*/
|
||||
public function deserialize(): self
|
||||
{
|
||||
if (!$this->serialized) {
|
||||
// The record implementor is deserialized
|
||||
|
||||
// Exit (fail)
|
||||
throw new exception_runtime('The record implementor is already deserialized');
|
||||
}
|
||||
|
||||
// Deserializing the record parameters
|
||||
$this->record->currency = currency::{$this->record->currency} ?? CURRENCY_DEFAULT ?? currency::usd;
|
||||
$this->record->active = (bool) $this->record->active;
|
||||
|
||||
// Writing the status of serializing
|
||||
$this->serialized = false;
|
||||
|
||||
// Exit (success)
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace kodorvan\constructor\models\worker\enumerations;
|
||||
|
||||
// The library for languages support
|
||||
use mirzaev\languages\language;
|
||||
|
||||
// Built-in libraries
|
||||
use InvalidArgumentException as exception_argument,
|
||||
DomainException as exception_domain;
|
||||
|
||||
/**
|
||||
* Type
|
||||
*
|
||||
* @package kodorvan\neurobot\models\worker\enumerations
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
enum type
|
||||
{
|
||||
case programmer;
|
||||
case designer;
|
||||
case booster;
|
||||
|
||||
/**
|
||||
* Label
|
||||
*
|
||||
* @param language $language The language
|
||||
*
|
||||
* @return string The project architecture label
|
||||
*/
|
||||
public function label(language $language = LANGUAGE_DEFAULT): string
|
||||
{
|
||||
// Exit (success)
|
||||
return match ($this) {
|
||||
static::programmer => match ($language) {
|
||||
language::en => 'Programmer',
|
||||
language::ru => 'Программист'
|
||||
},
|
||||
static::designer => match ($language) {
|
||||
language::en => 'Designer',
|
||||
language::ru => 'Дизайнер'
|
||||
},
|
||||
static::booster => match ($language) {
|
||||
language::en => 'Booster',
|
||||
language::ru => 'Бустер'
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace kodorvan\constructor;
|
||||
|
||||
// Framework for PHP
|
||||
use mirzaev\minimal\core,
|
||||
mirzaev\minimal\route;
|
||||
|
||||
// Enabling debugging
|
||||
/* ini_set('error_reporting', E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1); */
|
||||
|
||||
// Initializing path to the public directory
|
||||
define('INDEX', __DIR__);
|
||||
|
||||
// Initializing path to the project root directory
|
||||
define('ROOT', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
|
||||
|
||||
// Initializing path to the directory of views
|
||||
define('VIEWS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views');
|
||||
|
||||
// Initializing path to the directory of settings
|
||||
define('SETTINGS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'settings');
|
||||
|
||||
// Initializing system settings
|
||||
require SETTINGS . DIRECTORY_SEPARATOR . 'system.php';
|
||||
|
||||
// Initializing path to the directory of the storage
|
||||
define('STORAGE', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage');
|
||||
|
||||
// Initializing path to the databases directory
|
||||
define('DATABASES', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'databases');
|
||||
|
||||
// Initializing path to the localizations directory
|
||||
define('LOCALIZATIONS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'localizations');
|
||||
|
||||
// Initializing dependencies
|
||||
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
|
||||
// Initializing core
|
||||
$core = new core(namespace: __NAMESPACE__);
|
||||
|
||||
// Initializing routes
|
||||
$core->router
|
||||
->write('/', new route('index', 'index'), 'GET')
|
||||
;
|
||||
|
||||
// Handling request
|
||||
$core->start();
|
||||
@@ -1,109 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace kodorvan\constructor;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\account,
|
||||
kodorvan\constructor\models\telegram\middlewares,
|
||||
kodorvan\constructor\models\telegram\commands\start,
|
||||
kodorvan\constructor\models\telegram\settings;
|
||||
|
||||
// Library for languages support
|
||||
use mirzaev\languages\language;
|
||||
|
||||
// Framework for PHP
|
||||
use mirzaev\minimal\core,
|
||||
mirzaev\minimal\route;
|
||||
|
||||
// Framework for Telegram
|
||||
use Telegram\Bot\BotsManager as telegram;
|
||||
|
||||
// Enabling debugging
|
||||
/* ini_set('error_reporting', E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1); */
|
||||
|
||||
// Initializing path to the public directory
|
||||
define('INDEX', __DIR__);
|
||||
|
||||
// Initializing path to the project root directory
|
||||
define('ROOT', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
|
||||
|
||||
// Initializing path to the directory of views
|
||||
define('VIEWS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views');
|
||||
|
||||
// Initializing path to the directory of settings
|
||||
define('SETTINGS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'settings');
|
||||
|
||||
// Initializing system settings
|
||||
require SETTINGS . DIRECTORY_SEPARATOR . 'system.php';
|
||||
|
||||
// Initializing path to the directory of the storage
|
||||
define('STORAGE', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage');
|
||||
|
||||
// Initializing path to the databases directory
|
||||
define('DATABASES', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'databases');
|
||||
|
||||
// Initializing path to the localizations directory
|
||||
define('LOCALIZATIONS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'localizations');
|
||||
|
||||
// Initiailizing Telegram chat-robot settings
|
||||
define('TELEGRAM', require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php'));
|
||||
|
||||
// Initializing dependencies
|
||||
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
|
||||
// Initializing the robots manager settings
|
||||
$settings = [
|
||||
'bots' => [
|
||||
'constructor' => [
|
||||
'token' => TELEGRAM['constructor']['key'],
|
||||
'certificate_path' => PROJECT_CERTIFICATE,
|
||||
'webhook_url' => 'https://' . PROJECT_DOMAIN . '/telegram/constructor.php',
|
||||
'commands' => [
|
||||
start::class,
|
||||
]
|
||||
],
|
||||
'async_requests' => true,
|
||||
'base_bot_url' => 'https://' . PROJECT_DOMAIN . '/telegram',
|
||||
]
|
||||
];
|
||||
|
||||
// Initializing the robots manager
|
||||
$robot = new telegram($settings);
|
||||
|
||||
var_dump($telegram->bot('constructor')->getWebhookUpdate());
|
||||
|
||||
/* // Initializing the updates listener
|
||||
$robot->onUpdate(function (context $context): void {});
|
||||
|
||||
// Initializing the robot middlewares
|
||||
$robot->middleware([middlewares::class, 'account']);
|
||||
$robot->middleware([middlewares::class, 'language']);
|
||||
$robot->middleware([middlewares::class, 'localization']);
|
||||
$robot->middleware([middlewares::class, 'authorizations']);
|
||||
|
||||
// Initializing the robot commands handlers
|
||||
$robot->onCommand('start', [commands::class, 'start']);
|
||||
|
||||
$robot->onCommand('start telegram voronka', [commands::class, 'start']);
|
||||
$robot->onCommand('start parser', [commands::class, 'start']);
|
||||
$robot->onCommand('start calculator', [commands::class, 'start']);
|
||||
|
||||
$robot->onCommand('language', [commands::class, 'language'])->middleware([middlewares::class, 'settings']);
|
||||
$robot->onCommand('society', [commands::class, 'society']);
|
||||
|
||||
// Initializing the robot settings language buttons handlers
|
||||
foreach (language::cases() as $language) {
|
||||
// Iterating over languages
|
||||
|
||||
// Initializing language buttons
|
||||
$robot->onCbQueryData(["settings_language_$language->name"], fn(context $context) => settings::language($context, $language));
|
||||
};
|
||||
|
||||
$robot->onCbQueryData('project_create', ['process_project_create', 'name']);
|
||||
|
||||
// Starting chat-robot
|
||||
$robot->run(); */
|
||||
@@ -60,9 +60,9 @@ require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
|
||||
// Initializing the robot
|
||||
$robot = new telegram(
|
||||
token: TELEGRAM['constructor']['key'],
|
||||
token: TELEGRAM['key'],
|
||||
config: new telegram_settings(
|
||||
botName: TELEGRAM['constructor']['name']
|
||||
botName: TELEGRAM['name']
|
||||
)
|
||||
);
|
||||
|
||||
@@ -72,5 +72,5 @@ $robot->setWebhook(
|
||||
ip_address: SERVER_IP_ADDRESS,
|
||||
max_connections: 10,
|
||||
drop_pending_updates: false,
|
||||
secret_token: 'bebra228'
|
||||
secret_token: TELEGRAM['password']
|
||||
);
|
||||
|
||||
@@ -6,12 +6,14 @@ namespace kodorvan\constructor;
|
||||
|
||||
// Files of the project
|
||||
use kodorvan\constructor\models\account,
|
||||
kodorvan\constructor\models\telegram\settings,
|
||||
kodorvan\constructor\models\localization,
|
||||
kodorvan\constructor\models\telegram\settings as telegram_settings,
|
||||
kodorvan\constructor\models\telegram\project as telegram_project,
|
||||
kodorvan\constructor\models\telegram\commands\start as command_start,
|
||||
kodorvan\constructor\models\telegram\commands\account as command_account,
|
||||
kodorvan\constructor\models\telegram\commands\society as command_society,
|
||||
kodorvan\constructor\models\telegram\commands\language as command_language,
|
||||
kodorvan\constructor\models\telegram\conversations\project\create as conversation_project_create,
|
||||
/* kodorvan\constructor\models\telegram\conversations\project\create as conversation_project_create, */
|
||||
kodorvan\constructor\models\telegram\middlewares\account as middleware_account,
|
||||
kodorvan\constructor\models\telegram\middlewares\language as middleware_language,
|
||||
kodorvan\constructor\models\telegram\middlewares\localization as middleware_localization,
|
||||
@@ -25,15 +27,25 @@ use mirzaev\languages\language;
|
||||
use mirzaev\minimal\core,
|
||||
mirzaev\minimal\route;
|
||||
|
||||
// The library for escaping all markdown symbols
|
||||
use function mirzaev\unmarkdown;
|
||||
|
||||
// Framework for Telegram
|
||||
use SergiX44\Nutgram\Nutgram as telegram,
|
||||
SergiX44\Nutgram\Configuration as telegram_settings,
|
||||
SergiX44\Nutgram\RunningMode\Webhook as webhook;
|
||||
use SergiX44\Nutgram\Nutgram as framework_telegram,
|
||||
SergiX44\Nutgram\Configuration as framework_telegram_settings,
|
||||
SergiX44\Nutgram\RunningMode\Webhook as framework_telegram_webhook,
|
||||
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode,
|
||||
SergiX44\Nutgram\Telegram\Exceptions\TelegramException as framework_telegram_exception,
|
||||
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup as keyboard,
|
||||
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardButton as button;
|
||||
|
||||
// The symphony cache library
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter as cache_adapter,
|
||||
Symfony\Component\Cache\Psr16Cache as cache;
|
||||
|
||||
// Built-in libraries
|
||||
use Exception as exception;
|
||||
|
||||
// Enabling debugging
|
||||
/* ini_set('error_reporting', E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
@@ -70,25 +82,25 @@ define('TELEGRAM', require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php'));
|
||||
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
|
||||
// Initializing the robot
|
||||
$robot = new telegram(
|
||||
token: TELEGRAM['constructor']['key'],
|
||||
config: new telegram_settings(
|
||||
botName: TELEGRAM['constructor']['name'],
|
||||
$robot = new framework_telegram(
|
||||
token: TELEGRAM['key'],
|
||||
config: new framework_telegram_settings(
|
||||
botName: TELEGRAM['name'],
|
||||
cache: new cache(new cache_adapter())
|
||||
)
|
||||
);
|
||||
|
||||
$webhook = new webhook(secretToken: 'bebra228');
|
||||
$webhook = new framework_telegram_webhook(secretToken: TELEGRAM['password']);
|
||||
$webhook->setSafeMode(true);
|
||||
|
||||
$robot->setRunningMode($webhook);
|
||||
$robot->throttle(10);
|
||||
|
||||
$robot->middleware(middleware_account::class);
|
||||
$robot->middleware(middleware_language::class);
|
||||
$robot->middleware(middleware_localization::class);
|
||||
$robot->middleware(middleware_authorizations::class);
|
||||
|
||||
|
||||
// Start
|
||||
$robot->registerCommand(command_start::class);
|
||||
$robot->onCommand('start telegram voronka', command_start::class);
|
||||
@@ -104,13 +116,108 @@ foreach (language::cases() as $language) {
|
||||
// Iterating over languages
|
||||
|
||||
// Select the language
|
||||
$robot->onCallbackQueryData('settings_language_$language->name', fn(telegram $robot) => settings::language(robot: $robot, language: $language));
|
||||
$robot->onCallbackQueryData('settings_language_$language->name', fn(framework_telegram $robot) => telegram_settings::language(robot: $robot, language: $language));
|
||||
};
|
||||
|
||||
// Society
|
||||
$robot->registerCommand(command_society::class);
|
||||
|
||||
// Project: create
|
||||
$robot->onCallbackQueryData('project_create', conversation_project_create::class);
|
||||
$robot->onCallbackQueryData('project_create', [telegram_project::class, 'create']);
|
||||
|
||||
$robot->run();
|
||||
// Project: request
|
||||
$robot
|
||||
->onCallbackQueryData('project_deal_accept', [telegram_project::class, 'accept']);
|
||||
|
||||
$robot->onApiError(function (framework_telegram $robot, framework_telegram_exception $exception) {
|
||||
try {
|
||||
// Writing into the errors output
|
||||
error_log($exception->getMessage());
|
||||
|
||||
// Initializing the account language
|
||||
$language = $robot->get('language') ?? LANGUAGE_DEFAULT;
|
||||
|
||||
// Initializing the account localization
|
||||
$localization = $robot->get('localization') ?? new localization($language);
|
||||
|
||||
// Initializing the keyboard
|
||||
$keyboard = keyboard::make();
|
||||
|
||||
// Writing the row into the keyboard
|
||||
$keyboard->addRow(
|
||||
button::make(
|
||||
text: "✉️ $localization->error_button_chat_operator",
|
||||
url: PROJECT_OPERATOR_URL ?? PROJECT_MEDIA_URL ?? 'https://t.me/kodorvan'
|
||||
)
|
||||
);
|
||||
|
||||
// Title
|
||||
$title = "🔥 *$localization->error_title*";
|
||||
|
||||
// Description
|
||||
$description = $localization->error_description;
|
||||
|
||||
// Repeat
|
||||
$repeat = $localization->error_repeat;
|
||||
|
||||
// Sending the message
|
||||
$robot->sendMessage(
|
||||
text: implode(
|
||||
"\n\n",
|
||||
[
|
||||
$title,
|
||||
$description,
|
||||
$repeat
|
||||
]
|
||||
),
|
||||
disable_notification: true,
|
||||
parse_mode: mode::MARKDOWN,
|
||||
reply_markup: $keyboard
|
||||
);
|
||||
|
||||
// Ending the conversation
|
||||
$robot->endConversation();
|
||||
|
||||
foreach (ERRORS_RECEIVERS as $receiver) {
|
||||
// Iterating over errors receivers
|
||||
|
||||
// Initializing the keyboard
|
||||
$keyboard = keyboard::make();
|
||||
|
||||
// Writing the row into the keyboard
|
||||
$keyboard->addRow(
|
||||
button::make(
|
||||
text: "✉️ $localization->error_button_chat_user",
|
||||
url: 'https://t.me/' . $robot->user()->username
|
||||
)
|
||||
);
|
||||
|
||||
// Domain
|
||||
/* $domain = "*$localization->error_account:* @" . $robot->user()->username; */
|
||||
|
||||
// Sending the message
|
||||
$robot->sendMessage(
|
||||
text: implode(
|
||||
"\n\n",
|
||||
[
|
||||
$exception->getMessage(),
|
||||
/* $domain */
|
||||
]
|
||||
),
|
||||
chat_id: $receiver,
|
||||
/* parse_mode: mode::MARKDOWN, */
|
||||
reply_markup: $keyboard
|
||||
);
|
||||
}
|
||||
} catch (exception $exception) {
|
||||
// Writing into the errors output
|
||||
error_log($exception->getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
$robot->run();
|
||||
} catch (exception $exception) {
|
||||
// Writing into the errors output
|
||||
error_log($exception->getMessage());
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
*
|
||||
!.gitignore
|
||||
!*.sample
|
||||
!*/
|
||||
!*.md
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
openssl req -newkey rsa:2048 -sha256 -nodes -keyout private.key -x509 -days 365 -out public.pem -subj "/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=Sex"
|
||||
@@ -21,10 +21,22 @@ define('PROJECT_MEDIA_URL', 'https://t.me/kodorvan');
|
||||
define('PROJECT_OPERATOR_URL', 'https://t.me/kodorvan?direct');
|
||||
define('PROJECT_REPOSITORY', REPOSITORY . '/' . PROJECT_CREATOR . '/' . PROJECT_NAME);
|
||||
define('PROJECT_REPOSITORY_LANGUAGE_ADD', PROJECT_REPOSITORY . '/src/branch/stable/' . PROJECT_CREATOR . '/' . PROJECT_NAME . '/system/localizations');
|
||||
/* define('PROJECT_CERTIFICATE', SETTINGS . DIRECTORY_SEPARATOR . 'cert.pem'); */
|
||||
|
||||
define('CURRENCY_DEFAULT', currency::usd);
|
||||
define('LANGUAGE_DEFAULT', language::en);
|
||||
|
||||
define('PROJECT_CREATE_START_HOURS', 1);
|
||||
define('PROJECT_CREATE_START_COEFFICIENT', 0);
|
||||
define('PROJECT_CREATE_HOURS_ADDITIONAL', 0);
|
||||
define('PROJECT_CREATE_HOURS_MINIMAL', 4);
|
||||
define('PROJECT_CREATE_DAY_HOURS', 4);
|
||||
define('PROJECT_CREATE_DAY_ADDITIONAL', 1);
|
||||
define('PROJECT_CREATE_COST_HOUR_DEFAULT', 20);
|
||||
define('PROJECT_CREATE_COST_CURRENCY', CURRENCY_DEFAULT);
|
||||
|
||||
define('PROJECT_CREATE_REQUEST_RECEIVERS', [
|
||||
'-0000000000000'
|
||||
]);
|
||||
|
||||
// Initializing default theme for the views templater
|
||||
define('THEME', 'default');
|
||||
|
||||
@@ -2,18 +2,17 @@
|
||||
|
||||
// Telegram API chat-robot
|
||||
return [
|
||||
'constructor' => [
|
||||
'identifier' => 0,
|
||||
'name' => 'kodorvan',
|
||||
'domain' => '',
|
||||
'key' => '',
|
||||
'database' => [
|
||||
'host' => '/run/mysqld/mysqld.sock',
|
||||
'port' => 3306,
|
||||
'user' => '',
|
||||
'password' => '',
|
||||
'database' => '',
|
||||
]
|
||||
'identifier' => 0,
|
||||
'domain' => 'kodorvan_bot',
|
||||
'name' => 'kodorvan',
|
||||
'password' => '',
|
||||
'key' => '',
|
||||
'database' => [
|
||||
'host' => '/run/mysqld/mysqld.sock',
|
||||
'port' => 3306,
|
||||
'user' => '',
|
||||
'password' => '',
|
||||
'database' => '',
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user