Browse Source

Evolution #832: Element: Prise en compte anciens count_favorited & count_playlisted

Bastien Sevajol 11 years ago
parent
commit
4d6bd2ccc1

+ 54 - 1
src/Muzich/CoreBundle/Command/MigrationUpgradeCommand.php View File

9
 use Symfony\Component\Console\Output\OutputInterface;
9
 use Symfony\Component\Console\Output\OutputInterface;
10
 //use Muzich\CoreBundle\Managers\CommentsManager;
10
 //use Muzich\CoreBundle\Managers\CommentsManager;
11
 use Muzich\CoreBundle\Util\StrictCanonicalizer;
11
 use Muzich\CoreBundle\Util\StrictCanonicalizer;
12
+use Muzich\CoreBundle\Entity\Element;
12
 
13
 
13
 class MigrationUpgradeCommand extends ContainerAwareCommand
14
 class MigrationUpgradeCommand extends ContainerAwareCommand
14
 {
15
 {
72
       foreach ($elements as $element)
73
       foreach ($elements as $element)
73
       {
74
       {
74
         $element->setSlug($canonicalizer->canonicalize_stricter($element->getName()));
75
         $element->setSlug($canonicalizer->canonicalize_stricter($element->getName()));
75
-        $output->write('.');
76
+        $this->updateCountFavorited($element);
77
+        $this->updateCountPlaylisted($element);
78
+        
79
+        $output->writeln('<info>Element '.$element->getName().' favorited ...'.$element->getCountFavorited().'</info>');
80
+        $output->writeln('<info>Element '.$element->getName().' playlisted ...'.$element->getCountPlaylisted().'</info>');
81
+        
82
+        //$output->write('.');
76
         $em->persist($element);
83
         $em->persist($element);
77
       }
84
       }
78
       
85
       
86
+      $output->writeln('');
79
       $output->writeln('<info>Save in Database ...</info>');
87
       $output->writeln('<info>Save in Database ...</info>');
80
       $em->flush();
88
       $em->flush();
81
       $output->writeln('<info>Terminé !</info>');
89
       $output->writeln('<info>Terminé !</info>');
86
       $output->writeln('<error>Versions saisies non prises en charges</error>');
94
       $output->writeln('<error>Versions saisies non prises en charges</error>');
87
     }
95
     }
88
   }
96
   }
97
+  
98
+  protected function updateCountFavorited(Element $element)
99
+  {
100
+    $em = $this->getContainer()->get('doctrine')->getEntityManager();
101
+    
102
+    // Compter le nombre de favoris de cet élement 
103
+    // + Effectué par un autre que le proprio
104
+    // + Qui ont l'email confirmé
105
+    
106
+    $count = $em->createQueryBuilder()
107
+      ->select('COUNT(DISTINCT element)')
108
+      ->from('MuzichCoreBundle:UsersElementsFavorites', 'fav')
109
+      ->join('fav.user', 'owner')
110
+      ->join('fav.element', 'element')
111
+      ->where('fav.user != :element_owner_id AND owner.email_confirmed = 1')
112
+      ->andWhere('fav.element = :element_id')
113
+      ->setParameter('element_owner_id', $element->getOwner()->getId())
114
+      ->setParameter('element_id', $element->getId())
115
+      ->getQuery()
116
+      ->getSingleScalarResult()
117
+    ;
118
+    $element->setCountFavorited($count);
119
+  }
120
+  
121
+  protected function updateCountPlaylisted(Element $element)
122
+  {
123
+    $em = $this->getContainer()->get('doctrine')->getEntityManager();
124
+    
125
+    // Compter le nombre d'user qui ont l'element dans une playlist
126
+    // + Effectué par un user différent que le proprio
127
+    // + Qui ont l'email confirmé
128
+    
129
+    $count = $em->createQueryBuilder()
130
+      ->select('COUNT(DISTINCT user)')
131
+      ->from('MuzichCoreBundle:Playlist', 'playlist')
132
+      ->join('playlist.owner', 'user')
133
+      ->where('playlist.elements LIKE :element_id AND playlist.owner != :element_owner_id AND user.email_confirmed = 1')
134
+      ->setParameter('element_owner_id', $element->getOwner()->getId())
135
+      ->setParameter('element_id', '%"id":"'.$element->getId().'"%')
136
+      ->getQuery()
137
+      ->getSingleScalarResult()
138
+    ;
139
+    $element->setCountPlaylisted($count);
140
+  }
141
+  
89
 }
