Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHRAS-4041:Prod - matomo - Field display - improve rendering of Matomomediametrics #4497

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions lib/Alchemy/Phrasea/Core/Provider/TwigServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
class TwigServiceProvider implements ServiceProviderInterface
{

private $metricTrans;

/**
* Registers services on the given app.
*
Expand Down Expand Up @@ -61,7 +63,27 @@ public function register(Application $app)

$twig->addGlobal('current_date', new \DateTime());

$this->metricTrans = [
'nb_plays' => $app['translator']->trans('matomomediametrics:: nb_plays'),
'nb_unique_visitors_plays' => $app['translator']->trans('matomomediametrics:: nb_unique_visitors_plays'),
'nb_impressions' => $app['translator']->trans('matomomediametrics:: nb_impressions'),
'nb_unique_visitors_impressions'=> $app['translator']->trans('matomomediametrics:: nb_unique_visitors_impressions'),
'nb_finishes' => $app['translator']->trans('matomomediametrics:: nb_finishes'),
'sum_time_progress' => $app['translator']->trans('matomomediametrics:: sum_time_progress'),
'nb_plays_with_tip' => $app['translator']->trans('matomomediametrics:: nb_plays_with_tip'),
'nb_plays_with_ml' => $app['translator']->trans('matomomediametrics:: nb_plays_with_ml'),
'sum_fullscreen_plays' => $app['translator']->trans('matomomediametrics:: sum_fullscreen_plays'),
'play_rate' => $app['translator']->trans('matomomediametrics:: play_rate'),
'finish_rate' => $app['translator']->trans('matomomediametrics:: finish_rate'),
'fullscreen_rate' => $app['translator']->trans('matomomediametrics:: fullscreen_rate'),
'avg_time_watched' => $app['translator']->trans('matomomediametrics:: avg_time_watched'),
'avg_completion_rate' => $app['translator']->trans('matomomediametrics:: avg_completion_rate'),
'avg_time_to_play' => $app['translator']->trans('matomomediametrics:: avg_time_to_play'),
'avg_media_length' => $app['translator']->trans('matomomediametrics:: avg_media_length'),
];

$this->registerExtensions($twig, $app);

$this->registerFilters($twig, $app);

return $twig;
Expand Down Expand Up @@ -144,6 +166,25 @@ private function registerFilters(\Twig_Environment $twig, Application $app)
return implode('; ', $stringArr);
}, ['needs_environment' => true, 'is_safe' => ['html']]));

$twig->addFilter(new \Twig_SimpleFilter('mediaMetricsInfo', function (\Twig_Environment $twig, $string) use ($app) {
$metricInfo = $string;

if (!empty($string)) {
$metricsInfos = json_decode(html_entity_decode(trim($string)), true);
if ($metricsInfos != null) {
$metricInfo = [];
foreach ($metricsInfos as $key => $value) {
if (isset($this->metricTrans[trim($key)])) {
$metricInfo[] = '<i>' .$this->metricTrans[trim($key)] . ' </i>: ' . $value;
}
}
$metricInfo = implode('<br>', $metricInfo);
}
}

return $metricInfo;
}, ['needs_environment' => true, 'is_safe' => ['html']]));

$twig->addFilter(new \Twig_SimpleFilter('bounce',
function (\Twig_Environment $twig, $fieldValue, $fieldName, $searchRequest, $sbasId) {
// bounce value if it is present in thesaurus as well
Expand Down
226 changes: 153 additions & 73 deletions resources/locales/messages.de.xlf

Large diffs are not rendered by default.

226 changes: 153 additions & 73 deletions resources/locales/messages.en.xlf

Large diffs are not rendered by default.

230 changes: 155 additions & 75 deletions resources/locales/messages.fr.xlf

Large diffs are not rendered by default.

124 changes: 102 additions & 22 deletions resources/locales/messages.nl.xlf

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/locales/validators.de.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?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="2024-03-07T15:14:33Z" source-language="en" target-language="de" datatype="plaintext" original="not.available">
<file date="2024-04-17T13:04:48Z" 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>
Expand Down
2 changes: 1 addition & 1 deletion resources/locales/validators.en.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?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="2024-03-07T15:14:49Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
<file date="2024-04-17T13:05:04Z" source-language="en" target-language="en" 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>
Expand Down
2 changes: 1 addition & 1 deletion resources/locales/validators.fr.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?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="2024-03-07T15:15:10Z" source-language="en" target-language="fr" datatype="plaintext" original="not.available">
<file date="2024-04-17T13:05:24Z" source-language="en" target-language="fr" 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>
Expand Down
2 changes: 1 addition & 1 deletion resources/locales/validators.nl.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?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="2024-03-07T15:15:34Z" source-language="en" target-language="nl" datatype="plaintext" original="not.available">
<file date="2024-04-17T13:05:47Z" source-language="en" target-language="nl" 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>
Expand Down
10 changes: 8 additions & 2 deletions templates/web/common/macro_caption.html.twig
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{% macro caption(record, can_see_business, display_exif, limitedWidth = false) %}
<dl class="{% if limitedWidth %}{% else %}dl-horizontal{% endif %}">
<dl class="{% if limitedWidth %}dl-horizontal{% else %}dl-horizontal{% endif %}">
{% for name, value in record.getCaption(caption_field_order(record, can_see_business)) %}
{% if caption_field_gui_visible(record, name) == 1 %}
<dt>{{ caption_field_label(record, name) }}</dt>
<dd>{{ caption_field(record, name, value)|e|highlight|linkify|parseColor }}</dd>
<dd>
{% if name == 'MatomoMediaMetrics' %}
{{ caption_field(record, name, value)|e|highlight|linkify|parseColor|mediaMetricsInfo }}
{% else %}
{{ caption_field(record, name, value)|e|highlight|linkify|parseColor }}
{% endif %}
</dd>
{% endif %}
{% endfor %}
</dl>
Expand Down
Loading