Browse Source

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

bastien 13 years ago
parent
commit
a263897f50

+ 4 - 0
app/Resources/translations/users.fr.yml View File

21
     no:                         Pas de nouveaux partages mis en favoris
21
     no:                         Pas de nouveaux partages mis en favoris
22
     one:                        %count% de vos partage a été mis en favoris
22
     one:                        %count% de vos partage a été mis en favoris
23
     yes:                        %count% de vos partages ont été mis en favoris
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
 reputation:
29
 reputation:
26
   bar:
30
   bar:

+ 1 - 1
src/Muzich/CoreBundle/Controller/CoreController.php View File

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

+ 1 - 0
src/Muzich/CoreBundle/Entity/Event.php View File

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

+ 32 - 0
src/Muzich/CoreBundle/Entity/User.php View File

134
   protected $events;
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
   public function __construct()
146
   public function __construct()
616
     return $this->email_requested_datetime;
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 View File

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

+ 7 - 1
src/Muzich/CoreBundle/Propagator/EventUser.php View File

21
    * 
21
    * 
22
    * @param User $user Utilisateur suivis
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
     $ur = new UserReputation($user);
27
     $ur = new UserReputation($user);
27
     $ur->addPoints(
28
     $ur->addPoints(
28
       $this->container->getParameter('reputation_element_follow_value')
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 View File

15
    *
15
    *
16
    * @Template()
16
    * @Template()
17
    */
17
    */
18
-  public function indexAction()
18
+  public function indexAction($event_id)
19
   {    
19
   {    
20
     $user = $this->getUser(true, array('join' => array(
20
     $user = $this->getUser(true, array('join' => array(
21
       'followeds_users', 'followers_users', 'followeds_groups'
21
       'followeds_users', 'followers_users', 'followeds_groups'
25
     $followeds_groups = $user->getFollowedGroups();
25
     $followeds_groups = $user->getFollowedGroups();
26
     $followers_users = $user->getFollowersUsers();
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
     return array(
43
     return array(
29
       'followeds_users' => $followeds_users,
44
       'followeds_users' => $followeds_users,
30
       'followeds_groups' => $followeds_groups,
45
       'followeds_groups' => $followeds_groups,
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
    * d'utilisateurs et de groupes.
72
    * d'utilisateurs et de groupes.
38
    * 
73
    * 
39
    * @Template()
74
    * @Template()

+ 2 - 2
src/Muzich/MynetworkBundle/Resources/config/routing.yml View File

1
 
1
 
2
 mynetwork_index:
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
 mynetwork_search:
6
 mynetwork_search:
7
   pattern:  /my-network/search
7
   pattern:  /my-network/search

+ 1 - 1
src/Muzich/MynetworkBundle/Resources/views/Mynetwork/index.html.twig View File

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

+ 0 - 1
src/Muzich/UserBundle/Resources/config/routing.yml View File

37
 event_view_elements:
37
 event_view_elements:
38
   pattern: /event/view/elements/{event_id}
38
   pattern: /event/view/elements/{event_id}
39
   defaults: { _controller: MuzichUserBundle:Event:viewElements }
39
   defaults: { _controller: MuzichUserBundle:Event:viewElements }
40
-  

+ 19 - 0
src/Muzich/UserBundle/Resources/views/Info/bar.html.twig View File

41
         {% endif %}
41
         {% endif %}
42
           
42
           
43
     </div>
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
   </div>
64
   </div>

+ 20 - 0
web/bundles/muzichcore/css/main.css View File

1154
 {
1154
 {
1155
   font-weight: bold;
1155
   font-weight: bold;
1156
   margin-left: 5px;
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
 }

BIN
web/bundles/muzichcore/img/1333474994_people.png View File