Completed
Push — 16.1 ( b1f46d...895f95 )
by Nathan
36:53 queued 22:15
created
api/src/Framework/Favorites.php 1 patch
Spacing   +22 added lines, -23 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @return array with a single sidebox menu item (array) containing html for favorites
44 44
 	 */
45
-	public static function list_favorites($app, $default=null)
45
+	public static function list_favorites($app, $default = null)
46 46
 	{
47 47
 		if (!$app)
48 48
 		{
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 		$target = 'favorite_sidebox_'.$app;
59 59
 
60 60
 		/* @var $filters array an array of favorites*/
61
-		$filters =  self::get_favorites($app);
61
+		$filters = self::get_favorites($app);
62 62
 		$is_admin = $GLOBALS['egw_info']['user']['apps']['admin'];
63 63
 		$html = "<span id='$target' class='ui-helper-clearfix sidebox-favorites'><ul class='ui-menu ui-widget-content ui-corner-all favorites' role='listbox'>\n";
64 64
 
@@ -69,25 +69,24 @@  discard block
 block discarded – undo
69 69
 		}
70 70
 
71 71
 		// Get link for if there is no nextmatch - this is the fallback
72
-		$registry = Api\Link::get_registry($app,'list');
72
+		$registry = Api\Link::get_registry($app, 'list');
73 73
 		if (!$registry)
74 74
 		{
75 75
 			$registry = Api\Link::get_registry($app, 'index');
76 76
 		}
77
-		foreach($filters as $name => $filter)
77
+		foreach ($filters as $name => $filter)
78 78
 		{
79 79
 			//filter must not be empty if there's one, ignore it at the moment but it need to be checked how it got there in database
80 80
 			if (!$filter)
81 81
 			{
82
-				error_log(__METHOD__.'Favorite filter "'.$name.'" is not supposed to be empty, it should be an array.  Skipping, more investigation needed. filter = '. array2string($filters[$name]));
82
+				error_log(__METHOD__.'Favorite filter "'.$name.'" is not supposed to be empty, it should be an array.  Skipping, more investigation needed. filter = '.array2string($filters[$name]));
83 83
 				continue;
84 84
 			}
85 85
 			$li = "<li data-id='$name' data-group='{$filter['group']}' class='ui-menu-item' role='menuitem'>\n";
86 86
 			$li .= '<a href="#" class="ui-corner-all" tabindex="-1">';
87
-			$li .= "<div class='" . ((string)$name === (string)$default_filter ? 'ui-icon ui-icon-heart' : 'sideboxstar') . "'></div>".
87
+			$li .= "<div class='".((string)$name === (string)$default_filter ? 'ui-icon ui-icon-heart' : 'sideboxstar')."'></div>".
88 88
 				$filter['name'];
89
-			$li .= ($filter['group'] != false && !$is_admin || $name === 'blank' ? "" :
90
-				"<div class='ui-icon ui-icon-trash' title='" . lang('Delete') . "'></div>");
89
+			$li .= ($filter['group'] != false && !$is_admin || $name === 'blank' ? "" : "<div class='ui-icon ui-icon-trash' title='".lang('Delete')."'></div>");
91 90
 			$li .= "</a></li>\n";
92 91
 			//error_log(__METHOD__."() $name, filter=".array2string($filter)." --> ".$li);
93 92
 			$html .= $li;
@@ -95,7 +94,7 @@  discard block
 block discarded – undo
95 94
 
96 95
 		// If were're here, the app supports favorites, so add a 'Add' link too
97 96
 		$html .= "<li data-id='add' class='ui-menu-item' role='menuitem'><a href='javascript:app.$app.add_favorite()' class='ui-corner-all'>";
98
-		$html .= Api\Html::image($app, 'new') . lang('Add current'). '</a></li>';
97
+		$html .= Api\Html::image($app, 'new').lang('Add current').'</a></li>';
99 98
 
100 99
 		$html .= '</ul></span>';
101 100
 
@@ -117,7 +116,7 @@  discard block
 block discarded – undo
117 116
 	 * @return (array|boolean) An array of sorted favorites or False if there's no preferenced sorted list
118 117
 	 *
119 118
 	 */
120
-	public static function get_fav_sort_pref ($app)
119
+	public static function get_fav_sort_pref($app)
121 120
 	{
122 121
 		$fav_sorted_list = array();
123 122
 
@@ -157,13 +156,13 @@  discard block
 block discarded – undo
157 156
 		$fav_sort_pref = self::get_fav_sort_pref($app);
158 157
 
159 158
 		// Look through all preferences & pull out favorites
160
-		foreach((array)$GLOBALS['egw_info']['user']['preferences'][$app] as $pref_name => $pref)
159
+		foreach ((array)$GLOBALS['egw_info']['user']['preferences'][$app] as $pref_name => $pref)
161 160
 		{
162
-			if(strpos($pref_name, $pref_prefix) === 0)
161
+			if (strpos($pref_name, $pref_prefix) === 0)
163 162
 			{
164
-				if(!is_array($pref)) continue;	// old favorite
163
+				if (!is_array($pref)) continue; // old favorite
165 164
 
166
-				$favorites[(string)substr($pref_name,strlen($pref_prefix))] = $pref;
165
+				$favorites[(string)substr($pref_name, strlen($pref_prefix))] = $pref;
167 166
 			}
168 167
 		}
169 168
 		if (is_array($fav_sort_pref))
@@ -172,7 +171,7 @@  discard block
 block discarded – undo
172 171
 			{
173 172
 				$sorted_list[$key] = $favorites[$key];
174 173
 			}
175
-			$favorites = array_merge($sorted_list,$favorites);
174
+			$favorites = array_merge($sorted_list, $favorites);
176 175
 		}
177 176
 		return $favorites;
178 177
 	}
@@ -204,7 +203,7 @@  discard block
 block discarded – undo
204 203
 			}
