Author: kingpin393
Date: 2010-01-18 15:54:12 +0100 (Mon, 18 Jan 2010)
New Revision: 26819

Added:
   
plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/templates/_user_actions.php
Modified:
   plugins/sfAdminDashPlugin/trunk/README
   plugins/sfAdminDashPlugin/trunk/lib/sfAdminDash.class.php
   
plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/lib/BasesfAdminDashComponents.class.php
   plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/templates/_header.php
   plugins/sfAdminDashPlugin/trunk/web/css/default.css
Log:
[sfAdminDashPlugin] Added ability to add user actions 

Modified: plugins/sfAdminDashPlugin/trunk/README
===================================================================
--- plugins/sfAdminDashPlugin/trunk/README      2010-01-18 14:19:22 UTC (rev 
26818)
+++ plugins/sfAdminDashPlugin/trunk/README      2010-01-18 14:54:12 UTC (rev 
26819)
@@ -233,7 +233,18 @@
     // in application/modules/sfGuardAuth/templates/signinSuccess.php
     <?php include_partial('sfAdminDash/login', array('form' => $form)); ?>
 
+###Step 7 (optional) - setting up User actions
 
+User actions can be optionally set in *app.yml*:
+
+    all:
+      sf_admin_dash:
+        user_actions:
+          "New Ticket":       { url: cms_ticket_new }
+          "My Tickets":       { url: cms_ticket }
+
+These show up as a list of links beside the logout button.  Override the 
_user_actions partial if you wish to add some kind of logic to the action 
display.
+
 ###todo
 * use an actual admin generator theme
 * clean up css

Modified: plugins/sfAdminDashPlugin/trunk/lib/sfAdminDash.class.php
===================================================================
--- plugins/sfAdminDashPlugin/trunk/lib/sfAdminDash.class.php   2010-01-18 
14:19:22 UTC (rev 26818)
+++ plugins/sfAdminDashPlugin/trunk/lib/sfAdminDash.class.php   2010-01-18 
14:54:12 UTC (rev 26819)
@@ -6,74 +6,85 @@
  * @subpackage sfAdminDash
  * @author     kevin
  * @version    SVN: $Id$
- */ 
-class sfAdminDash 
+ */
+class sfAdminDash
 {
 
   /**
-  * Check if the item is allowed to go in the menu
-  * 
-  * @param array $item
-  * 
-  * @return boolean
-  */
-       public static function itemInMenu($item)
-       {
-         return isset($item['in_menu']) ? $item['in_menu'] : true;     
-       }
-       
-  
+   * Check if the item is allowed to go in the menu
+   *
+   * @param array $item
+   *
+   * @return boolean
+   */
+  public static function itemInMenu($item)
+  {
+    return isset($item['in_menu']) ? $item['in_menu'] : true;
+  }
+
   /**
-  * Check if there is at least one item in the supplied array that is allowed 
to go in the menu
-  * 
-  * @param array $items
-  * 
-  * @return boolean
-  */
-       public static function hasItemsMenu($items)
-       {
-               foreach($items as $item)
-               {
-                       if (self::itemInMenu($item))
-                       {
-                               return true;
-                       }
-               }
-               
-               return false;
-       }
-       
-  
+   * Return the user actions from the sf_admin_dash configuration
+   *
+   * @return array
+   */
+  public static function getUserActions()
+  {
+    $actions = self::getProperty('user_actions');
+
+    return $actions;
+  }
+
   /**
-  * Return the items from the sf_admin_dash configuration
-  * 
-  * @return array
-  * 
-  * @see sfAdminDash::initItem()  All items are initialized before being 
returned through this method
-  * @see sfAdminDash::getProperty()
-  */
+   * Check if there is at least one item in the supplied array that is allowed 
to go in the menu
+   *
+   * @param array $items
+   *
+   * @return boolean
+   */
+  public static function hasItemsMenu($items)
+  {
+    foreach($items as $item)
+    {
+      if (self::itemInMenu($item))
+      {
+        return true;
+      }
+    }
+
+    return false;
+  }
+
+
+  /**
+   * Return the items from the sf_admin_dash configuration
+   *
+   * @return array
+   *
+   * @see sfAdminDash::initItem()  All items are initialized before being 
returned through this method
+   * @see sfAdminDash::getProperty()
+   */
   public static function getItems()
   {
-    $items = self::getProperty('items', array());         
+    $items = self::getProperty('items', array());
     array_walk($items, 'sfAdminDash::initItem');
-    
+
     return $items;
   }
-  
-  
+
+
   /**
-  * Return all items from the configuration, conbining the one from the plain 
items array and the categories
-  * 
-  * @return array
-  * 
-  * @see sfAdminDash::getItems()
-  * @see sfAdminDash::getCategories()
-  * @see sfAdminDash::getProperty()
-  */
+   * Return all items from the configuration, conbining the one from the plain 
items array and the categories
+   *
+   * @return array
+   *
+   * @see sfAdminDash::getItems()
+   * @see sfAdminDash::getCategories()
+   * @see sfAdminDash::getProperty()
+   */
   public static function getAllItems()
   {
     $items = self::getItems();
-    
+
     foreach (self::getCategories() as $category)
     {
       if (isset($category['items']))
@@ -81,64 +92,64 @@
         $items = array_merge($items, $category['items']);
       }
     }
-    
+
     return $items;
   }
 
