Browse Source

Merge branch 'feature/group' into unstable

bastien 13 years ago
parent
commit
fa8bc2fc33

+ 4 - 1
app/Resources/translations/elements.fr.yml View File

4
   
4
   
5
 element:
5
 element:
6
   favorite:
6
   favorite:
7
-    add:                Ajouter a mes favoris
7
+    add:                Ajouter a mes favoris
8
+  add:
9
+    group:
10
+      will_be_in:       L'élément sera ajouté dans le groupe

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

116
   /**
116
   /**
117
    *  Procédure d'ajout d'un element
117
    *  Procédure d'ajout d'un element
118
    */
118
    */
119
-  public function elementAddAction()
120
-  {
119
+  public function elementAddAction($group_slug)
120
+  {    
121
     $user = $this->getUser();
121
     $user = $this->getUser();
122
     $em = $this->getDoctrine()->getEntityManager();
122
     $em = $this->getDoctrine()->getEntityManager();
123
     
123
     
126
       array(),
126
       array(),
127
       array(
127
       array(
128
        'tags'   => $this->getTagsArray(),
128
        'tags'   => $this->getTagsArray(),
129
+        // Ligne non obligatoire (cf. verif du contenu du form -> ticket)
129
        'groups' => $this->getGroupsArray()
130
        'groups' => $this->getGroupsArray()
130
       )
131
       )
131
     );
132
     );
142
         $factory = new ElementManager($element, $em, $this->container);
143
         $factory = new ElementManager($element, $em, $this->container);
143
         $factory->proceedFill($data, $user);
144
         $factory->proceedFill($data, $user);
144
         
145
         
146
+        // Si on a précisé un groupe
147
+        if ($group_slug)
148
+        {
149
+          $group = $this->findGroupWithSlug($group_slug);
150
+          if ($group->userCanAddElement($this->getUserId()))
151
+          {
152
+            $element->setGroup($group);
153
+          }
154
+          else
155
+          {
156
+            throw $this->createNotFoundException('Vous ne pouvez ajouter d\'element a ce groupe.');
157
+          }
158
+          $redirect_url = $this->generateUrl('show_group', array('slug' => $group->getSlug()));
159
+        }
160
+        else
161
+        {
162
+          $redirect_url = $this->generateUrl('home');
163
+        }
164
+        
145
         $em->persist($element);
165
         $em->persist($element);
146
         $em->flush();
166
         $em->flush();
147
         
167
         
148
         if ($this->getRequest()->isXmlHttpRequest())
168
         if ($this->getRequest()->isXmlHttpRequest())
149
         {
169
         {
150
-
170
+          
151
         }
171
         }
152
         else
172
         else
153
         {
173
         {
154
-          return $this->redirect($this->generateUrl('home'));
174
+          return $this->redirect($redirect_url);
155
         }
175
         }
156
         
176
         
157
       }
177
       }
164
         else
184
         else
165
         {
185
         {
166
           $this->setFlash('error', 'element.add.error');
186
           $this->setFlash('error', 'element.add.error');
167
-          return $this->redirect($this->generateUrl('home'));
187
+          return $this->redirect($redirect_url);
168
         }
188
         }
169
         
189
         
170
       }
190
       }

+ 2 - 2
src/Muzich/CoreBundle/ElementFactory/ElementManager.php View File

83
   
83
   
84
   protected function setGroup($params)
84
   protected function setGroup($params)
85
   {
85
   {
86
-    if ($params['group_id'])
86
+    if ($params['group'])
87
     {
87
     {
88
-      $group = $this->em->getRepository('MuzichCoreBundle:Group')->findOneById($params['group_id']);
88
+      $group = $this->em->getRepository('MuzichCoreBundle:Group')->findOneById($params['group']);
89
       $this->element->setGroup($group);
89
       $this->element->setGroup($group);
90
     }
90
     }
91
   }
91
   }

+ 9 - 0
src/Muzich/CoreBundle/Entity/Element.php View File

210
     return $this->tags;
210
     return $this->tags;
211
   }
211
   }
212
   
212
   
213
+  public function setTags($tags)
214
+  {
215
+    $this->tags = $tags;
216
+  }
213
 
217
 
214
   /**
218
   /**
215
    * Set owner
219
    * Set owner
352
     return count($this->elements_favorites);
356
     return count($this->elements_favorites);
353
   }
357
   }
354
   
358
   
359
+  public function setGroupToId()
360
+  {
361
+    $this->group = $this->group->getId();
362
+  }
363
+  
355
 }
364
 }

+ 20 - 0
src/Muzich/CoreBundle/Entity/Group.php View File

321
     $this->tags = $tags_id;
321
     $this->tags = $tags_id;
322
   }
322
   }
323
   
323
   
324
+  /**
325
+   * Retourne vrai si l'user_id peut poster dans ce groupe.
326
+   * 
327
+   * @param int $user_id
328
+   * @return boolean 
329
+   */
330
+  public function userCanAddElement($user_id)
331
+  {
332
+    if ($this->open)
333
+    {
334
+      return true;
335
+    }
336
+    
337
+    if ($this->getOwner()->getId() == $user_id)
338
+    {
339
+      return true;
340
+    }
341
+    
342
+    return false;
343
+  }
324
 }
344
 }

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

260
   {
260
   {
261
     return $this->groups_owned;
261
     return $this->groups_owned;
262
   }
262
   }
263
+
264
+  /**
265
+   * Get groups in array (id => name)
266
+   *
267
+   * @return Doctrine\Common\Collections\Collection 
268
+   */
269
+  public function getGroupsOwnedArray()
270
+  {
271
+    $groups = array();
272
+    foreach ($this->groups_owned as $group)
273
+    {
274
+      $groups[$group->getId()] = $group->getName();
275
+    }
276
+    return $groups;
277
+  }
263
   
278
   
264
   public function getSlug()
279
   public function getSlug()
265
   {
280
   {

+ 6 - 5
src/Muzich/CoreBundle/Form/Element/ElementAddForm.php View File

22
       'expanded'          => true,
22
       'expanded'          => true,
23
       'multiple'          => true
23
       'multiple'          => true
24
     ));
24
     ));
25
-        
26
-    $options['groups'][''] = '';
27
     
25
     
28
-    $builder->add('group_id', 'choice', array(
26
+    $options['groups'][''] = '';
27
+    $builder->add('group', 'choice', array(
29
       'choices'           => $options['groups'],
28
       'choices'           => $options['groups'],
30
       'expanded'          => false,
29
       'expanded'          => false,
31
-      'multiple'          => false
30
+      'multiple'          => false,
31
+      'required'          => false
32
     ));
32
     ));
33
+    
33
   }
34
   }
34
 
35
 
35
   public function getName()
36
   public function getName()
43
       'name' => '',
44
       'name' => '',
44
       'url' => '',
45
       'url' => '',
45
       'tags' => array(),
46
       'tags' => array(),
46
-      'groups' => '',
47
+      'groups' => array(),
47
       'data_class' => 'Muzich\CoreBundle\Entity\Element'
48
       'data_class' => 'Muzich\CoreBundle\Entity\Element'
48
     );
49
     );
49
   }
50
   }

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

9
   defaults: { _controller: MuzichCoreBundle:Core:follow }
9
   defaults: { _controller: MuzichCoreBundle:Core:follow }
10
    
10
    
11
 element_add:
11
 element_add:
12
-  pattern:  /element/add
13
-  defaults: { _controller: MuzichCoreBundle:Core:elementAdd }
12
+  pattern:  /element/add/{group_slug}
13
+  defaults: { _controller: MuzichCoreBundle:Core:elementAdd, group_slug: null }

+ 1 - 1
src/Muzich/CoreBundle/Resources/views/Element/form.add.html.twig View File

6
 
6
 
7
 {{ form_row(form.tags) }}
7
 {{ form_row(form.tags) }}
8
 
8
 
9
-{{ form_row(form.group_id) }}
9
+{{ form_row(form.group) }}
10
 
10
 
11
 {{ form_rest(form) }}
11
 {{ form_rest(form) }}

+ 4 - 1
src/Muzich/HomeBundle/Controller/HomeController.php View File

21
   public function indexAction()
21
   public function indexAction()
22
   {
22
   {
23
     $search_object = $this->getElementSearcher();
23
     $search_object = $this->getElementSearcher();
24
+    $user = $this->getUser(true, array('join' => array(
25
+      'groups_owned'
26
+    )), true);
24
     
27
     
25
     $search_form = $this->createForm(
28
     $search_form = $this->createForm(
26
       new ElementSearchForm(), 
29
       new ElementSearchForm(), 
35
       array(),
38
       array(),
36
       array(
39
       array(
37
         'tags' => $tags,
40
         'tags' => $tags,
38
-        'groups' => $this->getGroupsArray(),
41
+        'groups' => $user->getGroupsOwnedArray(),
39
       )
42
       )
40
     );
43
     );
41
         
44
         

+ 16 - 1
src/Muzich/HomeBundle/Controller/ShowController.php View File

4
 
4
 
5
 use Muzich\CoreBundle\lib\Controller;
5
 use Muzich\CoreBundle\lib\Controller;
6
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
6
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7
+use Muzich\CoreBundle\Form\Element\ElementAddForm;
8
+use Muzich\CoreBundle\Entity\Element;
7
 
9
 
8
 class ShowController extends Controller
10
 class ShowController extends Controller
9
 {
11
 {
44
       'group_id'  => $group->getId()
46
       'group_id'  => $group->getId()
45
     ));
47
     ));
46
     
48
     
49
+    ($group->getOwner()->getId() == $this->getUserId()) ? $his = true : $his = false;
50
+    if ($his || $group->getOpen())
51
+    {      
52
+      $add_form = $this->createForm(
53
+        new ElementAddForm(),
54
+        array(),
55
+        array(
56
+          'tags' => $this->getTagsArray()
57
+        )
58
+      );
59
+    }
60
+    
47
     return array(
61
     return array(
48
       'group'     => $group,
62
       'group'     => $group,
49
       'his_group' => ($group->getOwner()->getId() == $this->getUserId()) ? true : false,
63
       'his_group' => ($group->getOwner()->getId() == $this->getUserId()) ? true : false,
50
       'elements'  => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
64
       'elements'  => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
51
       'following' => $this->getUser()->isFollowingGroupByQuery($this->getDoctrine(), $group->getId()),
65
       'following' => $this->getUser()->isFollowingGroupByQuery($this->getDoctrine(), $group->getId()),
52
-      'user'      => $this->getUser()
66
+      'user'      => $this->getUser(),
67
+      'add_form'  => (isset($add_form)) ? $add_form->createView() : null
53
     );
68
     );
54
   }
69
   }
55
   
70
   

+ 12 - 0
src/Muzich/HomeBundle/Resources/views/Show/showGroup.html.twig View File

24
     
24
     
25
   <h2>{{ group.name }}</h2>
25
   <h2>{{ group.name }}</h2>
26
   
26
   
27
+  <form action="{{ path('element_add', {'group_slug' : group.slug}) }}" method="post" {{ form_enctype(add_form) }}>
28
+    
29
+    {% include "MuzichCoreBundle:Element:form.add.html.twig" with { 'form': add_form } %}
30
+
31
+    <p>
32
+      <i>
33
+        {{ 'element.add.group.will_be_in'|trans({}, 'elements') }}
34
+      </i>
35
+    </p>
36
+    <input type="submit" />
37
+  </form>
38
+  
27
   {% include "MuzichCoreBundle:SearchElement:default.html.twig" %}
39
   {% include "MuzichCoreBundle:SearchElement:default.html.twig" %}
28
     
40
     
29
 {% endblock %}
41
 {% endblock %}