142
 }

+ 3 - 27
src/Muzich/CoreBundle/Command/RecalculateReputationCommand.php View File

33
     $output->writeln('#');
33
     $output->writeln('#');
34
 
34
 
35
     $output->writeln('<info>Début du traitement ...</info>');
35
     $output->writeln('<info>Début du traitement ...</info>');
36
-    $this->recalculateUserScores($input, $output);
37
     $this->recalculateElementScores($input, $output);
36
     $this->recalculateElementScores($input, $output);
37
+    $this->recalculateUserScores($input, $output);
38
     
38
     
39
     $output->writeln('<info>Saving in database ...</info>');
39
     $output->writeln('<info>Saving in database ...</info>');
40
     $em->flush();
40
     $em->flush();
87
        ->getResult()      
87
        ->getResult()      
88
       ;
88
       ;
89
       
89
       
90
-      $coef_element_point = $this->getContainer()->getParameter('reputation_element_point_value');
90
+      //$coef_element_point = $this->getContainer()->getParameter('reputation_element_point_value');
91
       $element_points = 0;
91
       $element_points = 0;
92
       foreach ($elements as $element)
92
       foreach ($elements as $element)
93
       {
93
       {
94
         $element_points += $element->getPoints();
94
         $element_points += $element->getPoints();
95
-        // Point déjà ajoutés a l'user
96
-        $element_points -= ($element->getCountFavorited()*$this->getContainer()->getParameter('reputation_element_favorite_value'));
97
-      }
98
-      
99
-      /*
100
-       * On calcule pour les favoris
101
-       */
102
-      $coef_element_fav = $this->getContainer()->getParameter('reputation_element_favorite_value');
103
-      $count_favs = 0;
104
-      $fav = $em->createQuery(
105
-        "SELECT COUNT(f) FROM MuzichCoreBundle:UsersElementsFavorites f"
106
-        . " JOIN f.element e JOIN f.user fu"
107
-        . " WHERE e.owner = :uid AND f.user != :uid AND fu.email_confirmed = 1"
108
-      )->setParameter('uid', $user->getId())
109
-       ->getScalarResult()      
110
-      ;
111
-      
112
-      if (count($fav))
113
-      {
114
-        if (count($fav[0]))
115
-        {
116
-          $count_favs = $fav[0][1];
117
-        }
118
       }
95
       }
119
       
96
       
120
       /*
97
       /*
160
       }
137
       }
161
 
138
 
162
       $points = 
139
       $points = 
163
-          ($element_points * $coef_element_point)
164
-        + ($count_favs     * $coef_element_fav)
140
+          $element_points
165
         + ($count_follow   * $coef_follow)
141
         + ($count_follow   * $coef_follow)
166
         + ($count_tag_prop * $coef_tag_prop)
142
         + ($count_tag_prop * $coef_tag_prop)
167
       ;
143
       ;

+ 6 - 0
src/Muzich/CoreBundle/Security/Context.php View File

116
       ),
116
       ),
117
       self::ACTION_USER_FOLLOW => array(
117
       self::ACTION_USER_FOLLOW => array(
118
         self::CONDITION_USER_EMAIL_NOT_CONFIRMED
118
         self::CONDITION_USER_EMAIL_NOT_CONFIRMED
119
+      ),
120
+      self::ACTION_PLAYLIST_ADD_ELEMENT => array(
121
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
122
+      ),
123
+      self::ACTION_PLAYLIST_REMOVE_ELEMENT => array(
124
+        self::CONDITION_USER_EMAIL_NOT_CONFIRMED
119
       )
125
       )
120
     )
126
     )
121
   );
127
   );