Completed
Push — master ( 913402...2b342c )
by Mark
16:33
created
code/ShopSearch.php 1 patch
Braces   +25 added lines, -8 removed lines patch added patch discarded remove patch
@@ -177,11 +177,20 @@  discard block
 block discarded – undo
177 177
 		$qs_ps  = $this->config()->get('qs_parent_search');
178 178
 		$qs_t   = $this->config()->get('qs_title');
179 179
 		$qs_sort= $this->config()->get('qs_sort');
180
-		if ($limit < 0) $limit  = $this->config()->get('page_size');
181
-		if ($start < 0) $start  = !empty($vars['start']) ? (int)$vars['start'] : 0; // as far as i can see, fulltextsearch hard codes 'start'
180
+		if ($limit < 0) {
181
+			$limit  = $this->config()->get('page_size');
182
+		}
183
+		if ($start < 0) {
184
+			$start  = !empty($vars['start']) ? (int)$vars['start'] : 0;
185
+		}
186
+		// as far as i can see, fulltextsearch hard codes 'start'
182 187
 		$facets = $useFacets ? $this->config()->get('facets') : array();
183
-		if (!is_array($facets)) $facets = array();
184
-		if (empty($limit)) $limit = -1;
188
+		if (!is_array($facets)) {
189
+			$facets = array();
190
+		}
191
+		if (empty($limit)) {
192
+			$limit = -1;
193
+		}
185 194
 
186 195
 		// figure out and scrub the sort
187 196
 		$sortOptions = $this->config()->get('sort_options');
@@ -201,9 +210,15 @@  discard block
 block discarded – undo
201 210
 		$results  = self::adapter()->searchFromVars($keywords, $filters, $facets, $start, $limit, $sort);
202 211
 
203 212
 		// massage the results a bit
