Skip to content

Commit

Permalink
PHRAS-3668 subtitle notification (#4416)
Browse files Browse the repository at this point in the history
* subtitle notification

* fix notif
  • Loading branch information
aynsix authored Nov 22, 2023
1 parent ab26d49 commit 1ccba2d
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 71 deletions.
3 changes: 2 additions & 1 deletion lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ public function autoSubtitleAction(Request $request)
new RecordAutoSubtitleEvent(
$record,
$request->request->get("subtitle_language_source"),
json_decode($request->request->get("subtitle_destination"), true)
json_decode($request->request->get("subtitle_destination"), true),
$this->getAuthenticatedUser()->getId()
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
class RecordAutoSubtitleEvent extends RecordEvent
{
private $languageSource;
private $metaStructureIdSource;
private $languageDestination;
private $metaStructureIdDestination;
private $authenticatedUserId;

public function __construct(
RecordInterface $record,
$languageSource,
$languageDestination
$languageDestination,
$authenticatedUserId
)
{
parent::__construct($record);

$this->languageSource = $languageSource;
$this->languageDestination = $languageDestination;
$this->authenticatedUserId = $authenticatedUserId;
}

public function getLanguageSource()
Expand All @@ -33,8 +34,8 @@ public function getLanguageDestination()
return $this->languageDestination;
}

public function getMetaStructureIdDestination()
public function getAuthenticatedUserId()
{
return $this->metaStructureIdDestination;
return $this->authenticatedUserId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Alchemy\Phrasea\Core\Event\Record\RecordAutoSubtitleEvent;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Model\Entities\WorkerJob;
use Alchemy\Phrasea\Model\Repositories\WorkerJobRepository;
use Alchemy\Phrasea\WorkerManager\Queue\MessagePublisher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand Down Expand Up @@ -33,6 +32,7 @@ public function onRecordAutoSubtitle(RecordAutoSubtitleEvent $event)
"recordId" => $event->getRecord()->getRecordId(),
"languageSource" => $event->getLanguageSource(),
"languageDestination" => $event->getLanguageDestination(),
"authenticatedUserId" => $event->getAuthenticatedUserId(),
"type" => MessagePublisher::SUBTITLE_TYPE // used to specify the final Q to publish message
];

Expand Down
23 changes: 23 additions & 0 deletions lib/Alchemy/Phrasea/WorkerManager/Worker/SubtitleWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@ public function process(array $payload)
// order to write meta in file
$this->dispatcher->dispatch(WorkerEvents::RECORDS_WRITE_META,
new RecordsWriteMetaEvent([$record->getRecordId()], $record->getDataboxId()));

$this->getEventsManager()->notify(
$payload['authenticatedUserId'],
'eventsmanager_notify_subtitle',
json_encode([
'translateMessage' => 'notification:: subtitle "%langues%" generated for "%title%" !',
'langues' => implode(', ', array_keys($payload['languageDestination'])),
'title' => htmlentities($record->get_title())
]),
false
);

} catch (\Exception $e) {
$this->logger->error($e->getMessage());
$this->jobFinished();
Expand Down Expand Up @@ -476,4 +488,15 @@ private function getTargetLanguageByCode($code)

return $t[0];
}

/**
* @return \eventsmanager_broker
*/
private function getEventsManager()
{
$app = $this->getApplicationBox()->getPhraseApplication();

return $app['events-manager'];
}

}
1 change: 1 addition & 0 deletions lib/classes/eventsmanager/broker.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function start()
'eventsmanager_notify_push',
'eventsmanager_notify_basketwip',
'eventsmanager_notify_register',
'eventsmanager_notify_subtitle',
'eventsmanager_notify_uploadquarantine',
'eventsmanager_notify_validate',
'eventsmanager_notify_validationdone',
Expand Down
69 changes: 69 additions & 0 deletions lib/classes/eventsmanager/notify/subtitle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
* This file is part of Phraseanet
*
* (c) 2005-2023 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Alchemy\Phrasea\Model\Entities\User;

