From 1fc2b8597672ed8b2011ec8e29cac3df1878494c Mon Sep 17 00:00:00 2001
From: Julio Montoya <gugli100@gmail.com>
Date: Mon, 22 Sep 2014 14:52:45 +0200
Subject: [PATCH] Fixing portal blog.

---
 app/config/sonata/sonata_news.yml             |  4 +-
 app/config/sonata/sonata_seo.yml              | 10 +--
 data/home/register_top.html                   |  0
 .../Resources/views/standard_layout.html.twig | 72 ++++++++++++-------
 .../Resources/views/Post/archive.html.twig    | 58 +++++++++++++++
 .../views/Post/comment_form.html.twig         | 26 +++++++
 .../Resources/views/Post/comments.html.twig   | 34 +++++++++
 .../Resources/views/Post/view.html.twig       | 57 +++++++++++++++
 .../Migrations/Schema/v10/Extra.php           | 42 +++++++++++
 9 files changed, 272 insertions(+), 31 deletions(-)
 delete mode 100755 data/home/register_top.html
 create mode 100644 src/Application/Sonata/NewsBundle/Resources/views/Post/archive.html.twig
 create mode 100644 src/Application/Sonata/NewsBundle/Resources/views/Post/comment_form.html.twig
 create mode 100644 src/Application/Sonata/NewsBundle/Resources/views/Post/comments.html.twig
 create mode 100644 src/Application/Sonata/NewsBundle/Resources/views/Post/view.html.twig

diff --git a/app/config/sonata/sonata_news.yml b/app/config/sonata/sonata_news.yml
index e6eac41a6f..046bcc5b86 100644
--- a/app/config/sonata/sonata_news.yml
+++ b/app/config/sonata/sonata_news.yml
@@ -16,6 +16,8 @@ sonata_news:
             emails:   %sonata_news.comment.emails%
             from:     %sonata_news.comment.email_from%
             template: 'SonataNewsBundle:Mail:comment_notification.txt.twig'
+    class:
+        user:       Chamilo\UserBundle\Entity\User
 
 
 # Enable Doctrine to map the provided entities
@@ -25,4 +27,4 @@ doctrine:
             default:
                 mappings:
                     ApplicationSonataNewsBundle: ~
-                    SonataNewsBundle: ~
\ No newline at end of file
+                    SonataNewsBundle: ~
diff --git a/app/config/sonata/sonata_seo.yml b/app/config/sonata/sonata_seo.yml
index 03865778b7..265ec4689f 100644
--- a/app/config/sonata/sonata_seo.yml
+++ b/app/config/sonata/sonata_seo.yml
@@ -5,11 +5,11 @@ sonata_seo:
     encoding:             UTF-8
     page:
         default:          sonata.seo.page.default
-        title:            Chamilo LMS
+        title:            %sonata_admin.title%
         metas:
             name:
-                keywords:             foo bar
-                description:          The description
+                keywords:
+                description:
                 robots:               index, follow
 
             property:
@@ -19,8 +19,8 @@ sonata_seo:
 
                 # Open Graph information
                 # see http://developers.facebook.com/docs/opengraphprotocol/#types or http://ogp.me/
-                'og:site_name':       Chamilo
-                'og:description':     Chamilo LMS
+                'og:site_name':        %sonata_admin.title%
+                'og:description':      %sonata_admin.title%
 
             http-equiv:
                 'Content-Type':         text/html; charset=utf-8
diff --git a/data/home/register_top.html b/data/home/register_top.html
deleted file mode 100755
index e69de29bb2..0000000000
diff --git a/src/Application/Sonata/AdminBundle/Resources/views/standard_layout.html.twig b/src/Application/Sonata/AdminBundle/Resources/views/standard_layout.html.twig
index 525b00d0d1..64cabc0f48 100644
--- a/src/Application/Sonata/AdminBundle/Resources/views/standard_layout.html.twig
+++ b/src/Application/Sonata/AdminBundle/Resources/views/standard_layout.html.twig
@@ -30,7 +30,7 @@ file that was distributed with this source code.
     {% block stylesheets %}
 
         {% for stylesheet in admin_pool.getOption('stylesheets', []) %}
-            <link rel="stylesheet" type="text/css"  href="{{ asset(stylesheet) }}"  />
+            <link rel="stylesheet" href="{{ asset(stylesheet) }}">
         {% endfor %}
 
     {% endblock %}
@@ -48,35 +48,55 @@ file that was distributed with this source code.
         </script>
 
         {% for javascript in admin_pool.getOption('javascripts', []) %}
-        <script src="{{ asset(javascript) }}" type="text/javascript"></script>
+        <script src="{{ asset(javascript) }}"></script>
         {% endfor %}
 
