Development

Changeset 26819 for plugins/sfAdminDashPlugin

You must first sign up to be able to contribute.

Show
Ignore:
Timestamp:
01/18/10 15:54:12 (3 years ago)
Author:
kingpin393
Message:

[sfAdminDashPlugin] Added ability to add user actions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfAdminDashPlugin/trunk/README

    r25695 r26819  
    234234    <?php include_partial('sfAdminDash/login', array('form' => $form)); ?> 
    235235 
     236###Step 7 (optional) - setting up User actions 
     237 
     238User actions can be optionally set in *app.yml*: 
     239 
     240    all: 
     241      sf_admin_dash: 
     242        user_actions: 
     243          "New Ticket":       { url: cms_ticket_new } 
     244          "My Tickets":       { url: cms_ticket } 
     245 
     246These 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. 
    236247 
    237248###todo 
  • plugins/sfAdminDashPlugin/trunk/lib/sfAdminDash.class.php

    r25249 r26819  
    77 * @author     kevin 
    88 * @version    SVN: $Id$ 
    9  */  
    10 class sfAdminDash  
     9 */ 
     10class sfAdminDash 
    1111{ 
    1212 
    1313  /** 
    14   * Check if the item is allowed to go in the menu 
    15   *  
    16   * @param array $item 
    17   *  
    18   * @return boolean 
    19   */ 
    20   public static function itemInMenu($item) 
    21   { 
    22     return isset($item['in_menu']) ? $item['in_menu'] : true;  
    23   } 
    24    
    25    
    26   /** 
    27   * Check if there is at least one item in the supplied array that is allowed to go in the menu 
    28   *  
    29   * @param array $items 
    30   *  
    31   * @return boolean 
    32   */ 
    33   public static function hasItemsMenu($items) 
    34   { 
    35     foreach($items as $item) 
    36     { 
    37       if (self::itemInMenu($item)) 
    38       { 
    39         return true; 
    40       } 
    41     } 
    42      
    43     return false; 
    44   } 
    45    
    46    
    47   /** 
    48   * Return the items from the sf_admin_dash configuration 
    49   *  
    50   * @return array 
    51   *  
    52   * @see sfAdminDash::initItem()  All items are initialized before being returned through this method 
    53   * @see sfAdminDash::getProperty() 
    54   */ 
     14   * Check if the item is allowed to go in the menu 
     15   * 
     16   * @param array $item 
     17   * 
     18   * @return boolean 
     19   */ 
     20  public static function itemInMenu($item) 
     21  { 
     22    return isset($item['in_menu']) ? $item['in_menu'] : true; 
     23  } 
     24 
     25  /** 
     26   * Return the user actions from the sf_admin_dash configuration 
     27   * 
     28   * @return array 
     29   */ 
     30  public static function getUserActions() 
     31  { 
     32    $actions = self::getProperty('user_actions'); 
     33 
     34    return $actions; 
     35  } 
     36 
     37  /** 
     38   * Check if there is at least one item in the supplied array that is allowed to go in the menu 
     39   * 
     40   * @param array $items 
     41   * 
     42   * @return boolean 
     43   */ 
     44  public static function hasItemsMenu($items) 
     45  { 
     46    foreach($items as $item) 
     47    { 
     48      if (self::itemInMenu($item)) 
     49      { 
     50        return true; 
     51      } 
     52    } 
     53 
     54    return false; 
     55  } 
     56 
     57 
     58  /** 
     59   * Return the items from the sf_admin_dash configuration 
     60   * 
     61   * @return array 
     62   * 
     63   * @see sfAdminDash::initItem()  All items are initialized before being returned through this method 
     64   * @see sfAdminDash::getProperty() 
     65   */ 
    5566  public static function getItems() 
    5667  { 
    57     $items = self::getProperty('items', array());          
     68    $items = self::getProperty('items', array()); 
    5869    array_walk($items, 'sfAdminDash::initItem'); 
    59      
     70 
    6071    return $items; 
    6172  } 
    62    
    63    
    64   /** 
    65   * Return all items from the configuration, conbining the one from the plain items array and the categories 
    66   *  
    67   * @return array 
    68   *  
    69   * @see sfAdminDash::getItems() 
    70   * @see sfAdminDash::getCategories() 
    71   * @see sfAdminDash::getProperty() 
    72   */ 
     73 
     74 
     75  /** 
     76  * Return all items from the configuration, conbining the one from the plain items array and the categories 
     77  * 
     78  * @return array 
     79  * 
     80  * @see sfAdminDash::getItems() 
     81  * @see sfAdminDash::getCategories() 
     82  * @see sfAdminDash::getProperty() 
     83  */ 
    7384  public static function getAllItems() 
    7485  { 
    7586    $items = self::getItems(); 
    76      
     87 
    7788    foreach (self::getCategories() as $category) 
    7889    { 
     
    8293      } 
    8394    } 
    84      
     95 
    8596    return $items; 
    8697  } 
    8798 
    88    
    89   /** 
    90   * Return the categories as defined in the configuration, initializing their items (if they have any) 
    91   *  
    92   * @see sfAdminDash::initItem() 
    93   * @see sfAdminDash::getProperty() 
    94   */ 
     99 
     100  /** 
     101  * Return the categories as defined in the configuration, initializing their items (if they have any) 
     102  * 
     103  * @see sfAdminDash::initItem() 
     104  * @see sfAdminDash::getProperty() 
     105  */ 
    95106  public static function getCategories() 
    96   {     
     107  { 
    97108    $categories = self::getProperty('categories', array()); 
    98109    foreach ($categories as $category_name => $category_data) 
    99110    { 
    100111      if (isset($category_data['items'])) 
    101       {             
     112      { 
    102113        array_walk($categories[$category_name]['items'], 'sfAdminDash::initItem'); 
    103114      } 
    104115    } 
    105      
     116 
    106117    return $categories; 
    107118  } 
    108119 
    109    
    110   /** 
    111   * A proxy method for sfConfig::get(), used bacause it's more readible this way 
    112   *  
    113   * @param string $name The name of the config value we want 
    114   * @param mixed $default The default value to be returned if the config option is not set 
    115   *  
    116   * @return mixed 
    117   */ 
     120 
     121  /** 
     122  * A proxy method for sfConfig::get(), used bacause it's more readible this way 
     123  * 
     124  * @param string $name The name of the config value we want 
     125  * @param mixed $default The default value to be returned if the config option is not set 
     126  * 
     127  * @return mixed 
     128  */ 
    118129  public static function getProperty($name, $default = null) 
    119130  { 
     
    121132  } 
    122133 
    123    
    124   /** 
    125   * A proxy method for sfConfig::set(), userd because it's more convenient 
    126   *  
    127   * @param string $name The name of the config value we want to set 
    128   * @param mixed $value Guess what ;) 
    129   */ 
     134 
     135  /** 
     136  * A proxy method for sfConfig::set(), userd because it's more convenient 
     137  * 
     138  * @param string $name The name of the config value we want to set 
     139  * @param mixed $value Guess what ;) 
     140  */ 
    130141  public static function setProperty($name, $value) 
    131142  { 
    132143    sfConfig::set('app_sf_admin_dash_'.$name, $value); 
    133144  } 
    134    
    135    
    136   /** 
    137   * Check if the user the necessary credentials to see this particular item 
    138   *  
    139   * @param array $item 
    140   * @param sfUser $user 
    141   */ 
     145 
     146 
     147  /** 
     148  * Check if the user the necessary credentials to see this particular item 
     149  * 
     150  * @param array $item 
     151  * @param sfUser $user 
     152  */ 
    142153  public static function hasPermission($item, $user) 
    143154  { 
     
    149160    return isset($item['credentials']) ? $user->hasCredential($item['credentials']) : true; 
    150161  } 
    151     
    152    
    153   /** 
    154   * Check if the supplied route exists 
    155   *  
    156   * @param string $route 
    157   * @param sfContext $context 
    158   *  
    159   * @return boolean 
    160   */ 
     162 
     163 
     164  /** 
     165  * Check if the supplied route exists 
     166  * 
     167  * @param string $route 
     168  * @param sfContext $context 
     169  * 
     170  * @return boolean 
     171  */ 
    161172  public static function routeExists($route, sfContext $context) 
    162173  { 
     
    171182    } 
    172183  } 
    173                     
    174    
    175   /** 
    176   * Get the current module name (as defined in the sfAdminDash configuration), if possible, with translation 
    177   * If no specific name was found for the module name, it is returned as is 
    178   *  
    179   * @param sfContext $context 
    180   *  
    181   * @return string 
    182   */ 
     184 
     185 
     186  /** 
     187  * Get the current module name (as defined in the sfAdminDash configuration), if possible, with translation 
     188  * If no specific name was found for the module name, it is returned as is 
     189  * 
     190  * @param sfContext $context 
     191  * 
     192  * @return string 
     193  */ 
    183194  public static function getModuleName(sfContext $context) 
    184195  { 
    185   $modulename = $context -> getModuleName(); 
    186   $translation = self::getProperty("translator", array()); 
    187      
    188   if (isset($translation[$modulename])) 
    189  
    190      if (is_array($translation[$modulename])) 
    191      {  
    192        return empty($translation[$modulename]["title"]) ? $modulename : $translation[$modulename]["title"];   
    193      
    194      else 
    195      
    196        return $translation[$modulename]; 
    197      
    198   }  
     196    $modulename = $context -> getModuleName(); 
     197    $translation = self::getProperty("translator", array()); 
     198 
     199    if (isset($translation[$modulename])) 
     200   
     201      if (is_array($translation[$modulename])) 
     202      { 
     203        return empty($translation[$modulename]["title"]) ? $modulename : $translation[$modulename]["title"]; 
     204     
     205      else 
     206     
     207        return $translation[$modulename]; 
     208     
     209    } 
    199210    // we should check if we can get the module name from the item representing it in the dash menu 
    200211    else foreach (self::getAllItems() as $key => $item) 
    201     {                           
    202       if (($modulename == $key || $modulename == $item['url'])) 
    203       {                                                        
    204         if (isset($item['name'])) 
     212      { 
     213        if (($modulename == $key || $modulename == $item['url'])) 
    205214        { 
    206           return $item['name']; // yay, we got the name! 
     215          if (isset($item['name'])) 
     216          { 
     217            return $item['name']; // yay, we got the name! 
     218          } 
     219          else 
     220          { 
     221            break; // we found our item, but it didn't have a special name, break from the search 
     222          } 
    207223        } 
    208         else 
    209         { 
    210           break; // we found our item, but it didn't have a special name, break from the search 
    211         } 
    212       } 
    213     } 
    214  
    215     return $modulename; 
    216   } 
    217    
    218    
    219   /** 
    220   * Get the current action name, with translatio, if possible 
    221   *  
    222   * @param sfContext $context 
    223   *  
    224   * @return string 
    225   */ 
     224      } 
     225 
     226    return $modulename; 
     227  } 
     228 
     229 
     230  /** 
     231   * Get the current action name, with translatio, if possible 
     232   * 
     233   * @param sfContext $context 
     234   * 
     235   * @return string 
     236   */ 
    226237  public static function getActionName(sfContext $context) 
    227238  { 
    228   $modulename = $context -> getModuleName(); 
    229   $actionname = $context -> getActionName(); 
    230   $translation = self::getProperty("translator", array()); 
    231      
    232   return isset($translation[$modulename]["actions"][$actionname]) ? $translation[$modulename]["actions"][$actionname] : $actionname; 
    233   } 
    234      
    235    
    236   /** 
    237   * This function primes the item for use, making sure all required fields are set 
    238   *  
    239   * @param array $item The item data, sent by reference 
    240   * @param string|integer $key  The key that points to the specific item 
    241   */ 
     239    $modulename = $context -> getModuleName(); 
     240    $actionname = $context -> getActionName(); 
     241    $translation = self::getProperty("translator", array()); 
     242 
     243    return isset($translation[$modulename]["actions"][$actionname]) ? $translation[$modulename]["actions"][$actionname] : $actionname; 
     244  } 
     245 
     246 
     247  /** 
     248  * This function primes the item for use, making sure all required fields are set 
     249  * 
     250  * @param array $item The item data, sent by reference 
     251  * @param string|integer $key  The key that points to the specific item 
     252  */ 
    242253  public static function initItem(&$item, $key) 
    243254  { 
     
    251262 
    252263    //if url isn't specified - use key 
    253     $item['url'] = isset($item['url']) ? $item['url'] : $key;     
    254      
     264    $item['url'] = isset($item['url']) ? $item['url'] : $key; 
     265 
    255266    //if in_menu isn't specified - use true 
    256267    $item['in_menu'] = isset($item['in_menu']) ? $item['in_menu'] : true; 
    257   }   
     268  } 
    258269} 
  • plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/lib/BasesfAdminDashComponents.class.php

    r25335 r26819  
    1616  public function executeHeader() 
    1717  { 
    18     $this->items      = sfAdminDash::getItems(); 
    19     $this->categories = sfAdminDash::getCategories(); 
     18    $this->items        = sfAdminDash::getItems(); 
     19    $this->categories   = sfAdminDash::getCategories(); 
     20    $this->user_actions = sfAdminDash::getUserActions(); 
    2021    $this->called_from_component = true; // BC check 
    2122         
  • plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/templates/_header.php

    r25331 r26819  
    3232      <div id="logout"><?php echo link_to(__('Logout', null, 'sf_admin_dash'), sfAdminDash::getProperty('logout_route', '@sf_guard_signout ')); ?> <?php echo $sf_user; ?></div> 
    3333    <?php endif; ?> 
     34    <?php if ($user_actions): ?> 
     35      <?php include_partial('sfAdminDash/user_actions', array('user_actions' => $user_actions)) ?> 
     36    <?php endif; ?> 
    3437    <div class="clear"></div> 
    3538  </div> 
  • plugins/sfAdminDashPlugin/trunk/web/css/default.css

    r26685 r26819  
    1414} 
    1515 
    16 #logout 
    17 
     16#logout, #sf_admin_menu ul#sf_admin_user_actions 
     17
     18  float: right; 
    1819  font-weight: bold; 
    1920  text-align: right; 
    2021  padding-top: 7px; 
    2122  padding-right: 10px; 
     23} 
     24 
     25#sf_admin_user_actions li { 
     26  display: inline; 
     27  border-right: #CCC solid 1px; 
     28  padding: 0 8px; 
    2229} 
    2330