Browse Source

Merge branch 'feature/mynetwork' into feature/viewprofile

bastien 13 years ago
parent
commit
bc3a0a0dfe
24 changed files with 491 additions and 6 deletions
  1. 1 0
      app/AppKernel.php
  2. 4 0
      app/config/routing.yml
  3. 1 0
      src/Muzich/CoreBundle/Entity/Group.php
  4. 19 4
      src/Muzich/CoreBundle/Entity/User.php
  5. 32 0
      src/Muzich/CoreBundle/Repository/GroupRepository.php
  6. 22 0
      src/Muzich/CoreBundle/Repository/UserRepository.php
  7. 1 1
      src/Muzich/CoreBundle/Resources/views/layout.html.twig
  8. 1 1
      src/Muzich/CoreBundle/Searcher/ElementSearcher.php
  9. 5 0
      src/Muzich/CoreBundle/Searcher/SearcherInterface.php
  10. 70 0
      src/Muzich/CoreBundle/Searcher/UserAndGroupSearcher.php
  11. 93 0
      src/Muzich/MynetworkBundle/Controller/MynetworkController.php
  12. 29 0
      src/Muzich/MynetworkBundle/DependencyInjection/Configuration.php
  13. 28 0
      src/Muzich/MynetworkBundle/DependencyInjection/MuzichMynetworkExtension.php
  14. 9 0
      src/Muzich/MynetworkBundle/MuzichMynetworkBundle.php
  15. 13 0
      src/Muzich/MynetworkBundle/Resources/config/routing.yml
  16. 7 0
      src/Muzich/MynetworkBundle/Resources/config/services.yml
  17. 0 0
      src/Muzich/MynetworkBundle/Resources/doc/index.rst
  18. 11 0
      src/Muzich/MynetworkBundle/Resources/translations/messages.fr.xliff
  19. 46 0
      src/Muzich/MynetworkBundle/Resources/views/Mynetwork/index.html.twig
  20. 62 0
      src/Muzich/MynetworkBundle/Resources/views/Mynetwork/search.html.twig
  21. 9 0
      src/Muzich/MynetworkBundle/Resources/views/layout.html.twig
  22. 17 0
      src/Muzich/MynetworkBundle/Tests/Controller/DefaultControllerTest.php
  23. 4 0
      web/bundles/muzichcore/js/jquery-1.6.4.min.js
  24. 7 0
      web/bundles/mynetwork/css/mynetwork.css

+ 1 - 0
app/AppKernel.php View File

@@ -24,6 +24,7 @@ class AppKernel extends Kernel
24 24
             new Muzich\UserBundle\MuzichUserBundle(),
25 25
             new Muzich\IndexBundle\MuzichIndexBundle(),
26 26
             new Muzich\HomeBundle\MuzichHomeBundle(),
27
+            new Muzich\MynetworkBundle\MuzichMynetworkBundle(),
27 28
         );
28 29
 