+        {# localize select2 #}
+        {% if admin_pool is defined and admin_pool.getOption('use_select2') %}
+        {% set locale = app.request.locale %}
+        {% if locale == 'pt' %}{% set locale = 'pt_PT' %}{% endif %}
+
+        {# omit default EN locale #}
+        {% if locale[:2] != 'en' %}
+        <script src="{{ asset('bundles/sonataadmin/vendor/select2/select2_locale_' ~ locale|replace({'_':'-'}) ~ '.js') }}"></script>
+        {% endif %}
+        {% endif %}
+
     {% endblock %}
 
     <title>
-        {{ 'Admin'|trans({}, 'SonataAdminBundle') }}
-
-        {% if _title is not empty %}
-            {{ _title|raw }}
-        {% else %}
-            {% if action is defined %}
-                -
-                {% for menu in admin.breadcrumbs(action) %}
-                    {% if not loop.first %}
-                        {%  if loop.index != 2 %}
-                            &gt;
-                        {% endif %}
+        {% block sonata_head_title %}
+            {{ 'Admin'|trans({}, 'SonataAdminBundle') }}
 
-                        {{ menu.label }}
-                    {% endif %}
-                {% endfor %}
-            {% endif %}
-        {% endif%}
+            {% if _title is not empty %}
+                {{ _title|raw }}
+            {% else %}
+                {% if action is defined %}
+                    -
+                    {% for menu in admin.breadcrumbs(action) %}
+                        {% if not loop.first %}
+                            {%  if loop.index != 2 %}
+                                &gt;
+                            {% endif %}
+
+                            {{ menu.label }}
+                        {% endif %}
+                    {% endfor %}
+                {% endif %}
+            {% endif%}
+        {% endblock %}
     </title>
 </head>
 <body {% block body_attributes %}class="sonata-bc skin-black fixed"{% endblock %}>
 {% block sonata_header %}
     <header class="header">
+        {% block sonata_header_noscript_warning %}
+            <noscript>
+                <div class="noscript-warning">
+                    {{ 'noscript_warning'|trans({}, 'SonataAdminBundle') }}
+                </div>
+            </noscript>
+        {% endblock %}
         {% block logo %}
             {% spaceless %}
                 <a class="logo" href="{{ url('sonata_admin_dashboard') }}">
@@ -235,11 +255,13 @@ file that was distributed with this source code.
                         {% block sonata_page_content_nav %}
                             {% if _tab_menu is not empty or _actions is not empty %}
                                 <nav class="navbar navbar-default" role="navigation">
-                                    {% if _navbar_title is not empty %}
-                                        <div class="navbar-header">
-                                            <span class="navbar-brand">{{ _navbar_title|raw }}</span>
-                                        </div>
-                                    {% endif %}
+                                    {% block tab_menu_navbar_header %}
+                                        {% if _navbar_title is not empty %}
+                                            <div class="navbar-header">
+                                                <span class="navbar-brand">{{ _navbar_title|raw }}</span>
+                                            </div>
+                                        {% endif %}
+                                    {% endblock %}
                                     <div class="container-fluid">
                                         <div class="navbar-left">
                                             {% if _tab_menu is not empty %}
@@ -247,7 +269,7 @@ file that was distributed with this source code.
                                             {% endif %}
                                         </div>
 
-                                        {% if _actions is not empty %}
+                                        {% if _actions|replace({ '<li>': '', '</li>': '' })|trim is not empty %}
                                             <ul class="nav navbar-nav navbar-right">
                                                 <li class="dropdown sonata-actions">
                                                     <a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ 'link_actions'|trans({}, 'SonataAdminBundle') }} <b class="caret"></b></a>
