浏览代码

Mise en place du resharing, par le biais d'une boite de dialogue standart.

Sevajol Bastien 11 年前
父节点
当前提交
8eb3d0e916

+ 6 - 0
app/Resources/translations/userui.fr.yml 查看文件

@@ -131,6 +131,12 @@ element:
131 131
       no:                Non
132 132
   proposition_tags:
133 133
     link_title:        Proposer des tags
134
+  reshare:
135
+    link_title:        Re-partager
136
+    confirm: 
137
+      sentence:          Re-partager ce partage ?
138
+      yes:               Oui
139
+      no:                Non
134 140
     
135 141
 comment:
136 142
   report:

+ 2 - 40
src/Muzich/CoreBundle/Controller/CoreController.php 查看文件

@@ -271,14 +271,14 @@ class CoreController extends Controller
271 271
         {
272 272
           $html = $this->render('MuzichCoreBundle:SearchElement:li.element.html.twig', array(
273 273
             'element'     => $element,
274
-            'class_color' => 'odd'
274
+            'class_color' => 'odd'  // TODO: n'est plus utilisé
275 275
           ))->getContent();
276 276
         }
277 277
          else 
278 278
         {
279 279
           $html = $this->render('MuzichCoreBundle:SearchElement:li.element.html.twig', array(
280 280
             'element'     => $element,
281
-            'class_color' => 'odd',
281
+            'class_color' => 'odd',  // TODO: n'est plus utilisé
282 282
             'no_group_name' => true
283 283
           ))->getContent();
284 284
         }
@@ -380,44 +380,6 @@ class CoreController extends Controller
380 380
   }
381 381
   
382 382
   /**
383
-   * Cette méthode vérifie si l'élément qui vient d'être envoyé pourrais être
384
-   * associé a un groupe de l'utilisateur.
385
-   * 
386
-   * @param Element $element
387
-   * @return array
388
-   */
389
-  protected function isAddedElementCanBeInGroup(Element $element)
390
-  {
391
-    $element_tags = $element->getTags();
392
-    $groups = array();
393
-    
394
-    if ($element_tags)
395
-    {
396
-      foreach ($this->getUser()->getGroupsOwned() as $group)
397
-      {
398
-        foreach ($element_tags as $element_tag)
399
-        {
400
-          if ($group->hasThisTag($element_tag->getId()))
401
-          {
402
-            $groups[] = array(
403
-              'name' => $group->getName(),
404
-              'id'   => $group->getId(),
405
-              'url'  => $this->generateUrl('ajax_set_element_group', array(
406
-                'token'      => $this->getUser()->getPersonalHash(),
407
-                'element_id' => $element->getId(),
408
-                'group_id'   => $group->getId()
409
-              ))
410
-            );
411
-          }
412
-
413
-        }
414
-      }
415
-    }
416
-    
417
-    return $groups;
418
-  }
419
-  
420
-  /**
421 383
    * Action non ajax nettoyant la liste de tags du chercheur d'éléments
422 384
    * 
423 385
    * @return RedirectResponse 

+ 66 - 0
src/Muzich/CoreBundle/Controller/ElementController.php 查看文件

@@ -6,6 +6,8 @@ use Muzich\CoreBundle\lib\Controller;
6 6
 use Muzich\CoreBundle\Managers\ElementManager;
7 7
 use Muzich\CoreBundle\Propagator\EventElement;
8 8
 use Muzich\CoreBundle\Entity\ElementTagsProposition;
9
+use Symfony\Component\HttpFoundation\Request;
10
+use Muzich\CoreBundle\Entity\Element;
9 11
 
10 12
 class ElementController extends Controller
11 13
 {
@@ -805,4 +807,68 @@ class ElementController extends Controller
805 807
     ));
806 808
   }
807 809
   
810
+  public function reshareAction(Request $request, $element_id, $token)
811
+  {
812
+    if (($response = $this->mustBeConnected(true)))
813
+    {
814
+      return $response;
815
+    }
816
+    
817
+    if ($this->getUser()->getPersonalHash('reshare_'.$element_id) != $token)
818
+    {
819
+      throw new \Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException();
820
+    }
821
+    
822
+    if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
823
+      ->findOneById($element_id)))
824
+    {
825
+      throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
826
+    }
827
+    
828
+    if ($element->getOwner()->getId() == $this->getUserId())
829
+    {
830
+      throw new \Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException();
831
+    }
832
+    
833
+    
834
+    /**
835
+      * Bug lors des tests: L'user n'est pas 'lié' a celui en base par doctrine.
836
+      * Docrine le voit si on faire une requete directe.
837
+      */
838
+    $user = $this->getUser();
839
+    if ($this->container->getParameter('env') == 'test')
840
+    {
841
+      $user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneById(
842
+        $this->container->get('security.context')->getToken()->getUser()->getId(),
843
+        array()
844
+      )->getSingleResult();
845
+    }
846
+    
847
+    // Pour le repartage on crée un nouvel élément
848
+    $element_reshared = new Element();
849
+    $element_reshared->setUrl($element->getUrl());
850
+    $element_reshared->setName($element->getName());
851
+    $element_reshared->addTags($element->getTags());
852
+    $element_reshared->setParent($element);
853
+
854
+    // On utilise le gestionnaire d'élément
855
+    $factory = new ElementManager($element_reshared, $this->getEntityManager(), $this->container);
856
+    $factory->proceedFill($user, false);
857
+    
858
+    // On se retrouve maintenant avec un nouvel element tout neuf
859
+    $this->persist($element_reshared);
860
+    $this->flush();
861
+    
862
+    $html_element = $this->render('MuzichCoreBundle:SearchElement:li.element.html.twig', array(
863
+      'element'     => $element_reshared,
864
+      'class_color' => 'odd' // TODO: n'est plus utilisé
865
+    ))->getContent();
866
+
867
+    return $this->jsonResponse(array(
868
+      'status' => 'success',
869
+      'html'   => $html_element,
870
+      'groups' => $this->isAddedElementCanBeInGroup($element_reshared)
871
+    ));
872
+  }
873
+  
808 874
 }