29 30
         if (in_array($this->getEnvironment(), array('dev', 'test'))) {

+ 4 - 0
app/config/routing.yml View File

@@ -1,3 +1,7 @@
1
+MuzichMynetworkBundle:
2
+    resource: "@MuzichMynetworkBundle/Resources/config/routing.yml"
3
+    prefix:   /
4
+
1 5
 # Internal routing configuration to handle ESI
2 6
 #_internal:
3 7
 #   resource: "@FrameworkBundle/Resources/config/routing/internal.xml"

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

@@ -14,6 +14,7 @@ use Gedmo\Mapping\Annotation as Gedmo;
14 14
  * 
15 15
  * @ORM\Entity
16 16
  * @ORM\Table(name="m_group")
17
+ * @ORM\Entity(repositoryClass="Muzich\CoreBundle\Repository\GroupRepository")
17 18
  */
18 19
 class Group
19 20
 {

+ 19 - 4
src/Muzich/CoreBundle/Entity/User.php View File

@@ -71,7 +71,7 @@ class User extends BaseUser
71 71
    * Cet attribut contient les enregistrements FollowGroup lié 
72 72
    * a cet utilisateur dans le cadre des groupes suivis.
73 73
    * 
74
-   * @ORM\OneToMany(targetEntity="FollowGroup", mappedBy="user")
74
+   * @ORM\OneToMany(targetEntity="FollowGroup", mappedBy="follower")
75 75
    */
76 76
   protected $followed_groups;
77 77
   
@@ -184,7 +184,12 @@ class User extends BaseUser
184 184
    */
185 185
   public function getFollowedsUsers()
186 186
   {
187
-    return $this->followeds_users;
187
+    $users = array();
188
+    foreach ($this->followeds_users as $follow_user)
189
+    {
190
+      $users[] = $follow_user->getFollowed();
191
+    }
192
+    return $users;
188 193
   }
189 194
 
190 195
   /**
@@ -194,7 +199,12 @@ class User extends BaseUser
194 199
    */
195 200
   public function getFollowersUsers()
196 201
   {
197
-    return $this->followers_users;
202
+    $users = array();
203
+    foreach ($this->followers_users as $follow_user)
204
+    {
205
+      $users[] = $follow_user->getFollower();
206
+    }
207
+    return $users;
198 208
   }
199 209
 
200 210
   /**
@@ -214,7 +224,12 @@ class User extends BaseUser
214 224
    */
215 225
   public function getFollowedGroups()
216 226
   {
217
-    return $this->followed_groups;
227
+    $groups = array();
228
+    foreach ($this->followed_groups as $follow_group)
229
+    {
230
+      $groups[] = $follow_group->getGroup();
231
+    }
232
+    return $groups;
218 233
   }
219 234
 
220 235
   /**

+ 32 - 0
src/Muzich/CoreBundle/Repository/GroupRepository.php View File

@@ -0,0 +1,32 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Repository;
4
+
5
+use Doctrine\ORM\EntityRepository;
6
+
7
+class GroupRepository extends EntityRepository
8
+{
9
+  
10
+  /**
11
+   * Retourne un tableau d'user correspondant a un chaine de caractère
12
+   * La recherche est effectué sur le username.
13
+   * 
14
+   * @param type $string
15
+   * @return Doctrine\ORM\Query
16
+   */
17
+  public function findByString($string)
18
+  {
19
+    return $this->getEntityManager()
20
+      ->createQuery("
21
+        SELECT g FROM MuzichCoreBundle:Group g
22
+        WHERE UPPER(g.name) LIKE :str
23
+        ORDER BY g.name ASC"
24
+      )
25
+      ->setParameters(array(
26
+        'str' => '%'.strtoupper(trim($string)).'%'
27
+      ))
28
+    ;
29
+  }
30
+  
31
+}
32
+  

+ 22 - 0
src/Muzich/CoreBundle/Repository/UserRepository.php View File

@@ -34,5 +34,27 @@ class UserRepository extends EntityRepository
34 34
     return $tag_ids;
35 35
   }
36 36
   
37
+  /**
38
+   * Retourne un tableau d'user correspondant a un chaine de caractère
39
+   * La recherche est effectué sur le username.
40
+   * 
41
+   * @param type $string
42
+   * @return Doctrine\ORM\Query
43
+   */
44
+  public function findByString($string)
45
+  {
46
+    return $this->getEntityManager()
47
+      ->createQuery("
48
+        SELECT u FROM MuzichCoreBundle:User u
49
+        WHERE UPPER(u.username) LIKE :str
50
+        OR UPPER(u.usernameCanonical) LIKE :str
51
+        ORDER BY u.username ASC"
52
+      )
53
+      ->setParameters(array(
54
+        'str' => '%'.strtoupper(trim($string)).'%'
55
+      ))
56
+    ;
57
+  }
58
+  
37 59
 }
38 60
   

