Completed
Push — 14.2 ( 5d5d3f...19b4ef )
by Nathan
74:47 queued 45:33
created
importexport/inc/class.importexport_export_csv.inc.php 1 patch
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -94,22 +94,22 @@  discard block
 block discarded – undo
94 94
 	 * @param array _options options for specific backends
95 95
 	 * @return bool
96 96
 	 */
97
-	public function __construct( $_stream, array $_options ) {
97
+	public function __construct($_stream, array $_options) {
98 98
 		if (!is_object($GLOBALS['egw']->translation)) {
99 99
 			$GLOBALS['egw']->translation = new translation();
100 100
 		}
101 101
 		$this->translation = &$GLOBALS['egw']->translation;
102 102
 		$this->handle = $_stream;
103
-		if($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
103
+		if ($_options['charset'] == 'user') $_options['charset'] = $GLOBALS['egw_info']['user']['preferences']['common']['csv_charset'];
104 104
 		$this->csv_charset = $_options['charset'] ? $_options['charset'] : 'utf-8';
105
-		if ( !empty( $_options ) ) {
106
-			$this->csv_options = array_merge( $this->csv_options, $_options );
105
+		if (!empty($_options)) {
106
+			$this->csv_options = array_merge($this->csv_options, $_options);
107 107
 		}
108 108
 		//error_log(__METHOD__.__LINE__.array2string($_options['appname']));
109
-		if(!bo_merge::is_export_limit_excepted()) {
109
+		if (!bo_merge::is_export_limit_excepted()) {
110 110
 			$this->export_limit = bo_merge::getExportLimit($_options['appname']);
111 111
 			//error_log(__METHOD__.__LINE__.' app:'.$_options['appname'].' limit:'.$this->export_limit);
112
-			if($this->export_limit == 'no') throw new egw_exception_no_permission_admin('Export disabled');
112
+			if ($this->export_limit == 'no') throw new egw_exception_no_permission_admin('Export disabled');
113 113
 		}
114 114
 	}
115 115
 	
@@ -118,15 +118,15 @@  discard block
 block discarded – undo
118 118
 	 *
119 119
 	 * @param array $_mapping egw_field_name => csv_field_name
120 120
 	 */
121
-	public function set_mapping( array &$_mapping) {
121
+	public function set_mapping(array &$_mapping) {
122 122
 		if ($this->num_of_records > 0) {
123 123
 			throw new Exception('Error: Field mapping can\'t be set during ongoing export!');
124 124
 		}
125
-		if($_mapping['all_custom_fields']) {
125
+		if ($_mapping['all_custom_fields']) {
126 126
 			// Field value is the appname, so we can pull the fields
127 127
 			$custom = config::get_customfields($_mapping['all_custom_fields']);
128 128
 			unset($_mapping['all_custom_fields']);
129
-			foreach($custom as $field => $info) {
129
+			foreach ($custom as $field => $info) {
130 130
 				$_mapping['#'.$field] = $this->csv_options['begin_with_fieldnames'] == 'label' ? $info['label'] : $field;
131 131
 			}
132 132
 		}
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @param array $_conversion
141 141
 	 */
142
-	public function set_conversion( array $_conversion) {
142
+	public function set_conversion(array $_conversion) {
143 143
 		$this->conversion = $_conversion;
144 144
 	}
145 145
 	
@@ -149,59 +149,59 @@  discard block
 block discarded – undo
149 149
 	 * @param importexport_iface_egw_record record
150 150
 	 * @return bool
151 151
 	 */
152
-	public function export_record( importexport_iface_egw_record $_record ) {
152
+	public function export_record(importexport_iface_egw_record $_record) {
153 153
 		$this->record = $_record;
154 154
 		$this->record_array = $_record->get_record_array();
155 155
 		
156 156
 		// begin with fieldnames ?
157
-		if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames'] ) {
158
-			if($this->csv_options['begin_with_fieldnames'] == 'label') {
157
+		if ($this->num_of_records == 0 && $this->csv_options['begin_with_fieldnames']) {
158
+			if ($this->csv_options['begin_with_fieldnames'] == 'label') {
159 159
 				// Load translations for app
160 160
 				list($appname, $part2) = explode('_', get_class($_record));
161
-				if(!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name
161
+				if (!$GLOBALS['egw_info']['apps'][$appname]) $appname .= $part2; // Handle apps with _ in the name
162 162
 
163 163
 				// Get translations from wizard, if possible
164
-				if(!$this->csv_options['no_header_translation'])
164
+				if (!$this->csv_options['no_header_translation'])
165 165
 				{
166 166
 					$backtrace = debug_backtrace();
167 167
 					$plugin = $backtrace[1]['class'];
168
-					$wizard_name = $appname . '_wizard_' . str_replace($appname . '_', '', $plugin);
168
+					$wizard_name = $appname.'_wizard_'.str_replace($appname.'_', '', $plugin);
169 169
 					try {
170 170
 						$wizard = new $wizard_name;
171 171
 						$fields = $wizard->get_export_fields();
172
-						foreach($this->mapping as $field => &$label)
172
+						foreach ($this->mapping as $field => &$label)
173 173
 						{
174
-							if($fields[$field])
174
+							if ($fields[$field])
175 175
 							{
176 176
 								$label = $label != $fields[$field] ? $fields[$field] : lang($label);
177 177
 							}
178 178
 							// Make sure no *
179
-							if(substr($label,-1) == '*') $label = substr($label,0,-1);
179
+							if (substr($label, -1) == '*') $label = substr($label, 0, -1);
180 180
 						}
181 181
 					} catch (Exception $e) {
182 182
 						translation::add_app($appname);
183
-						foreach($this->mapping as $field => &$label) {
183
+						foreach ($this->mapping as $field => &$label) {
184 184
 							$label = lang($label);
185 185
 						}
186 186
 					}
187 187
 				}
188 188
 			}
189
-			$mapping = ! empty( $this->mapping ) ? $this->mapping : array_keys ( $this->record_array );
190
-			self::fputcsv( $this->handle ,$mapping ,$this->csv_options['delimiter'], $this->csv_options['enclosure'] );
189
+			$mapping = !empty($this->mapping) ? $this->mapping : array_keys($this->record_array);
190
+			self::fputcsv($this->handle, $mapping, $this->csv_options['delimiter'], $this->csv_options['enclosure']);
191 191
 		}
192 192
 
193 193
 		// Check for limit
194
-		if($this->export_limit && $this->num_of_records >= $this->export_limit) {
194
+		if ($this->export_limit && $this->num_of_records >= $this->export_limit) {
195 195
 			return;
196 196
 		}
197 197
 		
198 198
 		// do conversions
199
-		if ( !empty( $this->conversion )) {
200
-			$this->record_array = importexport_helper_functions::conversion( $this->record_array, $this->conversion );
199
+		if (!empty($this->conversion)) {
200
+			$this->record_array = importexport_helper_functions::conversion($this->record_array, $this->conversion);
201 201
 		}
202 202
 		
203 203
 		// do fieldmapping
204
-		if ( !empty( $this->mapping ) ) {
204
+		if (!empty($this->mapping)) {
205 205
 			$record_data = $this->record_array;
206 206
 			$this->record_array = array();
207 207
 			foreach ($this->mapping as $egw_field => $csv_field) {
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 			}
210 210
 		}
211 211
 		
212
-		self::fputcsv( $this->handle, $this->record_array, $this->csv_options['delimiter'], $this->csv_options['enclosure'] );
212
+		self::fputcsv($this->handle, $this->record_array, $this->csv_options['delimiter'], $this->csv_options['enclosure']);
213 213
 		$this->num_of_records++;
214 214
 	}
215 215
 
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
 	 * @return Array of fields to be added to list of fields needing conversion
234 234
 	 */
235 235
 	public static function convert_parse_custom_fields($appname, &$selects = array(), &$links = array(), &$methods = array()) {
236
-		if(!$appname) return;
236
+		if (!$appname) return;
237 237
 
238 238
 		$fields = array();
239 239
 		$custom = config::get_customfields($appname);
240
-		foreach($custom as $name => $c_field) {
241
-			$name = '#' . $name;
242
-			switch($c_field['type']) {
240
+		foreach ($custom as $name => $c_field) {
241
+			$name = '#'.$name;
242
+			switch ($c_field['type']) {
243 243
 				case 'date':
244 244
 					$fields['date'][] = $name;
245 245
 					break;
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 					$fields['select-account'][] = $name;
251 251
 					break;
252 252
 				case 'ajax_select':
253
-					if($c_field['values']['get_title']) {
253
+					if ($c_field['values']['get_title']) {
254 254
 						$methods[$name] = $c_field['values']['get_title'];
255 255
 						break;
256 256
 					}
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
 					$selects[$name] = $c_field['values'];
265 265
 					break;
266 266
 				default:
267
-					list($type) = explode('-',$c_field['type'],2);
268
-					if(in_array($type, array_keys($GLOBALS['egw_info']['apps']))) {
267
+					list($type) = explode('-', $c_field['type'], 2);
268
+					if (in_array($type, array_keys($GLOBALS['egw_info']['apps']))) {
269 269
 						$fields['links'][] = $name;
270 270
 						$links[$name] = $c_field['type'];
271 271
 					}
@@ -284,18 +284,18 @@  discard block
 block discarded – undo
284 284
 	 * @parem fields List of field types => field names to be converted
285 285
 	 * @param appname Current appname if you want to do custom fields too
286 286
 	 */
287
-	public static function convert(importexport_iface_egw_record &$record, Array $fields = array(), $appname = null, $selects = array()) {
288
-		if($appname) {
289
-			if(!self::$cf_parse_cache[$appname]) {
287
+	public static function convert(importexport_iface_egw_record&$record, Array $fields = array(), $appname = null, $selects = array()) {
288
+		if ($appname) {
289
+			if (!self::$cf_parse_cache[$appname]) {
290 290
 				$c_fields = self::convert_parse_custom_fields($appname, $selects, $links, $methods);
291 291
 				self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods);
292 292
 			}
293 293
 			list($c_fields, $c_selects, $links, $methods) = self::$cf_parse_cache[$appname];
294 294
 
295 295
 			// Add in any fields that are keys to another app
296
-			foreach((array)$fields['links'] as $link_field => $app)
296
+			foreach ((array)$fields['links'] as $link_field => $app)
297 297
 			{
298
-				if(is_numeric($link_field)) continue;
298
+				if (is_numeric($link_field)) continue;
299 299
 				$links[$link_field] = $app;
300 300
 				// Set it as a normal link field
301 301
 				$fields['links'][] = $link_field;
@@ -303,8 +303,8 @@  discard block
 block discarded – undo
303 303
 			}
304 304
 
305 305
 			// Not quite a recursive merge, since only one level
306
-			foreach($fields as $type => &$list) {
307
-				if($c_fields[$type]) {
306
+			foreach ($fields as $type => &$list) {
307
+				if ($c_fields[$type]) {
308 308
 					$list = array_merge($c_fields[$type], $list);
309 309
 					unset($c_fields[$type]);
310 310
 				}
@@ -312,12 +312,12 @@  discard block
 block discarded – undo
312 312
 			$fields += $c_fields;
313 313
 			$selects += $c_selects;
314 314
 		}
315
-		foreach((array)$fields['select'] as $name) {
316
-			if($record->$name != null && is_array($selects) && $selects[$name]) {
315
+		foreach ((array)$fields['select'] as $name) {
316
+			if ($record->$name != null && is_array($selects) && $selects[$name]) {
317 317
 				$record->$name = explode(',', $record->$name);
318
-				if(is_array($record->$name)) {
318
+				if (is_array($record->$name)) {
319 319
 					$names = array();
320
-					foreach($record->$name as $_name) {
320
+					foreach ($record->$name as $_name) {
321 321
 						$names[] = lang($selects[$name][$_name]);
322 322
 					}
323 323
 					$record->$name = implode(', ', $names);
@@ -330,17 +330,17 @@  discard block
 block discarded – undo
330 330
 				$record->$name = '';
331 331
 			}
332 332
 		}
333
-		foreach((array)$fields['links'] as $name) {
334
-			if($record->$name) {
335
-				if(is_numeric($record->$name) && !$links[$name]) {
333
+		foreach ((array)$fields['links'] as $name) {
334
+			if ($record->$name) {
335
+				if (is_numeric($record->$name) && !$links[$name]) {
336 336
 					$link = egw_link::get_link($record->$name);
337 337
 					$links[$name] = ($link['link_app1'] == $appname ? $link['link_app2'] : $link['link_app1']);
338 338
 					$record->$name = ($link['link_app1'] == $appname ? $link['link_id2'] : $link['link_id1']);
339 339
 				}
340
-				if($links[$name]) {
340
+				if ($links[$name]) {
341 341
 					$record->$name = egw_link::title($links[$name], $record->$name);
342 342
 				}
343
-				else if ( is_array($record->$name) && $record->$name['app'] && $record->$name['id'])
343
+				else if (is_array($record->$name) && $record->$name['app'] && $record->$name['id'])
344 344
 				{
345 345
 					$record->$name = Link::title($record->$name['app'], $record->$name['id']);
346 346
 				}
@@ -350,12 +350,12 @@  discard block
 block discarded – undo
350 350
 				$record->$name = '';
351 351
 			}
352 352
 		}
353
-		foreach((array)$fields['select-account'] as $name) {
353
+		foreach ((array)$fields['select-account'] as $name) {
354 354
 			// Compare against null to deal with empty arrays
355 355
 			if ($record->$name !== null) {
356
-				if(is_array($record->$name)) {
356
+				if (is_array($record->$name)) {
357 357
 					$names = array();
358
-					foreach($record->$name as $_name) {
358
+					foreach ($record->$name as $_name) {
359 359
 						$names[] = common::grab_owner_name($_name);
360 360
 					}
361 361
 					$record->$name = implode(', ', $names);
@@ -368,64 +368,64 @@  discard block
 block discarded – undo
368 368
 				$record->$name = '';
369 369
 			}
370 370
 		}
371
-		foreach((array)$fields['select-bool'] as $name) {
372
-			if($record->$name !== null) {
371
+		foreach ((array)$fields['select-bool'] as $name) {
372
+			if ($record->$name !== null) {
373 373
 				$record->$name = $record->$name ? lang('Yes') : lang('No');
374 374
 			}
375 375
 		}
376
-		foreach((array)$fields['date-time'] as $name) {
376
+		foreach ((array)$fields['date-time'] as $name) {
377 377
 			//if ($record->$name) $record->$name = date('Y-m-d H:i:s',$record->$name); // Standard date format
378 378
 			if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string
379
-			if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . ' '.
380
-				($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'),$record->$name); // User date format
379
+			if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' '.
380
+				($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == '24' ? 'H:i:s' : 'h:i:s a'), $record->$name); // User date format
381 381
 			if (!$record->$name) $record->$name = '';
382 382
 		}
383
-		foreach((array)$fields['date'] as $name) {
383
+		foreach ((array)$fields['date'] as $name) {
384 384
 			//if ($record->$name) $record->$name = date('Y-m-d',$record->$name); // Standard date format
385 385
 			if ($record->$name && !is_numeric($record->$name)) $record->$name = strtotime($record->$name); // Custom fields stored as string
386 386
 			if ($record->$name && is_numeric($record->$name)) $record->$name = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $record->$name); // User date format
387 387
 			if (!$record->$name) $record->$name = '';
388 388
 		}
389
-		foreach((array)$fields['float'] as $name)
389
+		foreach ((array)$fields['float'] as $name)
390 390
 		{
391
-			static $dec_separator,$thousands_separator;
391
+			static $dec_separator, $thousands_separator;
392 392
 			if (is_null($dec_separator))
393 393
 			{
394 394
 				$dec_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][0];
395 395
 				if (empty($dec_separator)) $dec_separator = '.';
396 396
 				$thousands_separator = $GLOBALS['egw_info']['user']['preferences']['common']['number_format'][1];
397 397
 			}
398
-			if($record->$name && (string)$record->$name != '')
398
+			if ($record->$name && (string)$record->$name != '')
399 399
 			{
400
-				if(!is_numeric($record->$name))
400
+				if (!is_numeric($record->$name))
401 401
 				{
402 402
 					$record->$name = floatval(str_replace($dec_separator, '.', preg_replace('/[^\d'.preg_quote($dec_separator).']/', '', $record->$name)));
403 403
 				}
404
-				$record->$name = number_format(str_replace(' ','',$record->$name), 2,
405
-					$dec_separator,$thousands_separator
404
+				$record->$name = number_format(str_replace(' ', '', $record->$name), 2,
405
+					$dec_separator, $thousands_separator
406 406
 				);
407 407
 			}
408 408
 		}
409 409
 
410 410
 		// Some custom methods for conversion
411
-		foreach((array)$methods as $name => $method) {
412
-			if($record->$name) $record->$name = ExecMethod($method, $record->$name);
411
+		foreach ((array)$methods as $name => $method) {
412
+			if ($record->$name) $record->$name = ExecMethod($method, $record->$name);
413 413
 		}
414 414
 
415 415
 		static $cat_object;
416
-		if(is_null($cat_object)) $cat_object = new categories(false,$appname);
417
-		foreach((array)$fields['select-cat'] as $name) {
418
-			if($record->$name) {
416
+		if (is_null($cat_object)) $cat_object = new categories(false, $appname);
417
+		foreach ((array)$fields['select-cat'] as $name) {
418
+			if ($record->$name) {
419 419
 				$cats = array();
420 420
 				$ids = is_array($record->$name) ? $record->$name : explode(',', $record->$name);
421
-				foreach($ids as $n => $cat_id) {
421
+				foreach ($ids as $n => $cat_id) {
422 422
 
423
-					if ($cat_id && $cat_object->check_perms(EGW_ACL_READ,$cat_id))
423
+					if ($cat_id && $cat_object->check_perms(EGW_ACL_READ, $cat_id))
424 424
 					{
425 425
 						$cats[] = $cat_object->id2name($cat_id);
426 426
 					}
427 427
 				}
428
-				$record->$name = implode(', ',$cats);
428
+				$record->$name = implode(', ', $cats);
429 429
 			}
430 430
 			else
431 431
 			{
@@ -452,18 +452,18 @@  discard block
 block discarded – undo
452 452
 	 * @param char $delimiter
453 453
 	 * @param char $enclosure
454 454
 	 */
455
-	protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure){
455
+	protected function fputcsv($filePointer, Array $dataArray, $delimiter, $enclosure) {
456 456
 		$string = "";
457 457
 		$writeDelimiter = false;
458
-		foreach($dataArray as $dataElement) {
459
-			if($writeDelimiter) $string .= $delimiter;
460
-			$string .= $enclosure . str_replace(array("\r\n", '"'), array("\n",'""'), $dataElement) . $enclosure;
458
+		foreach ($dataArray as $dataElement) {
459
+			if ($writeDelimiter) $string .= $delimiter;
460
+			$string .= $enclosure.str_replace(array("\r\n", '"'), array("\n", '""'), $dataElement).$enclosure;
461 461
 			$writeDelimiter = true;
462 462
 		}
463 463
 		$string .= "\n";
464 464
 		
465 465
 		// do charset translation
466
-		$string = $this->translation->convert( $string, $this->translation->charset(), $this->csv_charset );
466
+		$string = $this->translation->convert($string, $this->translation->charset(), $this->csv_charset);
467 467
 		
468 468
 		fwrite($filePointer, $string);
469 469
 			
Please login to merge, or discard this patch.
infolog/inc/class.infolog_export_csv.inc.php 2 patches
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param egw_record $_definition
31 31
 	 */
32
-	public function export( $_stream, importexport_definition $_definition)
32
+	public function export($_stream, importexport_definition $_definition)
33 33
 	{
34 34
 		$options = $_definition->plugin_options;
35 35
 
@@ -41,46 +41,46 @@  discard block
 block discarded – undo
41 41
 		$this->export_object->set_mapping($options['mapping']);
42 42
 
43 43
 		$ids = array();
44
-		switch($options['selection'])
44
+		switch ($options['selection'])
45 45
 		{
46 46
 			case 'search':
47
-				$query = array_merge((array)$GLOBALS['egw']->session->appsession('session_data','infolog'), $query);
47
+				$query = array_merge((array)$GLOBALS['egw']->session->appsession('session_data', 'infolog'), $query);
48 48
 				// Fall through
49 49
 			case 'filter':
50 50
 			case 'all':
51 51
 				// do we need to query the cf's
52 52
 				$query['custom_fields'] = false;
53
-				foreach($options['mapping'] + (array)$_definition->filter as $field => $map) {
54
-					if($field[0] == '#')
53
+				foreach ($options['mapping'] + (array)$_definition->filter as $field => $map) {
54
+					if ($field[0] == '#')
55 55
 					{
56 56
 						$query['custom_fields'] = true;
57 57
 						$query['selectcols'] .= ",$field";
58 58
 
59
-						if($GLOBALS['egw_info']['user']['apps'][$this->bo->customfields[substr($field,1)]['type']])
59
+						if ($GLOBALS['egw_info']['user']['apps'][$this->bo->customfields[substr($field, 1)]['type']])
60 60
 						{
61
-							$cf_links[$field] = $this->bo->customfields[substr($field,1)]['type'];
61
+							$cf_links[$field] = $this->bo->customfields[substr($field, 1)]['type'];
62 62
 						}
63 63
 					}
64 64
 				}
65
-				if($options['selection'] == 'filter')
65
+				if ($options['selection'] == 'filter')
66 66
 				{
67 67
 					$fields = importexport_helper_functions::get_filter_fields($_definition->application, $this);
68 68
 					$query['col_filter'] = $_definition->filter;
69 69
 
70 70
 					// Backend expects a string
71
-					if($query['col_filter']['info_responsible'])
71
+					if ($query['col_filter']['info_responsible'])
72 72
 					{
73
-						$query['col_filter']['info_responsible'] = implode(',',$query['col_filter']['info_responsible']);
73
+						$query['col_filter']['info_responsible'] = implode(',', $query['col_filter']['info_responsible']);
74 74
 					}
75 75
 
76 76
 					// Handle ranges
77
-					foreach($query['col_filter'] as $field => $value)
77
+					foreach ($query['col_filter'] as $field => $value)
78 78
 					{
79
-						if(!is_array($value) || (!$value['from'] && !$value['to'])) continue;
79
+						if (!is_array($value) || (!$value['from'] && !$value['to'])) continue;
80 80
 
81 81
 						// Ranges are inclusive, so should be provided that way (from 2 to 10 includes 2 and 10)
82
-						if($value['from']) $query['col_filter'][] = "$field >= " . (int)$value['from'];
83
-						if($value['to']) $query['col_filter'][] = "$field <= " . (int)$value['to'];
82
+						if ($value['from']) $query['col_filter'][] = "$field >= ".(int)$value['from'];
83
+						if ($value['to']) $query['col_filter'][] = "$field <= ".(int)$value['to'];
84 84
 						unset($query['col_filter'][$field]);
85 85
 					}
86 86
 				}
@@ -93,13 +93,13 @@  discard block
 block discarded – undo
93 93
 
94 94
 					// Pre-load any cfs that are links
95 95
 					$cf_preload = array();
96
-					foreach($cf_links as $field => $app)
96
+					foreach ($cf_links as $field => $app)
97 97
 					{
98
-						foreach($selection as &$row)
98
+						foreach ($selection as &$row)
99 99
 						{
100
-							if($row[$field]) $cf_preload[$app][] = $row[$field];
100
+							if ($row[$field]) $cf_preload[$app][] = $row[$field];
101 101
 						}
102
-						if($cf_preload[$app]){
102
+						if ($cf_preload[$app]) {
103 103
 							 $selects[$field] = egw_link::titles($app, $cf_preload[$app]);
104 104
 							//error_log('Preload ' . $field . '['.$app . ']: ' . implode(',',$cf_preload[$app]));
105 105
 						}
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
 
108 108
 					$this->export_records($this->export_object, $options, $selection, $ids);
109 109
 					$query['start'] += $query['num_rows'];
110
-				} while($query['start'] < $query['total']);
110
+				} while ($query['start'] < $query['total']);
111 111
 
112 112
 				return $this->export_object;
113 113
 				break;
114 114
 			default:
115
-				$ids = $selection = explode(',',$options['selection']);
115
+				$ids = $selection = explode(',', $options['selection']);
116 116
 				$this->export_records($this->export_object, $options, $selection, $ids);
117 117
 				break;
118 118
 		}
@@ -122,35 +122,35 @@  discard block
 block discarded – undo
122 122
 	protected function export_records(&$export_object, $options, &$selection, $ids = array())
123 123
 	{
124 124
 		// Pre-load links all at once
125
-		if($ids && $options['mapping']['info_link_id'])
125
+		if ($ids && $options['mapping']['info_link_id'])
126 126
 		{
127 127
 			$links = egw_link::get_links_multiple('infolog', $ids, true, '!'.egw_link::VFS_APPNAME);
128
-			foreach($links as $id => $link) {
129
-				if(!is_array($selection[$id])) break;
128
+			foreach ($links as $id => $link) {
129
+				if (!is_array($selection[$id])) break;
130 130
 				$selection[$id]['info_link_id'] = $link;
131
-				if($options['convert']) $selection[$id]['info_link_id'] = egw_link::title($link['app'], $link['id']);
131
+				if ($options['convert']) $selection[$id]['info_link_id'] = egw_link::title($link['app'], $link['id']);
132 132
 			}
133 133
 		}
134 134
 		// If exporting PM fields, pre-load them all at once
135
-		if($ids && ($options['mapping']['pm_id'] || $options['mapping']['project']))
135
+		if ($ids && ($options['mapping']['pm_id'] || $options['mapping']['project']))
136 136
 		{
137 137
 			$projects = egw_link::get_links_multiple('infolog', $ids, true, 'projectmanager');
138
-			foreach($projects as $id => $links)
138
+			foreach ($projects as $id => $links)
139 139
 			{
140
-				if(!is_array($selection[$id])) break;
140
+				if (!is_array($selection[$id])) break;
141 141
 				$selection[$id]['pm_id'] = current($links);
142 142
 				$selection[$id]['project'] = egw_link::title('projectmanager', $selection[$id]['pm_id']);
143
-				$this->selects['pl_id'] = ExecMethod('projectmanager.projectmanager_pricelist_bo.pricelist',$selection[$id]['pm_id']);
143
+				$this->selects['pl_id'] = ExecMethod('projectmanager.projectmanager_pricelist_bo.pricelist', $selection[$id]['pm_id']);
144 144
 			}
145 145
 		}
146 146
 
147 147
 		foreach ($selection as $_identifier)
148 148
 		{
149
-			if(!is_array($_identifier))
149
+			if (!is_array($_identifier))
150 150
 			{
151 151
 				$record = new infolog_egw_record($_identifier);
152
-				if($link = $links[$record->info_id]) $record->info_link_id = $options['convert'] ? egw_link::title($link['app'], $link['id']) : $link;
153
-				if($project = $projects[$record->info_id])
152
+				if ($link = $links[$record->info_id]) $record->info_link_id = $options['convert'] ? egw_link::title($link['app'], $link['id']) : $link;
153
+				if ($project = $projects[$record->info_id])
154 154
 				{
155 155
 					$record->pm_id = current($project);
156 156
 					$record->project = egw_link::title('projectmanager', $record->pm_id);
@@ -162,24 +162,24 @@  discard block
 block discarded – undo
162 162
 				$record->set_record($_identifier);
163 163
 			}
164 164
 			// Some conversion
165
-			if($options['convert'])
165
+			if ($options['convert'])
166 166
 			{
167 167
 				$this->selects['info_status'] = $this->bo->get_status($record->info_type);
168 168
 				importexport_export_csv::convert($record, infolog_egw_record::$types, 'infolog', $this->selects);
169 169
 				$this->convert($record);
170 170
 
171 171
 				// Force 0 times to ''
172
-				foreach(array('info_planned_time', 'info_used_time', 'info_replanned_time') as $field)
172
+				foreach (array('info_planned_time', 'info_used_time', 'info_replanned_time') as $field)
173 173
 				{
174
-					if($record->$field == 0) $record->$field = '';
174
+					if ($record->$field == 0) $record->$field = '';
175 175
 				}
176 176
 			}
177 177
 			else
178 178
 			{
179 179
 				// Implode arrays, so they don't say 'Array'
180
-				foreach($record->get_record_array() as $key => $value)
180
+				foreach ($record->get_record_array() as $key => $value)
181 181
 				{
182
-					if(is_array($value)) $record->$key = implode(',', $value);
182
+					if (is_array($value)) $record->$key = implode(',', $value);
183 183
 				}
184 184
 			}
185 185
 			$export_object->export_record($record);
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 */
229 229
 	public function get_filename()
230 230
 	{
231
-		if(is_object($this->export_object) && $this->export_object->get_num_of_records() == 1)
231
+		if (is_object($this->export_object) && $this->export_object->get_num_of_records() == 1)
232 232
 		{
233 233
 			return $this->export_object->record->get_title();
234 234
 		}
@@ -260,18 +260,18 @@  discard block
 block discarded – undo
260 260
 	{
261 261
 		$this->selects['info_type'] = $this->bo->enums['type'];
262 262
 		$this->selects['info_priority'] = $this->bo->enums['priority'];
263
-		$this->selects['pl_id'] = ExecMethod('projectmanager.projectmanager_pricelist_bo.pricelist',false);
263
+		$this->selects['pl_id'] = ExecMethod('projectmanager.projectmanager_pricelist_bo.pricelist', false);
264 264
 		$this->selects['info_status'] = $this->bo->get_status();
265 265
 	}
266 266
 
267 267
 	public function get_filter_fields(Array &$filters)
268 268
 	{
269
-		foreach($filters as $field_name => &$settings)
269
+		foreach ($filters as $field_name => &$settings)
270 270
 		{
271
-			if($this->selects[$field_name]) $settings['values'] = $this->selects[$field_name];
271
+			if ($this->selects[$field_name]) $settings['values'] = $this->selects[$field_name];
272 272
 			
273 273
 			// Infolog can't handle ranges in custom fields due to the way searching is done.
274
-			if(strpos($field_name, '#') === 0 && strpos($settings['type'],'date') === 0) unset($filters[$field_name]);
274
+			if (strpos($field_name, '#') === 0 && strpos($settings['type'], 'date') === 0) unset($filters[$field_name]);
275 275
 		}
276 276
 	}
277 277
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 	*
281 281
 	* This is for something specific to Infolog, in addition to the normal conversions.
282 282
 	*/
283
-	public static function convert(infolog_egw_record &$record)
283
+	public static function convert(infolog_egw_record&$record)
284 284
 	{
285 285
 		// Stub, for now
286 286
 	}
Please login to merge, or discard this patch.
Braces   +56 added lines, -16 removed lines patch added patch discarded remove patch
@@ -18,7 +18,8 @@  discard block
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-	public function __construct() {
21
+	public function __construct()
22
+	{
22 23
 		translation::add_app('infolog');
23 24
 		$this->bo = new infolog_bo();
24 25
 		$this->get_selects();
@@ -50,7 +51,8 @@  discard block
 block discarded – undo
50 51
 			case 'all':
51 52
 				// do we need to query the cf's
52 53
 				$query['custom_fields'] = false;
53
-				foreach($options['mapping'] + (array)$_definition->filter as $field => $map) {
54
+				foreach($options['mapping'] + (array)$_definition->filter as $field => $map)
55
+				{
54 56
 					if($field[0] == '#')
55 57
 					{
56 58
 						$query['custom_fields'] = true;
@@ -76,11 +78,20 @@  discard block
 block discarded – undo
76 78
 					// Handle ranges
77 79
 					foreach($query['col_filter'] as $field => $value)
78 80
 					{
79
-						if(!is_array($value) || (!$value['from'] && !$value['to'])) continue;
81
+						if(!is_array($value) || (!$value['from'] && !$value['to']))
82
+						{
83
+							continue;
84
+						}
80 85
 
81 86
 						// Ranges are inclusive, so should be provided that way (from 2 to 10 includes 2 and 10)
82
-						if($value['from']) $query['col_filter'][] = "$field >= " . (int)$value['from'];
83
-						if($value['to']) $query['col_filter'][] = "$field <= " . (int)$value['to'];
87
+						if($value['from'])
88
+						{
89
+							$query['col_filter'][] = "$field >= " . (int)$value['from'];
90
+						}
91
+						if($value['to'])
92
+						{
93
+							$query['col_filter'][] = "$field <= " . (int)$value['to'];
94
+						}
84 95
 						unset($query['col_filter'][$field]);
85 96
 					}
86 97
 				}
@@ -97,9 +108,13 @@  discard block
 block discarded – undo
97 108
 					{
98 109
 						foreach($selection as &$row)
99 110
 						{
100
-							if($row[$field]) $cf_preload[$app][] = $row[$field];
111
+							if($row[$field])
112
+							{
113
+								$cf_preload[$app][] = $row[$field];
114
+							}
101 115
 						}
102
-						if($cf_preload[$app]){
116
+						if($cf_preload[$app])
117
+						{
103 118
 							 $selects[$field] = egw_link::titles($app, $cf_preload[$app]);
104 119
 							//error_log('Preload ' . $field . '['.$app . ']: ' . implode(',',$cf_preload[$app]));
105 120
 						}
@@ -125,10 +140,17 @@  discard block
 block discarded – undo
125 140
 		if($ids && $options['mapping']['info_link_id'])
126 141
 		{
127 142
 			$links = egw_link::get_links_multiple('infolog', $ids, true, '!'.egw_link::VFS_APPNAME);
128
-			foreach($links as $id => $link) {
129
-				if(!is_array($selection[$id])) break;
143
+			foreach($links as $id => $link)
144
+			{
145
+				if(!is_array($selection[$id]))
146
+				{
147
+					break;
148
+				}
130 149
 				$selection[$id]['info_link_id'] = $link;
131
-				if($options['convert']) $selection[$id]['info_link_id'] = egw_link::title($link['app'], $link['id']);
150
+				if($options['convert'])
151
+				{
152
+					$selection[$id]['info_link_id'] = egw_link::title($link['app'], $link['id']);
153
+				}
132 154
 			}
133 155
 		}
134 156
 		// If exporting PM fields, pre-load them all at once
@@ -137,7 +159,10 @@  discard block
 block discarded – undo
137 159
 			$projects = egw_link::get_links_multiple('infolog', $ids, true, 'projectmanager');
138 160
 			foreach($projects as $id => $links)
139 161
 			{
140
-				if(!is_array($selection[$id])) break;
162
+				if(!is_array($selection[$id]))
163
+				{
164
+					break;
165
+				}
141 166
 				$selection[$id]['pm_id'] = current($links);
142 167
 				$selection[$id]['project'] = egw_link::title('projectmanager', $selection[$id]['pm_id']);
143 168
 				$this->selects['pl_id'] = ExecMethod('projectmanager.projectmanager_pricelist_bo.pricelist',$selection[$id]['pm_id']);
@@ -149,7 +174,10 @@  discard block
 block discarded – undo
149 174
 			if(!is_array($_identifier))
150 175
 			{
151 176
 				$record = new infolog_egw_record($_identifier);
152
-				if($link = $links[$record->info_id]) $record->info_link_id = $options['convert'] ? egw_link::title($link['app'], $link['id']) : $link;
177
+				if($link = $links[$record->info_id])
178
+				{
179
+					$record->info_link_id = $options['convert'] ? egw_link::title($link['app'], $link['id']) : $link;
180
+				}
153 181
 				if($project = $projects[$record->info_id])
154 182
 				{
155 183
 					$record->pm_id = current($project);
@@ -171,7 +199,10 @@  discard block
 block discarded – undo
171 199
 				// Force 0 times to ''
172 200
 				foreach(array('info_planned_time', 'info_used_time', 'info_replanned_time') as $field)
173 201
 				{
174
-					if($record->$field == 0) $record->$field = '';
202
+					if($record->$field == 0)
203
+					{
204
+						$record->$field = '';
205
+					}
175 206
 				}
176 207
 			}
177 208
 			else
@@ -179,7 +210,10 @@  discard block
 block discarded – undo
179 210
 				// Implode arrays, so they don't say 'Array'
180 211
 				foreach($record->get_record_array() as $key => $value)
181 212
 				{
182
-					if(is_array($value)) $record->$key = implode(',', $value);
213
+					if(is_array($value))
214
+					{
215
+						$record->$key = implode(',', $value);
216
+					}
183 217
 				}
184 218
 			}
185 219
 			$export_object->export_record($record);
@@ -268,10 +302,16 @@  discard block
 block discarded – undo
268 302
 	{
269 303
 		foreach($filters as $field_name => &$settings)
270 304
 		{
271
-			if($this->selects[$field_name]) $settings['values'] = $this->selects[$field_name];
305
+			if($this->selects[$field_name])
306
+			{
307
+				$settings['values'] = $this->selects[$field_name];
308
+			}
272 309
 			
273 310
 			// Infolog can't handle ranges in custom fields due to the way searching is done.
274
-			if(strpos($field_name, '#') === 0 && strpos($settings['type'],'date') === 0) unset($filters[$field_name]);
311
+			if(strpos($field_name, '#') === 0 && strpos($settings['type'],'date') === 0)
312
+			{
313
+				unset($filters[$field_name]);
314
+			}
275 315
 		}
276 316
 	}
277 317
 
Please login to merge, or discard this patch.