-  
+
   /**
-  * Return the categories as defined in the configuration, initializing their 
items (if they have any)
-  * 
-  * @see sfAdminDash::initItem()
-  * @see sfAdminDash::getProperty()
-  */
+   * Return the categories as defined in the configuration, initializing their 
items (if they have any)
+   *
+   * @see sfAdminDash::initItem()
+   * @see sfAdminDash::getProperty()
+   */
   public static function getCategories()
-  {    
+  {
     $categories = self::getProperty('categories', array());
     foreach ($categories as $category_name => $category_data)
     {
       if (isset($category_data['items']))
-      {            
+      {
         array_walk($categories[$category_name]['items'], 
'sfAdminDash::initItem');
       }
     }
-    
+
     return $categories;
   }
 
-  
+
   /**
-  * A proxy method for sfConfig::get(), used bacause it's more readible this 
way
-  * 
-  * @param string $name The name of the config value we want
-  * @param mixed $default The default value to be returned if the config 
option is not set
-  * 
-  * @return mixed
-  */
+   * A proxy method for sfConfig::get(), used bacause it's more readible this 
way
+   *
+   * @param string $name The name of the config value we want
+   * @param mixed $default The default value to be returned if the config 
option is not set
+   *
+   * @return mixed
+   */
   public static function getProperty($name, $default = null)
   {
     return sfConfig::get('app_sf_admin_dash_'.$name, $default);
   }
 
-  
+
   /**
-  * A proxy method for sfConfig::set(), userd because it's more convenient
-  * 
-  * @param string $name The name of the config value we want to set
-  * @param mixed $value Guess what ;)
-  */
+   * A proxy method for sfConfig::set(), userd because it's more convenient
+   *
+   * @param string $name The name of the config value we want to set
+   * @param mixed $value Guess what ;)
+   */
   public static function setProperty($name, $value)
   {
     sfConfig::set('app_sf_admin_dash_'.$name, $value);
   }
-  
-  
+
+
   /**
-  * Check if the user the necessary credentials to see this particular item
-  * 
-  * @param array $item
-  * @param sfUser $user
-  */
+   * Check if the user the necessary credentials to see this particular item
+   *
+   * @param array $item
+   * @param sfUser $user
+   */
   public static function hasPermission($item, $user)
   {
     if (!$user->isAuthenticated())
@@ -148,16 +159,16 @@
 
     return isset($item['credentials']) ? 
$user->hasCredential($item['credentials']) : true;
   }
-   
-  
+
+
   /**
-  * Check if the supplied route exists
-  * 
-  * @param string $route
-  * @param sfContext $context
-  * 
-  * @return boolean
-  */
+   * Check if the supplied route exists
+   *
+   * @param string $route
+   * @param sfContext $context
+   *
+   * @return boolean
+   */
   public static function routeExists($route, sfContext $context)
   {
     try
@@ -170,75 +181,75 @@
       return false;
     }
   }
