Pārlūkot izejas kodu

Evolution #143: Commentaires sur un élément

bastien 12 gadus atpakaļ
vecāks
revīzija
83fbd1426e

+ 1 - 0
app/AppKernel.php Parādīt failu

@@ -32,6 +32,7 @@ class AppKernel extends Kernel
32 32
             new Muzich\AdminBundle\MuzichAdminBundle(),
33 33
             new Muzich\GroupBundle\MuzichGroupBundle(),
34 34
             new Muzich\FavoriteBundle\MuzichFavoriteBundle(),
35
+            new Muzich\CommentBundle\MuzichCommentBundle(),
35 36
         );
36 37
 
37 38
         if (in_array($this->getEnvironment(), array('dev', 'test'))) {

+ 6 - 0
app/Resources/translations/elements.fr.yml Parādīt failu

@@ -26,6 +26,12 @@ element:
26 26
     link:               Modifier
27 27
   remove:
28 28
     link:               Supprimer
29
+  comments: 
30
+    add:                Ajouter un commentaire
31
+    thereis:            Afficher le commentaire
32
+    thereare:           Afficher les <strong>%count%</strong> commentaires
33
+    hideis:             Cacher le commentaire
34
+    hideare:            Cacher les commentaires
29 35
   
30 36
 elements:
31 37
   ajax:

+ 11 - 0
src/Muzich/CommentBundle/Controller/CommentController.php Parādīt failu

@@ -0,0 +1,11 @@
1
+<?php
2
+
3
+namespace Muzich\CommentBundle\Controller;
4
+
5
+use Muzich\CoreBundle\lib\Controller;
6
+
7
+class CommentController extends Controller
8
+{
9
+  
10
+  
11
+}

+ 9 - 0
src/Muzich/CommentBundle/MuzichCommentBundle.php Parādīt failu

@@ -0,0 +1,9 @@
1
+<?php
2
+
3
+namespace Muzich\CommentBundle;
4
+
5
+use Symfony\Component\HttpKernel\Bundle\Bundle;
6
+
7
+class MuzichCommentBundle extends Bundle
8
+{
9
+}

+ 0 - 0
src/Muzich/CommentBundle/Resources/config/routing.yml Parādīt failu


+ 0 - 0
src/Muzich/CommentBundle/Resources/doc/index.rst Parādīt failu


+ 34 - 4
src/Muzich/CoreBundle/DataFixtures/ORM/LoadElementData.php Parādīt failu

@@ -8,6 +8,7 @@ use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
8 8
 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
9 9
 use Symfony\Component\DependencyInjection\ContainerInterface;
10 10
 use Muzich\CoreBundle\Entity\Element;
11
+use Muzich\CoreBundle\Managers\CommentsManager;
11 12
 
12 13
 class LoadElementData  extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
13 14
 {
@@ -38,7 +39,7 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
38 39
   /**
39 40
    *  
40 41
    */
41
-  protected function createElement($reference_id, $name, $url, $tags, $type, $owner, $group = null, $date = null)
42
+  protected function createElement($reference_id, $name, $url, $tags, $type, $owner, $group = null, $date = null, $comments = null)
42 43
   {    
43 44
     $element = new Element();
44 45
     $element->setName(ucfirst($name));
@@ -60,6 +61,8 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
60 61
       $element->addTag($tag);
61 62
     }
62 63
     
64
+    $element->setComments($comments);
65
+    
63 66
     $this->entity_manager->persist($element);
64 67
   }
65 68
   
@@ -195,22 +198,49 @@ class LoadElementData  extends AbstractFixture implements OrderedFixtureInterfac
195 198
       'youtube.com', $bux, null, $this->dateD(183)
196 199
     );
197 200
     
201
+    $cm = new CommentsManager();
202
+    $cm->add($joelle, "J'aime bien quand ça tape. Ca rapelle ".
203
+      "le grincement sinistre des volets de vieilles".
204
+      "maisons. D'ailleur j'ai repeint mon mur des shiots !", $this->dateD(180));
205
+    
198 206
     $this->createElement('azyd_azylum_1', 'AZYD AZYLUM Live au Café Provisoire', 
199 207
       'http://www.youtube.com/watch?v=8AXhRXAt2E4', 
200 208
       $this->getArrayOfTag(array('metal')),
201
-      'youtube.com', $bux, null, $this->dateD(182)
209
+      'youtube.com', $bux, null, $this->dateD(182),
210
+      $cm->get()
202 211
     );
203 212
     
