浏览代码

Evolution #163: Evenements: Prise en comptes des autres facteurs

bastien 13 年前
父节点
当前提交
a263897f50

+ 4 - 0
app/Resources/translations/users.fr.yml 查看文件

@@ -21,6 +21,10 @@ events:
21 21
     no:                         Pas de nouveaux partages mis en favoris
22 22
     one:                        %count% de vos partage a été mis en favoris
23 23
     yes:                        %count% de vos partages ont été mis en favoris
24
+  new_follows:
25
+    no:                         Pas de nouveaux utilisateurs qui vous suivent
26
+    one:                        %count% nouvel utilisateur vous suis
27
+    yes:                        %count% nouveaux utilisateurs vous suivent
24 28
     
25 29
 reputation:
26 30
   bar:

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

@@ -139,7 +139,7 @@ class CoreController extends Controller
139 139
         $Follow->setFollowed($followed); 
140 140
         
141 141
         $event = new EventUser($this->container);
142
-        $event->addToFollow($followed);
142
+        $event->addToFollow($followed, $this->getUser());
143 143
         $em->persist($followed);
144 144
       }
145 145
       else { $Follow->setGroup($followed); }

+ 1 - 0
src/Muzich/CoreBundle/Entity/Event.php 查看文件

@@ -20,6 +20,7 @@ class Event
20 20
   
21 21
   const TYPE_COMMENT_ADDED_ELEMENT = "com.adde.ele";
22 22
   const TYPE_FAV_ADDED_ELEMENT     = "fav.adde.ele";
23
+  const TYPE_USER_FOLLOW           = "user.follow";
23 24
   
24 25
   /**
25 26
    * @ORM\Id

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

@@ -134,6 +134,13 @@ class User extends BaseUser
134 134
   protected $events;
135 135
   
136 136
   /**
137
+   * Contient des données pratique pour par exemple influencer l'affichange dans twig.
138
+   * 
139
+   * @var array 
140
+   */
141
+  protected $live_datas = array();
142
+  
143
+  /**
137 144
    * 
138 145
    */
139 146
   public function __construct()
@@ -616,4 +623,29 @@ class User extends BaseUser
616 623
     return $this->email_requested_datetime;
617 624
   }
618 625
   
626
+  public function addLiveData($id, $data)
627
+  {
628
+    $this->live_datas[$id] = $data;
629
+  }
630
+  
631
+  public function removeLiveData($id)
632
+  {
633
+    if (array_key_exists($id, $this->live_datas))
634
+    {
635
+      unset($this->live_datas[$id]);
636
+    }
637
+  }
638
+  
639
+  public function hasLiveData($id, $data = null)
640
+  {
641
+    if (array_key_exists($id, $this->live_datas))
642
+    {
643
+      if ($this->live_datas[$id] == $data)
644
+      {
645
+        return true;
646
+      }
647
+    }
648
+    return false;
649
+  }
650
+  
619 651
 }

+ 6 - 2
src/Muzich/CoreBundle/Extension/MyTwigExtension.php 查看文件

@@ -3,6 +3,7 @@
3 3
 namespace Muzich\CoreBundle\Extension;
4 4
 
5 5
 use Symfony\Bundle\FrameworkBundle\Translation\Translator;
6
+use Muzich\CoreBundle\Entity\Event;
6 7
 