+ 1 - 1
src/Muzich/CoreBundle/Resources/views/layout.html.twig View File

@@ -15,7 +15,7 @@
15 15
 	<link href="{{ asset('bundles/muzichcore/css/base.css') }}" rel="stylesheet" media="screen" type="text/css" />
16 16
 	<link href="{{ asset('bundles/muzichcore/css/main.css') }}" rel="stylesheet" media="screen" type="text/css" />
17 17
   {% block css %}{% endblock %}
18
-	{#<script src="{{ asset('js/main.js') }}" type="text/javascript"></script>#}
18
+	<script src="{{ asset('bundles/muzichcore/js/jquery-1.6.4.min.js') }}" type="text/javascript"></script>
19 19
   {% block js %}{% endblock %}
20 20
 </head>
21 21
 <body>

+ 1 - 1
src/Muzich/CoreBundle/Searcher/ElementSearcher.php View File

@@ -65,7 +65,7 @@ class ElementSearcher extends Searcher implements SearcherInterface
65 65
   }
66 66
   
67 67
   /**
68
-   * Récupération des paramètres de la recherche.
68
+   * @see SearcherInterface
69 69
    * 
70 70
    * @return array 
71 71
    */

+ 5 - 0
src/Muzich/CoreBundle/Searcher/SearcherInterface.php View File

@@ -19,6 +19,11 @@ interface SearcherInterface
19 19
    */
20 20
   public function update($params);
21 21
   
22
+  /**
23
+   * Récupération des paramètres
24
+   */
25
+  public function getParams();
26
+  
22 27
 //  /**
23 28
 //   * Procédure qui construit la requete.
24 29
 //   */

+ 70 - 0
src/Muzich/CoreBundle/Searcher/UserAndGroupSearcher.php View File

@@ -0,0 +1,70 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Searcher;
4
+
5
+use Symfony\Component\Validator\Constraints as Assert;
6
+
7
+class UserAndGroupSearcher extends Searcher implements SearcherInterface
8
+{
9
+  
10
+  /**
11
+   * Chaine de caractère représentant la recherche.
12
+   * 
13
+   * @var string
14
+   * @Assert\NotBlank()
15
+   * @Assert\Type("string")
16
+   * @Assert\MinLength(3)
17
+   */
18
+  protected $string;
19
+  
20
+  /**
21
+   * @see SearcherInterface
22
+   * @param array $params 
23
+   */
24
+  public function init($params)
25
+  {
26
+    // Control des parametres transmis.
27
+    $this->checkParams($params, array(
28
+      'string' => "Muzich\CoreBundle\Searcher\UserAndGroupSearch::init(): \$params: Un string est nécéssaire"
29
+    ));
30
+    
31
+    // Mise a jour des attributs
32
+    $this->setAttributes(array('string', 'min_lenght'), $params);
33
+  }
34
+  
35
+  /**
36
+   * @see SearcherInterface
37
+   * @param array $params 
38
+   */
39
+  public function update($params)
40
+  {
41
+    // Mise a jour des attributs
42
+    $this->setAttributes(array(
43
+      'string', 'min_length'
44
+    ), $params);
45
+  }
46
+  
47
+  /**
48
+   * @see SearcherInterface
49
+   * 
50
+   * @return array 
51
+   */
52
+  public function getParams()
53
+  {
54
+    return array(
55
+      'string' => $this->string,
56
+      'min_length' => $this->min_length
57
+    );
58
+  }
59
+  
60
+  public function getString()
61
+  {
62
+    return $this->string;
63
+  }
64
+  
65
+  public function setString($string)
66
+  {
67
+    $this->string = $string;
68
+  }
69
+  
70
+}

+ 93 - 0
src/Muzich/MynetworkBundle/Controller/MynetworkController.php View File