205 204
 			else
206 205
 			{
207
-				foreach($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $gid)
206
+				foreach ($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $gid)
208 207
 				{
209 208
 					$prefs = new Api\Preferences($gid);
210 209
 					$prefs->read_repository();
@@ -216,7 +215,7 @@  discard block
 block discarded – undo
216 215
 				}
217 216
 			}
218 217
 		}
219
-		if($group && $GLOBALS['egw_info']['apps']['admin'] && $group !== 'all')
218
+		if ($group && $GLOBALS['egw_info']['apps']['admin'] && $group !== 'all')
220 219
 		{
221 220
 			$prefs = new Api\Preferences(is_numeric($group) ? $group : $GLOBALS['egw_info']['user']['account_id']);
222 221
 		}
@@ -227,7 +226,7 @@  discard block
 block discarded – undo
227 226
 		$prefs->read_repository();
228 227
 		$type = $group === "all" ? "default" : "user";
229 228
 		//error_log(__METHOD__."('$app', '$name', '$action', ".array2string($group).", ...) pref_name=$pref_name, type=$type");
230
-		if($action == "add")
229
+		if ($action == "add")
231 230
 		{
232 231
 			$filters = array(
233 232
 				// This is the name as user entered it, minus tags
@@ -235,9 +234,9 @@  discard block
 block discarded – undo
235 234
 				'group' => $group ? $group : false,
236 235
 				'state' => $filters
237 236
 			);
238
-			$pref_name = "favorite_".preg_replace('/[^A-Za-z0-9-_]/u','_',$name);
239
-			$result = $prefs->add($app,$pref_name,$filters,$type);
240
-			$pref = $prefs->save_repository(false,$type);
237
+			$pref_name = "favorite_".preg_replace('/[^A-Za-z0-9-_]/u', '_', $name);
238
+			$result = $prefs->add($app, $pref_name, $filters, $type);
239
+			$pref = $prefs->save_repository(false, $type);
241 240
 
242 241
 			// Update preferences client side, or it could disappear
243 242
 			Api\Json\Response::get()->call('egw.set_preferences', (array)$pref[$app], $app);
@@ -247,8 +246,8 @@  discard block
 block discarded – undo
247 246
 		}
248 247
 		else if ($action == "delete")
249 248
 		{
250
-			$result = $prefs->delete($app,$pref_name, $type);
251
-			$pref = $prefs->save_repository(false,$type);
249
+			$result = $prefs->delete($app, $pref_name, $type);
250
+			$pref = $prefs->save_repository(false, $type);
252 251
 
253 252
 			// Update preferences client side, or it could come back
254 253
 			Api\Json\Response::get()->call('egw.set_preferences', (array)$pref[$app], $app);
Please login to merge, or discard this patch.