Browse Source

Evolution #164: Proposition de tag sur un élément

bastien 13 years ago
parent
commit
d20371032e

+ 6 - 4
src/Muzich/CoreBundle/Controller/ElementController.php View File

@@ -6,6 +6,8 @@ use Muzich\CoreBundle\lib\Controller;
6 6
 use Muzich\CoreBundle\ElementFactory\ElementManager;
7 7
 use Muzich\CoreBundle\Propagator\EventElement;
8 8
 use Muzich\CoreBundle\Entity\ElementTagsProposition;
9
+use Muzich\CoreBundle\Managers\EventArchiveManager;
10
+use Muzich\CoreBundle\Entity\EventArchive;
9 11
 
10 12
 class ElementController extends Controller
11 13
 {
@@ -686,14 +688,14 @@ class ElementController extends Controller
686 688
     $element->setHasTagProposition(false);
687 689
     $this->getDoctrine()->getEntityManager()->persist($element);
688 690
     
691
+    // On archive le fait que la proposition est été accepté
692
+    $eam = new EventArchiveManager($this->getDoctrine()->getEntityManager());
693
+    $eam->add($proposition->getUser(), EventArchive::PROP_TAGS_ELEMENT_ACCEPTED);
694
+    
689 695
     $propositions = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:ElementTagsProposition')
690 696
       ->findByElement($element->getId())
691 697
     ;
692 698
     
693
-    /*
694
-     * TODO: ARCHIVAGE (c avant ou aprés event déjà ?) (cf doc), notifs (event)
695
-     */
696
-    
697 699
     // On supprime les proposition liés a cet élement
698 700
     foreach ($propositions as $proposition)
699 701
     {

+ 101 - 0
src/Muzich/CoreBundle/Entity/EventArchive.php View File

@@ -0,0 +1,101 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Entity;
4
+
5
+use Doctrine\ORM\Mapping as ORM;
6
+use Gedmo\Mapping\Annotation as Gedmo;
7
+
8
+/**
9
+ * EventArchive contient l'archive des événement passés nécéssaire pour des 
10
+ * calculs.
11
+ * 
12
+ * @ORM\Entity
13
+ * @ORM\Table(name="event_archive")
14
+ * @ORM\Entity(repositoryClass="Muzich\CoreBundle\Repository\EventArchiveRepository")
15
+ * 
16
+ */
17
+class EventArchive
18
+{
19
+  
20
+  const PROP_TAGS_ELEMENT_ACCEPTED = "pro.tagel.ac";
21
+  
22
+  /**
23
+   * @ORM\Id
24
+   * @ORM\Column(type="integer")
25
+   * @ORM\GeneratedValue(strategy="AUTO")
26
+   * @var type int
27
+   */
28
+  protected $id;
29
+  
30
+  /**
31
+   * Type (constitué de la valeur d'une des constantes d'Event)
32
+   * 
33
+   * @ORM\Column(type = "string", length = 12)
34
+   * @var type string
35
+   */
36
+  protected $type;
37
+  
38
+  /**
39
+   * Propriétaire de l'archive d'event
40
+   * 
41
+   * @ORM\ManyToOne(targetEntity="User", inversedBy="events")
42
+   * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
43
+   */
44
+  protected $user;
45
+  
46
+  /**
47
+   * Compteur de fois ou l'évnènement c'est produit
48
+   * 
49
+   * @ORM\Column(type="integer", nullable=true)
50
+   * @var int 
51
+   */
52
+  protected $count;
53
+  
54
+  /*
55
+   * 
56
+   * getters / setters
57
+   * 
58
+   */
59
+  
60
+  public function getId()
61
+  {
62
+    return $this->id;
63
+  }
64
+  
65
+  public function getCount()
66
+  {
67
+    return $this->count;
68
+  }
69
+  
70
+  public function setCount($count)
71
+  {
72
+    $this->count = $count;
73
+  }
74
+  
75
+  public function getType()
76
+  {
77
+    return $this->type;
78
+  }
79
+  
80
+  public function setType($type)
81
+  {
82
+    $this->type = $type;
83
+  }
84
+  
85
+  public function getUser()
86
+  {
87
+    return $this->user;
88
+  }
89
+  
90
+  public function setUser($user)
91
+  {
92
+    $this->user = $user;
93
+  }
94
+  
95
+  /*
96
+   * other methods
97
+   * 
98
+   */
99
+  
100
+  
101
+}

+ 85 - 0
src/Muzich/CoreBundle/Managers/EventArchiveManager.php View File

@@ -0,0 +1,85 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Managers;
4
+
5
+use Doctrine\ORM\EntityManager;
6
+use Muzich\CoreBundle\Entity\User;
7
+use Muzich\CoreBundle\Entity\EventArchive;
8
+
9
+/**
10
+ * 
11
+ * 
12
+ * @author bux
13
+ */
14
+class EventArchiveManager
15
+{
16
+  
17
+  /**
18
+   *
19
+   * @var EntityManager 
20
+   */
21
+  private $em;
22
+  /**
23
+   *
24
+   * @var EventArchive 
25
+   */
26
+  private $archive;
27
+  /**
28
+   *
29
+   * @var boolean 
30
+   */
31
+  private $new;
32
+  
33
+  public function __construct(EntityManager $em)
34
+  {
35
+    $this->em = $em;
36
+  }
37
+  
38
+  private function determineArchive(User $user, $type)
39
+  {
40
+    try
41
+    {
42
+      $this->archive = $this->em->createQuery(
43
+        'SELECT a FROM MuzichCoreBundle:EventArchive a
44
+        WHERE a.user = :uid AND a.type = :type'
45
+      )->setParameters(array(
46
+        'uid'  => $user->getId(),
47
+        'type' => $type
48
+      ))->getSingleResult()
49
+      ;
50
+      $this->new = false;
51
+    } 
52
+    catch (\Doctrine\ORM\NoResultException $e)
53
+    {
54
+      $this->archive = new EventArchive();
55
+      $this->new = true;
56
+    }
57
+  }
58
+  
59
+  private function initArchive(User $user, $type)
60
+  {
61
+    $this->archive->setUser($user);
62
+    $this->archive->setCount(1);
63
+    $this->archive->setType($type);
64
+  }
65
+  
66
+  private function incrementArchive()
67
+  {
68
+    $this->archive->setCount($this->archive->getCount()+1);
69
+  }
70
+  
71
+  public function add(User $user, $type)
72
+  {
73
+    $this->determineArchive($user, $type);
74
+    if ($this->new)
75
+    {
76
+      $this->initArchive($user, $type);
77
+    }
78
+    else
79
+    {
80
+      $this->incrementArchive();
81
+    }
82
+    $this->em->persist($this->archive);
83
+  }
84
+  
85
+}

+ 10 - 0
src/Muzich/CoreBundle/Repository/EventArchiveRepository.php View File

@@ -0,0 +1,10 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Repository;
4
+
5
+use Doctrine\ORM\EntityRepository;
6
+
7
+class EventArchiveRepository extends EntityRepository
8
+{
9
+  
10
+}

+ 2 - 1
web/bundles/muzichcore/js/muzich.js View File

@@ -1685,7 +1685,7 @@ $(document).ready(function(){
1685 1685
   
1686 1686
   
1687 1687
   // Enlever les ids du ElementSearch
1688
-  $('div.more_filters a.new_comments, div.more_filters a.new_favorites, div.more_filters a.tags').live('click', function(){
1688
+  $('div.more_filters a.new_comments, div.more_filters a.new_favorites, div.more_filters a.new_tags').live('click', function(){
1689 1689
     
1690 1690
     $('img.elements_more_loader').show();
1691 1691
     $('ul.elements').html('');
@@ -1703,6 +1703,7 @@ $(document).ready(function(){
1703 1703
         $('form[name="search"]').submit();
1704 1704
         $('div.more_filters a.new_comments').hide();
1705 1705
         $('div.more_filters a.new_favorites').hide();
1706
+        $('div.more_filters a.new_tags').hide();
1706 1707
       }
1707 1708
       
1708 1709
     });