Commit c983f6dd authored by Ghislain Loas's avatar Ghislain Loas

dev #69586 read article in newsletter content

parent d1138728
Pipeline #6112 failed with stage
in 25 minutes and 8 seconds
......@@ -138,11 +138,12 @@ class Class_Newsletter extends Storm_Model_Abstract {
$template = new Class_Entity();
$notices = $this->getNotices();
$articles = $this->getArticles();
$template
->setTitre($this->getTitre())
->setBodyText($this->_getBodyText($notices))
->setBodyHTML($this->_getBodyHTML($notices))
->setBodyText($this->_getBodyText($notices, $articles))
->setBodyHTML($this->_getBodyHTML($notices, $articles))
->setExpediteur($this->getExpediteur());
return $template;
......@@ -216,10 +217,16 @@ class Class_Newsletter extends Storm_Model_Abstract {
'only_img' => false,
'aleatoire' => 0,
'tri' => 1);
return Class_Notice::getNoticesFromPreferences($preferences);
}
public function getArticles() {
return Class_Article::findAllBy(['id_article' => $this->getIdItems()]);
}
protected function _htmlToText($html) {
return strip_tags(preg_replace('/<br[^>]*>/i', "\n", $html));
}
......@@ -246,12 +253,15 @@ class Class_Newsletter extends Storm_Model_Abstract {
}
protected function _getBodyText($records) {
protected function _getBodyText($records, $articles) {
$lines = [$this->_htmlToText($this->getContenu())];
foreach($records as $record)
$this->_addBodyTextRecordInto($record, $lines);
foreach($articles as $article)
$this->_addBodyTextArticleInto($article, $lines);
$lines[] = $this->_getUnsubscribeText();
return implode("\n", $lines);
......@@ -269,6 +279,16 @@ class Class_Newsletter extends Storm_Model_Abstract {
}
protected function _addBodyTextArticleInto($article, &$data) {
if (!$article)
return;
$data[] = '- ' . $article->getTitre();
$data[] = strip_tags($article->getContenu());
$data[] = "\n";
}
protected function _getRecordUrlWithoutRouter($record) {
return sprintf('%s/recherche/viewnotice/id/%d',
Class_Url::siteUrl(),
......@@ -291,12 +311,15 @@ class Class_Newsletter extends Storm_Model_Abstract {
* @param array $records
* @return string
*/
protected function _getBodyHTML($records) {
protected function _getBodyHTML($records, $articles) {
$html = $this->getContenu();
foreach($records as $record)
$html .= $this->_getBodyHTMLRecord($record);
foreach($articles as $article)
$html .= $this->_getBodyHTMLArticle($article);
$html .= $this->_getUnsubscribeHTML();
return $html;
......@@ -317,6 +340,15 @@ class Class_Newsletter extends Storm_Model_Abstract {
}
protected function _getBodyHTMLArticle($article) {
return '<div style="padding:5px">' .
'<h1>' . $article->getLabel() . '</h1>' .
'<div>' . $article->getFullContent() . '</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="" />'
......
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