Skip to content

Commit

Permalink
Merge pull request #1056 from FrancoisDoussin/order_articles_by_creat…
Browse files Browse the repository at this point in the history
…edAt_desc

Split articles and drafts in blog and order by date
  • Loading branch information
lenybernard authored May 2, 2018
2 parents 8ef1236 + 2cffb17 commit e54c784
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 7 deletions.
41 changes: 38 additions & 3 deletions Bundle/BlogBundle/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Victoire\Bundle\BlogBundle\Entity\Article;
use Victoire\Bundle\BlogBundle\Entity\Blog;
use Victoire\Bundle\BlogBundle\Form\BlogCategoryType;
use Victoire\Bundle\BlogBundle\Form\BlogSettingsType;
Expand Down Expand Up @@ -47,7 +48,7 @@ public function indexAction(Request $request, $blog = null, $tab = 'articles')
'locale' => $locale,
'blog' => $blog,
'currentTab' => $tab,
'tabs' => ['articles', 'settings', 'category'],
'tabs' => ['articles', 'drafts', 'settings', 'category'],
'businessProperties' => $blog ? $this->getBusinessProperties($blog) : null,
];
if ($blogRepo->hasMultipleBlog()) {
Expand Down Expand Up @@ -262,11 +263,45 @@ public function categoryAction(Request $request, BasePage $blog)
*/
public function articlesAction(Request $request, BasePage $blog, $articleLocale = null)
{
$articles = $this->getDoctrine()
->getRepository(Article::class)
->getArticles($blog);

return new Response($this->container->get('templating')->render(
$this->getBaseTemplatePath().':Tabs/_articles.html.twig',
[
'locale' => $articleLocale ? $articleLocale : $request->getLocale(),
'blog' => $blog,
'locale' => $articleLocale ? $articleLocale : $request->getLocale(),
'blog' => $blog,
'articles' => $articles,
]
));
}

/**
* List Blog drafts.
*
* @param Request $request
* @param BasePage $blog
*
* @Route("/{id}/drafts/{articleLocale}", name="victoire_blog_drafts")
* @ParamConverter("blog", class="VictoirePageBundle:BasePage")
*
* @throws \InvalidArgumentException
*
* @return Response
*/
public function draftsAction(Request $request, BasePage $blog, $articleLocale = null)
{
$articles = $this->getDoctrine()
->getRepository(Article::class)
->getDrafts($blog);

return new Response($this->container->get('templating')->render(
$this->getBaseTemplatePath().':Tabs/_drafts.html.twig',
[
'locale' => $articleLocale ? $articleLocale : $request->getLocale(),
'blog' => $blog,
'articles' => $articles,
]
));
}
Expand Down
44 changes: 44 additions & 0 deletions Bundle/BlogBundle/Repository/ArticleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,48 @@ public function getVeryLastRecord()
->getQuery()
->getOneOrNullResult();
}

/**
* Get Article by blog ordered by publication DESC.
*
* @param Blog $blog
*
* @return array()
*/
public function getArticles(Blog $blog)
{
$queryBuilder = $this->getAll(false, $blog)
->getInstance();

return $queryBuilder
->andWhere('article.status IN (:status)')
->setParameter('status', [
PageStatus::PUBLISHED,
PageStatus::SCHEDULED,
PageStatus::UNPUBLISHED,
])
->orderBy('article.publishedAt', 'DESC')
->getQuery()
->getResult();
}