@@ -0,0 +1,93 @@
1
+<?php
2
+
3
+namespace Muzich\MynetworkBundle\Controller;
4
+
5
+use Muzich\CoreBundle\lib\Controller;
6
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7
+use Muzich\CoreBundle\Searcher\UserAndGroupSearcher;
8
+
9
+class MynetworkController extends Controller
10
+{
11
+  
12
+  /**
13
+   * 
14
+   * @Template()
15
+   */
16
+  public function indexAction()
17
+  {
18
+    $user = $this->getUser();
19
+    
20
+    $followeds_users = $user->getFollowedsUsers();
21
+    $followeds_groups = $user->getFollowedGroups();
22
+    $followers_users = $user->getFollowersUsers();
23
+    
24
+    return array(
25
+      'followeds_users' => $followeds_users,
26
+      'followeds_groups' => $followeds_groups,
27
+      'followers_users' => $followers_users
28
+    );
29
+  }
30
+  
31
+  /**
32
+   * Action qui affiche la page de recherche, et efectue la recherche
33
+   * d'utilisateurs et de groupes.
34
+   * 
35
+   * @Template()
36
+   */
37
+  public function searchAction()
38
+  {
39
+    $request = $this->getRequest();
40
+    $search = new UserAndGroupSearcher();
41
+    $results = array('users' => null, 'groups' => null);
42
+    
43
+    $search_form = $this->createFormBuilder($search)
44
+      ->add('string', 'text')
45
+    ->getForm();
46
+    
47
+    // Si l'utilisateur effectue la recherche
48
+    if ($request->getMethod() == 'POST')
49
+    {
50
+      $search_form->bindRequest($request);
51
+      if ($search_form->isValid())
52
+      {
53
+        $results = $this->doSearchAction($search);
54
+      }
55
+    }
56
+    
57
+    if ($this->getRequest()->isXmlHttpRequest())
58
+    {
59
+      
60
+    }
61
+    else
62
+    {
63
+      return array(
64
+        'search_form' => $search_form->createView(),
65
+        'results'     => $results,
66
+        'search_done' => $search->getString() ? true : false
67
+      );
68
+    }
69
+  }
70
+  
71
+  protected function doSearchAction($search)
72
+  {
73
+    $string = str_replace('%', '#', $search->getString());
74
+    
75
+    $users = $this->getDoctrine()
76
+      ->getRepository('MuzichCoreBundle:User')
77
+      ->findByString($string)
78
+      ->execute()
79
+    ;
80
+    
81
+    $groups = $this->getDoctrine()
82
+      ->getRepository('MuzichCoreBundle:Group')
83
+      ->findByString($string)
84
+      ->execute()
85
+    ;
86
+    
87
+    return array(
88
+      'users'  => $users,
89
+      'groups' => $groups
90
+    );
91
+  }
92
+  
93
+}

+ 29 - 0
src/Muzich/MynetworkBundle/DependencyInjection/Configuration.php View File

@@ -0,0 +1,29 @@
1
+<?php
2
+
3
+namespace Muzich\MynetworkBundle\DependencyInjection;
4
+
5
+use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
+use Symfony\Component\Config\Definition\ConfigurationInterface;
7
+
8
+/**
9
+ * This is the class that validates and merges configuration from your app/config files
10
+ *
11
+ * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
12
+ */
13
+class Configuration implements ConfigurationInterface
14
+{
15
+    /**
16
+     * {@inheritDoc}
17
+     */
18
+    public function getConfigTreeBuilder()
19
+    {
20
+        $treeBuilder = new TreeBuilder();
21
+        $rootNode = $treeBuilder->root('muzich_mynetwork');
22
+
23
+        // Here you should define the parameters that are allowed to
24
+        // configure your bundle. See the documentation linked above for
25
+        // more information on that topic.
26
+
27
+        return $treeBuilder;
28
+    }
29
+}

+ 28 - 0
src/Muzich/MynetworkBundle/DependencyInjection/MuzichMynetworkExtension.php View File