-                   
-  
+
+
   /**
-  * Get the current module name (as defined in the sfAdminDash configuration), 
if possible, with translation
-  * If no specific name was found for the module name, it is returned as is
-  * 
-  * @param sfContext $context
-  * 
-  * @return string
-  */
+   * Get the current module name (as defined in the sfAdminDash 
configuration), if possible, with translation
+   * If no specific name was found for the module name, it is returned as is
+   *
+   * @param sfContext $context
+   *
+   * @return string
+   */
   public static function getModuleName(sfContext $context)
   {
-       $modulename = $context -> getModuleName();
-       $translation = self::getProperty("translator", array());
-       
-       if (isset($translation[$modulename]))
-       {
-               if (is_array($translation[$modulename]))
-               {       
-                       return empty($translation[$modulename]["title"]) ? 
$modulename : $translation[$modulename]["title"];    
-               }
-               else
-               {
-                       return $translation[$modulename];
-               }
-       } 
+    $modulename = $context -> getModuleName();
+    $translation = self::getProperty("translator", array());
+
+    if (isset($translation[$modulename]))
+    {
+      if (is_array($translation[$modulename]))
+      {
+        return empty($translation[$modulename]["title"]) ? $modulename : 
$translation[$modulename]["title"];
+      }
+      else
+      {
+        return $translation[$modulename];
+      }
+    }
     // we should check if we can get the module name from the item 
representing it in the dash menu
     else foreach (self::getAllItems() as $key => $item)
-    {                          
-      if (($modulename == $key || $modulename == $item['url']))
-      {                                                       
-        if (isset($item['name']))
+      {
+        if (($modulename == $key || $modulename == $item['url']))
         {
-          return $item['name']; // yay, we got the name!
+          if (isset($item['name']))
+          {
+            return $item['name']; // yay, we got the name!
+          }
+          else
+          {
+            break; // we found our item, but it didn't have a special name, 
break from the search
+          }
         }
-        else
-        {
-          break; // we found our item, but it didn't have a special name, 
break from the search
-        }
       }
-    }
 
-       return $modulename;
+    return $modulename;
   }
-  
-  
+
+
   /**
-  * Get the current action name, with translatio, if possible
-  * 
-  * @param sfContext $context
-  * 
-  * @return string
-  */
+   * Get the current action name, with translatio, if possible
+   *
+   * @param sfContext $context
+   *
+   * @return string
+   */
   public static function getActionName(sfContext $context)
   {
-       $modulename = $context -> getModuleName();
-       $actionname = $context -> getActionName();
-       $translation = self::getProperty("translator", array());
-       
-       return isset($translation[$modulename]["actions"][$actionname]) ? 
$translation[$modulename]["actions"][$actionname] : $actionname;
+    $modulename = $context -> getModuleName();
+    $actionname = $context -> getActionName();
+    $translation = self::getProperty("translator", array());
+
+    return isset($translation[$modulename]["actions"][$actionname]) ? 
$translation[$modulename]["actions"][$actionname] : $actionname;
   }
-    
-  
+
+
   /**
-  * This function primes the item for use, making sure all required fields are 
set
-  * 
-  * @param array $item The item data, sent by reference
-  * @param string|integer $key  The key that points to the specific item
-  */
+   * This function primes the item for use, making sure all required fields 
are set
+   *
+   * @param array $item The item data, sent by reference
+   * @param string|integer $key  The key that points to the specific item
+   */
   public static function initItem(&$item, $key)
   {
     $image = isset($item['image']) ? $item['image'] : 
sfAdminDash::getProperty('default_image');
@@ -250,9 +261,9 @@
     $item['name'] = isset($item['name']) ? $item['name'] : $key;
 
     //if url isn't specified - use key
-    $item['url'] = isset($item['url']) ? $item['url'] : $key;    
-    
+    $item['url'] = isset($item['url']) ? $item['url'] : $key;
+
     //if in_menu isn't specified - use true
     $item['in_menu'] = isset($item['in_menu']) ? $item['in_menu'] : true;
-  }  
+  }
 }
