Skip to content
Snippets Groups Projects
Commit 078375ee authored by lbrun's avatar lbrun
Browse files

dev#25728: refacto

parent 7ac3468e
Branches
Tags
2 merge requests!1196Dev#25728 bonus ajouter la possibilite de flux rss a la boite sitotheque,!1184Dev#25728 bonus ajouter la possibilite de flux rss a la boite sitotheque
......@@ -84,21 +84,7 @@ class CmsController extends ZendAfi_Controller_Action {
public function calendarrssAction() {
$id_profil = (int)$this->_getParam('id_profil');
$id_module = (int)$this->_getParam('id_module');
$profil = Class_Profil::find($id_profil);
$preferences = $profil->getModuleAccueilPreferences($id_module, 'NEWS');
$articles=Class_Calendar::getAllNextEvents($id_module,$profil);
$data_rss = [
'title' => trim($preferences['titre']) ? trim($preferences['titre']) : $profil->getLibelle(),
'link' => $profil->urlForModule('cms', 'articleviewbydate', $id_module),
'charset' => 'utf-8',
'description' => 'Agenda: ' . $preferences['titre'],
'lastUpdate' => time()
];
$this->_renderRSS($articles, $data_rss);
$this->_helper->renderRss($id_profil, $id_module, $this->view, 'NEWS');
}
......@@ -170,35 +156,7 @@ class CmsController extends ZendAfi_Controller_Action {
public function rssAction(){
$id_profil = (int)$this->_getParam('id_profil');
$id_module = (int)$this->_getParam('id_module');
$articles = [];
$data_rss = [
'title' => 'Flux indisponible',
'link' => $this->_request->getScheme() . '://'
. $this->_request->getServer('HTTP_HOST'),
'charset' => 'utf-8',
'description' => '',
'lastUpdate' => time()
];
if (null != ($profil = Class_Profil::find($id_profil))) {
$preferences = $profil->getModuleAccueilPreferences($id_module, 'NEWS');
$data_rss = array_merge(
$data_rss,
[
'title' => $preferences['titre'],
'link' => $profil->urlForModule('cms', 'viewselection', $id_module),
'description' => 'Articles: '.$preferences['titre']
]
);
$articles = Class_Article::getArticlesByPreferences($preferences);
$articles = Class_Article::filterByLocaleAndWorkflow($articles);
}
$this->_renderRSS($articles, $data_rss);
$this->_helper->renderRss($id_profil, $id_module, $this->view, 'ARTICLE');
}
......@@ -307,46 +265,6 @@ class CmsController extends ZendAfi_Controller_Action {
$this->view->param = $param;
}
/**
* @param array $article
*/
protected function _getPubDate($article) {
if ($article->hasEventsDebut())
return $article->getEventsDebut();
if ($article->hasDebut())
return $article->getDebut();
return $article->getDateMaj();
}
/**
* @param array $articles
* @param array $rss_array
*/
private function _renderRSS($articles, $rss_array) {
$entries = [];
foreach ($articles as $article) {
$entries[] =
[
'title' => html_entity_decode($article->getTitre()),
'link' => $this->_request->getScheme() . '://'
. $this->_request->getServer('HTTP_HOST')
. $this->view->url($article->getUrl()),
'lastUpdate' => strtotime($this->_getPubDate($article)),
'description' => html_entity_decode(Class_CmsUrlTransformer::imgUrlRelativeToAbsolute($this->view->tagArticleEvent($article).$article->getFullContent()))];
}
$rss_array['entries'] = $entries;
$feed = Zend_Feed::importArray($rss_array, 'rss');
$this->getHelper('ViewRenderer')->setNoRender();
$this->_response->setHeader('Content-Type', 'application/rss+xml;charset=utf-8') ;
$this->_response->setBody($feed->saveXML());
}
/**
* @param int $id_module
* @param int $id_profil
......
......@@ -92,38 +92,7 @@ class SitoController extends Zend_Controller_Action {
$id_profil = (int)$this->_getParam('id_profil');
$id_module = (int)$this->_getParam('id_module');
$data_rss =
[
'title' => 'Flux indisponible',
'link' => $this->_request->getScheme() . '://'
. $this->_request->getServer('HTTP_HOST'),
'charset' => 'utf-8',
'description' => '',
'lastUpdate' => time()
];
$sitotheques = [];
if (null != ($profil = Class_Profil::find($id_profil))) {
$preferences = $profil->getModuleAccueilPreferences($id_module, 'SITO');
$data_rss = array_merge(
$data_rss,
[
'title' => trim($preferences['titre'])
? trim($preferences['titre'])
: $profil->getLibelle(),
'link' => '',
'description' => $preferences['titre']
]
);
$sitotheques =
Class_Sitotheque::getSitesFromIdsAndCategories(
explode('-', $preferences['id_items']),
explode('-', $preferences['id_categorie']));
}
$this->_renderRSS($sitotheques, $data_rss);
$this->_helper->renderRss($id_profil, $id_module, $this->view, 'SITO');
}
......
......@@ -782,6 +782,15 @@ class Class_Article extends Storm_Model_Abstract {
$this->setDateMaj(date('Y-m-d H:i:s', $this->getCurrentTime()));
}
public function getPubDate() {
if ($this->hasEventsDebut())
return $this->getEventsDebut();
if ($this->hasDebut())
return $this->getDebut();
return $this->getDateMaj();
}
public function beforeSave() {
if ($this->isNew() && !$this->getDateCreation())
......
<?php
/**
* Copyright (c) 2012-2014, 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 ZendAfi_Controller_Action_Helper_RenderRss extends Zend_Controller_Action_Helper_Abstract {
protected $_type, $_view;
public function renderRss($id_profil, $id_module, $view, $type) {
$this->_type = $type;
$this->_view = $view;
$datas = [];
$default_values =
[
'title' => 'Flux indisponible',
'link' => ($this->getActionController()->getRequest()->getScheme() . '://'
. $this->getActionController()->getRequest()->getServer('HTTP_HOST')),
'charset' => 'utf-8',
'description' => '',
'lastUpdate' => time()
];
$profil = Class_Profil::find($id_profil);
if ($profil != null) {
$preferences = $profil->getModuleAccueilPreferences($id_module, ($this->_type == 'SITO') ? 'SITO' : 'NEWS');
$datas = $this->_getObjectDatas($id_module, $profil, $preferences);
$data_rss = array_merge(
$default_values,
[
'title' => (trim($preferences['titre']) ? trim($preferences['titre']) : $profil->getLibelle()),
'link' => $this->_getLink($profil, $id_module),
'description' => $this->_getDescription() . $preferences['titre']
]
);
}
$this->_renderRssFeed($datas, $data_rss);
}
public function _renderRssFeed($datas, $rss_array) {
$entries = [];
foreach ($datas as $data) {
$entries[] =
[
'title' => html_entity_decode($data->getTitre()),
'link' => (($this->_type == 'SITO')
? $data->getUrl()
: $this->getActionController()->getRequest()->getScheme() . '://'
. $this->getActionController()->getRequest()->getServer('HTTP_HOST')
. $this->_view->url($data->getUrl())),
'lastUpdate' => (($this->_type == 'SITO')
? strtotime($data->getDateMaj())
: strtotime($data->getPubDate())),
'description' => (($this->_type == 'SITO')
? html_entity_decode($data->getDescription())
: html_entity_decode(Class_CmsUrlTransformer::imgUrlRelativeToAbsolute($this->_view->tagArticleEvent($data)
. $data->getFullContent())))
];
}
$rss_array['entries'] = $entries;
$feed = Zend_Feed::importArray($rss_array, 'rss');
$this->getActionController()->getHelper('ViewRenderer')->setNoRender();
$this->getActionController()->getResponse()->setHeader('Content-Type', 'application/rss+xml;charset=utf-8') ;
$this->getActionController()->getResponse()->setBody($feed->saveXML());
}
protected function _getObjectDatas($id_module, $profil, $preferences) {
if ($this->_type == 'SITO')
return Class_Sitotheque::getSitesFromIdsAndCategories(
explode('-', $preferences['id_items']),
explode('-', $preferences['id_categorie']));;
if ($this->_type == 'NEWS')
return Class_Calendar::getAllnextEvents($id_module, $profil);
if ($this->_type == 'ARTICLE') {
$articles = Class_Article::getArticlesByPreferences($preferences);
return Class_Article::filterByLocaleAndWorkflow($articles);
}
}
protected function _getDescription() {
if ($this->_type == 'NEWS')
return 'Agenda: ';
if ($this->_type == 'ARTICLE')
return 'Articles: ';
return '';
}
protected function _getLink($profil, $id_module) {
if ($this->_type == 'NEWS')
return $profil->urlForModule('cms', 'articleviewbydate', $id_module);
if ($this->_type == 'ARTICLE')
return $profil->urlForModule('cms', 'viewselection', $id_module);
return '';
}
public function direct($id_module, $id_profil, $view, $type) {
$this->renderRss($id_module, $id_profil, $view, $type);
}
}
\ No newline at end of file
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