+ 56 - 0
src/Muzich/CoreBundle/Entity/Element.php 查看文件

@@ -58,6 +58,22 @@ class Element
58 58
   protected $owner;
59 59
 
60 60
   /**
61
+   * Objet parent (si a été repartagé)
62
+   * 
63
+   * @ORM\ManyToOne(targetEntity="Element", inversedBy="childs")
64
+   * @ORM\JoinColumn(name="element_parent_id", referencedColumnName="id")
65
+   */
66
+  protected $parent;
67
+  
68
+  
69
+  /**
70
+   * Liste des Elements qui on reshare cet element
71
+   * 
72
+   * @ORM\OneToMany(targetEntity="Element", mappedBy="parent")
73
+   */
74
+  protected $childs;
75
+
76
+  /**
61 77
    * Groupe de l'élément
62 78
    * 
63 79
    * @ORM\ManyToOne(targetEntity="Group", inversedBy="elements")
@@ -332,6 +348,18 @@ class Element
332 348
   {
333 349
     $this->tags = $tags;
334 350
   }
351
+  
352
+  /**
353
+   *
354
+   * @param Collection|Array $tags 
355
+   */
356
+  public function addTags($tags)
357
+  {
358
+    foreach ($tags as $tag)
359
+    {
360
+      $this->addTag($tag);
361
+    }
362
+  }
335 363
 
336 364
   /**
337 365
    * Set owner
@@ -759,4 +787,32 @@ class Element
759 787
     return $cm->userFollow($user_id);
760 788
   }
761 789
   
790
+  /**
791
+   * 
792
+   * @param Element $element 
793
+   */
794
+  public function setParent(Element $element = null)
795
+  {
796
+    $this->parent = $element;
797
+  }
798
+  
799
+  /**
800
+   *
801
+   * @return Element 
802
+   */
803
+  public function getParent()
804
+  {
805
+    return $this->parent;
806
+  }
807
+  
808
+  public function setChilds($elements)
809
+  {
810
+    $this->childs = $elements;
811
+  }
812
+  
813
+  public function getChilds()
814
+  {
815
+    return $this->childs;
816
+  }
817
+  
762 818
 }

+ 2 - 2
src/Muzich/CoreBundle/Entity/User.php 查看文件

@@ -617,9 +617,9 @@ class User extends BaseUser
617 617
     ;
618 618
   }
619 619
   
620
-  public function getPersonalHash()
620
+  public function getPersonalHash($salt_context = null)
621 621
   {
622
-    return hash('sha256', $this->getSalt().$this->getUsername());
622
+    return hash('sha256', $this->getSalt().$this->getUsername().$salt_context);
623 623
   }
624 624
   
625 625
   /**

+ 5 - 2
src/Muzich/CoreBundle/Managers/ElementManager.php 查看文件

@@ -69,10 +69,13 @@ class ElementManager
69 69
    * @param array $params
70 70
    * @param User $owner
71 71
    */
72
-  public function proceedFill(User $owner)
72
+  public function proceedFill(User $owner, $do_tags = true)
73 73
   {
74 74
     $this->element->setOwner($owner);
75
-    $this->element->setTagsWithIds($this->em, json_decode($this->element->getTags()));
75
+    if ($do_tags)
76
+    {
77
+      $this->element->setTagsWithIds($this->em, json_decode($this->element->getTags()));
78
+    }
76 79
     $this->determineType();
77 80
     $this->proceedExtraFields();
78 81
   }

