Skip to content
Snippets Groups Projects

hotline: #137761 : Carousel articles should be filtered with status

Merged Sebastien ANDRE requested to merge hotline#137761_actualites_en_ligne_non_visible into hotline
Files
3
+ 61
8
@@ -349,20 +349,53 @@ class ArticleLoader extends Storm_Model_Loader {
* @return ArticleLoader
*/
protected function _filterByStatus() {
if (null === $this->_status) {
if (null === $this->_select)
return $this;
}
if (null === $this->_select) {
return $this;
}
$filters = ($filters = $this->_getFilterByWorkflow())
? $filters
: $this->_status;
$this->_select->where('STATUS in (?)', $this->_status);
if ($filters)
$this->_select->where('STATUS in (?)', $filters);
return $this;
}
protected function _getFilterByWorkflow() {
if (! $this->_filter_by_workflow)
return null;
if (!Class_AdminVar::isWorkflowEnabled())
return null;
$status_filter = [Class_Article::STATUS_VALIDATED];
if (Class_Users::isCurrentUserCanAccesBackend())
$status_filter [] = Class_Article::STATUS_DRAFT;
if ($this->_status)
$status_filter [] = $this->_status;
return array_unique($status_filter);
}
protected function _filterByLocal() {
if (! $this->_filter_by_local)
return $this;
if (!Class_AdminVar::isTranslationEnabled())
return $this;
if ($langue = Zend_Registry::get('translate')->getLocale())
$this->_select
->where('(cms_article.langue = "' . $langue . '" or exists (select \'x\' from cms_article as translation where translation.PARENT_ID = cms_article.ID_ARTICLE and trim(translation.langue) = "' . $langue . '") or cms_article.langue = "" or cms_article.langue is null)');
return $this;
}
public function getArticlesByPreferencesDefaults() {
return ['id_categorie' => '', // catégories d'article, ex: 12-2-8-1-89
@@ -383,7 +416,9 @@ class ArticleLoader extends Storm_Model_Loader {
'id_lieu' => null, // id du lieu Class_Lieu
'place_town' => null,
'display_mode' => 'Title',
'custom_fields' => []];
'custom_fields' => [],
'filter_by_workflow' => false,
'filter_by_local' => false];
}
@@ -420,6 +455,9 @@ class ArticleLoader extends Storm_Model_Loader {
$this->_display_mode = $preferences['display_mode'];
$this->_custom_fields = $preferences['custom_fields'];
$this->_filter_by_workflow = $preferences['filter_by_workflow'];
$this->_filter_by_local = $preferences['filter_by_local'];
if ($this->_sort_order == static::ORDER_SELECTION && !$this->_has_selection)
return [];
@@ -433,6 +471,7 @@ class ArticleLoader extends Storm_Model_Loader {
->_whereEventDateIn($this->_event_date)
->_whereEventStartAfter($this->_event_start_after)
->_whereEventEndAfter($this->_event_end_after)
->_filterByLocal()
->_filterByLangue()
->_filterByStatus()
->_orderAndLimit()
@@ -447,7 +486,9 @@ class ArticleLoader extends Storm_Model_Loader {
if ((new ZendAfi_Validate_DateFormat)->isValid($this->_event_date))
$articles = $this->_filterByDay($this->_event_date, $articles);
$this->_all_articles = $articles = $this->_sortArticles($articles);
$articles = $this->_sortArticles($articles);
$this->_all_articles = $articles = $this->_loadTranslateFor($articles);
if (
($this->_sort_order == static::ORDER_SELECTION)
@@ -459,6 +500,18 @@ class ArticleLoader extends Storm_Model_Loader {
}
protected function _loadTranslateFor($articles) {
if ( ($langue = Zend_Registry::get('translate')->getLocale()) && Class_AdminVar::isTranslationEnabled() && $this->_filter_by_local)
return array_map(function ($article) use ($langue)
{
return $article->getTraductionLangue($langue);
},
$articles);
return $articles;
}
public function getAllArticles() {
return $this->_all_articles;
}