class eventsmanager_notify_subtitle extends eventsmanager_notifyAbstract
{
/**
*
* @return string
*/
public function icon_url()
{
return null;
}

/**
*
* @param Array $data
* @param boolean $unread
* @return Array
*/
public function datas(array $data, $unread)
{
$text = $this->app->trans($data['translateMessage'], ['%title%' => $data['title'], '%langues%' => $data['langues']]);

return [
'text' => $text,
'class' => ($unread == 1 ? 'reload_baskets' : '')
];
}

/**
*
* @return string
*/
public function get_name()
{
return $this->app->trans('notification:: subtitle');
}

/**
*
* @return string
*/
public function get_description()
{
return $this->app->trans('notification:: Receive notification when subtitle generated');
}

/**
* @param integer $usr_id The id of the user to check
*
* @return boolean
*/
public function is_available(User $user)
{
return true;
}

}
52 changes: 36 additions & 16 deletions resources/locales/messages.de.xlf
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
<file date="2023-11-17T12:25:19Z" source-language="en" target-language="de" datatype="plaintext" original="not.available">
<file date="2023-11-20T14:57:43Z" source-language="en" target-language="de" datatype="plaintext" original="not.available">
<header>
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
</header>
<body>
<trans-unit id="da39a3ee5e6b4b0d3255bfef95601890afd80709" resname="">
<source/>
<target state="new"/>
<source></source>
<target state="new"></target>
<jms:reference-file line="363">WorkerManager/Worker/DownloadAsyncWorker.php</jms:reference-file>
<jms:reference-file line="51">Form/Configuration/EmailFormType.php</jms:reference-file>
<jms:reference-file line="64">Form/Login/PhraseaAuthenticationForm.php</jms:reference-file>
Expand Down Expand Up @@ -196,7 +196,7 @@
<jms:reference-file line="7">Bridge/Dailymotion/element_informations.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="de0804eb70c10b14d71df74292e45c6daa13d672" resname="%number% documents&lt;br/&gt;selectionnes" approved="yes">
<source>%number% documents&lt;br/&gt;selectionnes</source>
<source><![CDATA[%number% documents<br/>selectionnes]]></source>
<target state="translated"><![CDATA[%number% Dokumente<br/> ausgewählt]]></target>
<jms:reference-file line="269">Controller/Prod/QueryController.php</jms:reference-file>
</trans-unit>
Expand Down Expand Up @@ -2558,7 +2558,7 @@
<jms:reference-file line="68">Form/Configuration/ActionsFormType.php</jms:reference-file>
</trans-unit>
<trans-unit id="fa9fd169cd55f0433c6e7a4b5d758f90d0847411" resname="Display &amp; action settings" approved="yes">
<source>Display &amp; action settings</source>
<source><![CDATA[Display & action settings]]></source>
<target state="translated">Anzeige und Handlung-Einstellungen</target>
<jms:reference-file line="154">admin/fields/templates.html.twig</jms:reference-file>
</trans-unit>
Expand Down Expand Up @@ -4754,7 +4754,7 @@
<trans-unit id="ac0b3b17f88b480b11c468d0b5bea6409bbd14b8" resname="Notifications globales" approved="yes">
<source>Notifications globales</source>
<target state="translated">Allgemeine Benachrichtigungen</target>
<jms:reference-file line="432">classes/eventsmanager/broker.php</jms:reference-file>
<jms:reference-file line="433">classes/eventsmanager/broker.php</jms:reference-file>
</trans-unit>
<trans-unit id="18ee7ad22bf04f818fd95599481303c7f7d1b29f" resname="Notify third party application when an event occurs in Phraseanet" approved="yes">
<source>Notify third party application when an event occurs in Phraseanet</source>
Expand Down Expand Up @@ -6511,7 +6511,7 @@
<jms:reference-file line="677">Controller/Admin/CollectionController.php</jms:reference-file>
<jms:reference-file line="710">Controller/Admin/CollectionController.php</jms:reference-file>
<jms:reference-file line="818">Controller/Admin/CollectionController.php</jms:reference-file>
<jms:reference-file line="310">actions/Tools/videoEditor.html.twig</jms:reference-file>
<jms:reference-file line="313">actions/Tools/videoEditor.html.twig</jms:reference-file>
<jms:reference-file line="20">admin/collection/suggested_value.html.twig</jms:reference-file>
<jms:reference-file line="18">admin/collection/collection.html.twig</jms:reference-file>
<jms:reference-file line="10">web/admin/databases.html.twig</jms:reference-file>
Expand Down Expand Up @@ -10015,7 +10015,7 @@
<source>alert</source>
<target state="translated">Vorsicht</target>
<jms:reference-file line="263">actions/Tools/index.html.twig</jms:reference-file>
<jms:reference-file line="306">actions/Tools/videoEditor.html.twig</jms:reference-file>
<jms:reference-file line="309">actions/Tools/videoEditor.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="d87c448044defb778f33158d8ccf94a20531d600" resname="all">
<source>all</source>
Expand Down Expand Up @@ -11779,7 +11779,7 @@
<source>no image selected</source>
<target state="translated">Kein Bild wurde ausgewählt</target>
<jms:reference-file line="264">actions/Tools/index.html.twig</jms:reference-file>
<jms:reference-file line="307">actions/Tools/videoEditor.html.twig</jms:reference-file>
<jms:reference-file line="310">actions/Tools/videoEditor.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="37031f99ac78580c9f82e04fa237d295ea10ca41" resname="non" approved="yes">
<source>non</source>
Expand Down Expand Up @@ -11810,11 +11810,26 @@
<target state="translated">Eine Benachrichtigung über geteilte Sammelkörbe erhalten</target>
<jms:reference-file line="63">eventsmanager/notify/basketwip.php</jms:reference-file>
</trans-unit>
<trans-unit id="9f936de43554d1aecd5cb765d8f9d9d3ecd12218" resname="notification:: Receive notification when subtitle generated">
<source>notification:: Receive notification when subtitle generated</source>
<target state="new">notification:: Receive notification when subtitle generated</target>
<jms:reference-file line="56">eventsmanager/notify/subtitle.php</jms:reference-file>
</trans-unit>
<trans-unit id="a688627f4dd71b157e89c24314fd077ce0e44571" resname="notification:: mark all notification as read">
<source>notification:: mark all notification as read</source>
<target state="translated">Alle Benachrichtigungen als "Gelesen" markieren</target>
<jms:reference-file line="4">web/prod/notifications_dialog.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="76530655c84498297daae00f2666315dffb4d690" resname="notification:: subtitle">
<source>notification:: subtitle</source>
<target state="new">notification:: subtitle</target>
<jms:reference-file line="47">eventsmanager/notify/subtitle.php</jms:reference-file>
</trans-unit>
<trans-unit id="b7f8baa53412467286a8b71a44ceb6da4cff8a2d" resname="notification:: subtitle generation finished">
<source>notification:: subtitle generation finished</source>
<target state="new">notification:: subtitle generation finished</target>
<jms:reference-file line="33">eventsmanager/notify/subtitle.php</jms:reference-file>
</trans-unit>
<trans-unit id="ef8ffaf5527518b39ca6500ef0e9a47a4b7cceec" resname="notification::read:tooltip">
<source>notification::read:tooltip</source>
<target state="translated">Benachrichtigung gelesen</target>
Expand Down Expand Up @@ -12434,7 +12449,7 @@
<jms:reference-file line="563">Controller/Root/AccountController.php</jms:reference-file>
</trans-unit>
<trans-unit id="bf7028b694aea3fc9ede5014a9f8b5d617b83b6f" resname="phraseanet::account: &lt;&lt; your account can be deleted via admin interface &gt;&gt; " approved="yes">
<source>phraseanet::account: &lt;&lt; your account can be deleted via admin interface &gt;&gt;</source>
<source><![CDATA[phraseanet::account: << your account can be deleted via admin interface >>]]></source>
<target state="translated">Ihr Benutzerkonto kann nur durch die Administration Anwendung gelöscht werden.</target>
<jms:reference-file line="289">web/account/account.html.twig</jms:reference-file>
</trans-unit>
Expand Down Expand Up @@ -13021,7 +13036,7 @@
<source>processing</source>
<target state="translated">verarbeitend</target>
<jms:reference-file line="265">actions/Tools/index.html.twig</jms:reference-file>
<jms:reference-file line="308">actions/Tools/videoEditor.html.twig</jms:reference-file>
<jms:reference-file line="311">actions/Tools/videoEditor.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="f63658cad863dee4a5876278e836472380183ade" resname="prod::Les enregistrements ne provienent pas tous de la meme base et ne peuvent donc etre traites ensemble" approved="yes">
<source>prod::Les enregistrements ne provienent pas tous de la meme base et ne peuvent donc etre traites ensemble</source>
Expand Down Expand Up @@ -14216,6 +14231,11 @@ Vorsicht: die aktuelle Werte werden durch die neue Werte überschrieben</target>
<target state="translated">Die ausgewählten Datensätze gehören zu verschiedenen Databoxen, das Hinzufügen dieser Auswahl zur Berichte ist nicht möglich.</target>
<jms:reference-file line="40">prod/Story/Create.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="b7ee9779ae9a09607df07dcc561ef328d7229de2" resname="prod:videoeditor field filled">
<source>prod:videoeditor field filled</source>
<target state="new">prod:videoeditor field filled</target>
<jms:reference-file line="255">actions/Tools/videoEditor.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="b307f0594b48cbb3440eb6a38c7fb90858617791" resname="prod:videoeditor:subtitleRequestTab:: Autosubtitling" approved="yes">
<source>prod:videoeditor:subtitleRequestTab:: Autosubtitling</source>
<target state="translated">Automatisierte Untertitelung</target>
Expand All @@ -14224,12 +14244,12 @@ Vorsicht: die aktuelle Werte werden durch die neue Werte überschrieben</target>
<trans-unit id="4415c59007c7e89865ff4e7ef0b717b459e6d6cf" resname="prod:videoeditor:subtitleRequestTab:: Request in process" approved="yes">
<source>prod:videoeditor:subtitleRequestTab:: Request in process</source>
<target state="translated">Anfrage in Bearbeitung</target>
<jms:reference-file line="264">actions/Tools/videoEditor.html.twig</jms:reference-file>
<jms:reference-file line="267">actions/Tools/videoEditor.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="ca51b1b3be02d8e640243e090dec0a6ee8089d28" resname="prod:videoeditor:subtitleRequestTab:: submit" approved="yes">
<source>prod:videoeditor:subtitleRequestTab:: submit</source>
<target state="translated">Anfrage einreichen</target>
<jms:reference-file line="259">actions/Tools/videoEditor.html.twig</jms:reference-file>
<jms:reference-file line="262">actions/Tools/videoEditor.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="3c08c8314c595e8d2dcab6bab15a07eda8833935" resname="prod:videoeditor:subtitleRequestTab:: title" approved="yes">
<source>prod:videoeditor:subtitleRequestTab:: title</source>
Expand Down Expand Up @@ -15589,7 +15609,7 @@ Vorsicht: die aktuelle Werte werden durch die neue Werte überschrieben</target>
<jms:reference-file line="1327">web/thesaurus/thesaurus.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="33df70d7fa528a31071e11d1b987b49dc947ce16" resname="thesaurus:: Supprimer cette branche ?&amp;#10;(les termes concernes remonteront en candidats a la prochaine indexation)" approved="yes">
<source>thesaurus:: Supprimer cette branche ?&amp;#10;(les termes concernes remonteront en candidats a la prochaine indexation)</source>
<source><![CDATA[thesaurus:: Supprimer cette branche ?&#10;(les termes concernes remonteront en candidats a la prochaine indexation)]]></source>
<target state="translated"><![CDATA[Diese Verzweigung löschen?&#10; (die betroffenende Begriffe werden als mögliche Begriffe beim nächsten Indexierung erscheinen)]]></target>
<jms:reference-file line="536">web/thesaurus/thesaurus.html.twig</jms:reference-file>
</trans-unit>
Expand Down Expand Up @@ -16106,7 +16126,7 @@ Vorsicht: die aktuelle Werte werden durch die neue Werte überschrieben</target>
<source>thumbnail validation</source>
<target state="translated">Miniaturansicht Validierung</target>
<jms:reference-file line="266">actions/Tools/index.html.twig</jms:reference-file>
<jms:reference-file line="309">actions/Tools/videoEditor.html.twig</jms:reference-file>
<jms:reference-file line="312">actions/Tools/videoEditor.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="7e96ed809b61066d6ea96ba9afc8747a042b361a" resname="tout le monde" approved="yes">
<source>tout le monde</source>
Expand Down
Loading

0 comments on commit 1ccba2d

Please sign in to comment.