204
-		if (!empty($keywords) && !$results->hasValue('Query')) $results->Query = $keywords;
205
-		if (!empty($filters) && !$results->hasValue('Filters')) $results->Filters = new ArrayData($filters);
206
-		if (!$results->hasValue('Sort')) $results->Sort = $sort;
213
+		if (!empty($keywords) && !$results->hasValue('Query')) {
214
+			$results->Query = $keywords;
215
+		}
216
+		if (!empty($filters) && !$results->hasValue('Filters')) {
217
+			$results->Filters = new ArrayData($filters);
218
+		}
219
+		if (!$results->hasValue('Sort')) {
220
+			$results->Sort = $sort;
221
+		}
207 222
 		if (!$results->hasValue('TotalMatches')) {
208 223
 			$results->TotalMatches = $results->Matches->hasMethod('getTotalItems')
209 224
 				? $results->Matches->getTotalItems()
@@ -329,7 +344,9 @@  discard block
 block discarded – undo
329 344
 
330 345
 			$products   = array();
331 346
 			foreach ($results['products'] as $prod) {
332
-				if (!$prod || !$prod->exists()) continue;
347
+				if (!$prod || !$prod->exists()) {
348
+					continue;
349
+				}
333 350
 				$img = $prod->hasMethod('ProductImage') ? $prod->ProductImage() : $prod->Image();
334 351
 				$thumb = ($img && $img->exists()) ? $img->getThumbnail() : null;
335 352
 
Please login to merge, or discard this patch.
code/ShopSearchAjax.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,9 @@
 block discarded – undo
17 17
 	 */
18 18
 	public function updateSearchResultsResponse(&$request, &$response, $results, $data) {
19 19
 		if ($request->isAjax() && $this->owner->hasExtension('AjaxControllerExtension')) {
20
-			if (!$response) $response = $this->owner->getAjaxResponse();
20
+			if (!$response) {
21
+				$response = $this->owner->getAjaxResponse();
22
+			}
21 23
 			$response->addRenderContext('RESULTS', $results);
22 24
 			$response->pushRegion('SearchResults', $results);
23 25
 			$response->pushRegion('SearchHeader', $results);
Please login to merge, or discard this patch.
code/ShopSearchForm.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@  discard block
 block discarded – undo
29 29
 	function __construct($controller, $method, $suggestURL = '') {
30 30
 		$searchField = TextField::create('q', '');
31 31
 		$searchField->setAttribute('placeholder', _t('ShopSearch.SEARCH', 'Search'));
32
-		if ($suggestURL) $searchField->setAttribute('data-suggest-url', $suggestURL);
32
+		if ($suggestURL) {
33
+			$searchField->setAttribute('data-suggest-url', $suggestURL);
34
+		}
33 35
 
34 36
 		$fields = FieldList::create($searchField);
35 37
 		if (!self::config()->disable_category_dropdown) {
@@ -48,7 +50,9 @@  discard block
 block discarded – undo
48 50
 
49 51
 		$this->setFormMethod('GET');
50 52
 		$this->disableSecurityToken();
51
-		if ($c = self::config()->css_classes) $this->addExtraClass($c);
53
+		if ($c = self::config()->css_classes) {
54
+			$this->addExtraClass($c);
55
+		}
52 56
 
53 57
 		Requirements::css(SHOP_SEARCH_FOLDER . '/css/ShopSearch.css');
54 58
 
Please login to merge, or discard this patch.
code/adapters/ShopSearchSimple.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,9 @@
 block discarded – undo
37 37
 					$keywordFilter[$name] = $keywords;
38 38
 				}
39 39
 			}
40
-			if (count($keywordFilter) > 0) $list = $list->filterAny($keywordFilter);
40
+			if (count($keywordFilter) > 0) {
41
+				$list = $list->filterAny($keywordFilter);
42
+			}
41 43
 
42 44
 			// add in any other filters
43 45
 			$list = FacetHelper::inst()->addFiltersToDataList($list, $filters);
Please login to merge, or discard this patch.
code/adapters/ShopSearchSolr.php 1 patch
Braces   +89 added lines, -52 removed lines patch added patch discarded remove patch
@@ -102,7 +102,9 @@  discard block
 block discarded – undo
102 102
 	 */
103 103
 	protected function scrubFieldList($in) {
104 104
 		$out = array();
105
-		if (empty($in) || !is_array($in)) return $out;
105
+		if (empty($in) || !is_array($in)) {
106
+			return $out;
107
+		}
106 108
 
107 109
 		foreach ($in as $name => $val) {
108 110
 			// supports an indexed array format of simple field names
@@ -121,8 +123,12 @@  discard block
 block discarded – undo
121 123
 				'params'    => $params,
122 124
 			);
123 125
 
124
-			if (isset($def['params']['field'])) unset($def['params']['field']);
125
-			if (isset($def['params']['type']))  unset($def['params']['type']);
126
+			if (isset($def['params']['field'])) {
127
+				unset($def['params']['field']);
128
+			}
129
+			if (isset($def['params']['type'])) {
130
+				unset($def['params']['type']);
131
+			}
126 132
 
127 133
 			$out[$name] = $def;
128 134
 		}
@@ -136,7 +142,9 @@  discard block
 block discarded – undo
136 142
 	 */
137 143
 	protected function getFulltextSpec() {
138 144
 		$fields = Config::inst()->get('ShopSearch', 'solr_fulltext_fields');
139
-		if (empty($fields)) $fields = array('Title', 'Content');
145
+		if (empty($fields)) {
146
+			$fields = array('Title', 'Content');
147
+		}
140 148
 		return $this->scrubFieldList($fields);
141 149
 	}
142 150
 
@@ -196,7 +204,9 @@  discard block
 block discarded – undo
196 204
 	 */
197 205
 	function getTypes() {
198 206
 		$val = parent::getTypes();
199
-		if (!$val || !is_object($val)) return $val;
207
+		if (!$val || !is_object($val)) {
208
+			return $val;
209
+		}
200 210
 		$xml = $val->getValue();
201 211
 		$xml .= <<<XML
202 212
 
@@ -241,7 +251,9 @@  discard block
 block discarded – undo
241 251
 		);
242 252
 
243 253
 		// swap out title search
244
-		if ($params['sort'] == 'SiteTree_Title') $params['sort'] = '_titleSort';
254
+		if ($params['sort'] == 'SiteTree_Title') {
255
+			$params['sort'] = '_titleSort';
256
+		}
245 257
 
246 258
 		// search by keywords
247 259
 		$query->search(empty($keywords) ? '*:*' : $keywords);
@@ -349,11 +361,16 @@  discard block
 block discarded – undo
349 361
 		$classq = array();
350 362
 
351 363
 		foreach ($query->classes as $class) {
352
-			if (!empty($class['includeSubclasses'])) $classq[] = 'ClassHierarchy:'.$class['class'];
353
-			else $classq[] = 'ClassName:'.$class['class'];
364
+			if (!empty($class['includeSubclasses'])) {
365
+				$classq[] = 'ClassHierarchy:'.$class['class'];
366
+			} else {
367
+				$classq[] = 'ClassName:'.$class['class'];
368
+			}
354 369
 		}
355 370
 
356
-		if ($classq) $fq[] = '+('.implode(' ', $classq).')';
371
+		if ($classq) {
372
+			$fq[] = '+('.implode(' ', $classq).')';
373
+		}
357 374
 
358 375
 		// Filter by filters
359 376
 		foreach ($query->require as $field => $values) {
@@ -362,16 +379,17 @@  discard block
 block discarded – undo
362 379
 			foreach ($values as $value) {
363 380
 				if ($value === SearchQuery::$missing) {
364 381
 					$requireq[] = "(*:* -{$field}:[* TO *])";
365
-				}
366
-				else if ($value === SearchQuery::$present) {
382
+				} else if ($value === SearchQuery::$present) {
367 383
 					$requireq[] = "{$field}:[* TO *]";
368
-				}
369
-				else if ($value instanceof SearchQuery_Range) {
370
-					$start = $value->start; if ($start === null) $start = '*';
371
-					$end = $value->end; if ($end === null) $end = '*';
384
+				} else if ($value instanceof SearchQuery_Range) {
385
+					$start = $value->start; if ($start === null) {
386
+						$start = '*';
387
+					}
388
+					$end = $value->end; if ($end === null) {
389
+						$end = '*';
390
+					}
372 391
 					$requireq[] = "$field:[$start TO $end]";
373
-				}
374
-				else {
392
+				} else {
375 393
 					$requireq[] = $field.':"'.$value.'"';
376 394
 				}
377 395
 			}
@@ -386,16 +404,17 @@  discard block
 block discarded – undo
386 404
 			foreach ($values as $value) {
387 405
 				if ($value === SearchQuery::$missing) {
388 406
 					$missing = true;
389
-				}
390
-				else if ($value === SearchQuery::$present) {
407
+				} else if ($value === SearchQuery::$present) {
391 408
 					$excludeq[] = "{$field}:[* TO *]";
392
-				}
393
-				else if ($value instanceof SearchQuery_Range) {
394
-					$start = $value->start; if ($start === null) $start = '*';
395
-					$end = $value->end; if ($end === null) $end = '*';
409
+				} else if ($value instanceof SearchQuery_Range) {
410
+					$start = $value->start; if ($start === null) {
411
+						$start = '*';
412
+					}
413
+					$end = $value->end; if ($end === null) {
414
+						$end = '*';
415
+					}
396 416
 					$excludeq[] = "$field:[$start TO $end]";
397
-				}
398
-				else {
417
+				} else {
399 418
 					$excludeq[] = $field.':"'.$value.'"';
400 419
 				}
401 420
 			}
@@ -509,7 +528,9 @@  discard block
 block discarded – undo
509 528
 
510 529
 			foreach ($parts[0] as $part) {
511 530
 				$fields = (isset($search['fields'])) ? $search['fields'] : array();
512
-				if(isset($search['boost'])) $fields = array_merge($fields, array_keys($search['boost']));
531
+				if(isset($search['boost'])) {
532
+					$fields = array_merge($fields, array_keys($search['boost']));
533
+				}
513 534
 				if ($fields) {
514 535
 					$searchq = array();
515 536
 					foreach ($fields as $field) {
@@ -517,8 +538,7 @@  discard block
 block discarded – undo
517 538
 						$searchq[] = "{$field}:".$part.$fuzzy.$boost;
518 539
 					}
519 540
 					$q[] = '+('.implode(' OR ', $searchq).')';
520
-				}
521
-				else {
541
+				} else {
522 542
 					$q[] = '+'.$part.$fuzzy;
523 543
 				}
524 544
 			}
@@ -529,11 +549,16 @@  discard block
 block discarded – undo
529 549
 		$classq = array();
530 550
 
531 551
 		foreach ($query->classes as $class) {
532
-			if (!empty($class['includeSubclasses'])) $classq[] = 'ClassHierarchy:'.$class['class'];
533
-			else $classq[] = 'ClassName:'.$class['class'];
552
+			if (!empty($class['includeSubclasses'])) {
553
+				$classq[] = 'ClassHierarchy:'.$class['class'];
554
+			} else {
555
+				$classq[] = 'ClassName:'.$class['class'];
556
+			}
534 557
 		}
535 558
 
536
-		if ($classq) $fq[] = '+('.implode(' ', $classq).')';
559
+		if ($classq) {
560
+			$fq[] = '+('.implode(' ', $classq).')';
561
+		}
537 562
 
538 563
 		// Filter by filters
539 564
 
@@ -543,16 +568,17 @@  discard block
 block discarded – undo
543 568
 			foreach ($values as $value) {
544 569
 				if ($value === SearchQuery::$missing) {
545 570
 					$requireq[] = "(*:* -{$field}:[* TO *])";
546
-				}
547
-				else if ($value === SearchQuery::$present) {
571
+				} else if ($value === SearchQuery::$present) {
548 572
 					$requireq[] = "{$field}:[* TO *]";
549
-				}
550
-				else if ($value instanceof SearchQuery_Range) {
551
-					$start = $value->start; if ($start === null) $start = '*';
552
-					$end = $value->end; if ($end === null) $end = '*';
573
+				} else if ($value instanceof SearchQuery_Range) {
574
+					$start = $value->start; if ($start === null) {
575
+						$start = '*';
576
+					}
577
+					$end = $value->end; if ($end === null) {
578
+						$end = '*';
579
+					}
553 580
 					$requireq[] = "$field:[$start TO $end]";
554
-				}
555
-				else {
581
+				} else {
556 582
 					$requireq[] = $field.':"'.$value.'"';
557 583
 				}
558 584
 			}
@@ -567,16 +593,17 @@  discard block
 block discarded – undo
567 593
 			foreach ($values as $value) {
568 594
 				if ($value === SearchQuery::$missing) {
569 595
 					$missing = true;
570
-				}
571
-				else if ($value === SearchQuery::$present) {
596
+				} else if ($value === SearchQuery::$present) {
572 597
 					$excludeq[] = "{$field}:[* TO *]";
573
-				}
574
-				else if ($value instanceof SearchQuery_Range) {
575
-					$start = $value->start; if ($start === null) $start = '*';
576
-					$end = $value->end; if ($end === null) $end = '*';
598
+				} else if ($value instanceof SearchQuery_Range) {
599
+					$start = $value->start; if ($start === null) {
600
+						$start = '*';
601
+					}
602
+					$end = $value->end; if ($end === null) {
603
+						$end = '*';
604
+					}
577 605
 					$excludeq[] = "$field:[$start TO $end]";
578
-				}
579
-				else {
606
+				} else {
580 607
 					$excludeq[] = $field.':"'.$value.'"';
581 608
 				}
582 609
 			}
@@ -589,9 +616,15 @@  discard block
 block discarded – undo
589 616
 //			if ($fq) header('X-Filters: "'.implode('", "', $fq).'"');
590 617
 //		}
591 618
 
592
-		if ($offset == -1) $offset = $query->start;
593
-		if ($limit == -1) $limit = $query->limit;
594
-		if ($limit == -1) $limit = SearchQuery::$default_page_size;
619
+		if ($offset == -1) {
620
+			$offset = $query->start;
621
+		}
622
+		if ($limit == -1) {
623
+			$limit = $query->limit;
624
+		}
625
+		if ($limit == -1) {
626
+			$limit = SearchQuery::$default_page_size;
627
+		}
595 628
 
596 629
 		$params = array_merge($params, array('fq' => implode(' ', $fq)));
597 630
 
@@ -677,8 +710,12 @@  discard block
 block discarded – undo
677 710
 			if ($facet['Type'] == ShopSearch::FACET_TYPE_RANGE) {
678 711
 				// If it's a range facet, set up the min/max
679 712
 				// TODO: we could probably get the real min and max with solr's range faceting if we tried
680
-				if (isset($facet['RangeMin'])) $facet['MinValue'] = $facet['RangeMin'];
681
-				if (isset($facet['RangeMax'])) $facet['MaxValue'] = $facet['RangeMax'];
713
+				if (isset($facet['RangeMin'])) {
714
+					$facet['MinValue'] = $facet['RangeMin'];
715
+				}
716
+				if (isset($facet['RangeMax'])) {
717
+					$facet['MaxValue'] = $facet['RangeMax'];
718
+				}
682 719
 				$out->push(new ArrayData($facet));
683 720
 			} elseif (isset($this->fieldMap[$field])) {
684 721
 				// Otherwise, look through Solr's results
Please login to merge, or discard this patch.
code/helpers/BetweenFilter.php 1 patch
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,8 +18,11 @@  discard block
 block discarded – undo
18 18
 		$this->model = $query->applyRelation($this->relation);
19 19
 		$value = $this->getDbFormattedValue();
20 20
 
21
-		if(is_numeric($value)) $filter = sprintf("%s > %s", $this->getDbName(), Convert::raw2sql($value));
22
-		else $filter = sprintf("%s > '%s'", $this->getDbName(), Convert::raw2sql($value));
21
+		if(is_numeric($value)) {
22
+			$filter = sprintf("%s > %s", $this->getDbName(), Convert::raw2sql($value));
23
+		} else {
24
+			$filter = sprintf("%s > '%s'", $this->getDbName(), Convert::raw2sql($value));
25
+		}
23 26
 
24 27
 		return $query->where($filter);
25 28
 	}
@@ -32,8 +35,11 @@  discard block
 block discarded – undo
32 35
 		$this->model = $query->applyRelation($this->relation);
33 36
 		$value = $this->getDbFormattedValue();
34 37
 
35
-		if(is_numeric($value)) $filter = sprintf("%s <= %s", $this->getDbName(), Convert::raw2sql($value));
36
-		else $filter = sprintf("%s <= '%s'", $this->getDbName(), Convert::raw2sql($value));
38
+		if(is_numeric($value)) {
39
+			$filter = sprintf("%s <= %s", $this->getDbName(), Convert::raw2sql($value));
40
+		} else {
41
+			$filter = sprintf("%s <= '%s'", $this->getDbName(), Convert::raw2sql($value));
42
+		}
37 43
 
38 44
 		return $query->where($filter);
39 45
 	}
Please login to merge, or discard this patch.
code/helpers/FacetHelper.php 1 patch
Braces   +99 added lines, -33 removed lines patch added patch discarded remove patch
@@ -41,12 +41,18 @@  discard block
 block discarded – undo
41 41
 	 * @return array
42 42
 	 */
43 43
 	public function scrubFilters($filters) {
44
-		if (!is_array($filters)) $filters = array();
44
+		if (!is_array($filters)) {
45
+			$filters = array();
46
+		}
45 47
 
46 48
 		foreach ($filters as $k => $v) {
47
-			if (empty($v)) unset($filters[$k]);
49
+			if (empty($v)) {
50
+				unset($filters[$k]);
51
+			}
48 52
 			// this allows you to send an array as a comma-separated list, which is easier on the query string length
49
-			if (is_string($v) && strpos($v, 'LIST~') === 0) $filters[$k] = explode(',', substr($v, 5));
53
+			if (is_string($v) && strpos($v, 'LIST~') === 0) {
54
+				$filters[$k] = explode(',', substr($v, 5));
55
+			}
50 56
 		}
51 57
 
52 58
 		return $filters;
@@ -60,8 +66,12 @@  discard block
 block discarded – undo
60 66
 	 * @return DataList
61 67
 	 */
62 68
 	public function addFiltersToDataList($list, array $filters, $sing=null) {
63
-		if (!$sing) $sing = singleton($list->dataClass());
64
-		if (is_string($sing)) $sing = singleton($sing);
69
+		if (!$sing) {
70
+			$sing = singleton($list->dataClass());
71
+		}
72
+		if (is_string($sing)) {
73
+			$sing = singleton($sing);
74
+		}
65 75
 
66 76
 		if (!empty($filters)) {
67 77
 			foreach ($filters as $filterField => $filterVal) {
@@ -105,7 +115,9 @@  discard block
 block discarded – undo
105 115
 				// Lists have to be handled a little differently
106 116
 				$f = $rec->getVFIFieldName($filterField) . ':PartialMatch';
107 117
 				if (is_array($filterVal)) {
108
-					foreach ($filterVal as &$val) $val = '|' . $val . '|';
118
+					foreach ($filterVal as &$val) {
119
+						$val = '|' . $val . '|';
120
+					}
109 121
 					return array($f => $filterVal);
110 122
 				} else {
111 123
 					return array($f => '|' . $filterVal . '|');
@@ -137,7 +149,9 @@  discard block
 block discarded – undo
137 149
 	 * @return array
138 150
 	 */
139 151
 	public function expandFacetSpec(array $facetSpec) {
140
-		if (is_null($facetSpec)) return array();
152
+		if (is_null($facetSpec)) {
153
+			return array();
154
+		}
141 155
 		$facets = array();
142 156
 
143 157
 		foreach ($facetSpec as $field => $label) {
@@ -147,14 +161,20 @@  discard block
 block discarded – undo
147 161
 				$facets[$field] = array('Label' => $label);
148 162
 			}
149 163
 
150
-			if (empty($facets[$field]['Source'])) $facets[$field]['Source'] = $field;
151
-			if (empty($facets[$field]['Type']))  $facets[$field]['Type']  = ShopSearch::FACET_TYPE_LINK;
164
+			if (empty($facets[$field]['Source'])) {
165
+				$facets[$field]['Source'] = $field;
166
+			}
167
+			if (empty($facets[$field]['Type'])) {
168
+				$facets[$field]['Type']  = ShopSearch::FACET_TYPE_LINK;
169
+			}
152 170
 
153 171
 			if (empty($facets[$field]['Values'])) {
154 172
 				$facets[$field]['Values'] = array();
155 173
 			} else {
156 174
 				$vals = $facets[$field]['Values'];
157
-				if (is_string($vals)) $vals = eval('return ' . $vals . ';');
175
+				if (is_string($vals)) {
176
+					$vals = eval('return ' . $vals . ';');
177
+				}
158 178
 				$facets[$field]['Values'] = array();
159 179
 				foreach ($vals as $val => $lbl) {
160 180
 					$facets[$field]['Values'][$val] = new ArrayData(array(
@@ -199,7 +219,9 @@  discard block
 block discarded – undo
199 219
 	 */
200 220
 	public function buildFacets(SS_List $matches, array $facetSpec, $autoFacetAttributes=false) {
201 221
 		$facets = $this->expandFacetSpec($facetSpec);
202
-		if (!$autoFacetAttributes && (empty($facets) || !$matches || !$matches->count())) return new ArrayList();
222
+		if (!$autoFacetAttributes && (empty($facets) || !$matches || !$matches->count())) {
223
+			return new ArrayList();
224
+		}
203 225
 		$fasterMethod = (bool)$this->config()->faster_faceting;
204 226
 
205 227
 		// fill them in
@@ -212,8 +234,12 @@  discard block
 block discarded – undo
212 234
 			// NOTE: using this method range and checkbox facets don't get counts
213 235
 			if ($fasterMethod && $facet['Type'] != ShopSearch::FACET_TYPE_LINK) {
214 236
 				if ($facet['Type'] == ShopSearch::FACET_TYPE_RANGE) {
215
-					if (isset($facet['RangeMin'])) $facet['MinValue'] = $facet['RangeMin'];
216
-					if (isset($facet['RangeMax'])) $facet['MaxValue'] = $facet['RangeMax'];
237
+					if (isset($facet['RangeMin'])) {
238
+						$facet['MinValue'] = $facet['RangeMin'];
239
+					}
240
+					if (isset($facet['RangeMax'])) {
241
+						$facet['MaxValue'] = $facet['RangeMax'];
242
+					}
217 243
 				}
218 244
 
219 245
 				continue;
@@ -222,25 +248,37 @@  discard block
 block discarded – undo
222 248
 			foreach ($matches as $rec) {
223 249
 				// If it's a range facet, set up the min/max
224 250
 				if ($facet['Type'] == ShopSearch::FACET_TYPE_RANGE) {
225
-					if (isset($facet['RangeMin'])) $facet['MinValue'] = $facet['RangeMin'];
226
-					if (isset($facet['RangeMax'])) $facet['MaxValue'] = $facet['RangeMax'];
251
+					if (isset($facet['RangeMin'])) {
252
+						$facet['MinValue'] = $facet['RangeMin'];
253
+					}
254
+					if (isset($facet['RangeMax'])) {
255
+						$facet['MaxValue'] = $facet['RangeMax'];
256
+					}
227 257
 				}
228 258
 
229 259
 				// If the field is accessible via normal methods, including
230 260
 				// a user-defined getter, prefer that
231 261
 				$fieldValue = $rec->relObject($field);
232
-				if (is_null($fieldValue) && $rec->hasMethod($meth = "get{$field}")) $fieldValue = $rec->$meth();
262
+				if (is_null($fieldValue) && $rec->hasMethod($meth = "get{$field}")) {
263
+					$fieldValue = $rec->$meth();
264
+				}
233 265
 
234 266
 				// If not, look for a VFI field
235
-				if (!$fieldValue && $rec->hasExtension('VirtualFieldIndex')) $fieldValue = $rec->getVFI($field);
267
+				if (!$fieldValue && $rec->hasExtension('VirtualFieldIndex')) {
268
+					$fieldValue = $rec->getVFI($field);
269
+				}
236 270
 
237 271
 				// If we found something, process it
238 272
 				if (!empty($fieldValue)) {
239 273
 					// normalize so that it's iterable
240
-					if (!is_array($fieldValue) && !$fieldValue instanceof SS_List) $fieldValue = array($fieldValue);
274
+					if (!is_array($fieldValue) && !$fieldValue instanceof SS_List) {
275
+						$fieldValue = array($fieldValue);
276
+					}
241 277
 
242 278
 					foreach ($fieldValue as $obj) {
243
-						if (empty($obj)) continue;
279
+						if (empty($obj)) {
280
+							continue;
281
+						}
244 282
 
245 283
 						// figure out the right label
246 284
 						if (is_object($obj) && $obj->hasMethod('Nice')) {
@@ -311,7 +349,9 @@  discard block
 block discarded – undo
311 349
 		$out = new ArrayList();
312 350
 		$sortValues = self::config()->sort_facet_values;
313 351
 		foreach ($facets as $f) {
314
-			if ($sortValues) ksort($f['Values']);
352
+			if ($sortValues) {
353
+				ksort($f['Values']);
354
+			}
315 355
 			$f['Values'] = new ArrayList($f['Values']);
316 356
 			$out->push(new ArrayData($f));
317 357
 		}
@@ -335,7 +375,9 @@  discard block
 block discarded – undo
335 375
 		}
336 376
 
337 377
 		$baseTable = $q->getFrom();
338
-		if (is_array($baseTable)) $baseTable = reset($baseTable);
378
+		if (is_array($baseTable)) {
379
+			$baseTable = reset($baseTable);
380
+		}
339 381
 
340 382
 		$q = $q->setSelect(array())
341 383
 			->selectField('"ProductAttributeValue"."ID"', 'Value')
@@ -367,7 +409,9 @@  discard block
 block discarded – undo
367 409
 
368 410
 		// this is the easiest way to get SiteTree vs SiteTree_Live
369 411
 		$baseTable = $q->getFrom();
370
-		if (is_array($baseTable)) $baseTable = reset($baseTable);
412
+		if (is_array($baseTable)) {
413
+			$baseTable = reset($baseTable);
414
+		}
371 415
 
372 416
 		$q = $q->setSelect(array())
373 417
 			->selectField('"ProductAttributeType"."ID"', 'TypeID')
@@ -395,7 +439,9 @@  discard block
 block discarded – undo
395 439
 		$curFacet = null;
396 440
 		foreach ($q as $row) {
397 441
 			if ($curType != $row['TypeID']) {
398
-				if ($curType > 0) $facets['ATT'.$curType] = $curFacet;
442
+				if ($curType > 0) {
443
+					$facets['ATT'.$curType] = $curFacet;
444
+				}
399 445
 				$curType = $row['TypeID'];
400 446
 				$curFacet = array(
401 447
 					'Label'  => $row['TypeLabel'],
@@ -410,7 +456,9 @@  discard block
 block discarded – undo
410 456
 			$curFacet['Values'][ $row['Value'] ] = new ArrayData($row);
411 457
 		}
412 458
 
413
-		if ($curType > 0) $facets['ATT'.$curType] = $curFacet;
459
+		if ($curType > 0) {
460
+			$facets['ATT'.$curType] = $curFacet;
461
+		}
414 462
 		return $facets;
415 463
 	}
416 464
 
@@ -432,7 +480,9 @@  discard block
 block discarded – undo
432 480
 			switch ($facet->Type) {
433 481
 				case ShopSearch::FACET_TYPE_RANGE:
434 482
 					$params = array_merge($baseParams, array());
435
-					if (!isset($params[$qs_f])) $params[$qs_f] = array();
483
+					if (!isset($params[$qs_f])) {
484
+						$params[$qs_f] = array();
485
+					}
436 486
 					$params[$qs_f][$facet->Source] = 'RANGEFACETVALUE';
437 487
 					$params[$qs_t] = $facet->Label . ': RANGEFACETLABEL';
438 488
 					$facet->Link = $baseLink . '?' . http_build_query($params);
@@ -453,7 +503,9 @@  discard block
 block discarded – undo
453 503
 						$params = array_merge($baseParams, array());
454 504
 
455 505
 						// add the filter for this value
456
-						if (!isset($params[$qs_f])) $params[$qs_f] = array();
506
+						if (!isset($params[$qs_f])) {
507
+							$params[$qs_f] = array();
508
+						}
457 509
 						if ($facet->Type == ShopSearch::FACET_TYPE_CHECKBOX) {
458 510
 							unset($params[$qs_f][$facet->Source]); // this will be figured out via javascript
459 511
 							$params[$qs_t] = ($value->Active ? 'Remove ' : '') . $facet->Label . ': ' . $value->Label;
@@ -481,7 +533,9 @@  discard block
 block discarded – undo
481 533
 
482 534
 		foreach ($children as $child) {
483 535
 			$out[$child->Value] = $child->Value;
484
-			if (!empty($child->Children)) $out += $this->getRecursiveChildValues($child->Children);
536
+			if (!empty($child->Children)) {
537
+				$out += $this->getRecursiveChildValues($child->Children);
538
+			}
485 539
 		}
486 540
 
487 541
 		return $out;
@@ -507,7 +561,9 @@  discard block
 block discarded – undo
507 561
 					}
508 562
 				} else {
509 563
 					$filterVals = $filters[$facet->Source];
510
-					if (!is_array($filterVals)) $filterVals = array($filterVals);
564
+					if (!is_array($filterVals)) {
565
+						$filterVals = array($filterVals);
566
+					}
511 567
 					$this->updateCheckboxFacetState(
512 568
 						!empty($facet->NestedValues) ? $facet->NestedValues : $facet->Values,
513 569
 						$filterVals,
@@ -541,7 +597,9 @@  discard block
 block discarded – undo
541 597
 					// This wouldn't be normal, but even if it's not a leaf, we want to handle
542 598
 					// the case where a filter might be set for this node. It should still show up correctly.
543 599
 					$value->Active = true;
544
-					foreach ($value->Children as $c) $c->Active = true;
600
+					foreach ($value->Children as $c) {
601
+						$c->Active = true;
602
+					}
545 603
 					// TODO: handle more than one level of recursion here
546 604
 				} else {
547 605
 					$value->Active = $this->updateCheckboxFacetState($value->Children, $filterVals, $filterOnlyLeaves);
@@ -550,7 +608,9 @@  discard block
 block discarded – undo
550 608
 				$value->Active = in_array($value->Value, $filterVals);
551 609
 			}
552 610
 
553
-			if ($value->Active) $out = true;
611
+			if ($value->Active) {
612
+				$out = true;
613
+			}
554 614
 		}
555 615
 
556 616
 		return $out;
@@ -571,19 +631,25 @@  discard block
 block discarded – undo
571 631
 				$parentStack = array();
572 632
 
573 633
 				foreach ($facet->Values as $value) {
574
-					if (empty($value->Label)) continue;
634
+					if (empty($value->Label)) {
635
+						continue;
636
+					}
575 637
 					$value->FullLabel = $value->Label;
576 638
 
577 639
 					// Look for the most recent parent that matches the beginning of this one
578 640
 					while (count($parentStack) > 0) {
579 641
 						$curParent = $parentStack[ count($parentStack)-1 ];
580 642
 						if (strpos($value->Label, $curParent->FullLabel) === 0) {
581
-							if (!isset($curParent->Children)) $curParent->Children = new ArrayList();
643
+							if (!isset($curParent->Children)) {
644
+								$curParent->Children = new ArrayList();
645
+							}
582 646
 
583 647
 							// Modify the name so we only show the last component
584 648
 							$value->FullLabel = $value->Label;
585 649
 							$p = strrpos($value->Label, $facet->HierarchyDivider);
586
-							if ($p > -1) $value->Label = trim( substr($value->Label, $p + 1) );
650
+							if ($p > -1) {
651
+								$value->Label = trim( substr($value->Label, $p + 1) );
652
+							}
587 653
 
588 654
 							$curParent->Children->push($value);
589 655
 							break;
Please login to merge, or discard this patch.
code/helpers/FacetedCategory.php 1 patch
Braces   +21 added lines, -7 removed lines patch added patch discarded remove patch
@@ -40,7 +40,9 @@  discard block
 block discarded – undo
40 40
 		if (Config::inst()->get('FacetedCategory', 'show_disabled_facets_tab')) {
41 41
 			$spec = FacetHelper::inst()->expandFacetSpec( $this->getFacetSpec() );
42 42
 			$facets = array();
43
-			foreach ($spec as $f => $v) $facets[$f] = $v['Label'];
43
+			foreach ($spec as $f => $v) {
44
+				$facets[$f] = $v['Label'];
45
+			}
44 46
 			$fields->addFieldToTab('Root.Facets', CheckboxSetField::create('DisabledFacets', "Don't show the following facets for this category:", $facets));
45 47
 		}
46 48
 	}
@@ -68,10 +70,14 @@  discard block
 block discarded – undo
68 70
 	 */
69 71
 	protected function getFilters() {
70 72
 		$qs_f       = Config::inst()->get('ShopSearch', 'qs_filters');
71
-		if (!$qs_f) return array();
73
+		if (!$qs_f) {
74
+			return array();
75
+		}
72 76
 		$request    = $this->getController()->getRequest();
73 77
 		$filters    = $request->requestVar($qs_f);
74
-		if (empty($filters) || !is_array($filters)) return array();
78
+		if (empty($filters) || !is_array($filters)) {
79
+			return array();
80
+		}
75 81
 		return FacetHelper::inst()->scrubFilters($filters);
76 82
 	}
77 83
 
@@ -83,7 +89,9 @@  discard block
 block discarded – undo
83 89
 	public function FilteredProducts($recursive=true) {
84 90
 		if (!isset($this->_filteredProducts)) {
85 91
 			$fn = Config::inst()->get('FacetedCategory', 'products_method');
86
-			if (empty($fn)) $fn = 'ProductsShowable';
92
+			if (empty($fn)) {
93
+				$fn = 'ProductsShowable';
94
+			}
87 95
 			$this->_filteredProducts = $this->owner->$fn($recursive);
88 96
 			$this->_filteredProducts = FacetHelper::inst()->addFiltersToDataList($this->_filteredProducts, $this->getFilters());
89 97
 		}
@@ -98,7 +106,9 @@  discard block
 block discarded – undo
98 106
 	 * @return array
99 107
 	 */
100 108
 	public function getDisabledFacetsArray() {
101
-		if (empty($this->owner->DisabledFacets)) return array();
109
+		if (empty($this->owner->DisabledFacets)) {
110
+			return array();
111
+		}
102 112
 		return explode(',', $this->owner->DisabledFacets);
103 113
 	}
104 114
 
@@ -108,11 +118,15 @@  discard block
 block discarded – undo
108 118
 	 */
109 119
 	public function Facets() {
110 120
 		$spec       = $this->getFacetSpec();
111
-		if (empty($spec)) return new ArrayList;
121
+		if (empty($spec)) {
122
+			return new ArrayList;
123
+		}
112 124
 
113 125
 		// remove any disabled facets
114 126
 		foreach ($this->getDisabledFacetsArray() as $disabled) {
115
-			if (isset($spec[$disabled])) unset($spec[$disabled]);
127
+			if (isset($spec[$disabled])) {
128
+				unset($spec[$disabled]);
129
+			}
116 130
 		}
117 131
 
118 132
 		$request    = $this->getController()->getRequest();
Please login to merge, or discard this patch.
code/helpers/HasStaticAttributes.php 1 patch
Braces   +21 added lines, -7 removed lines patch added patch discarded remove patch
@@ -70,7 +70,9 @@  discard block
 block discarded – undo
70 70
 		}
71 71
 
72 72
 		foreach ($this->owner->StaticAttributeValues() as $val) {
73
-			if (!isset($list[$val->TypeID])) continue;
73
+			if (!isset($list[$val->TypeID])) {
74
+				continue;
75
+			}
74 76
 			$list[$val->TypeID]->ActiveValues->push($val);
75 77
 		}
76 78
 
@@ -86,7 +88,9 @@  discard block
 block discarded – undo
86 88
 			$defaultAttributes = Config::inst()->get($this->owner->ClassName, 'default_attributes');
87 89
 			if (!empty($defaultAttributes)) {
88 90
 				$types = $this->owner->StaticAttributeTypes();
89
-				foreach ($defaultAttributes as $typeID) $types->add($typeID);
91
+				foreach ($defaultAttributes as $typeID) {
92
+					$types->add($typeID);
93
+				}
90 94
 			}
91 95
 		}
92 96
 	}
@@ -131,11 +135,17 @@  discard block
 block discarded – undo
131 135
 	 */
132 136
 	public function saveInto(DataObjectInterface $record) {
133 137
 		$fieldname  = $this->getFieldName();
134
-		if (empty($fieldname)) return;
138
+		if (empty($fieldname)) {
139
+			return;
140
+		}
135 141
 		$typeID     = $this->getAttributeTypeID();
136
-		if (empty($typeID)) return;
142
+		if (empty($typeID)) {
143
+			return;
144
+		}
137 145
 		$relation   = $record->$fieldname();
138
-		if (!$relation) return;
146
+		if (!$relation) {
147
+			return;
148
+		}
139 149
 		$relation   = $relation->filter('TypeID', $typeID);
140 150
 
141 151
 		// make a list of id's that should be there
@@ -160,10 +170,14 @@  discard block
 block discarded – undo
160 170
 		}
161 171
 
162 172
 		// add
163
-		foreach ($idList as $id) $relation->add($id);
173
+		foreach ($idList as $id) {
174
+			$relation->add($id);
175
+		}
164 176
 
165 177
 		// remove
166
-		foreach ($toDelete as $id) $relation->removeByID($id);
178
+		foreach ($toDelete as $id) {
179
+			$relation->removeByID($id);
180
+		}
167 181
 	}
168 182
 
169 183
 
Please login to merge, or discard this patch.