Commit 118d0617 authored by Ghislain Loas's avatar Ghislain Loas

dev #69826 mail with records list

parent b08ff163
Pipeline #3355 failed with stage
in 48 seconds
......@@ -247,8 +247,9 @@ class Class_Newsletter extends Storm_Model_Abstract {
protected function _getBodyText($records) {
$lines = [$this->_htmlToText($this->getContenu())];
$renderer = new Class_Notice_MailRenderer();
foreach($records as $record)
$this->_addBodyTextRecordInto($record, $lines);
$renderer->renderTextInto($record, $lines)
$lines[] = $this->_getUnsubscribeText();
......@@ -256,24 +257,6 @@ class Class_Newsletter extends Storm_Model_Abstract {
}
protected function _addBodyTextRecordInto($record, &$data) {
if (!$record)
return;
$data[] = '- ' . $this->_getTitleForNotice($record);
$data[] = $record->getResume();
$data[] = 'Lien: ' . $this->_getRecordUrlWithoutRouter($record);
$data[] = "\n";
}
protected function _getRecordUrlWithoutRouter($record) {
return sprintf('%s/recherche/viewnotice/id/%d',
Class_Url::siteUrl(),
$record->getId());
}
/**
* @return string
*/
......@@ -292,8 +275,9 @@ class Class_Newsletter extends Storm_Model_Abstract {
protected function _getBodyHTML($records) {
$html = $this->getContenu();
$renderer = new Class_Notice_MailRenderer();
foreach($records as $record)
$html .= $this->_getBodyHTMLRecord($record);
$html .= $renderer->renderHtml($record);
$html .= $this->_getUnsubscribeHTML();
......@@ -301,39 +285,6 @@ class Class_Newsletter extends Storm_Model_Abstract {
}
protected function _getBodyHTMLRecord($record) {
$title = $this->_getTitleForNotice($record);
$anchor = '<a href="' . $this->_getRecordUrlWithoutRouter($record) . '">'
. $this->_getRecordThumbWithoutRouter($record) . $title . '</a>';
return '<div style="padding:5px">' .
$anchor .
'<div>' . $record->getResume() . '</div>' .
'<div style="clear:both"></div>'.
'</div>';
}
protected function _getRecordThumbWithoutRouter($record) {
return $record->hasVignette() ?
'<img src="' . $record->getUrlVignette() . '" style="float:left;width:50px;vertical-align:top;padding:5px" alt="" />'
: '';
}
protected function _getTitleForNotice($notice) {
$title = $notice->getTitrePrincipal();
$infos = array();
if ($auteur = $notice->getAuteurPrincipal()) $infos []= $auteur;
if ($annee = $notice->getAnnee()) $infos []= $annee;
if (!empty($infos)) $title .= ' ('.implode(', ', $infos).')';
return $title;
}
public function unsubscribeUser($user) {
$this->unsubscribeByMail($user->getMail());
}
......
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_Notice_MailRenderer {
use Trait_Translator;
protected $_record;
public function renderTextInto($record, &$data) {
if (!$record)
return;
$data[] = '- ' . $this->_title($record);
$data[] = $record->getResume();
$data[] = $this->_('Lien: ') . $this->_urlWithoutRouter($record);
$data[] = "\n";
}
public function renderText($record) {
$lines = [];
$this->renderTextInto($record, $lines);
return implode("\n", $lines);
}
public function renderHtml($record) {
$title = $this->_title($record);
$anchor = '<a href="' . $this->_urlWithoutRouter($record) . '">'
. $this->_thumbWithoutRouter($record) . $title . '</a>';
return '<div style="padding:5px">' .
$anchor .
'<div>' . $record->getResume() . '</div>' .
'<div style="clear:both"></div>'.
'</div>';
}
protected function _title($record) {
return $record->getTitrePrincipal() . $this->_infos($record);
}
protected function _infos($record) {
$infos = [];
if ($auteur = $record->getAuteurPrincipal())
$infos[] = $auteur;
if ($annee = $record->getAnnee())
$infos[] = $annee;
return $infos
? ' (' . implode(', ', $infos) .')'
: '';
}
protected function _urlWithoutRouter($record) {
return sprintf('%s/recherche/viewnotice/id/%d',
Class_Url::siteUrl(),
$record->getId());
}
protected function _thumbWithoutRouter($record) {
return $record->hasVignette() ?
'<img src="' . $record->getUrlVignette() . '" style="float:left;width:50px;vertical-align:top;padding:5px" alt="" />'
: '';
}
}
......@@ -103,8 +103,33 @@ class Class_User_BookmarkedSearch extends Storm_Model_Abstract {
(new Class_Mail())
->mail($recipient,
$this->_('Il y a du nouveau!'),
'');
$this->_('Nouveau(x) résultat(s) pour votre recherche %s', $this->getLabel()),
$this->_('Bonjour,
Il y a %s nouveau(x) résultat(s) pour votre recherche "%s" :
%s',
count($diff),
$this->getLabel(),
$this->_renderRecordsFromKeys($diff)
));
}
public function _renderRecordsFromKeys($keys) {
$content = [];
foreach($keys as $key)
$content[] = $this->_renderRecordFromKey($key);
return implode("\n", array_filter($content));
}
public function _renderRecordFromKey($key) {
if (!$record = Class_Notice::findFirstBy(['clef_alpha' => $key]))
return;
return (new Class_Notice_MailRenderer())->renderText($record);
}
......
......@@ -475,7 +475,8 @@ class Bookmarks_SearchCosmogrammePhaseTest
$this->fixture('Class_Notice',
['id' => 1888,
'clef_alpha' => 'DROITDEVANT--ODAEIICHIRO-15-GLENAT-2013-1']);
'clef_alpha' => 'DROITDEVANT--ODAEIICHIRO-15-GLENAT-2013-1',
'titre_principal' => 'Droit devant']);
Zend_Registry::set('sql',
$this->mock()
......@@ -534,7 +535,8 @@ class Bookmarks_SearchCosmogrammePhaseTest
/** @test */
public function withRecordDiffShouldNotifyItToUserByMail() {
$this->assertContains('laurel@server.io',
$this->_mail_transport->getSentMails()[0]->getRecipients());
$mail = $this->_mail_transport->getSentMails()[0];
$this->assertContains('laurel@server.io', $mail->getRecipients());
$this->assertContains('Droit devant', $mail->getBodyText(true));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment