Преглед изворни кода

Evolution #42: Pagination des éléments

bastien пре 12 година
родитељ
комит
183abe568f

+ 3 - 1
app/Resources/translations/userui.fr.yml Прегледај датотеку

@@ -8,4 +8,6 @@ my_account:
8 8
   change_email:     Changer mon adresse email
9 9
   
10 10
 connexion:
11
-  password_lost:    Mot de passe perdu ?
11
+  password_lost:    Mot de passe perdu ?
12
+  
13
+more:    plus

+ 11 - 5
app/config/routing.yml Прегледај датотеку

@@ -27,24 +27,30 @@ MuzichCoreBundle:
27 27
 
28 28
 MuzichHomeBundle:
29 29
   resource: "@MuzichHomeBundle/Resources/config/routing.yml"
30
-  prefix: /
30
+  prefix: /{_locale}/
31
+  defaults:
32
+    _locale: en|fr
31 33
 
32 34
 MuzichUserBundle:
33 35
   resource: "@MuzichUserBundle/Resources/config/routing.yml"
34 36
   prefix: /{_locale}/
35
-  defaults: { _locale: fr }
37
+  defaults:
38
+    _locale: en|fr
36 39
 
37 40
 MuzichMynetworkBundle:
38 41
   resource: "@MuzichMynetworkBundle/Resources/config/routing.yml"
39 42
   prefix:   /{_locale}/
40
-  defaults: { _locale: fr }
43
+  defaults:
44
+    _locale: en|fr
41 45
   
42 46
 MuzichGroupBundle:
43 47
   resource: "@MuzichGroupBundle/Resources/config/routing.yml"
44 48
   prefix:   /{_locale}/
45
-  defaults: { _locale: fr }
49
+  defaults:
50
+    _locale: en|fr
46 51
   
47 52
 MuzichFavoriteBundle:
48 53
   resource: "@MuzichFavoriteBundle/Resources/config/routing.yml"
49 54
   prefix:   /{_locale}/
50
-  defaults: { _locale: fr }
55
+  defaults:
56
+    _locale: en|fr

+ 1 - 0
src/Muzich/CoreBundle/Repository/ElementRepository.php Прегледај датотеку

@@ -132,6 +132,7 @@ class ElementRepository extends EntityRepository
132 132
       $where_user
133 133
       $where_group
134 134
       $where_favorite
135
+      GROUP BY e, et, t2, eu, g, fav
135 136
       ORDER BY e.created DESC, e.name DESC"
136 137
     ;
137 138
     $params['uid'] = $user_id;

+ 10 - 1
src/Muzich/CoreBundle/Resources/views/SearchElement/default.html.twig Прегледај датотеку

@@ -2,7 +2,7 @@
2 2
 {% if elements|length %}
3 3
   <ul>
4 4
     {% for element in elements %} 
5
-      <li>
5
+      <li id="element_{{ element.id }}">
6 6
         {% if element.group %}
7 7
           <b>({{ element.group.name }})</b>
8 8
         {% endif %}
@@ -36,6 +36,15 @@
36 36
       </li>
37 37
     {% endfor %} 
38 38
   </ul>
39
+
40
+   {% if more_count is defined %} 
41
+     <span class="elements_more">
42
+       <a href="{{ path('home_more', {'count': more_count}) }}" >
43
+         {{ 'more'|trans({}, 'userui') }}
44
+       </a>
45
+     </span>
46
+   {% endif %}
47
+
39 48
 {% else %}
40 49
 
41 50
   <p class="no-elements">{{ 'noelements.sentence'|trans({}, 'elements') }}</p>

+ 10 - 2
src/Muzich/CoreBundle/Searcher/ElementSearcher.php Прегледај датотеку

@@ -57,6 +57,14 @@ class ElementSearcher extends Searcher implements SearcherInterface
57 57
   protected $favorite = false;
58 58
   
59 59
   /**
60
+   * Si id_limit est renseigné c'est que l'on veut trouver les elements
61
+   * plus vieux (ont utilise l'id comme référence) que l'id_limi passé.
62
+   * 
63
+   * @var type int
64
+   */
65
+  protected $id_limit = null;
66
+  
67
+  /**
60 68
    * @see SearcherInterface
61 69
    * @param array $params 
62 70
    */
@@ -69,7 +77,7 @@ class ElementSearcher extends Searcher implements SearcherInterface
69 77
     
70 78
     // Mise a jour des attributs
71 79
     $this->setAttributes(array(
72
-      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite'
80
+      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite', 'id_limit'
73 81
     ), $params);
74 82
     
75 83
   }
@@ -82,7 +90,7 @@ class ElementSearcher extends Searcher implements SearcherInterface
82 90
   {
83 91
     // Mise a jour des attributs
84 92
     $this->setAttributes(array(
85
-      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite'
93
+      'network', 'tags', 'count', 'user_id', 'group_id', 'favorite', 'id_limit'
86 94
     ), $params);
87 95
   }
88 96
   

+ 6 - 2
src/Muzich/CoreBundle/lib/Controller.php Прегледај датотеку

@@ -40,7 +40,7 @@ class Controller extends BaseController
40 40
    * 
41 41
    * @return  ElementSearcher
42 42
    */
43
-  protected function getElementSearcher()
43
+  protected function getElementSearcher($count = null)
44 44
   {
45 45
     $session = $this->get("session");
46 46
     // Si l'objet n'existe pas encore, a t-on déjà des paramètres de recherche
@@ -55,7 +55,7 @@ class Controller extends BaseController
55 55
             $this->getUserId(),
56 56
             $this->container->getParameter('search_default_favorites_tags_count')
57 57
           ),
58
-        'count' => $this->container->getParameter('search_default_count')
58
+        'count' => ($count)?$count:$this->container->getParameter('search_default_count')
59 59
       ));
60 60
 
61 61
       // Et on met en session les paramètres
@@ -67,6 +67,10 @@ class Controller extends BaseController
67 67
       $this->ElementSearcher = new ElementSearcher();
68 68
       // et on l'initatialise avec ces paramétres connus
69 69
       $this->ElementSearcher->init($session->get('user.element_search.params'));
70
+      if ($count)
71
+      {
72
+        $this->ElementSearcher->update(array('count' => $count));
73
+      }
70 74
     }
71 75
     
72 76
     // on le retourne

+ 5 - 4
src/Muzich/HomeBundle/Controller/HomeController.php Прегледај датотеку

@@ -18,9 +18,9 @@ class HomeController extends Controller
18 18
    * 
19 19
    * @Template()
20 20
    */
21
-  public function indexAction()
21
+  public function indexAction($count = null)
22 22
   {
23
-    $search_object = $this->getElementSearcher();
23
+    $search_object = $this->getElementSearcher($count);
24 24
     $user = $this->getUser(true, array('join' => array(
25 25
       'groups_owned'
26 26
     )), true);
@@ -41,12 +41,13 @@ class HomeController extends Controller
41 41
         //'groups' => $user->getGroupsOwnedArray(),
42 42
       )
43 43
     );
44
-        
44
+    
45 45
     return array(
46 46
       'user'        => $this->getUser(),
47 47
       'add_form'    => $add_form->createView(),
48 48
       'search_form' => $search_form->createView(),
49
-      'elements'    => $search_object->getElements($this->getDoctrine(), $this->getUserId())
49
+      'elements'    => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
50
+      'more_count'  => ($count)?$count+$this->container->getParameter('search_default_count'):$this->container->getParameter('search_default_count')*2
50 51
     );
51 52
   }
52 53
 }

+ 10 - 8
src/Muzich/HomeBundle/Resources/config/routing.yml Прегледај датотеку

@@ -1,15 +1,17 @@
1 1
 ## Routing du Bundle
2 2
 
3 3
 home:
4
-  pattern:  /{_locale}
5
-  defaults: { _controller: MuzichHomeBundle:Home:index, _locale: fr }
6
-  requirements:
7
-    _locale: en|fr
4
+  pattern:  /
5
+  defaults: { _controller: MuzichHomeBundle:Home:index }
6
+  
7
+home_more:
8
+  pattern:  /{count}
9
+  defaults: { _controller: MuzichHomeBundle:Home:index, count: null }
8 10
   
9 11
 show_user:
10
-  pattern: /{_locale}/user/{slug}
11
-  defaults: { _controller: MuzichHomeBundle:Show:showUser, _locale: fr }
12
+  pattern: /user/{slug}
13
+  defaults: { _controller: MuzichHomeBundle:Show:showUser }
12 14
   
13 15
 show_group:
14
-  pattern: /{_locale}/group/{slug}
15
-  defaults: { _controller: MuzichHomeBundle:Show:showGroup, _locale: fr }
16
+  pattern: /group/{slug}
17
+  defaults: { _controller: MuzichHomeBundle:Show:showGroup }