diff --git a/src/Application/Sonata/NewsBundle/Resources/views/Post/archive.html.twig b/src/Application/Sonata/NewsBundle/Resources/views/Post/archive.html.twig
new file mode 100644
index 0000000000..94a1317558
--- /dev/null
+++ b/src/Application/Sonata/NewsBundle/Resources/views/Post/archive.html.twig
@@ -0,0 +1,58 @@
+{# Original file:
+vendor/sonata-project/news-bundle/Resources/views/Post/archive.html.twig
+#}
+{% block sonata_page_breadcrumb %}
+    <div class="row-fluid clearfix">
+        {{ sonata_block_render_event('breadcrumb', { 'context': 'news_archive', 'collection': collection, 'tag': tag, 'current_uri': app.request.requestUri }) }}
+    </div>
+{% endblock %}
+
+<h1>{{ 'title_archive'|trans({}, 'SonataNewsBundle') }}</h1>
+
+<div class="sonata-blog-post-list">
+    {% for post in pager.getResults() %}
+        <div class="sonata-blog-post-container">
+            <header>
+                <h2 class="sonata-blog-post-title">
+                    <a href="{{ url('sonata_news_view', { 'permalink': sonata_news_permalink(post) }) }}">{{ post.title }}</a>
+                </h2>
+
+                <div class="sonata-blog-post-information">
+                    <span class="sonata-blog-post-author">{{ 'archive_author'|trans({'%author%': post.author }, 'SonataNewsBundle') }}</span> |
+
+                    <i class="icon-calendar"></i>
+                    {{ post.publicationDateStart | format_date }} |
+
+                    <i class="icon-comment"></i>
+                    <span class="sonata-blog-post-comments-count">{{ 'comments_count'|trans({'%comments_count%': post.commentsCount }, 'SonataNewsBundle') }}</span>
+
+                    <div class="sonata-blog-post-tags">
+                        {% if post.tags|length > 1 %}
+                            <i class="icon-tags"></i>
+                        {% else %}
+                            <i class="icon-tag"></i>
+                        {% endif %}
+                        {{ 'published_under'|transchoice(post.tags|length, {}, 'SonataNewsBundle') }}
+
+                        {% for tag in post.tags %}
+                            <a href="{{ url('sonata_news_tag', { 'tag': tag.slug } ) }}">{{ tag.name }}</a>{% if not loop.last %},{% endif %}
+                        {% endfor %}
+                    </div>
+                </div>
+            </header>
+
+            <div class="sonata-blog-post-abtract">
+                {{ post.abstract }}
+            </div>
+        </div>
+
+        <hr />
+    {% else %}
+        {{ 'no_post_found'|trans({}, 'SonataNewsBundle') }}
+    {% endfor %}
+
+    <ul class="pager">
+        <li{% if pager.page == pager.lastPage %} class="disabled"{% endif %}><a href="{{ url(route, route_parameters|merge({'page': pager.nextpage})) }}" title="{{ 'link_previous_page'|trans({}, 'SonataNewsBundle') }}">{{ 'link_previous_page'|trans({}, 'SonataNewsBundle') }}</a>
+        <li{% if pager.page == pager.firstPage %} class="disabled"{% endif %}><a href="{{ url(route, route_parameters|merge({'page': pager.previouspage})) }}" title="{{ 'link_next_page'|trans({}, 'SonataNewsBundle') }}">{{ 'link_next_page'|trans({}, 'SonataNewsBundle') }}</a></li>
+    </ul>
+</div>
diff --git a/src/Application/Sonata/NewsBundle/Resources/views/Post/comment_form.html.twig b/src/Application/Sonata/NewsBundle/Resources/views/Post/comment_form.html.twig
new file mode 100644
index 0000000000..faf5460a79
--- /dev/null
+++ b/src/Application/Sonata/NewsBundle/Resources/views/Post/comment_form.html.twig
@@ -0,0 +1,26 @@
+{#
+
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+#}
+
+<div class="panel panel-default">
+    <div class="panel-heading">
+        <h3>{{'title_leave_comment'|trans({}, 'SonataNewsBundle') }}</h3>
+    </div>
+    <div class="panel-body">
+        <form action="{{ url('sonata_news_add_comment', {'id': post_id}) }}" method="POST" class="form-horizontal" role="form">
+            {{ form_widget(form) }}
+            <div class="form-actions">
+                <button type="submit" class="btn btn-primary"><i class="glyphicon glyphicon-pencil"></i>&nbsp;{{'btn_add_comment'|trans({}, 'SonataNewsBundle') }}</button>
+            </div>
+        </form>
+    </div>
+</div>
\ No newline at end of file
diff --git a/src/Application/Sonata/NewsBundle/Resources/views/Post/comments.html.twig b/src/Application/Sonata/NewsBundle/Resources/views/Post/comments.html.twig
new file mode 100644
index 0000000000..ff396dcbff
--- /dev/null
+++ b/src/Application/Sonata/NewsBundle/Resources/views/Post/comments.html.twig
@@ -0,0 +1,34 @@
+{#
+
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+#}
+
+<div class="sonata-blog-comment-container">
+    <h3>{{ 'title_comments'|trans({}, 'SonataNewsBundle') }}</h3>
+
+    <ul class="sonata-blog-comment-list">
+        {% for comment in pager.results %}
+            <li class="sonata-blog-comment">
+                <div class="sonata-blog-comment-name">
+                    <a href="{{ comment.url }}" target="new" rel="nofollow">{{ comment.name }}</a>
+                </div>
+                <div class="sonata-blog-comment-date">
+                    {{ comment.createdAt | format_date }}
+                </div>
+                <div class="sonata-blog-comment-message">
+                    {{ comment.message }}
+                </div>
+            </li>
+        {% else %}
+            <li>{{ 'no_comments_available'|trans({}, 'SonataNewsBundle') }}</li>
+        {% endfor %}
+    </ul>
+</div>
diff --git a/src/Application/Sonata/NewsBundle/Resources/views/Post/view.html.twig b/src/Application/Sonata/NewsBundle/Resources/views/Post/view.html.twig
new file mode 100644
index 0000000000..9b9ba5c772
--- /dev/null
+++ b/src/Application/Sonata/NewsBundle/Resources/views/Post/view.html.twig
@@ -0,0 +1,57 @@
+{% block sonata_page_breadcrumb %}
+    <div class="row-fluid clearfix">
+        {{ sonata_block_render_event('breadcrumb', { 'context': 'news_post', 'post': post, 'current_uri': app.request.requestUri }) }}
+    </div>
+{% endblock %}
+
+<article class="sonata-blog-post-container">
+    <header>
+        <div class="sonata-blog-post-date-container">
+            <h5>
+                <i class="icon-calendar"></i>
+                {{ post.publicationDateStart | format_date }}
+            </h5>
+        </div>
+
+        <h1 class="sonata-blog-post-title">
+            <a href="{{ url('sonata_news_view', { 'permalink': sonata_news_permalink(post) }) }}">{{ post.title }}</a>
+            <span class="sonata-blog-post-author">{{ 'archive_author'|trans({'%author%': post.author }, 'SonataNewsBundle') }}</span>
+        </h1>
+
+        <div class="sonata-blog-post-information">
+            <div class="sonata-blog-post-tag-container">
+                <div class="sonata-blog-post-tag-title">
+                    {% if post.tags|length > 1 %}
+                        <i class="icon-tags"></i>
+                    {% else %}
+                        <i class="icon-tag"></i>
+                    {% endif %}
+                    {{ 'published_under'|transchoice(post.tags|length, {}, 'SonataNewsBundle') }}
+                </div>
+                <div class="sonata-blog-post-tag-list">
+                    {% for tag in post.tags %}
+                        <a href="{{ url('sonata_news_tag', { 'tag': tag.slug } ) }}">{{ tag.name }}</a>
+                    {% endfor %}
+                </div>
+            </div>
+        </div>
+    </header>
+
+    <div class="sonata-blog-post-content">
+        {% media post.image, 'wide' %}
+        {{ post.content|raw }}
+    </div>
+
+    {% render(controller('SonataNewsBundle:Post:comments', {'postId': post.id})) %}
+
+    {% if post.iscommentable %}
+        {% render(controller('SonataNewsBundle:Post:addCommentForm', {
+            'postId': post.id,
+            'form': form
+        })) %}
+    {% else %}
+        <div>
+            {{ 'message_comments_are_closed'|trans({}, 'SonataNewsBundle') }}
+        </div>
+    {% endif %}
+</article>
diff --git a/src/Chamilo/CoreBundle/Migrations/Schema/v10/Extra.php b/src/Chamilo/CoreBundle/Migrations/Schema/v10/Extra.php
index fb9ab93360..948f62e67e 100644
--- a/src/Chamilo/CoreBundle/Migrations/Schema/v10/Extra.php
+++ b/src/Chamilo/CoreBundle/Migrations/Schema/v10/Extra.php
@@ -113,6 +113,48 @@ class Extra implements Migration, OrderedMigrationInterface
         $queries->addQuery("ALTER TABLE acl_entries ADD CONSTRAINT FK_46C8B806EA000B10 FOREIGN KEY (class_id) REFERENCES acl_classes (id) ON UPDATE CASCADE ON DELETE CASCADE");
         $queries->addQuery("ALTER TABLE acl_entries ADD CONSTRAINT FK_46C8B8063D9AB4A6 FOREIGN KEY (object_identity_id) REFERENCES acl_object_identities (id) ON UPDATE CASCADE ON DELETE CASCADE");
         $queries->addQuery("ALTER TABLE acl_entries ADD CONSTRAINT FK_46C8B806DF9183C9 FOREIGN KEY (security_identity_id) REFERENCES acl_security_identities (id) ON UPDATE CASCADE ON DELETE CASCADE");
+
+        $queries->addQuery("ALTER TABLE news__post DROP FOREIGN KEY FK_7D109BC83DA5256D");
+        $queries->addQuery("ALTER TABLE news__post DROP FOREIGN KEY FK_7D109BC8514956FD");
+        $queries->addQuery("ALTER TABLE news__post DROP FOREIGN KEY FK_7D109BC8F675F31B");
+        $queries->addQuery("DROP INDEX IDX_7D109BC83DA5256D ON news__post");
+        $queries->addQuery("DROP INDEX IDX_7D109BC8F675F31B ON news__post");
+        $queries->addQuery("DROP INDEX IDX_7D109BC8514956FD ON news__post");
+        $queries->addQuery("ALTER TABLE news__post DROP image_id, DROP collection_id, DROP author_id");
+        $queries->addQuery("ALTER TABLE news__post_audit DROP image_id, DROP author_id, DROP collection_id");
+        $queries->addQuery("ALTER TABLE news__comment DROP FOREIGN KEY FK_A90210404B89032C");
+        $queries->addQuery("DROP INDEX IDX_A90210404B89032C ON news__comment");
+        $queries->addQuery("ALTER TABLE news__comment DROP post_id");
+        $queries->addQuery("ALTER TABLE news__comment_audit DROP post_id");
+        $queries->addQuery("ALTER TABLE classification__collection DROP FOREIGN KEY FK_A406B56AEA9FDD75");
+        $queries->addQuery("DROP INDEX IDX_A406B56AEA9FDD75 ON classification__collection");
+        $queries->addQuery("ALTER TABLE classification__collection DROP media_id");
+        $queries->addQuery("ALTER TABLE classification__collection_audit DROP media_id");
+        $queries->addQuery("ALTER TABLE classification__category DROP FOREIGN KEY FK_43629B36727ACA70");
+        $queries->addQuery("ALTER TABLE classification__category DROP FOREIGN KEY FK_43629B36EA9FDD75");
+        $queries->addQuery("DROP INDEX IDX_43629B36727ACA70 ON classification__category");
+        $queries->addQuery("DROP INDEX IDX_43629B36EA9FDD75 ON classification__category");
+        $queries->addQuery("ALTER TABLE classification__category DROP parent_id, DROP media_id");
+        $queries->addQuery("ALTER TABLE classification__category_audit DROP parent_id, DROP media_id");
+        $queries->addQuery("ALTER TABLE fos_user_user_group DROP FOREIGN KEY FK_B3C77447A76ED395");
+        $queries->addQuery("ALTER TABLE fos_user_user_group DROP FOREIGN KEY FK_B3C77447FE54D947");
+        $queries->addQuery("ALTER TABLE fos_user_user_group ADD CONSTRAINT FK_B3C77447A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)");
+        $queries->addQuery("ALTER TABLE fos_user_user_group ADD CONSTRAINT FK_B3C77447FE54D947 FOREIGN KEY (group_id) REFERENCES fos_group (id);");
+
+        $queries->addQuery("ALTER TABLE news__post ADD image_id INT DEFAULT NULL, ADD author_id INT DEFAULT NULL, ADD collection_id INT DEFAULT NULL");
+        $queries->addQuery("ALTER TABLE news__post ADD CONSTRAINT FK_7D109BC83DA5256D FOREIGN KEY (image_id) REFERENCES media__media (id)");
+        $queries->addQuery("ALTER TABLE news__post ADD CONSTRAINT FK_7D109BC8F675F31B FOREIGN KEY (author_id) REFERENCES user (id)");
+        $queries->addQuery("ALTER TABLE news__post ADD CONSTRAINT FK_7D109BC8514956FD FOREIGN KEY (collection_id) REFERENCES classification__collection (id)");
+        $queries->addQuery("CREATE INDEX IDX_7D109BC83DA5256D ON news__post (image_id)");
+        $queries->addQuery("CREATE INDEX IDX_7D109BC8F675F31B ON news__post (author_id)");
+        $queries->addQuery("CREATE INDEX IDX_7D109BC8514956FD ON news__post (collection_id)");
+        $queries->addQuery("ALTER TABLE news__post_audit ADD image_id INT DEFAULT NULL, ADD author_id INT DEFAULT NULL, ADD collection_id INT DEFAULT NULL");
+        $queries->addQuery("ALTER TABLE news__comment ADD post_id INT NOT NULL");
+        $queries->addQuery("ALTER TABLE news__comment ADD CONSTRAINT FK_A90210404B89032C FOREIGN KEY (post_id) REFERENCES news__post (id)");
+        $queries->addQuery("CREATE INDEX IDX_A90210404B89032C ON news__comment (post_id)");
+        $queries->addQuery("ALTER TABLE news__comment_audit ADD post_id INT DEFAULT NULL");
+
+
     }
 
     public function down(Schema $schema, QueryBag $queries)