7 8
 class MyTwigExtension extends \Twig_Extension {
8 9
 
@@ -122,10 +123,13 @@ class MyTwigExtension extends \Twig_Extension {
122 123
     switch ($const_name)
123 124
     {
124 125
       case 'TYPE_COMMENT_ADDED_ELEMENT':
125
-        return \Muzich\CoreBundle\Entity\Event::TYPE_COMMENT_ADDED_ELEMENT;
126
+        return Event::TYPE_COMMENT_ADDED_ELEMENT;
126 127
       break;
127 128
       case 'TYPE_FAV_ADDED_ELEMENT':
128
-        return \Muzich\CoreBundle\Entity\Event::TYPE_FAV_ADDED_ELEMENT;
129
+        return Event::TYPE_FAV_ADDED_ELEMENT;
130
+      break;
131
+      case 'TYPE_USER_FOLLOW':
132
+        return Event::TYPE_USER_FOLLOW;
129 133
       break;
130 134
       default:
131 135
         throw new \Exception('Constante non géré dans MyTwigExtension::event_const');

+ 7 - 1
src/Muzich/CoreBundle/Propagator/EventUser.php 查看文件

@@ -21,12 +21,18 @@ class EventUser extends EventPropagator
21 21
    * 
22 22
    * @param User $user Utilisateur suivis
23 23
    */
24
-  public function addToFollow(User $user)
24
+  public function addToFollow(User $user, User $follower)
25 25
   {
26
+    // Points de réputation
26 27
     $ur = new UserReputation($user);
27 28
     $ur->addPoints(
28 29
       $this->container->getParameter('reputation_element_follow_value')
29 30
     );
31
+    
32
+    // Event de suivis
33
+    $uea = new UserEventAction($user, $this->container);
34
+    $event = $uea->proceed(Event::TYPE_USER_FOLLOW, $follower->getId());
35
+    $this->container->get('doctrine')->getEntityManager()->persist($event);
30 36
   }
31 37
   
32 38
   /**

+ 37 - 2
src/Muzich/MynetworkBundle/Controller/MynetworkController.php 查看文件

@@ -15,7 +15,7 @@ class MynetworkController extends Controller
15 15
    *
16 16
    * @Template()
17 17
    */
18
-  public function indexAction()
18
+  public function indexAction($event_id)
19 19
   {    
20 20
     $user = $this->getUser(true, array('join' => array(
21 21
       'followeds_users', 'followers_users', 'followeds_groups'
@@ -25,6 +25,21 @@ class MynetworkController extends Controller
25 25
     $followeds_groups = $user->getFollowedGroups();
26 26
     $followers_users = $user->getFollowersUsers();
27 27
     
28
+    if ($event_id)
29
+    {
30
+      if (!($event = $this->getDoctrine()->getRepository('MuzichCoreBundle:Event')
31
+      ->findOneById($event_id)))
32
+      {
33
+        return $this->redirect($this->generateUrl('mynetwork_index'));
34
+      }
35
+
36
+      if ($event->getUser()->getId() != $this->getUserId())
37
+      {
38
+        throw $this->createNotFoundException('NotAllowed');
39
+      }
40
+      $followers_users = $this->proceedForEvent($event, $followers_users, $event_id);
41
+    }
42
+    
28 43
     return array(
29 44
       'followeds_users' => $followeds_users,
30 45
       'followeds_groups' => $followeds_groups,
@@ -32,8 +47,28 @@ class MynetworkController extends Controller
32 47
     );
33 48
   }
34 49
   
50
+  private function proceedForEvent($event, $followers_users, $event_id)
51
+  {
52
+    $ids = $event->getIds();
53
+    
54
+    $this->getDoctrine()->getEntityManager()->remove($event);
55
+    $this->getDoctrine()->getEntityManager()->flush();
56
+    
57
+    $followers_users_new = array();
58
+    foreach ($followers_users as $user)
59
+    {
60
+      if (in_array($user->getId(), $ids))
61
+      {
62
+        $user->addLiveData('new', true);
63
+      }
64
+      $followers_users_new[] = $user;
65
+    }
66
+    
67
+    return $followers_users_new;
68
+  }
69
+  
35 70
   /**
36
-   * Action qui affiche la page de recherche, et efectue la recherche
71
+   * Action qui affiche la page de recherche, et effectue la recherche
37 72
    * d'utilisateurs et de groupes.
38 73
    * 
39 74
    * @Template()

+ 2 - 2
src/Muzich/MynetworkBundle/Resources/config/routing.yml 查看文件

@@ -1,7 +1,7 @@
1 1
 
2 2
 mynetwork_index:
3
-  pattern:  /my-network
4
-  defaults: { _controller: MuzichMynetworkBundle:Mynetwork:index }
3
+  pattern:  /my-network/{event_id}
4
+  defaults: { _controller: MuzichMynetworkBundle:Mynetwork:index, event_id: null }
5 5
   
6 6
 mynetwork_search:
7 7
   pattern:  /my-network/search

+ 1 - 1
src/Muzich/MynetworkBundle/Resources/views/Mynetwork/index.html.twig 查看文件

@@ -34,7 +34,7 @@
34 34
     <b>{{ 'followed_by'|trans({}, 'network') }}</b>
35 35
     <ul id="followers_users" class="inline">
36 36
     {% for user in followers_users %} 
37
-      <li>
37
+      <li {% if user.hasLiveData('new', true) %}class="new"{% endif %}>
38 38
         <a href="{{ path('show_user', { 'slug': user.slug }) }}">{{ user.username }}</a>
39 39
       </li>
40 40
     {% endfor %}

+ 0 - 1
src/Muzich/UserBundle/Resources/config/routing.yml 查看文件

@@ -37,4 +37,3 @@ update_address:
37 37
 event_view_elements:
38 38
   pattern: /event/view/elements/{event_id}
39 39
   defaults: { _controller: MuzichUserBundle:Event:viewElements }
40
-  

+ 19 - 0
src/Muzich/UserBundle/Resources/views/Info/bar.html.twig 查看文件

@@ -41,5 +41,24 @@
41 41
         {% endif %}
42 42
           
43 43
     </div>
44
+    
45
+    <div class="follows">
46
+      
47
+        {% if events[event_const('TYPE_USER_FOLLOW')] is defined %}
48
+          <a 
49
+            href="{{ path('mynetwork_index', {'event_id':events[event_const('TYPE_USER_FOLLOW')].id}) }}" 
50
+            title="{%if events[event_const('TYPE_USER_FOLLOW')].count == 1 %}{{ 'events.new_follows.one'|trans({'%count%':1}, 'users') }}{% else %}{{ 'events.new_follows.yes'|trans({'%count%':events[event_const('TYPE_USER_FOLLOW')].count}, 'users') }}{% endif %}"
51
+            class="view_elements_event"
52
+          >
53
+            <img src="{{ asset('bundles/muzichcore/img/1333474994_people.png') }}" alt="favoriteds" />
54
+            <span class="new_comments">{{ events[event_const('TYPE_USER_FOLLOW')].count }}</span>
55
+          </a>
56
+        {% else %}
57
+          <img title="{{ 'events.new_follows.no'|trans({}, 'users') }}" src="{{ asset('bundles/muzichcore/img/1333474994_people.png') }}" alt="favoriteds" />
58
+          <span class="new_comments">0</span>
59
+        {% endif %}
60
+          
61
+    </div>
62
+  
44 63
   
45 64
   </div>

+ 20 - 0
web/bundles/muzichcore/css/main.css 查看文件

@@ -1154,4 +1154,24 @@ div#events div.favorites span
1154 1154
 {
1155 1155
   font-weight: bold;
1156 1156
   margin-left: 5px;
1157
+}
1158
+
1159
+div#events div.follows img
1160
+{
1161
+  margin-left: 3px;
1162
+  margin-bottom: -2px;
1163
+}
1164
+
1165
+div#events div.follows span
1166
+{
1167
+  font-weight: bold;
1168
+  margin-left: 5px;
1169
+}
1170
+
1171
+/*
1172
+* css mynetwork
1173
+*/
1174
+ul#followers_users li.new
1175
+{
1176
+  font-weight: bold;
1157 1177
 }

二进制
web/bundles/muzichcore/img/1333474994_people.png 查看文件