+ 4 - 0
src/Muzich/CoreBundle/Resources/config/routing.yml 查看文件

@@ -118,6 +118,10 @@ ajax_report_element:
118 118
   pattern: /ajax/element/report/{element_id}/{token}
119 119
   defaults: { _controller: MuzichCoreBundle:Core:reportElement }
120 120
   
121
+ajax_reshare_element:
122
+  pattern: /ajax/element/reshare/{element_id}/{token}
123
+  defaults: { _controller: MuzichCoreBundle:Element:reshare }
124
+  
121 125
 ajax_element_propose_tags_open:
122 126
   pattern: /ajax/element/propose/tags/{element_id}
123 127
   defaults: { _controller: MuzichCoreBundle:Element:proposeTagsOpen }

+ 6 - 0
src/Muzich/CoreBundle/Resources/views/SearchElement/element.html.twig 查看文件

@@ -64,6 +64,12 @@
64 64
           href="{{ path('ajax_report_element', {'element_id':element.id, 'token':app.user.getPersonalHash}) }}">
65 65
           <img src="{{ asset('bundles/muzichcore/img/1331832708_comment_alert.png') }}" alt="report" />
66 66
         </a>
67
+        
68
+        <a title="{{ 'element.reshare.link_title'|trans({}, 'userui') }}" 
69
+          class="element_reshare" 
70
+          href="{{ path('ajax_reshare_element', {'element_id':element.id, 'token':app.user.getPersonalHash('reshare_'~element.id)}) }}">
71
+          <img src="{{ asset('bundles/muzichcore/img/') }}" alt="re" />
72
+        </a>
67 73
       
68 74
       {% endif %}
69 75
       

+ 2 - 2
src/Muzich/CoreBundle/Resources/views/SearchElement/li.element.html.twig 查看文件

@@ -1,5 +1,5 @@
1 1
 <li class="element {{ class_color }}" id="element_{{ element.id }}">
2
-             
2
+  
3 3
   {% include "MuzichCoreBundle:SearchElement:element.html.twig" %}
4
-
4
+  
5 5
 </li>

+ 3 - 0
src/Muzich/CoreBundle/Resources/views/layout.html.twig 查看文件

@@ -49,6 +49,9 @@
49 49
     string_commentreport_confirm_sentence = "{{ 'comment.report.confirm.sentence'|trans({}, 'userui') }}";
50 50
     string_commentreport_confirm_yes = "{{ 'comment.report.confirm.yes'|trans({}, 'userui') }}";
51 51
     string_commentreport_confirm_no = "{{ 'comment.report.confirm.no'|trans({}, 'userui') }}";
52
+    string_elementreshare_confirm_sentence = "{{ 'element.reshare.confirm.sentence'|trans({}, 'userui') }}";
53
+    string_elementreshare_confirm_yes = "{{ 'element.reshare.confirm.yes'|trans({}, 'userui') }}";
54
+    string_elementreshare_confirm_no = "{{ 'element.reshare.confirm.no'|trans({}, 'userui') }}";
52 55
     {% autoescape false %}
53 56
     string_search_tag_title = "{{ 'search_tag.title'|trans({}, 'userui') }}";
54 57
     {% endautoescape %}

+ 68 - 1
src/Muzich/CoreBundle/lib/Controller.php 查看文件

@@ -9,6 +9,7 @@ use Muzich\CoreBundle\Form\Search\ElementSearchForm;
9 9
 use Muzich\CoreBundle\Form\Element\ElementAddForm;
10 10
 use Symfony\Component\HttpFoundation\Response;
11 11
 use Muzich\CoreBundle\Searcher\GlobalSearcher;
12
+use Muzich\CoreBundle\Entity\Element;
12 13
 
13 14
 class Controller extends BaseController
14 15
 {
@@ -100,7 +101,7 @@ class Controller extends BaseController
100 101
    * @param boolean $personal_query
101 102
    * @param array $params
102 103
    * @param boolean $force_refresh
103
-   * @return type 
104
+   * @return \Muzich\CoreBundle\Entity\User 
104 105
    */
105 106
   protected function getUser($personal_query = false, $params = array(), $force_refresh = false)
106 107
   {
@@ -393,4 +394,70 @@ class Controller extends BaseController
393 394
     }
394 395
   }
395 396
   