/**
* Get articles by blog ordered by creation DESC.
*
* @param Blog $blog
*
* @return array()
*/
public function getDrafts(Blog $blog)
{
$queryBuilder = $this->getAll(false, $blog)
->getInstance();

return $queryBuilder
->andWhere('article.status = :status')
->setParameter('status', PageStatus::DRAFT)
->orderBy('article.createdAt', 'DESC')
->getQuery()
->getResult();
}
}
4 changes: 4 additions & 0 deletions Bundle/BlogBundle/Resources/translations/victoire.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@
<source>victoire.blog.nav.articles.label</source>
<target>Posts lists</target>
</trans-unit>
<trans-unit id="5ae71b95cd1c1" resname="victoire.blog.nav.drafts.label">
<source>victoire.blog.nav.drafts.label</source>
<target>Drafts</target>
</trans-unit>
<trans-unit id="58893b9921ff6" resname="victoire.blog.nav.settings.label">
<source>victoire.blog.nav.settings.label</source>
<target>Settings</target>
Expand Down
4 changes: 4 additions & 0 deletions Bundle/BlogBundle/Resources/translations/victoire.es.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@
<source>victoire.blog.nav.articles.label</source>
<target>Lista de artículos</target>
</trans-unit>
<trans-unit id="5ae71b95cc0e0" resname="victoire.blog.nav.drafts.label">
<source>victoire.blog.nav.drafts.label</source>
<target>Borradores</target>
</trans-unit>
<trans-unit id="58893b9923598" resname="victoire.blog.nav.settings.label">
<source>victoire.blog.nav.settings.label</source>
<target>Configuración</target>
Expand Down
4 changes: 4 additions & 0 deletions Bundle/BlogBundle/Resources/translations/victoire.fr.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@
<source>victoire.blog.nav.articles.label</source>
<target>Listes des articles</target>
</trans-unit>
<trans-unit id="5ae71b95cb925" resname="victoire.blog.nav.drafts.label">
<source>victoire.blog.nav.drafts.label</source>
<target>Brouillons</target>
</trans-unit>
<trans-unit id="58893b9924c37" resname="victoire.blog.nav.settings.label">
<source>victoire.blog.nav.settings.label</source>
<target>Paramètres</target>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{% trans_default_domain "victoire" %}

{% if blog.articles|length %}
{% if articles|length %}

<a class="vic-btn vic-btn-success" data-toggle="vic-modal" href="{{ path('victoire_blog_article_new', {'id' : blog.id}) }}">
{{'modal.blog.list.articlesList.new_article'|trans({}, 'victoire')|raw}}
</a>

<div id="vic-blog-articleList">
{% for article in blog.articles if not article.deletedAt %}
{% for article in articles if not article.deletedAt %}
{% for translation in article.translations %}
{% if translation.locale == locale %}
{% set articleUrl = path('victoire_core_business_page_show_by_id', {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends "VictoireBlogBundle:Blog/Tabs:_articles.html.twig" %}
17 changes: 15 additions & 2 deletions Tests/Features/Blog/blogI18n.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ Feature: I can edit multiple blogs in multiples locales
And I open the hamburger menu
And I should see "Blog"
When I follow "Blog"
Then I should see "Brouillons"
When I follow "Brouillons"
Then I should see "titre article"
And I wait 2 seconds
When I select "en" from "choose_blog_locale"
And I wait 2 seconds
Then I should see "Brouillons"
When I follow "Brouillons"
Then I should see "title article"
When I follow "title article"
Then I should be on "en/blog-en/article-en-title-article"
Expand Down Expand Up @@ -77,7 +81,8 @@ Feature: I can edit multiple blogs in multiples locales
And I open the hamburger menu
And I should see "Blog"
When I follow "Blog"
And I wait 2 seconds
Then I should see "Brouillons"
When I follow "Brouillons"
When I select "blog 2" from "choose_blog_blog"
Then I should see "titre2"

Expand All @@ -102,6 +107,8 @@ Feature: I can edit multiple blogs in multiples locales
And I open the hamburger menu
And I should see "Blog"
When I follow "Blog"
Then I should see "Brouillons"
When I follow "Brouillons"
Then I should see "titre"
And I wait 2 seconds
When I select "fr" from "choose_blog_locale"
Expand All @@ -119,12 +126,18 @@ Feature: I can edit multiple blogs in multiples locales
And I open the hamburger menu
And I should see "Blog"
When I follow "Blog"
Then I should see "Brouillons"
When I follow "Brouillons"
And I wait 2 seconds
Then I should see "titre1"
When I select "en" from "choose_blog_locale"
And I wait 1 second
Then I should see "Brouillons"
When I follow "Brouillons"
And I should see "title1"
When I select "fr" from "choose_blog_locale"
And I wait 3 second
Then I should see "Brouillons"
When I follow "Brouillons"
When I select "blog 2 FR" from "choose_blog_blog"
Then I should see "titre2"
2 changes: 2 additions & 0 deletions Tests/Features/Blog/create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@ Background:
Then I should see "Blog"
When I follow "Blog"
Then I should see "Listes des articles"
Then I should see "Brouillons"
When I follow "Brouillons"
And I should see "I'm your father."
And I should see "Anakin Skywalker"

0 comments on commit e54c784

Please sign in to comment.