@@ -0,0 +1,28 @@
1
+<?php
2
+
3
+namespace Muzich\MynetworkBundle\DependencyInjection;
4
+
5
+use Symfony\Component\DependencyInjection\ContainerBuilder;
6
+use Symfony\Component\Config\FileLocator;
7
+use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8
+use Symfony\Component\DependencyInjection\Loader;
9
+
10
+/**
11
+ * This is the class that loads and manages your bundle configuration
12
+ *
13
+ * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
14
+ */
15
+class MuzichMynetworkExtension extends Extension
16
+{
17
+    /**
18
+     * {@inheritDoc}
19
+     */
20
+    public function load(array $configs, ContainerBuilder $container)
21
+    {
22
+        $configuration = new Configuration();
23
+        $config = $this->processConfiguration($configuration, $configs);
24
+
25
+        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26
+        $loader->load('services.yml');
27
+    }
28
+}

+ 9 - 0
src/Muzich/MynetworkBundle/MuzichMynetworkBundle.php View File

@@ -0,0 +1,9 @@
1
+<?php
2
+
3
+namespace Muzich\MynetworkBundle;
4
+
5
+use Symfony\Component\HttpKernel\Bundle\Bundle;
6
+
7
+class MuzichMynetworkBundle extends Bundle
8
+{
9
+}

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

@@ -0,0 +1,13 @@
1
+
2
+mynetwork_index:
3
+  pattern:  /my-network
4
+  defaults: { _controller: MuzichMynetworkBundle:Mynetwork:index }
5
+  
6
+mynetwork_search:
7
+  pattern:  /my-network/search
8
+  defaults: { _controller: MuzichMynetworkBundle:Mynetwork:search }
9
+  
10
+#mynetwork_search:
11
+#  pattern:  /my-network/search/do
12
+#  defaults: { _controller: MuzichMynetworkBundle:Mynetwork:search }
13
+  

+ 7 - 0
src/Muzich/MynetworkBundle/Resources/config/services.yml View File

@@ -0,0 +1,7 @@
1
+parameters:
2
+#    muzich_mynetwork.example.class: Muzich\MynetworkBundle\Example
3
+
4
+services:
5
+#    muzich_mynetwork.example:
6
+#        class: %muzich_mynetwork.example.class%
7
+#        arguments: [@service_id, "plain_value", %parameter%]

+ 0 - 0
src/Muzich/MynetworkBundle/Resources/doc/index.rst View File


+ 11 - 0
src/Muzich/MynetworkBundle/Resources/translations/messages.fr.xliff View File

@@ -0,0 +1,11 @@
1
+<?xml version="1.0"?>
2
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
3
+    <file source-language="en" datatype="plaintext" original="file.ext">
4
+        <body>
5
+            <trans-unit id="1">
6
+                <source>Symfony2 is great</source>
7
+                <target>J'aime Symfony2</target>
8
+            </trans-unit>
9
+        </body>
10
+    </file>
11
+</xliff>

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

@@ -0,0 +1,46 @@
1
+{% extends "MuzichMynetworkBundle::layout.html.twig" %}
2
+
3
+{% block title %}Mon réseau{% endblock %}
4
+
5
+{% block content %}
6
+
7
+  <p>
8
+    <a href="{{ path('mynetwork_search') }}" >
9
+      Rechercher
10
+    </a>
11
+  </p>
12
+  
13
+  {% if followeds_users %}
14
+    <b>Utilisateurs</b>
15
+    <ul>
16
+    {% for user in followeds_users %} 
17
+      <li>
18
+        {{ user.username }}
19
+      </li>
20
+    {% endfor %}
21
+    </ul>
22
+  {% endif %}
23
+  
24
+  {% if followeds_groups %}
25
+    <b>Groupes</b>
26
+    <ul>
27
+    {% for group in followeds_groups %} 
28
+      <li>
29
+        {{ group.name }}
30
+      </li>
31
+    {% endfor %}
32
+    </ul>
33
+  {% endif %}
34
+  
35
+  {% if followers_users %}
36
+    <b>Vous êtes suivis par</b>
37
+    <ul>
38
+    {% for user in followers_users %} 
39
+      <li>
40
+        {{ user.username }}
41
+      </li>
42
+    {% endfor %}
43
+    </ul>
44
+  {% endif %}
45
+
46
+{% endblock %}