213
+    $cm = new CommentsManager();
214
+    $cm->add($bux, "Je commenteuuh nanana 1", $this->dateD(180));
215
+    $cm->add($paul, "Je répond 2", $this->dateD(180));
216
+    $cm->add($bux, "Je répond 3", $this->dateD(179));
217
+    $cm->add($paul, "Je répond 4", $this->dateD(178));
218
+    $cm->add($bux, "Je répond 5", $this->dateD(177));
219
+    $cm->add($paul, "Je répond 6", $this->dateD(176));
220
+    $cm->add($bux, "Je répond 7", $this->dateD(175));
221
+    $cm->add($paul, "Je répond 8", $this->dateD(174));
222
+    $cm->add($bux, "Je répond 9", $this->dateD(173));
223
+    $cm->add($paul, "Je répond 10", $this->dateD(172));
224
+    $cm->add($bux, "Je répond 11", $this->dateD(161));
225
+    $cm->add($paul, "Je répond 12", $this->dateD(150));
226
+    $cm->add($bux, "Je répond 13", $this->dateD(140));
227
+    
204 228
     $this->createElement('babylon_pression_1', 'Babylon Pression - Des Tasers et des Pauvres', 
205 229
       'http://www.youtube.com/watch?v=XWkbaHxRvds&feature=related', 
206 230
       $this->getArrayOfTag(array('metal', 'hardcore')),
207
-      'youtube.com', $bux, null, $this->dateD(181)
231
+      'youtube.com', $bux, null, $this->dateD(181),
232
+      $cm->get()
208 233
     );
209 234
     
235
+    $cm = new CommentsManager();
236
+    $cm->add($bux, "C'est trop bon hein ?", $this->dateD(180));
237
+    $cm->add($paul, "C'est pas mal en effet", $this->dateD(180));
238
+        
210 239
     $this->createElement('ed_cox_1', 'Ed Cox - La fanfare des teuffeurs (Hardcordian)', 
211 240
       'http://www.youtube.com/watch?v=Lk1gnh-JCDs&feature=related', 
212 241
       $this->getArrayOfTag(array('electro')),
213
-      'youtube.com', $bux, null, $this->dateD(180)
242
+      'youtube.com', $bux, null, $this->dateD(180),
243
+      $cm->get()
214 244
     );
215 245
     
216 246
 

+ 39 - 0
src/Muzich/CoreBundle/Entity/Element.php Parādīt failu

@@ -125,6 +125,27 @@ class Element
125 125
    * @ORM\Column(type="string", length=512, nullable=true)
126 126
    */
127 127
   protected $thumbnail_url;
128
+  
129
+  /**
130
+   * Commentaires stocké au format json
131
+   * 
132
+   * array(
133
+   *   array(
134
+   *     "u" => array(              // Des infos sur l'utilisateur auteur du commentaire
135
+   *       "i" => "IdDuUser",       // l'id
136
+   *       "s" => "LeSlugDuUser",   // le slug
137
+   *       "n" => "NameDuUser"      // le name
138
+   *     ),
139
+   *     "d" => "LaDate",        // Date au format Y-m-d H:i:s
140
+   *     "c" => "Comment"           // Le commentaire
141
+   *   ),
142
+   *   [...]
143
+   * );
144
+   * 
145
+   * @ORM\Column(type="text", nullable=true)
146
+   * @var type string
147
+   */
148
+  protected $comments;
128 149
 
129 150
   /**
130 151
    * Get id
@@ -387,6 +408,24 @@ class Element
387 408
   }
388 409
   
389 410
   /**
411
+   *
412
+   * @return type array
413
+   */
414
+  public function getComments()
415
+  {
416
+    return json_decode($this->comments, true);
417
+  }
418
+  
419
+  /**
420
+   *
421
+   * @param array $comments 
422
+   */
423
+  public function setComments($comments)
424
+  {
425
+    $this->comments = json_encode($comments);
426
+  }
427
+  
428
+  /**
390 429
    * Etablie des relation vers des tags.
391 430
    * (Supprime les anciens tags, au niveau de l'objet seulement)
392 431
    * 

+ 51 - 0
src/Muzich/CoreBundle/Managers/CommentsManager.php Parādīt failu

@@ -0,0 +1,51 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Managers;
4
+
5
+/**
6
+ * @author bux
7
+ */
8
+class CommentsManager
9
+{
10
+  
11
+  protected $comments;
12
+  
13
+  public function __construct($comments = array())
14
+  {
15
+    $this->comments = $comments;
16
+  }
17
+  
18
+  /**
19
+   *
20
+   * @param \Muzich\CoreBundle\Entity\User $user
21
+   * @param String $comment
22
+   * @param String $date 
23
+   */
24
+  public function add($user, $comment, $date = null)
25
+  {
26
+    if (!$date)
27
+    {
28
+      $date = date('Y-m-d H:i:s');
29
+    }
30
+    
31
+    $this->comments[] = array(
32
+      "u" => array(
33
+        "i" => $user->getId(),
34
+        "s" => $user->getSlug(),
35
+        "n" => $user->getName()
36
+      ),
37
+      "d" => $date,
38
+      "c" => $comment
39
+    );
40
+  }
41
+  
42
+  /**
43
+   *
44
+   * @return array
45
+   */
46
+  public function get()
47
+  {
48
+    return $this->comments;
49
+  }
50
+  
51
+}

+ 44 - 0
src/Muzich/CoreBundle/Resources/views/SearchElement/element.html.twig Parādīt failu

@@ -111,6 +111,29 @@
111 111
         {{ 'element.show.close_embed'|trans({}, 'elements') }}
112 112
       </a>