397
+  /**
398
+   *
399
+   * @return \Doctrine\ORM\EntityManager 
400
+   */
401
+  public function getEntityManager()
402
+  {
403
+    return $this->getDoctrine()->getEntityManager();
404
+  }
405
+  
406
+  /**
407
+   *
408
+   * @param object $entity 
409
+   */
410
+  public function persist($entity)
411
+  {
412
+    $this->getEntityManager()->persist($entity);
413
+  }
414
+  
415
+  /**
416
+   * 
417
+   */
418
+  public function flush()
419
+  {
420
+    $this->getEntityManager()->flush();
421
+  }
422
+  
423
+  
424
+  
425
+  /**
426
+   * Cette méthode vérifie si l'élément qui vient d'être envoyé pourrais être
427
+   * associé a un groupe de l'utilisateur.
428
+   * 
429
+   * @param Element $element
430
+   * @return array
431
+   */
432
+  protected function isAddedElementCanBeInGroup(Element $element)
433
+  {
434
+    $element_tags = $element->getTags();
435
+    $groups = array();
436
+    
437
+    if ($element_tags)
438
+    {
439
+      foreach ($this->getUser()->getGroupsOwned() as $group)
440
+      {
441
+        foreach ($element_tags as $element_tag)
442
+        {
443
+          if ($group->hasThisTag($element_tag->getId()))
444
+          {
445
+            $groups[] = array(
446
+              'name' => $group->getName(),
447
+              'id'   => $group->getId(),
448
+              'url'  => $this->generateUrl('ajax_set_element_group', array(
449
+                'token'      => $this->getUser()->getPersonalHash(),
450
+                'element_id' => $element->getId(),
451
+                'group_id'   => $group->getId()
452
+              ))
453
+            );
454
+          }
455
+
456
+        }
457
+      }
458
+    }
459
+    
460
+    return $groups;
461
+  }
462
+  
396 463
 }

+ 53 - 12
web/bundles/muzichcore/js/muzich.js 查看文件

@@ -1089,18 +1089,9 @@ $(document).ready(function(){
1089 1089
       divSelect.find('select').val('network_personal');
1090 1090
     }
1091 1091
   });
1092
-
1093
-  // Ajout d'un element #ajouter
1094
-  $('form[name="add"] input[type="submit"]').live('click', function(){
1095
-    $('form[name="add"]').find('img.tag_loader').show();
1096
-  });
1097
-  $('form[name="add"]').ajaxForm(function(response) {
1098
-    if (response.status == 'mustbeconnected')
1099
-    {
1100
-      $(location).attr('href', url_index);
1101
-    }
1102
-    
1103
-    $('form[name="add"] img.tag_loader').hide();
1092
+  
1093
+  function element_add_proceed_json_response(response)
1094
+  {
1104 1095
     if (response.status == 'success')
1105 1096
     {
1106 1097
       $('form[name="add"]').find('ul.error_list').remove();
@@ -1153,6 +1144,20 @@ $(document).ready(function(){
1153 1144
       
1154 1145
       $('form[name="add"]').prepend(ul_errors);
1155 1146
     }
1147
+  }
1148
+
1149
+  // Ajout d'un element #ajouter
1150
+  $('form[name="add"] input[type="submit"]').live('click', function(){
1151
+    $('form[name="add"]').find('img.tag_loader').show();
1152
+  });
1153
+  $('form[name="add"]').ajaxForm(function(response) {
1154
+    if (response.status == 'mustbeconnected')
1155
+    {
1156
+      $(location).attr('href', url_index);
1157
+    }
1158
+    
1159
+    $('form[name="add"] img.tag_loader').hide();
1160
+    element_add_proceed_json_response(response);
1156 1161
     
1157 1162
     return false;
1158 1163
   });
@@ -2028,5 +2033,41 @@ $(document).ready(function(){
2028 2033
       
2029 2034
     }
2030 2035
   });
2036
+  
2037
+  
2038
+  /*
2039
+   * reshare repartage
2040
+   */
2041
+  
2042
+  $('a.element_reshare').jConfirmAction({
2043
+    question : string_elementreshare_confirm_sentence, 
2044
+    yesAnswer : string_elementreshare_confirm_yes, 
2045
+    cancelAnswer : string_elementreshare_confirm_no,
2046
+    onYes: function(link){
2047
+      
2048
+      $.getJSON(link.attr('href'), function(response){
2049
+        
2050
+        if (response.status == 'mustbeconnected')
2051
+        {
2052
+          $(location).attr('href', url_index);
2053
+        }
2054
+        
2055
+        element_add_proceed_json_response(response);
2056
+        $('div.question').fadeOut();
2057
+        return false;
2058
+        
2059
+      });
2060
+      
2061
+      
2062
+      
2063
+      return false;
2064
+    },
2065
+    onOpen: function(link){
2066
+      
2067
+    },
2068
+    onClose: function(link){
2069
+      
2070
+    }
2071
+  });
2031 2072
 
2032 2073
 });