+ 62 - 0
src/Muzich/MynetworkBundle/Resources/views/Mynetwork/search.html.twig View File

@@ -0,0 +1,62 @@
1
+{% extends "MuzichMynetworkBundle::layout.html.twig" %}
2
+
3
+{% block title %}Mon réseau{% endblock %}
4
+
5
+{% block content %}
6
+
7
+  <p>
8
+    <a href="{{ path('mynetwork_index') }}" >
9
+      Retour
10
+    </a>
11
+  </p>
12
+  
13
+  <b>Rechercher des utilisateurs et des groupes</b>
14
+  
15
+  <form action="{{ path('mynetwork_search') }}" method="post" {{ form_enctype(search_form) }}>
16
+    
17
+    {{ form_errors(search_form) }}
18
+
19
+    {{ form_row(search_form.string) }}
20
+
21
+    {{ form_rest(search_form) }}
22
+
23
+    <input type="submit" />
24
+  </form>
25
+  
26
+  {% if results.users|length or results.groups|length %}
27
+  
28
+    {% if results.users %}
29
+
30
+      <b>Utilisateurs</b>
31
+      
32
+      <ul>
33
+      {% for user in results.users %} 
34
+        <li>
35
+          {{ user.username }}
36
+        </li>
37
+      {% endfor %}
38
+      </ul>
39
+
40
+    {% endif %}
41
+  
42
+    {% if results.groups %}
43
+
44
+      <b>Groupes</b>
45
+      
46
+      <ul>
47
+      {% for group in results.groups %} 
48
+        <li>
49
+          {{ group.name }}
50
+        </li>
51
+      {% endfor %}
52
+      </ul>
53
+
54
+    {% endif %}
55
+  
56
+  {% elseif search_done %}
57
+      
58
+      <p>Il n'y a aucun résultat a votre recherche</p>
59
+      
60
+  {% endif %}
61
+
62
+{% endblock %}

+ 9 - 0
src/Muzich/MynetworkBundle/Resources/views/layout.html.twig View File

@@ -0,0 +1,9 @@
1
+{% extends 'MuzichCoreBundle::layout.html.twig' %}
2
+
3
+{% block css %}
4
+	<link href="{{ asset('bundles/mynetwork/css/mynetwork.css') }}" rel="stylesheet" media="screen" type="text/css" />
5
+{% endblock %}
6
+
7
+{% block main_content %}
8
+    {% block content %}{% endblock %}
9
+{% endblock %}

+ 17 - 0
src/Muzich/MynetworkBundle/Tests/Controller/DefaultControllerTest.php View File

@@ -0,0 +1,17 @@
1
+<?php
2
+
3
+namespace Muzich\MynetworkBundle\Tests\Controller;
4
+
5
+use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
+
7
+class DefaultControllerTest extends WebTestCase
8
+{
9
+    public function testIndex()
10
+    {
11
+        $client = static::createClient();
12
+
13
+        $crawler = $client->request('GET', '/hello/Fabien');
14
+
15
+        $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
16
+    }
17
+}

File diff suppressed because it is too large
+ 4 - 0
web/bundles/muzichcore/js/jquery-1.6.4.min.js


+ 7 - 0
web/bundles/mynetwork/css/mynetwork.css View File

@@ -0,0 +1,7 @@
1
+/* 
2
+    Document   : mynetwork
3
+    Created on : 27 sept. 2011, 14:41:54
4
+    Author     : bux
5
+    Description:
6
+        Purpose of the stylesheet follows.
7
+*/