diff --git a/composer.json b/composer.json index 2041d2c..b91d853 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "triagens/arangodb": "^3.6", "moonlandsoft/yii2-phpexcel": ">=2.0", "carono/yii2-1c-exchange": "^0.3.1", - "mirzaev/yii2-arangodb": "~2.1.x-dev" + "mirzaev/yii2-arangodb": "~2.1.x-dev", + "mirzaev/yii2-arangodb-sessions": "~1.0.0" }, "require-dev": { "codeception/codeception": ">=4.1", diff --git a/composer.lock b/composer.lock index b9ed6ad..0025dae 100644 --- a/composer.lock +++ b/composer.lock @@ -4,14 +4,14 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f259164a4251a4ef37262d42fbeb40d6", + "content-hash": "116946ecdb84687a081d5633fd8505f6", "packages": [ { "name": "bower-asset/bootstrap", "version": "v3.4.1", "source": { "type": "git", - "url": "https://github.com/twbs/bootstrap.git", + "url": "git@github.com:twbs/bootstrap.git", "reference": "68b0d231a13201eb14acd3dc84e51543d16e5f7e" }, "dist": { @@ -715,56 +715,6 @@ }, "time": "2021-01-23T16:37:31+00:00" }, - { - "name": "mirzaev/yii2-arangodb", - "version": "2.1.x-dev", - "source": { - "type": "git", - "url": "https://git.hood.su/mirzaev/yii2/arangodb", - "reference": "1592238e5f8495dd7385848e8d65300ba7940b46" - }, - "require": { - "php": "^8.0.0", - "triagens/arangodb": "~3.2", - "yiisoft/yii2": "2.*" - }, - "require-dev": { - "yiisoft/yii2-debug": "*" - }, - "type": "yii2-extension", - "autoload": { - "psr-4": { - "mirzaev\\yii2\\arangodb\\": "mirzaev/yii2-arangodb" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "AGPL-3.0-or-later" - ], - "authors": [ - { - "name": "Arsen Mirzaev Tatyano-Muradovich", - "email": "red@hood.su", - "homepage": "https://hood.su/mirzaev", - "role": "Developer" - }, - { - "name": "Ilya Rumyantsev", - "email": "explosivebit@gmail.com" - }, - { - "name": "Alvian Burhanuddin", - "email": "alvianthelfarqy@gmail.com" - } - ], - "description": "Library for connecting ArangoDB-PHP to Yii2", - "homepage": "https://git.hood.su/mirzaev/yii2/arangodb", - "keywords": [ - "ArangoDb", - "yii2" - ], - "time": "2021-03-15T16:41:18+00:00" - }, { "name": "moonlandsoft/yii2-phpexcel", "version": "2.0.0", @@ -3554,16 +3504,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.12.2", + "version": "1.13.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "245710e971a030f42e08f4912863805570f23d39" + "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/245710e971a030f42e08f4912863805570f23d39", - "reference": "245710e971a030f42e08f4912863805570f23d39", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/be1996ed8adc35c3fd795488a653f4b518be70ea", + "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea", "shasum": "" }, "require": { @@ -3615,9 +3565,9 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/1.12.2" + "source": "https://github.com/phpspec/prophecy/tree/1.13.0" }, - "time": "2020-12-19T10:15:11+00:00" + "time": "2021-03-17T13:42:18+00:00" }, { "name": "phpunit/php-code-coverage", @@ -3939,16 +3889,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.2", + "version": "9.5.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "f661659747f2f87f9e72095bb207bceb0f151cb4" + "reference": "27241ac75fc37ecf862b6e002bf713b6566cbe41" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f661659747f2f87f9e72095bb207bceb0f151cb4", - "reference": "f661659747f2f87f9e72095bb207bceb0f151cb4", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/27241ac75fc37ecf862b6e002bf713b6566cbe41", + "reference": "27241ac75fc37ecf862b6e002bf713b6566cbe41", "shasum": "" }, "require": { @@ -4026,7 +3976,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.2" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.3" }, "funding": [ { @@ -4038,7 +3988,7 @@ "type": "github" } ], - "time": "2021-02-02T14:45:58+00:00" + "time": "2021-03-17T07:30:34+00:00" }, { "name": "psr/container", @@ -6721,9 +6671,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "mirzaev/yii2-arangodb": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/mirzaev/skillparts/system/controllers/AuthenticationController.php b/mirzaev/skillparts/system/controllers/AuthenticationController.php index bd85bce..9d4292c 100644 --- a/mirzaev/skillparts/system/controllers/AuthenticationController.php +++ b/mirzaev/skillparts/system/controllers/AuthenticationController.php @@ -47,6 +47,9 @@ class AuthenticationController extends Controller if (!Yii::$app->user->isGuest || $model->authentication()) { // Аккаунт аутентифицирован + // Создание сессии + yii::$app->session->open(); + // Инициализация $notifications_button = $this->renderPartial('/notification/button'); $notifications_panel_full = true; diff --git a/mirzaev/skillparts/system/controllers/DeauthenticationController.php b/mirzaev/skillparts/system/controllers/DeauthenticationController.php index 13f42d6..a82c7e5 100644 --- a/mirzaev/skillparts/system/controllers/DeauthenticationController.php +++ b/mirzaev/skillparts/system/controllers/DeauthenticationController.php @@ -34,11 +34,15 @@ class DeauthenticationController extends Controller public function actionIndex() { + // Инициализация yii::$app->response->format = Response::FORMAT_JSON; // Выход из аккаунта yii::$app->user->logout(); + // Удаление сессии + yii::$app->session->destroy(); + // Инициализация $model = new AccountForm(yii::$app->request->post('AccountForm') ?? yii::$app->request->get('AccountForm') ?? null); diff --git a/mirzaev/skillparts/system/controllers/NotificationController.php b/mirzaev/skillparts/system/controllers/NotificationController.php index 1a5d05e..827acba 100644 --- a/mirzaev/skillparts/system/controllers/NotificationController.php +++ b/mirzaev/skillparts/system/controllers/NotificationController.php @@ -35,12 +35,15 @@ class NotificationController extends Controller */ public function actionIndex() { + var_dump(yii::$app->session->id); + if (yii::$app->request->isPost) { // POST-запрос // Инициализация $model = new Notification(yii::$app->request->post('Notification')); $preload = (bool) (int) yii::$app->request->post('preload'); + $account = yii::$app->user->identity; yii::$app->response->format = Response::FORMAT_JSON; @@ -67,7 +70,7 @@ class NotificationController extends Controller ->for(['account', $model::collectionName() . '_edge_account']) ->traversal($model::collectionName(), 'OUTBOUND') ->in('account_edge_' . $model::collectionName()) - ->where(['account._id' => yii::$app->user->id]) + ->where(['account._id == "' . $account->readId() . '" && notification_edge_account._from != account_edge_notification[0]._to']) ->select($model::collectionName() . '_edge_account'); if (yii::$app->request->post('last')) { @@ -90,8 +93,8 @@ class NotificationController extends Controller * * @param bool $new Активация проверки на то, что уведомление не получено * @param bool $count Посчитать - */ - $search = function (bool $new = false, bool $count = false) use ($model, $type, $let, $limit): array|int { + */ + $search = function (bool $new = false, bool $count = false) use ($model, $account, $type, $let, $limit): array|int { if ($count) { // Запрошен подсчёт непрочитанных уведомлений @@ -106,7 +109,7 @@ class NotificationController extends Controller params: $new ? $let->getBindVars() : [], subquery_where: [ [ - 'account._id' => yii::$app->user->id + 'account._id' => $account->readId() ], [ [ @@ -122,8 +125,11 @@ class NotificationController extends Controller 'notification_edge_account', '(' . (string) $let . ')' ], + foreach: [ + 'edge' => 'notification_edge_account' + ], where: $new ? [ - 'account_edge_notification[0]._to' => null + 'edge != null' ] : [], limit: $limit, sort: ['DESC'], @@ -131,7 +137,7 @@ class NotificationController extends Controller handle: $count ? function ($request) { // Посчитать рёбра (информация о количестве непрочитанных уведомлений) return $request->count(); - }: null + } : null ); }; diff --git a/mirzaev/skillparts/system/controllers/ProfileController.php b/mirzaev/skillparts/system/controllers/ProfileController.php index ff6e6e1..5eff1ba 100644 --- a/mirzaev/skillparts/system/controllers/ProfileController.php +++ b/mirzaev/skillparts/system/controllers/ProfileController.php @@ -248,13 +248,13 @@ class ProfileController extends Controller foreach: ['edge' => 'account_edge_search'], where: 'edge._to == search._id', limit: $rows_amount, - offset: ((int) $page_search_history ?? 0) * $rows_amount + offset: $offset = ((int) $page_search_history ?? 0) * $rows_amount ); // Проверка результатов monitoring_result_check: - if (count($search_history) === 0) { + if (count($search_history) === 0 && $offset !== 0) { // Вышли за границу поиска после последней страницы // Реинициализация (вычитание для идентичного конечного результата) @@ -271,7 +271,7 @@ class ProfileController extends Controller foreach: ['edge' => 'account_edge_search'], where: 'edge._to == search._id', limit: $rows_amount, - offset: ((int) $page_search_history ?? 0) * $rows_amount + offset: $offset = ((int) $page_search_history ?? 0) * $rows_amount ); // Повторная проверка diff --git a/mirzaev/skillparts/system/controllers/RegistrationController.php b/mirzaev/skillparts/system/controllers/RegistrationController.php index 4997020..a75e650 100644 --- a/mirzaev/skillparts/system/controllers/RegistrationController.php +++ b/mirzaev/skillparts/system/controllers/RegistrationController.php @@ -13,30 +13,30 @@ use app\models\AccountForm; class RegistrationController extends Controller { - public function behaviors() - { - return [ - 'access' => [ - 'class' => AccessControl::class, - 'rules' => [ - [ - 'allow' => true, - 'roles' => ['?'], - ] - ], - ] - ]; - } + // public function behaviors() + // { + // return [ + // 'access' => [ + // 'class' => AccessControl::class, + // 'rules' => [ + // [ + // 'allow' => true, + // 'roles' => ['?'], + // ] + // ], + // ] + // ]; + // } public function actionIndex() { + // Инициализация + $model = new AccountForm(yii::$app->request->post('AccountForm') ?? yii::$app->request->get('AccountForm')); + $model->scenario = $model::SCENARIO_REGISTRATION; + if (yii::$app->request->isPost) { // POST-запрос - // Инициализация - $model = new AccountForm(yii::$app->request->post('AccountForm')); - $model->scenario = $model::SCENARIO_REGISTRATION; - yii::$app->response->format = Response::FORMAT_JSON; if (!yii::$app->user->isGuest || $model->registration()) { @@ -46,9 +46,17 @@ class RegistrationController extends Controller $model->scenario = $model::SCENARIO_AUTHENTICATION; $model->authentication(); + // Инициализация + $notifications_button = $this->renderPartial('/notification/button'); + $notifications_panel_full = true; + $notifications_panel = $this->renderPartial('/notification/panel', compact('notifications_panel_full')); + // Запись ответа $return = [ - 'menu' => $this->renderPartial('/account/panel/authenticated'), + 'menu' => $this->renderPartial('/account/panel/authenticated', compact( + 'notifications_button', + 'notifications_panel' + )), '_csrf' => yii::$app->request->getCsrfToken() ]; @@ -80,7 +88,7 @@ class RegistrationController extends Controller yii::$app->response->statusCode = 400; return [ - 'main' => $this->renderPartial('/account', compact('model')), + 'main' => $this->renderPartial('/account/index', compact('model')), 'redirect' => '/registration', '_csrf' => yii::$app->request->getCsrfToken() ]; @@ -90,7 +98,7 @@ class RegistrationController extends Controller if (!yii::$app->user->isGuest) { yii::$app->response->redirect('/'); } else { - return $this->render('/account', compact('model')); + return $this->render('/account/index', compact('model')); } } } diff --git a/mirzaev/skillparts/system/models/Account.php b/mirzaev/skillparts/system/models/Account.php index cf9c98e..c7b43fe 100644 --- a/mirzaev/skillparts/system/models/Account.php +++ b/mirzaev/skillparts/system/models/Account.php @@ -165,7 +165,7 @@ class Account extends Document implements IdentityInterface, PartnerInterface * @todo Подождать обновление Yii2 и добавить * проверку типов передаваемых параметров */ - public static function findByMail($mail): self + public static function findByMail($mail): ?self { return static::findOne(['mail' => $mail]); } diff --git a/mirzaev/skillparts/system/models/Notification.php b/mirzaev/skillparts/system/models/Notification.php index fb9c7fd..874700f 100644 --- a/mirzaev/skillparts/system/models/Notification.php +++ b/mirzaev/skillparts/system/models/Notification.php @@ -16,6 +16,8 @@ use Exception; * Поиск * * @see Product Поиск по товарам + * + * @todo Нет смысла каждый раз возвращать кнопку, надо написать проверки */ class Notification extends Document { @@ -43,13 +45,18 @@ class Notification extends Document * * @see SCENARIO_TRUSTED_CREATE */ - public Account|string|array|null $account; + public string $account; /** * Текст уведомления */ public string $text; + /** + * Разделитель получателей уведомлений + */ + public static string $delimiter = ','; + /** * Типы уведомлений */ @@ -119,13 +126,10 @@ class Notification extends Document /** * Запись - * - * @param bool|string $html Содержимое уведомления (HTML или текст) - * @param Account|array|string|null $account Получатель уведомления */ - public function write(Account|array|string|null $account = null): self|array|null + public function write(): self|array|null { - return $this::_write($this->text, $this->html, $account, $this->type); + return $this::_write($this->text, $this->html, $this->account, $this->type); } /** @@ -133,14 +137,14 @@ class Notification extends Document * * @param string $html Содержимое уведомления (HTML или текст) * @param bool|string|null $html Содержимое уведомления (HTML или текст) - * @param Account|array|string|null $account Получатель уведомления + * @param string $account Получатель уведомления * @param string $type Тип уведомления */ - public static function _write(string $text, bool|string|null $html = false, Account|array|string|null $account = null, string $type = self::TYPE_NOTICE): self|array|null + public static function _write(string $text, bool|string|null $html = false, string $account = null, string $type = self::TYPE_NOTICE): self|array|null { // Инициализация $model = new self; - $account ?? $account = yii::$app->user->identity ?? throw new Exception('Не удалось инициализировать получателя'); + $account or $account = yii::$app->user->identity->_key ?? throw new Exception('Не удалось инициализировать получателя'); if ((bool) (int) $html) { // Получен текст в формете HTML-кода @@ -160,79 +164,56 @@ class Notification extends Document // Уведомление записано // Инициализация получателей и создание ребра - if (empty($account)) { - // Получатель не передан - - goto test; - } else if (is_string($account)) { - // Передана необработанная строка - - // Инициализация - $delimiter = ','; - - // Конвертация - $account = array_map('trim', explode($delimiter, $account)); - - - if (in_array('@all', $account, true)) { - // Найден флаг обозначающий отправку всем пользователям - - // Инициализация - $return = []; - - foreach (Account::readAll() as $account) { - // Перебор всех аккаунтов - - // Запись ребра: УВЕДОМЛЕНИЕ -> АККАУНТ - $return[] = AccountEdgeNotification::writeSafe($model->readId(), $account->readId(), $type) ? $model : null; - } - - return $return ? $return : null; - } - - if (in_array('@test', $account, true)) { - // Найден флаг обозначающий тестирование (отправка самому себе) - - test: - return AccountEdgeNotification::writeSafe($model->readId(), yii::$app->user->id, $type) ? $model : null; - } - } - - if (is_array($account)) { - // Несколько получателей - - // Инициализация - $return = []; - - foreach ($account as $account) { - // Перебор получателей - - if ($account instanceof Account) { - // Один получатель - - // Запись ребра: УВЕДОМЛЕНИЕ -> АККАУНТ - return AccountEdgeNotification::writeSafe($model->readId(), $account->readId(), $type) ? $model : null; - } - - if ($account = Account::searchById(Account::collectionName() . '/' . $account)) { - // Аккаунт найден - - echo ($account->readId()) . "\n"; - - // Запись ребра: УВЕДОМЛЕНИЕ -> АККАУНТ - $return[] = AccountEdgeNotification::writeSafe($model->readId(), $account->readId(), $type) ? $model : null; - } - } - - return $return ? $return : null; - } else if ($account instanceof Account) { - // Один получатель - - // Запись ребра: УВЕДОМЛЕНИЕ -> АККАУНТ - return AccountEdgeNotification::writeSafe($model->readId(), $account->readId(), $type) ? $model : null; - } + self::searchReceiverAndConnect($model, $account, $type); } return null; } + + /** + * Поиск получателя + * + * @param self $model Уведомление + * @param string $text Необработанный текст + * @param string $type Тип уведомления + */ + protected static function searchReceiverAndConnect(self $model, string $text, string $type = self::TYPE_NOTICE): AccountEdgeNotification|array|null + { + // Инициализация + $return = []; + + // Конвертация + $accounts = array_map('trim', explode(self::$delimiter, $text)); + + foreach ($accounts as $account) { + if (in_array('@all', $accounts, true)) { + // Найден флаг обозначающий отправку всем пользователям + + // Инициализация + $return = []; + + foreach (Account::readAll() as $account) { + // Перебор всех аккаунтов + + // Запись ребра: УВЕДОМЛЕНИЕ -> АККАУНТ + $return[] = AccountEdgeNotification::writeSafe($model->readId(), $account->readId(), $type); + } + } else if (in_array('@test', $accounts, true)) { + // Найден флаг обозначающий тестирование (отправка самому себе) + + $return[] = AccountEdgeNotification::writeSafe($model->readId(), yii::$app->user->id, $type); + } else { + // Найден идентификатор (подразумевается) + + if ($account = Account::searchById(Account::collectionName() . '/' . $account)) { + // Аккаунт найден + + // Запись ребра: УВЕДОМЛЕНИЕ -> АККАУНТ + $return[] = AccountEdgeNotification::writeSafe($model->readId(), $account->readId(), $type); + } + } + } + + return $return ? $return : null; + } } diff --git a/mirzaev/skillparts/system/views/account/index.php b/mirzaev/skillparts/system/views/account/index.php index 938f0a7..f87072e 100644 --- a/mirzaev/skillparts/system/views/account/index.php +++ b/mirzaev/skillparts/system/views/account/index.php @@ -9,8 +9,8 @@ use app\models\AccountForm; ?> -
-
+
+
-
+

Корзина

diff --git a/mirzaev/skillparts/system/views/index.php b/mirzaev/skillparts/system/views/index.php index 26b29f0..a822535 100644 --- a/mirzaev/skillparts/system/views/index.php +++ b/mirzaev/skillparts/system/views/index.php @@ -5,12 +5,13 @@ declare(strict_types=1); $this->title = 'SkillParts'; ?> + -
-
+
+
-

Проблема с подбором запчастей?

+

Проблема с подбором запчастей?

Связаться с менеджером @@ -19,9 +20,9 @@ $this->title = 'SkillParts';

Связаться с менеджером
-
+
-
+
Cummins Iveco Komatsu @@ -37,9 +38,9 @@ $this->title = 'SkillParts'; SHEHWA BOMAG Hitachi -
+ -
+
@@ -80,7 +81,7 @@ $this->title = 'SkillParts';
-
+
\ No newline at end of file diff --git a/mirzaev/skillparts/system/views/layouts/main.php b/mirzaev/skillparts/system/views/layouts/main.php index 12bbabb..bea61da 100644 --- a/mirzaev/skillparts/system/views/layouts/main.php +++ b/mirzaev/skillparts/system/views/layouts/main.php @@ -29,7 +29,7 @@ AppAsset::register($this); - + @@ -50,9 +50,11 @@ AppAsset::register($this);
- +
@@ -90,20 +92,20 @@ AppAsset::register($this);
controller->renderPartial('/search/panel', ['history' => true]); + // Сделать системные настройки и по ним работать + $search_panel = yii::$app->controller->renderPartial('/search/panel', ['history' => true]); - // if (!yii::$app->user->isGuest && $search_panel = $search_panel ?? yii::$app->controller->renderPartial('/search/panel', ['history' => true])) { - echo <<user->isGuest && $search_panel = $search_panel ?? yii::$app->controller->renderPartial('/search/panel', ['history' => true])) { + echo << $search_panel
HTML; - // } else { - // echo <<
- // HTML; - // } + // } else { + // echo <<
+ // HTML; + // } ?>
@@ -112,7 +114,7 @@ AppAsset::register($this);
-
+
diff --git a/mirzaev/skillparts/system/views/orders/index.php b/mirzaev/skillparts/system/views/orders/index.php index b551427..89d29d3 100644 --- a/mirzaev/skillparts/system/views/orders/index.php +++ b/mirzaev/skillparts/system/views/orders/index.php @@ -1,6 +1,6 @@ -
+

Заказы

@@ -24,7 +24,8 @@ // Инициализация extract($order); - $date = date('d.m.Y', $order['date']); + // Инициализация + $date = empty($jrnl) ? '' : date('H:i d.m.Y', end($jrnl)['date']); echo << diff --git a/mirzaev/skillparts/system/views/product/index.php b/mirzaev/skillparts/system/views/product/index.php index 4850bfa..85eba8b 100644 --- a/mirzaev/skillparts/system/views/product/index.php +++ b/mirzaev/skillparts/system/views/product/index.php @@ -8,10 +8,10 @@ use app\models\Product; ?> -
-
+
+
-
+
-
+