/
kev
/
Nextcloud_File-Changes-Tracker
Обзор
Документация
Войти
/
kev
/
Nextcloud_File-Changes-Tracker
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
lib/Notification/Notifier.php
92 строки
4 KB
Evgeny Konovalov
first_commit
16 фев 2026, 17:45
16 фев 2026, 17:45
476f06c
Код
Авторство
О чём код?
<?php declare(strict_types=1); namespace OCA\FileChangesTracker\Notification; use OCP\IURLGenerator; use OCP\L10N\IFactory; use OCP\Notification\INotification; use OCP\Notification\INotifier; /** * Обработчик уведомлений для File Changes Tracker */ class Notifier implements INotifier { private IFactory $l10nFactory; private IURLGenerator $urlGenerator; public function __construct( IFactory $l10nFactory, IURLGenerator $urlGenerator ) { $this->l10nFactory = $l10nFactory; $this->urlGenerator = $urlGenerator; } /** * Идентификатор приложения */ public function getID(): string { return 'file_changes_tracker'; } /** * Отображаемое имя */ public function getName(): string { return $this->l10nFactory->get('file_changes_tracker')->t('File Changes Tracker'); } /** * Подготовка уведомления для отображения */ public function prepare(INotification $notification, string $languageCode): INotification { if ($notification->getApp() !== 'file_changes_tracker') { throw new \InvalidArgumentException('Unknown app'); } $l = $this->l10nFactory->get('file_changes_tracker', $languageCode); switch ($notification->getSubject()) { case 'file_change': $parameters = $notification->getSubjectParameters(); $eventType = $parameters['event_type'] ?? 'unknown'; $filePath = $parameters['file_path'] ?? ''; $userDisplayName = $parameters['user_display_name'] ?? ''; $folderPath = $parameters['folder_path'] ?? ''; // Формируем текст уведомления в зависимости от типа события $subject = $this->getEventSubject($l, $eventType, $filePath, $userDisplayName, $folderPath); $notification->setParsedSubject($subject) ->setLink($this->urlGenerator->linkToRouteAbsolute('file_changes_tracker.page.index')) ->setIcon($this->urlGenerator->imagePath('file_changes_tracker', 'app.svg')); return $notification; default: throw new \InvalidArgumentException('Unknown subject'); } } /** * Получить текст уведомления в зависимости от типа события */ private function getEventSubject($l, string $eventType, string $filePath, string $userDisplayName, string $folderPath): string { $fileName = basename($filePath); switch ($eventType) { case 'created': return $l->t('%s создал файл "%s" в отслеживаемой папке "%s"', [$userDisplayName, $fileName, $folderPath]); case 'modified': return $l->t('%s изменил файл "%s" в отслеживаемой папке "%s"', [$userDisplayName, $fileName, $folderPath]); case 'deleted': return $l->t('%s удалил файл "%s" из отслеживаемой папки "%s"', [$userDisplayName, $fileName, $folderPath]); case 'renamed': return $l->t('%s переименовал файл "%s" в отслеживаемой папке "%s"', [$userDisplayName, $fileName, $folderPath]); default: return $l->t('%s выполнил действие с файлом "%s" в отслеживаемой папке "%s"', [$userDisplayName, $fileName, $folderPath]); } } }