Changeset 26819 for plugins/sfAdminDashPlugin
- Timestamp:
- 01/18/10 15:54:12 (3 years ago)
- Files:
-
- plugins/sfAdminDashPlugin/trunk/README (modified) (1 diff)
- plugins/sfAdminDashPlugin/trunk/lib/sfAdminDash.class.php (modified) (6 diffs)
- plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/lib/BasesfAdminDashComponents.class.php (modified) (1 diff)
- plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/templates/_header.php (modified) (1 diff)
- plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/templates/_user_actions.php (added)
- plugins/sfAdminDashPlugin/trunk/web/css/default.css (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfAdminDashPlugin/trunk/README
r25695 r26819 234 234 <?php include_partial('sfAdminDash/login', array('form' => $form)); ?> 235 235 236 ###Step 7 (optional) - setting up User actions 237 238 User 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 246 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. 236 247 237 248 ###todo plugins/sfAdminDashPlugin/trunk/lib/sfAdminDash.class.php
r25249 r26819 7 7 * @author kevin 8 8 * @version SVN: $Id$ 9 */ 10 class sfAdminDash 9 */ 10 class sfAdminDash 11 11 { 12 12 13 13 /** 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 */ 55 66 public static function getItems() 56 67 { 57 $items = self::getProperty('items', array()); 68 $items = self::getProperty('items', array()); 58 69 array_walk($items, 'sfAdminDash::initItem'); 59 70 60 71 return $items; 61 72 } 62 63 64 /** 65 * Return all items from the configuration, conbining the one from the plain items array and the categories66 *67 * @return array68 *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 */ 73 84 public static function getAllItems() 74 85 { 75 86 $items = self::getItems(); 76 87 77 88 foreach (self::getCategories() as $category) 78 89 { … … 82 93 } 83 94 } 84 95 85 96 return $items; 86 97 } 87 98 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 */ 95 106 public static function getCategories() 96 { 107 { 97 108 $categories = self::getProperty('categories', array()); 98 109 foreach ($categories as $category_name => $category_data) 99 110 { 100 111 if (isset($category_data['items'])) 101 { 112 { 102 113 array_walk($categories[$category_name]['items'], 'sfAdminDash::initItem'); 103 114 } 104 115 } 105 116 106 117 return $categories; 107 118 } 108 119 109 110 /** 111 * A proxy method for sfConfig::get(), used bacause it's more readible this way112 *113 * @param string $name The name of the config value we want114 * @param mixed $default The default value to be returned if the config option is not set115 *116 * @return mixed117 */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 */ 118 129 public static function getProperty($name, $default = null) 119 130 { … … 121 132 } 122 133 123 124 /** 125 * A proxy method for sfConfig::set(), userd because it's more convenient126 *127 * @param string $name The name of the config value we want to set128 * @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 */ 130 141 public static function setProperty($name, $value) 131 142 { 132 143 sfConfig::set('app_sf_admin_dash_'.$name, $value); 133 144 } 134 135 136 /** 137 * Check if the user the necessary credentials to see this particular item138 *139 * @param array $item140 * @param sfUser $user141 */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 */ 142 153 public static function hasPermission($item, $user) 143 154 { … … 149 160 return isset($item['credentials']) ? $user->hasCredential($item['credentials']) : true; 150 161 } 151 152 153 /** 154 * Check if the supplied route exists155 *156 * @param string $route157 * @param sfContext $context158 *159 * @return boolean160 */162 163 164 /** 165 * Check if the supplied route exists 166 * 167 * @param string $route 168 * @param sfContext $context 169 * 170 * @return boolean 171 */ 161 172 public static function routeExists($route, sfContext $context) 162 173 { … … 171 182 } 172 183 } 173 174 175 /** 176 * Get the current module name (as defined in the sfAdminDash configuration), if possible, with translation177 * If no specific name was found for the module name, it is returned as is178 *179 * @param sfContext $context180 *181 * @return string182 */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 */ 183 194 public static function getModuleName(sfContext $context) 184 195 { 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 else195 {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 } 199 210 // we should check if we can get the module name from the item representing it in the dash menu 200 211 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'])) 205 214 { 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 } 207 223 } 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 */ 226 237 public static function getActionName(sfContext $context) 227 238 { 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 set238 *239 * @param array $item The item data, sent by reference240 * @param string|integer $key The key that points to the specific item241 */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 */ 242 253 public static function initItem(&$item, $key) 243 254 { … … 251 262 252 263 //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 255 266 //if in_menu isn't specified - use true 256 267 $item['in_menu'] = isset($item['in_menu']) ? $item['in_menu'] : true; 257 } 268 } 258 269 } plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/lib/BasesfAdminDashComponents.class.php
r25335 r26819 16 16 public function executeHeader() 17 17 { 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(); 20 21 $this->called_from_component = true; // BC check 21 22 plugins/sfAdminDashPlugin/trunk/modules/sfAdminDash/templates/_header.php
r25331 r26819 32 32 <div id="logout"><?php echo link_to(__('Logout', null, 'sf_admin_dash'), sfAdminDash::getProperty('logout_route', '@sf_guard_signout ')); ?> <?php echo $sf_user; ?></div> 33 33 <?php endif; ?> 34 <?php if ($user_actions): ?> 35 <?php include_partial('sfAdminDash/user_actions', array('user_actions' => $user_actions)) ?> 36 <?php endif; ?> 34 37 <div class="clear"></div> 35 38 </div> plugins/sfAdminDashPlugin/trunk/web/css/default.css
r26685 r26819 14 14 } 15 15 16 #logout 17 { 16 #logout, #sf_admin_menu ul#sf_admin_user_actions 17 { 18 float: right; 18 19 font-weight: bold; 19 20 text-align: right; 20 21 padding-top: 7px; 21 22 padding-right: 10px; 23 } 24 25 #sf_admin_user_actions li { 26 display: inline; 27 border-right: #CCC solid 1px; 28 padding: 0 8px; 22 29 } 23 30