\ No newline at end of file

Modified: 
plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/lib/BasesfAdminDashComponents.class.php
===================================================================
--- 
plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/lib/BasesfAdminDashComponents.class.php
 2010-01-18 14:19:22 UTC (rev 26818)
+++ 
plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/lib/BasesfAdminDashComponents.class.php
 2010-01-18 14:54:12 UTC (rev 26819)
@@ -15,8 +15,9 @@
   */  
   public function executeHeader()
   {
-    $this->items      = sfAdminDash::getItems();
-    $this->categories = sfAdminDash::getCategories();
+    $this->items        = sfAdminDash::getItems();
+    $this->categories   = sfAdminDash::getCategories();
+    $this->user_actions = sfAdminDash::getUserActions();
     $this->called_from_component = true; // BC check
         
     if (sfConfig::get('sf_error_404_module') == 
$this->getContext()->getModuleName() && sfConfig::get('sf_error_404_action') == 
$this->getContext()->getActionName())

Modified: 
plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/templates/_header.php
===================================================================
--- plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/templates/_header.php   
2010-01-18 14:19:22 UTC (rev 26818)
+++ plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/templates/_header.php   
2010-01-18 14:54:12 UTC (rev 26819)
@@ -31,6 +31,9 @@
     <?php if (sfAdminDash::getProperty('logout') && 
$sf_user->isAuthenticated()): ?>
       <div id="logout"><?php echo link_to(__('Logout', null, 'sf_admin_dash'), 
sfAdminDash::getProperty('logout_route', '@sf_guard_signout ')); ?> <?php echo 
$sf_user; ?></div>
     <?php endif; ?>
+    <?php if ($user_actions): ?>
+      <?php include_partial('sfAdminDash/user_actions', array('user_actions' 
=> $user_actions)) ?>
+    <?php endif; ?>
     <div class="clear"></div>
   </div>
 

Added: 
plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/templates/_user_actions.php
===================================================================
--- 
plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/templates/_user_actions.php 
                            (rev 0)
+++ 
plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/templates/_user_actions.php 
    2010-01-18 14:54:12 UTC (rev 26819)
@@ -0,0 +1,5 @@
+<ul id="sf_admin_user_actions">
+  <?php foreach ($user_actions as $key =>$action): ?>
+  <li><?php echo link_to(__($key), $action['url']) ?></li>
+  <?php endforeach; ?>
+</ul>
\ No newline at end of file

Modified: plugins/sfAdminDashPlugin/trunk/web/css/default.css
===================================================================
--- plugins/sfAdminDashPlugin/trunk/web/css/default.css 2010-01-18 14:19:22 UTC 
(rev 26818)
+++ plugins/sfAdminDashPlugin/trunk/web/css/default.css 2010-01-18 14:54:12 UTC 
(rev 26819)
@@ -13,14 +13,21 @@
   text-decoration : underline;
 }
 
-#logout
+#logout, #sf_admin_menu ul#sf_admin_user_actions
 {
+  float: right;
   font-weight: bold;
   text-align: right;
   padding-top: 7px;
   padding-right: 10px;
 }
 
+#sf_admin_user_actions li {
+  display: inline;
+  border-right: #CCC solid 1px;
+  padding: 0 8px;
+}
+
 #sf_admin_container
 {
   padding: 10px 30px;

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.


Reply via email to