Browse Source

Add KnpMenu, fix README file

Joseph Bielawski 12 years ago
parent
commit
f078ea5213

+ 1 - 1
README.md

@@ -15,7 +15,7 @@ Installation
 ------------
 
 1. Clone the repository
-2. Copy `app/config/parameters.yml.dist` to `app/config/parameters.yml` and edit the relevant values for your setup.
+2. Edit `app/config/parameters.yml` and change the relevant values for your setup.
 3. Install dependencies: `php composer.phar install`
 4. Run `app/console doctrine:schema:create` to setup the DB.
 5. Run `app/console assets:install web` to deploy the assets on the web dir.

+ 7 - 2
app/AppKernel.php

@@ -1,7 +1,10 @@
 <?php
 
-use Symfony\Component\HttpKernel\Kernel;
+use Symfony\Component\ClassLoader\DebugUniversalClassLoader;
 use Symfony\Component\Config\Loader\LoaderInterface;
+use Symfony\Component\Debug\ErrorHandler;
+use Symfony\Component\Debug\ExceptionHandler;
+use Symfony\Component\HttpKernel\Kernel;
 
 class AppKernel extends Kernel
 {
@@ -19,10 +22,12 @@ class AppKernel extends Kernel
             new FOS\UserBundle\FOSUserBundle(),
             new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
             new Snc\RedisBundle\SncRedisBundle(),
-            new Packagist\WebBundle\PackagistWebBundle(),
             new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
             new Nelmio\SolariumBundle\NelmioSolariumBundle(),
             new Nelmio\SecurityBundle\NelmioSecurityBundle(),
+            new Knp\Bundle\MenuBundle\KnpMenuBundle(),
+
+            new Packagist\WebBundle\PackagistWebBundle(),
         );
 
         if (in_array($this->getEnvironment(), array('dev', 'test'))) {

+ 2 - 0
composer.json

@@ -52,6 +52,8 @@
 
         "kriswallsmith/assetic": "~1.2@alpha",
         "pagerfanta/pagerfanta": "~1.0"
+        "knplabs/knp-menu-bundle": "*@dev",
+        "knplabs/knp-menu": "*@dev"
     },
     "scripts": {
         "post-install-cmd": [

+ 49 - 0
src/Packagist/WebBundle/Menu/MenuBuilder.php

@@ -0,0 +1,49 @@
+<?php
+
+namespace Packagist\WebBundle\Menu;
+
+use Knp\Menu\FactoryInterface;
+use Symfony\Component\HttpFoundation\Request;
+
+class MenuBuilder
+{
+    private $factory;
+
+    /**
+     * @param FactoryInterface $factory
+     */
+    public function __construct(FactoryInterface $factory)
+    {
+        $this->factory = $factory;
+    }
+
+    public function createUserMenu()
+    {
+        $menu = $this->factory->createItem('root');
+        $menu->setChildrenAttribute('class', 'nav-user-menu');
+
+        $menu->addChild('Profile', array('label' => '<span class="icon-vcard"></span>Profile', 'route' => 'fos_user_profile_show', 'extras' => array('safe_label' => true)));
+        $menu->addChild('Settings', array('label' => '<span class="icon-tools"></span>Settings', 'route' => 'fos_user_profile_edit', 'extras' => array('safe_label' => true)));
+        $menu->addChild('Change password', array('label' => '<span class="icon-key"></span>Change password', 'route' => 'fos_user_change_password', 'extras' => array('safe_label' => true)));
+        $menu->addChild('My packages', array('label' => '<span class="icon-box"></span>My packages', 'route' => 'user_packages', 'routeParameters' => array('name' => 'stloyd'), 'extras' => array('safe_label' => true)));
+        $menu->addChild('My favorites', array('label' => '<span class="icon-leaf"></span>My favorites', 'route' => 'user_favorites', 'routeParameters' => array('name' => 'stloyd'), 'extras' => array('safe_label' => true)));
+        $menu->addChild('hr', array('label' => '<hr>', 'labelAttributes' => array('class' => 'normal'), 'extras' => array('safe_label' => true)));
+        $menu->addChild('Logout', array('label' => '<span class="icon-off"></span>Logout', 'route' => 'logout', 'extras' => array('safe_label' => true)));
+
+        return $menu;
+    }
+
+    public function createProfileMenu()
+    {
+        $menu = $this->factory->createItem('root');
+        $menu->setChildrenAttribute('class', 'nav nav-tabs nav-stacked');
+
+        $menu->addChild('Profile', array('label' => '<span class="icon-vcard"></span>Profile', 'route' => 'fos_user_profile_show', 'extras' => array('safe_label' => true)));
+        $menu->addChild('Edit your information', array('label' => '<span class="icon-tools"></span>Edit your information', 'route' => 'fos_user_profile_edit', 'extras' => array('safe_label' => true)));
+        $menu->addChild('Change password', array('label' => '<span class="icon-key"></span>Change password', 'route' => 'fos_user_change_password', 'extras' => array('safe_label' => true)));
+        $menu->addChild('View your packages', array('label' => '<span class="icon-box"></span>View your packages', 'route' => 'user_packages', 'routeParameters' => array('name' => 'stloyd'), 'extras' => array('safe_label' => true)));
+        $menu->addChild('View your favorites', array('label' => '<span class="icon-leaf"></span>View your favorites', 'route' => 'user_favorites', 'routeParameters' => array('name' => 'stloyd'), 'extras' => array('safe_label' => true)));
+
+        return $menu;
+    }
+}

+ 22 - 0
src/Packagist/WebBundle/Resources/config/services.yml

@@ -86,3 +86,25 @@ services:
         arguments: [%fos_user.model.user.class%]
         tags:
             - { name: form.type, alias: packagist_user_profile }
+
+    packagist.menu_builder:
+        class: Packagist\WebBundle\Menu\MenuBuilder
+        arguments: ["@knp_menu.factory"]
+
+    packagist.menu.user:
+        class: Knp\Menu\MenuItem
+        factory_service: packagist.menu_builder
+        factory_method: createUserMenu
+        arguments: ["@request"]
+        scope: request
+        tags:
+            - { name: knp_menu.menu, alias: user_menu }
+
+    packagist.menu.profile:
+        class: Knp\Menu\MenuItem
+        factory_service: packagist.menu_builder
+        factory_method: createProfileMenu
+        arguments: ["@request"]
+        scope: request
+        tags:
+            - { name: knp_menu.menu, alias: profile_menu }