113 113
       
114
+      
115
+      {% autoescape false %}
116
+        {% if element.comments|length > 1 %}
117
+          <a href="#hide_comments_{{ element.id }}" class="hide_comments" style="display: none;">
118
+            {{ 'element.comments.hideare'|trans({}, 'elements') }}
119
+          </a>   
120
+          <a href="#comments_{{ element.id }}" class="display_comments">
121
+            {{ 'element.comments.thereare'|trans({'%count%':element.comments|length}, 'elements') }}
122
+          </a> -
123
+        {% elseif element.comments|length == 1 %}
124
+          <a href="#hide_comments_{{ element.id }}" class="hide_comments" style="display: none;">
125
+            {{ 'element.comments.hideis'|trans({}, 'elements') }}
126
+          </a>
127
+          <a href="#comments_{{ element.id }}" class="display_comments">
128
+            {{ 'element.comments.thereis'|trans({}, 'elements') }}
129
+          </a> -
130
+        {%endif %}
131
+      {% endautoescape %}
132
+                
133
+      <a href="#add_comment_{{ element.id }}" class="add_comment">
134
+        {{ 'element.comments.add'|trans({}, 'elements') }}
135
+      </a>
136
+      
114 137
     </td>
115 138
   </tr>
116 139
 </table>
@@ -122,3 +145,24 @@
122 145
     </div>
123 146
   {% endautoescape %}
124 147
 {% endif %}
148
+
149
+{% if element.comments|length %}
150
+  <div class="comments" style="display: none;">
151
+    <ul class="comments">
152
+      {% for comment in element.comments %}
153
+        <li class="comment">
154
+          <a href="{{ path('show_user', {'slug': comment.u.s}) }}" >{{ comment.u.n }}</a>: 
155
+          {{ comment.c }}
156
+          <span class="datesince">({{ comment.d|date_or_relative_date }})</span>
157
+        </li>
158
+      {% endfor %}
159
+    </ul>
160
+      
161
+    
162
+      
163
+    <a href="#add_comment_{{ element.id }}" class="add_comment">
164
+      {{ 'element.comments.add'|trans({}, 'elements') }}
165
+    </a>
166
+      
167
+  </div>
168
+{% endif %}

+ 29 - 1
web/bundles/muzichcore/css/main.css Parādīt failu

@@ -932,4 +932,32 @@ input#element_add_url, input#element_add_name
932 932
 label#element_add_url, label#element_add_name
933 933
 {
934 934
   
935
-}
935
+}
936
+
937
+/* Commentaire */
938
+
939
+li.element div.comments
940
+{
941
+  padding-left: 18px;
942
+  padding-right: 18px;
943
+}
944
+
945
+div.comments ul.comments
946
+{
947
+  margin: 0px 0px 0px 0px;
948
+}
949
+
950
+li.comment
951
+{
952
+  list-style: none;
953
+  padding-bottom: 4px;
954
+  padding-top: 4px;
955
+  border-bottom: 1px dotted #d9d9d9;
956
+}
957
+
958
+li.comment span.datesince
959
+{
960
+  color: #868686;
961
+}
962
+
963
+/* END commentaires */

+ 48 - 0
web/bundles/muzichcore/js/muzich.js Parādīt failu

@@ -1276,5 +1276,53 @@ $(document).ready(function(){
1276 1276
       check_new_elements();
1277 1277
     }
1278 1278
   }
1279
+  
1280
+  /*
1281
+   * Commentaires d'élément
1282
+   */
1283
+  
1284
+  // Afficher les commentaires
1285
+    $('td.element_content a.display_comments').live('click', function(){
1286
+      display_comments(
1287
+        $('li#element_'+
1288
+          str_replace('#comments_', '', $(this).attr('href'))
1289
+        )
1290
+      );
1291
+    });
1292
+    
1293
+    $('td.element_content a.hide_comments').live('click', function(){
1294
+      hide_comments(
1295
+        $('li#element_'+
1296
+          str_replace('#hide_comments_', '', $(this).attr('href'))
1297
+        )
1298
+      );
1299
+    });
1300
+  
1301
+    function display_comments(li_element)
1302
+    {
1303
+      li_element.find('div.comments').slideDown();
1304
+      li_element.find('a.display_comments').hide();
1305
+      li_element.find('a.hide_comments').show();
1306
+    }
1307
+  
1308
+    function hide_comments(li)
1309
+    {
1310
+      li_element.find('div.comments').slideUp();
1311
+      li_element.find('a.display_comments').show();
1312
+      li_element.find('a.hide_comments').hide();
1313
+    }
1314
+    
1315
+  // Ajouter un commentaire
1316
+    $('li.element a.add_comment').live('click', function(){
1317
+      display_add_comment($('li#element_'+
1318
+        str_replace('#add_comment_', '', $(this).attr('href'))
1319
+      ));
1320
+    });
1321
+    
1322
+    function display_add_comment(li_element)
1323
+    {
1324
+      li_element.find('a.add_comment').hide();
1325
+      
1326
+    }
1279 1327
    
1280 1328
  });