@@ -322,7 +322,7 @@ discard block  | 
                                                    ||
| 322 | 322 | |
| 323 | 323 | /**  | 
                                                        
| 324 | 324 | * NOTE: this will break if applied to something that's not a SiteTree subclass.  | 
                                                        
| 325 | - * @param DataList|PaginatedList $matches  | 
                                                        |
| 325 | + * @param SS_List $matches  | 
                                                        |
| 326 | 326 | * @param array $facet  | 
                                                        
| 327 | 327 | * @param int $typeID  | 
                                                        
| 328 | 328 | */  | 
                                                        
@@ -359,7 +359,7 @@ discard block  | 
                                                    ||
| 359 | 359 | |
| 360 | 360 | /**  | 
                                                        
| 361 | 361 | * Builds facets from all attributes present in the data set.  | 
                                                        
| 362 | - * @param DataList|PaginatedList $matches  | 
                                                        |
| 362 | + * @param SS_List $matches  | 
                                                        |
| 363 | 363 | * @return array  | 
                                                        
| 364 | 364 | */  | 
                                                        
| 365 | 365 |  	protected function buildAllAttributeFacets($matches) { | 
                                                        
@@ -1,16 +1,16 @@ discard block  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | /**  | 
                                                        
| 3 | - * Adds methods for limited kinds of faceting using the silverstripe ORM.  | 
                                                        |
| 4 | - * This is used by the default ShopSearchSimple adapter but also can  | 
                                                        |
| 5 | - * be added to other contexts (such as ProductCategory).  | 
                                                        |
| 6 | - *  | 
                                                        |
| 7 | - * TODO: Facet class + subclasses  | 
                                                        |
| 8 | - *  | 
                                                        |
| 9 | - * @author Mark Guinn <[email protected]>  | 
                                                        |
| 10 | - * @date 10.21.2013  | 
                                                        |
| 11 | - * @package shop_search  | 
                                                        |
| 12 | - * @subpackage helpers  | 
                                                        |
| 13 | - */  | 
                                                        |
| 3 | + * Adds methods for limited kinds of faceting using the silverstripe ORM.  | 
                                                        |
| 4 | + * This is used by the default ShopSearchSimple adapter but also can  | 
                                                        |
| 5 | + * be added to other contexts (such as ProductCategory).  | 
                                                        |
| 6 | + *  | 
                                                        |
| 7 | + * TODO: Facet class + subclasses  | 
                                                        |
| 8 | + *  | 
                                                        |
| 9 | + * @author Mark Guinn <[email protected]>  | 
                                                        |
| 10 | + * @date 10.21.2013  | 
                                                        |
| 11 | + * @package shop_search  | 
                                                        |
| 12 | + * @subpackage helpers  | 
                                                        |
| 13 | + */  | 
                                                        |
| 14 | 14 | class FacetHelper extends Object  | 
                                                        
| 15 | 15 |  { | 
                                                        
| 16 | 16 | /** @var bool - if this is turned on it will use an algorithm that doesn't require traversing the data set if possible */  | 
                                                        
@@ -380,7 +380,7 @@ discard block  | 
                                                    ||
| 380 | 380 |  			->addInnerJoin('ProductAttributeType', '"Product_StaticAttributeTypes"."ProductAttributeTypeID" = "ProductAttributeType"."ID"') | 
                                                        
| 381 | 381 |  			->addInnerJoin('Product_StaticAttributeValues', $baseTable.'."ID" = "Product_StaticAttributeValues"."ProductID"') | 
                                                        
| 382 | 382 |  			->addInnerJoin('ProductAttributeValue', '"Product_StaticAttributeValues"."ProductAttributeValueID" = "ProductAttributeValue"."ID"' | 
                                                        
| 383 | - . ' AND "ProductAttributeValue"."TypeID" = "ProductAttributeType"."ID"')  | 
                                                        |
| 383 | + . ' AND "ProductAttributeValue"."TypeID" = "ProductAttributeType"."ID"')  | 
                                                        |
| 384 | 384 | ->setOrderBy(array(  | 
                                                        
| 385 | 385 | '"ProductAttributeType"."Label"' => 'ASC',  | 
                                                        
| 386 | 386 | '"ProductAttributeValue"."Sort"' => 'ASC',  | 
                                                        
@@ -59,7 +59,7 @@ discard block  | 
                                                    ||
| 59 | 59 | * @param DataObject|string $sing - just a singleton object we can get information off of  | 
                                                        
| 60 | 60 | * @return DataList  | 
                                                        
| 61 | 61 | */  | 
                                                        
| 62 | -	public function addFiltersToDataList($list, array $filters, $sing=null) { | 
                                                        |
| 62 | +	public function addFiltersToDataList($list, array $filters, $sing = null) { | 
                                                        |
| 63 | 63 | if (!$sing) $sing = singleton($list->dataClass());  | 
                                                        
| 64 | 64 | if (is_string($sing)) $sing = singleton($sing);  | 
                                                        
| 65 | 65 | |
@@ -148,7 +148,7 @@ discard block  | 
                                                    ||
| 148 | 148 | }  | 
                                                        
| 149 | 149 | |
| 150 | 150 | if (empty($facets[$field]['Source'])) $facets[$field]['Source'] = $field;  | 
                                                        
| 151 | - if (empty($facets[$field]['Type'])) $facets[$field]['Type'] = ShopSearch::FACET_TYPE_LINK;  | 
                                                        |
| 151 | + if (empty($facets[$field]['Type'])) $facets[$field]['Type'] = ShopSearch::FACET_TYPE_LINK;  | 
                                                        |
| 152 | 152 | |
| 153 | 153 |  			if (empty($facets[$field]['Values'])) { | 
                                                        
| 154 | 154 | $facets[$field]['Values'] = array();  | 
                                                        
@@ -197,7 +197,7 @@ discard block  | 
                                                    ||
| 197 | 197 | * @param bool $autoFacetAttributes [optional]  | 
                                                        
| 198 | 198 | * @return ArrayList  | 
                                                        
| 199 | 199 | */  | 
                                                        
| 200 | -	public function buildFacets(SS_List $matches, array $facetSpec, $autoFacetAttributes=false) { | 
                                                        |
| 200 | +	public function buildFacets(SS_List $matches, array $facetSpec, $autoFacetAttributes = false) { | 
                                                        |
| 201 | 201 | $facets = $this->expandFacetSpec($facetSpec);  | 
                                                        
| 202 | 202 | if (!$autoFacetAttributes && (empty($facets) || !$matches || !$matches->count())) return new ArrayList();  | 
                                                        
| 203 | 203 | $fasterMethod = (bool)$this->config()->faster_faceting;  | 
                                                        
@@ -340,9 +340,9 @@ discard block  | 
                                                    ||
| 340 | 340 | $q = $q->setSelect(array())  | 
                                                        
| 341 | 341 |  			->selectField('"ProductAttributeValue"."ID"', 'Value') | 
                                                        
| 342 | 342 |  			->selectField('"ProductAttributeValue"."Value"', 'Label') | 
                                                        
| 343 | -			->selectField('count(distinct '.$baseTable.'."ID")', 'Count') | 
                                                        |
| 343 | +			->selectField('count(distinct ' . $baseTable . '."ID")', 'Count') | 
                                                        |
| 344 | 344 |  			->selectField('"ProductAttributeValue"."Sort"') | 
                                                        
| 345 | -			->addInnerJoin('Product_StaticAttributeValues', $baseTable.'."ID" = "Product_StaticAttributeValues"."ProductID"') | 
                                                        |
| 345 | +			->addInnerJoin('Product_StaticAttributeValues', $baseTable . '."ID" = "Product_StaticAttributeValues"."ProductID"') | 
                                                        |
| 346 | 346 |  			->addInnerJoin('ProductAttributeValue', '"Product_StaticAttributeValues"."ProductAttributeValueID" = "ProductAttributeValue"."ID"') | 
                                                        
| 347 | 347 |  			->addWhere(sprintf("\"ProductAttributeValue\".\"TypeID\" = '%d'", $typeID)) | 
                                                        
| 348 | 348 |  			->setOrderBy('"ProductAttributeValue"."Sort"', 'ASC') | 
                                                        
@@ -352,7 +352,7 @@ discard block  | 
                                                    ||
| 352 | 352 | |
| 353 | 353 | $facet['Values'] = array();  | 
                                                        
| 354 | 354 |  		foreach ($q as $row) { | 
                                                        
| 355 | - $facet['Values'][ $row['Value'] ] = new ArrayData($row);  | 
                                                        |
| 355 | + $facet['Values'][$row['Value']] = new ArrayData($row);  | 
                                                        |
| 356 | 356 | }  | 
                                                        
| 357 | 357 | }  | 
                                                        
| 358 | 358 | |
@@ -374,11 +374,11 @@ discard block  | 
                                                    ||
| 374 | 374 |  			->selectField('"ProductAttributeType"."Label"', 'TypeLabel') | 
                                                        
| 375 | 375 |  			->selectField('"ProductAttributeValue"."ID"', 'Value') | 
                                                        
| 376 | 376 |  			->selectField('"ProductAttributeValue"."Value"', 'Label') | 
                                                        
| 377 | -			->selectField('count(distinct '.$baseTable.'."ID")', 'Count') | 
                                                        |
| 377 | +			->selectField('count(distinct ' . $baseTable . '."ID")', 'Count') | 
                                                        |
| 378 | 378 |  			->selectField('"ProductAttributeValue"."Sort"') | 
                                                        
| 379 | -			->addInnerJoin('Product_StaticAttributeTypes', $baseTable.'."ID" = "Product_StaticAttributeTypes"."ProductID"') | 
                                                        |
| 379 | +			->addInnerJoin('Product_StaticAttributeTypes', $baseTable . '."ID" = "Product_StaticAttributeTypes"."ProductID"') | 
                                                        |
| 380 | 380 |  			->addInnerJoin('ProductAttributeType', '"Product_StaticAttributeTypes"."ProductAttributeTypeID" = "ProductAttributeType"."ID"') | 
                                                        
| 381 | -			->addInnerJoin('Product_StaticAttributeValues', $baseTable.'."ID" = "Product_StaticAttributeValues"."ProductID"') | 
                                                        |
| 381 | +			->addInnerJoin('Product_StaticAttributeValues', $baseTable . '."ID" = "Product_StaticAttributeValues"."ProductID"') | 
                                                        |
| 382 | 382 |  			->addInnerJoin('ProductAttributeValue', '"Product_StaticAttributeValues"."ProductAttributeValueID" = "ProductAttributeValue"."ID"' | 
                                                        
| 383 | 383 | . ' AND "ProductAttributeValue"."TypeID" = "ProductAttributeType"."ID"')  | 
                                                        
| 384 | 384 | ->setOrderBy(array(  | 
                                                        
@@ -395,11 +395,11 @@ discard block  | 
                                                    ||
| 395 | 395 | $curFacet = null;  | 
                                                        
| 396 | 396 |  		foreach ($q as $row) { | 
                                                        
| 397 | 397 |  			if ($curType != $row['TypeID']) { | 
                                                        
| 398 | - if ($curType > 0) $facets['ATT'.$curType] = $curFacet;  | 
                                                        |
| 398 | + if ($curType > 0) $facets['ATT' . $curType] = $curFacet;  | 
                                                        |
| 399 | 399 | $curType = $row['TypeID'];  | 
                                                        
| 400 | 400 | $curFacet = array(  | 
                                                        
| 401 | 401 | 'Label' => $row['TypeLabel'],  | 
                                                        
| 402 | - 'Source' => 'ATT'.$curType,  | 
                                                        |
| 402 | + 'Source' => 'ATT' . $curType,  | 
                                                        |
| 403 | 403 | 'Type' => ShopSearch::FACET_TYPE_LINK,  | 
                                                        
| 404 | 404 | 'Values' => array(),  | 
                                                        
| 405 | 405 | );  | 
                                                        
@@ -407,10 +407,10 @@ discard block  | 
                                                    ||
| 407 | 407 | |
| 408 | 408 | unset($row['TypeID']);  | 
                                                        
| 409 | 409 | unset($row['TypeLabel']);  | 
                                                        
| 410 | - $curFacet['Values'][ $row['Value'] ] = new ArrayData($row);  | 
                                                        |
| 410 | + $curFacet['Values'][$row['Value']] = new ArrayData($row);  | 
                                                        |
| 411 | 411 | }  | 
                                                        
| 412 | 412 | |
| 413 | - if ($curType > 0) $facets['ATT'.$curType] = $curFacet;  | 
                                                        |
| 413 | + if ($curType > 0) $facets['ATT' . $curType] = $curFacet;  | 
                                                        |
| 414 | 414 | return $facets;  | 
                                                        
| 415 | 415 | }  | 
                                                        
| 416 | 416 | |
@@ -532,7 +532,7 @@ discard block  | 
                                                    ||
| 532 | 532 | * @param bool $filterOnlyLeaves [optional]  | 
                                                        
| 533 | 533 | * @return bool - true if any of the children are true, false if all children are false  | 
                                                        
| 534 | 534 | */  | 
                                                        
| 535 | -	protected function updateCheckboxFacetState(ArrayList $values, array $filterVals, $filterOnlyLeaves=false) { | 
                                                        |
| 535 | +	protected function updateCheckboxFacetState(ArrayList $values, array $filterVals, $filterOnlyLeaves = false) { | 
                                                        |
| 536 | 536 | $out = false;  | 
                                                        
| 537 | 537 | |
| 538 | 538 |  		foreach ($values as $value) { | 
                                                        
@@ -576,14 +576,14 @@ discard block  | 
                                                    ||
| 576 | 576 | |
| 577 | 577 | // Look for the most recent parent that matches the beginning of this one  | 
                                                        
| 578 | 578 |  					while (count($parentStack) > 0) { | 
                                                        
| 579 | - $curParent = $parentStack[ count($parentStack)-1 ];  | 
                                                        |
| 579 | + $curParent = $parentStack[count($parentStack) - 1];  | 
                                                        |
| 580 | 580 |  						if (strpos($value->Label, $curParent->FullLabel) === 0) { | 
                                                        
| 581 | 581 | if (!isset($curParent->Children)) $curParent->Children = new ArrayList();  | 
                                                        
| 582 | 582 | |
| 583 | 583 | // Modify the name so we only show the last component  | 
                                                        
| 584 | 584 | $value->FullLabel = $value->Label;  | 
                                                        
| 585 | 585 | $p = strrpos($value->Label, $facet->HierarchyDivider);  | 
                                                        
| 586 | - if ($p > -1) $value->Label = trim( substr($value->Label, $p + 1) );  | 
                                                        |
| 586 | + if ($p > -1) $value->Label = trim(substr($value->Label, $p + 1));  | 
                                                        |
| 587 | 587 | |
| 588 | 588 | $curParent->Children->push($value);  | 
                                                        
| 589 | 589 | break;  | 
                                                        
@@ -41,12 +41,18 @@ discard block  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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;  | 
                                                        
@@ -49,7 +49,7 @@  | 
                                                    ||
| 49 | 49 | |
| 50 | 50 | /**  | 
                                                        
| 51 | 51 | * @param $typeID  | 
                                                        
| 52 | - * @return callable  | 
                                                        |
| 52 | + * @return Closure  | 
                                                        |
| 53 | 53 | */  | 
                                                        
| 54 | 54 |  	protected function getValuesClosure($typeID) { | 
                                                        
| 55 | 55 |  		return function() use ($typeID) { | 
                                                        
@@ -1,14 +1,14 @@  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | /**  | 
                                                        
| 3 | - * Extension for Product that allows static attributes in the same way  | 
                                                        |
| 4 | - * they're used for variations. I'm separating this out because it will  | 
                                                        |
| 5 | - * probably be useful in other projects.  | 
                                                        |
| 6 | - *  | 
                                                        |
| 7 | - * @author Mark Guinn <[email protected]>  | 
                                                        |
| 8 | - * @date 01.21.2014  | 
                                                        |
| 9 | - * @package Daywind  | 
                                                        |
| 10 | - * @subpackage extensions  | 
                                                        |
| 11 | - */  | 
                                                        |
| 3 | + * Extension for Product that allows static attributes in the same way  | 
                                                        |
| 4 | + * they're used for variations. I'm separating this out because it will  | 
                                                        |
| 5 | + * probably be useful in other projects.  | 
                                                        |
| 6 | + *  | 
                                                        |
| 7 | + * @author Mark Guinn <[email protected]>  | 
                                                        |
| 8 | + * @date 01.21.2014  | 
                                                        |
| 9 | + * @package Daywind  | 
                                                        |
| 10 | + * @subpackage extensions  | 
                                                        |
| 11 | + */  | 
                                                        |
| 12 | 12 | class HasStaticAttributes extends DataExtension  | 
                                                        
| 13 | 13 |  { | 
                                                        
| 14 | 14 | private static $many_many = array(  | 
                                                        
@@ -38,8 +38,8 @@ discard block  | 
                                                    ||
| 38 | 38 | |
| 39 | 39 |  			$newValReq = RequiredFields::create('Value'); | 
                                                        
| 40 | 40 | |
| 41 | -			$valuesField = HasStaticAttributes_CheckboxSetField::create('StaticAttributeValues-'.$type->ID, $type->Title, $source()); | 
                                                        |
| 42 | -			$valuesField->setValue( $this->owner->StaticAttributeValues()->filter('TypeID', $type->ID)->getIDList() ); | 
                                                        |
| 41 | +			$valuesField = HasStaticAttributes_CheckboxSetField::create('StaticAttributeValues-' . $type->ID, $type->Title, $source()); | 
                                                        |
| 42 | +			$valuesField->setValue($this->owner->StaticAttributeValues()->filter('TypeID', $type->ID)->getIDList()); | 
                                                        |
| 43 | 43 |  			$valuesField->useAddNew('ProductAttributeValue', $source, $newValFields, $newValReq); | 
                                                        
| 44 | 44 | |
| 45 | 45 |  			$fields->addFieldToTab('Root.Attributes', $valuesField); | 
                                                        
@@ -141,8 +141,8 @@ discard block  | 
                                                    ||
| 141 | 141 | // make a list of id's that should be there  | 
                                                        
| 142 | 142 | $idList = array();  | 
                                                        
| 143 | 143 |  		if (!empty($this->value) && is_array($this->value)) { | 
                                                        
| 144 | -			foreach($this->value as $id => $bool) { | 
                                                        |
| 145 | -				if($bool) { | 
                                                        |
| 144 | +			foreach ($this->value as $id => $bool) { | 
                                                        |
| 145 | +				if ($bool) { | 
                                                        |
| 146 | 146 | $idList[$id] = $id;  | 
                                                        
| 147 | 147 | }  | 
                                                        
| 148 | 148 | }  | 
                                                        
@@ -70,7 +70,9 @@ discard block  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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 | |
@@ -214,7 +214,7 @@  | 
                                                    ||
| 214 | 214 | }  | 
                                                        
| 215 | 215 | |
| 216 | 216 | /**  | 
                                                        
| 217 | - * @param $name  | 
                                                        |
| 217 | + * @param string $name  | 
                                                        |
| 218 | 218 | * @return string  | 
                                                        
| 219 | 219 | */  | 
                                                        
| 220 | 220 |  	public function getVFIFieldName($name) { | 
                                                        
@@ -57,14 +57,14 @@  | 
                                                    ||
| 57 | 57 | |
| 58 | 58 | public static $disable_building = false;  | 
                                                        
| 59 | 59 | |
| 60 | - /**  | 
                                                        |
| 61 | - * @return array  | 
                                                        |
| 62 | - */  | 
                                                        |
| 63 | -    public static function get_classes_with_vfi() { | 
                                                        |
| 64 | -        $vfi_def = Config::inst()->get('VirtualFieldIndex', 'vfi_spec'); | 
                                                        |
| 65 | - if (!$vfi_def || !is_array($vfi_def)) return array();  | 
                                                        |
| 66 | - return array_keys($vfi_def);  | 
                                                        |
| 67 | - }  | 
                                                        |
| 60 | + /**  | 
                                                        |
| 61 | + * @return array  | 
                                                        |
| 62 | + */  | 
                                                        |
| 63 | +	public static function get_classes_with_vfi() { | 
                                                        |
| 64 | +		$vfi_def = Config::inst()->get('VirtualFieldIndex', 'vfi_spec'); | 
                                                        |
| 65 | + if (!$vfi_def || !is_array($vfi_def)) return array();  | 
                                                        |
| 66 | + return array_keys($vfi_def);  | 
                                                        |
| 67 | + }  | 
                                                        |
| 68 | 68 | |
| 69 | 69 | /**  | 
                                                        
| 70 | 70 | * Define extra db fields and indexes.  | 
                                                        
@@ -143,7 +143,7 @@ discard block  | 
                                                    ||
| 143 | 143 | *  | 
                                                        
| 144 | 144 | * @param string $class [optional] - if not given all indexes will be rebuilt  | 
                                                        
| 145 | 145 | */  | 
                                                        
| 146 | -	public static function build($class='') { | 
                                                        |
| 146 | +	public static function build($class = '') { | 
                                                        |
| 147 | 147 |  		if ($class) { | 
                                                        
| 148 | 148 | $list = DataObject::get($class);  | 
                                                        
| 149 | 149 | $count = $list->count();  | 
                                                        
@@ -168,12 +168,12 @@ discard block  | 
                                                    ||
| 168 | 168 | $val = $this->getVFI($field, true);  | 
                                                        
| 169 | 169 | |
| 170 | 170 |  			if ($spec['Type'] == self::TYPE_LIST) { | 
                                                        
| 171 | - if (is_object($val)) $val = $val->toArray(); // this would be an ArrayList or DataList  | 
                                                        |
| 172 | - if (!is_array($val)) $val = array($val); // this would be a scalar value  | 
                                                        |
| 171 | + if (is_object($val)) $val = $val->toArray(); // this would be an ArrayList or DataList  | 
                                                        |
| 172 | + if (!is_array($val)) $val = array($val); // this would be a scalar value  | 
                                                        |
| 173 | 173 | $val = self::encode_list($val);  | 
                                                        
| 174 | 174 |  			} else { | 
                                                        
| 175 | - if (is_array($val)) $val = (string)$val[0]; // if they give us an array, just take the first value  | 
                                                        |
| 176 | - if (is_object($val)) $val = (string)$val->first(); // if a SS_List, take the first as well  | 
                                                        |
| 175 | + if (is_array($val)) $val = (string)$val[0]; // if they give us an array, just take the first value  | 
                                                        |
| 176 | + if (is_object($val)) $val = (string)$val->first(); // if a SS_List, take the first as well  | 
                                                        |
| 177 | 177 | }  | 
                                                        
| 178 | 178 | |
| 179 | 179 |  			if (Config::inst()->get('VirtualFieldIndex', 'fast_writes_enabled')) { | 
                                                        
@@ -242,7 +242,7 @@ discard block  | 
                                                    ||
| 242 | 242 | * @param bool $forceIDs [optional] - if true, it will return an ID even if the norm is to return a DataObject  | 
                                                        
| 243 | 243 | * @return string|array|SS_List  | 
                                                        
| 244 | 244 | */  | 
                                                        
| 245 | -	public function getVFI($field, $fromSource=false, $forceIDs=false) { | 
                                                        |
| 245 | +	public function getVFI($field, $fromSource = false, $forceIDs = false) { | 
                                                        |
| 246 | 246 | $spec = $this->getVFISpec($field);  | 
                                                        
| 247 | 247 | if (!$spec) return null;  | 
                                                        
| 248 | 248 |  		if ($fromSource) { | 
                                                        
@@ -306,11 +306,11 @@ discard block  | 
                                                    ||
| 306 | 306 | * @param bool $forceIDs [optional] - if true encoded objects will not be returned as objects but as id's  | 
                                                        
| 307 | 307 | * @return array  | 
                                                        
| 308 | 308 | */  | 
                                                        
| 309 | -	protected static function decode_list($val, $forceIDs=false) { | 
                                                        |
| 309 | +	protected static function decode_list($val, $forceIDs = false) { | 
                                                        |
| 310 | 310 |  		if ($val[0] == '>') { | 
                                                        
| 311 | 311 | $firstBar = strpos($val, '|');  | 
                                                        
| 312 | 312 | if ($firstBar < 3) return array();  | 
                                                        
| 313 | - $className = substr($val, 1, $firstBar-1);  | 
                                                        |
| 313 | + $className = substr($val, 1, $firstBar - 1);  | 
                                                        |
| 314 | 314 |  			$ids = explode('|', trim(substr($val, $firstBar), '|')); | 
                                                        
| 315 | 315 |  			return $forceIDs ? $ids : DataObject::get($className)->filter('ID', $ids)->toArray(); | 
                                                        
| 316 | 316 |  		} else { | 
                                                        
@@ -345,7 +345,7 @@ discard block  | 
                                                    ||
| 345 | 345 | // Select db object  | 
                                                        
| 346 | 346 | $component = $dbObject;  | 
                                                        
| 347 | 347 |  				} else { | 
                                                        
| 348 | -					user_error("$relation is not a relation/field on ".get_class($component), E_USER_ERROR); | 
                                                        |
| 348 | +					user_error("$relation is not a relation/field on " . get_class($component), E_USER_ERROR); | 
                                                        |
| 349 | 349 | }  | 
                                                        
| 350 | 350 | }  | 
                                                        
| 351 | 351 | }  | 
                                                        
@@ -62,7 +62,9 @@ discard block  | 
                                                    ||
| 62 | 62 | */  | 
                                                        
| 63 | 63 |      public static function get_classes_with_vfi() { | 
                                                        
| 64 | 64 |          $vfi_def = Config::inst()->get('VirtualFieldIndex', 'vfi_spec'); | 
                                                        
| 65 | - if (!$vfi_def || !is_array($vfi_def)) return array();  | 
                                                        |
| 65 | +        if (!$vfi_def || !is_array($vfi_def)) { | 
                                                        |
| 66 | + return array();  | 
                                                        |
| 67 | + }  | 
                                                        |
| 66 | 68 | return array_keys($vfi_def);  | 
                                                        
| 67 | 69 | }  | 
                                                        
| 68 | 70 | |
@@ -75,7 +77,9 @@ discard block  | 
                                                    ||
| 75 | 77 | */  | 
                                                        
| 76 | 78 |  	public static function get_extra_config($class, $extension, $args) { | 
                                                        
| 77 | 79 | $vfi_def = self::get_vfi_spec($class);  | 
                                                        
| 78 | - if (!$vfi_def || !is_array($vfi_def)) return array();  | 
                                                        |
| 80 | +		if (!$vfi_def || !is_array($vfi_def)) { | 
                                                        |
| 81 | + return array();  | 
                                                        |
| 82 | + }  | 
                                                        |
| 79 | 83 | |
| 80 | 84 | $out = array(  | 
                                                        
| 81 | 85 | 'db' => array(),  | 
                                                        
@@ -99,7 +103,9 @@ discard block  | 
                                                    ||
| 99 | 103 | */  | 
                                                        
| 100 | 104 |  	public static function get_vfi_spec($class) { | 
                                                        
| 101 | 105 |  		$vfi_master = Config::inst()->get('VirtualFieldIndex', 'vfi_spec'); | 
                                                        
| 102 | - if (!$vfi_master || !is_array($vfi_master)) return array();  | 
                                                        |
| 106 | +		if (!$vfi_master || !is_array($vfi_master)) { | 
                                                        |
| 107 | + return array();  | 
                                                        |
| 108 | + }  | 
                                                        |
| 103 | 109 | |
| 104 | 110 | // merge in all the vfi's from ancestors as well  | 
                                                        
| 105 | 111 | $vfi_def = array();  | 
                                                        
@@ -109,7 +115,9 @@ discard block  | 
                                                    ||
| 109 | 115 | $vfi_def = $vfi_master[$c] + $vfi_def;  | 
                                                        
| 110 | 116 | }  | 
                                                        
| 111 | 117 | }  | 
                                                        
| 112 | - if (empty($vfi_def)) return array();  | 
                                                        |
| 118 | +		if (empty($vfi_def)) { | 
                                                        |
| 119 | + return array();  | 
                                                        |
| 120 | + }  | 
                                                        |
| 113 | 121 | |
| 114 | 122 | // convert shorthand to longhand  | 
                                                        
| 115 | 123 |  		foreach ($vfi_def as $k => $v) { | 
                                                        
@@ -129,8 +137,12 @@ discard block  | 
                                                    ||
| 129 | 137 | 'Source' => $v,  | 
                                                        
| 130 | 138 | );  | 
                                                        
| 131 | 139 |  			} else { | 
                                                        
| 132 | - if (!isset($v['Type'])) $vfi_def[$k]['Type'] = is_array($v['Source']) ? self::TYPE_LIST : self::TYPE_SIMPLE;  | 
                                                        |
| 133 | - if (!isset($v['DependsOn'])) $vfi_def[$k]['DependsOn'] = self::DEPENDS_ALL;  | 
                                                        |
| 140 | +				if (!isset($v['Type'])) { | 
                                                        |
| 141 | + $vfi_def[$k]['Type'] = is_array($v['Source']) ? self::TYPE_LIST : self::TYPE_SIMPLE;  | 
                                                        |
| 142 | + }  | 
                                                        |
| 143 | +				if (!isset($v['DependsOn'])) { | 
                                                        |
| 144 | + $vfi_def[$k]['DependsOn'] = self::DEPENDS_ALL;  | 
                                                        |
| 145 | + }  | 
                                                        |
| 134 | 146 | }  | 
                                                        
| 135 | 147 | }  | 
                                                        
| 136 | 148 | |
@@ -150,10 +162,14 @@ discard block  | 
                                                    ||
| 150 | 162 |  			for ($i = 0; $i < $count; $i += 10) { | 
                                                        
| 151 | 163 | $chunk = $list->limit(10, $i);  | 
                                                        
| 152 | 164 | // if (Controller::curr() instanceof TaskRunner) echo "Processing VFI #$i...\n";  | 
                                                        
| 153 | - foreach ($chunk as $rec) $rec->rebuildVFI();  | 
                                                        |
| 165 | +				foreach ($chunk as $rec) { | 
                                                        |
| 166 | + $rec->rebuildVFI();  | 
                                                        |
| 167 | + }  | 
                                                        |
| 154 | 168 | }  | 
                                                        
| 155 | 169 |  		} else { | 
                                                        
| 156 | - foreach (self::get_classes_with_vfi() as $c) self::build($c);  | 
                                                        |
| 170 | +			foreach (self::get_classes_with_vfi() as $c) { | 
                                                        |
| 171 | + self::build($c);  | 
                                                        |
| 172 | + }  | 
                                                        |
| 157 | 173 | }  | 
                                                        
| 158 | 174 | }  | 
                                                        
| 159 | 175 | |
@@ -168,12 +184,24 @@ discard block  | 
                                                    ||
| 168 | 184 | $val = $this->getVFI($field, true);  | 
                                                        
| 169 | 185 | |
| 170 | 186 |  			if ($spec['Type'] == self::TYPE_LIST) { | 
                                                        
| 171 | - if (is_object($val)) $val = $val->toArray(); // this would be an ArrayList or DataList  | 
                                                        |
| 172 | - if (!is_array($val)) $val = array($val); // this would be a scalar value  | 
                                                        |
| 187 | +				if (is_object($val)) { | 
                                                        |
| 188 | + $val = $val->toArray();  | 
                                                        |
| 189 | + }  | 
                                                        |
| 190 | + // this would be an ArrayList or DataList  | 
                                                        |
| 191 | +				if (!is_array($val)) { | 
                                                        |
| 192 | + $val = array($val);  | 
                                                        |
| 193 | + }  | 
                                                        |
| 194 | + // this would be a scalar value  | 
                                                        |
| 173 | 195 | $val = self::encode_list($val);  | 
                                                        
| 174 | 196 |  			} else { | 
                                                        
| 175 | - if (is_array($val)) $val = (string)$val[0]; // if they give us an array, just take the first value  | 
                                                        |
| 176 | - if (is_object($val)) $val = (string)$val->first(); // if a SS_List, take the first as well  | 
                                                        |
| 197 | +				if (is_array($val)) { | 
                                                        |
| 198 | + $val = (string)$val[0];  | 
                                                        |
| 199 | + }  | 
                                                        |
| 200 | + // if they give us an array, just take the first value  | 
                                                        |
| 201 | +				if (is_object($val)) { | 
                                                        |
| 202 | + $val = (string)$val->first();  | 
                                                        |
| 203 | + }  | 
                                                        |
| 204 | + // if a SS_List, take the first as well  | 
                                                        |
| 177 | 205 | }  | 
                                                        
| 178 | 206 | |
| 179 | 207 |  			if (Config::inst()->get('VirtualFieldIndex', 'fast_writes_enabled')) { | 
                                                        
@@ -244,7 +272,9 @@ discard block  | 
                                                    ||
| 244 | 272 | */  | 
                                                        
| 245 | 273 |  	public function getVFI($field, $fromSource=false, $forceIDs=false) { | 
                                                        
| 246 | 274 | $spec = $this->getVFISpec($field);  | 
                                                        
| 247 | - if (!$spec) return null;  | 
                                                        |
| 275 | +		if (!$spec) { | 
                                                        |
| 276 | + return null;  | 
                                                        |
| 277 | + }  | 
                                                        |
| 248 | 278 |  		if ($fromSource) { | 
                                                        
| 249 | 279 |  			if (is_array($spec['Source'])) { | 
                                                        
| 250 | 280 | $out = array();  | 
                                                        
@@ -291,7 +321,9 @@ discard block  | 
                                                    ||
| 291 | 321 | // If we've got objects, encode them a little differently  | 
                                                        
| 292 | 322 |  		if (count($list) > 0 && is_object($list[0])) { | 
                                                        
| 293 | 323 | $ids = array();  | 
                                                        
| 294 | - foreach ($list as $rec) $ids[] = $rec->ID;  | 
                                                        |
| 324 | +			foreach ($list as $rec) { | 
                                                        |
| 325 | + $ids[] = $rec->ID;  | 
                                                        |
| 326 | + }  | 
                                                        |
| 295 | 327 |  			$val = '>' . $list[0]->ClassName . '|' . implode('|', $ids) . '|'; | 
                                                        
| 296 | 328 |  		} else { | 
                                                        
| 297 | 329 |  			$val = '|' . implode('|', $list) . '|'; | 
                                                        
@@ -309,7 +341,9 @@ discard block  | 
                                                    ||
| 309 | 341 |  	protected static function decode_list($val, $forceIDs=false) { | 
                                                        
| 310 | 342 |  		if ($val[0] == '>') { | 
                                                        
| 311 | 343 | $firstBar = strpos($val, '|');  | 
                                                        
| 312 | - if ($firstBar < 3) return array();  | 
                                                        |
| 344 | +			if ($firstBar < 3) { | 
                                                        |
| 345 | + return array();  | 
                                                        |
| 346 | + }  | 
                                                        |
| 313 | 347 | $className = substr($val, 1, $firstBar-1);  | 
                                                        
| 314 | 348 |  			$ids = explode('|', trim(substr($val, $firstBar), '|')); | 
                                                        
| 315 | 349 |  			return $forceIDs ? $ids : DataObject::get($className)->filter('ID', $ids)->toArray(); | 
                                                        
@@ -248,7 +248,7 @@  | 
                                                    ||
| 248 | 248 | |
| 249 | 249 | /**  | 
                                                        
| 250 | 250 | * @param string $str  | 
                                                        
| 251 | - * @return SS_Query  | 
                                                        |
| 251 | + * @return SQLQuery  | 
                                                        |
| 252 | 252 | */  | 
                                                        
| 253 | 253 |  	public function getSuggestQuery($str='') { | 
                                                        
| 254 | 254 |  		$hasResults = 'CASE WHEN max("SearchLog"."NumResults") > 0 THEN 1 ELSE 0 END'; | 
                                                        
@@ -1,11 +1,11 @@  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | /**  | 
                                                        
| 3 | - * Fulltext search index for shop buyables  | 
                                                        |
| 4 | - *  | 
                                                        |
| 5 | - * @author Mark Guinn <[email protected]>  | 
                                                        |
| 6 | - * @date 08.29.2013  | 
                                                        |
| 7 | - * @package shop_search  | 
                                                        |
| 8 | - */  | 
                                                        |
| 3 | + * Fulltext search index for shop buyables  | 
                                                        |
| 4 | + *  | 
                                                        |
| 5 | + * @author Mark Guinn <[email protected]>  | 
                                                        |
| 6 | + * @date 08.29.2013  | 
                                                        |
| 7 | + * @package shop_search  | 
                                                        |
| 8 | + */  | 
                                                        |
| 9 | 9 | class ShopSearch extends Object  | 
                                                        
| 10 | 10 |  { | 
                                                        
| 11 | 11 | const FACET_TYPE_LINK = 'link';  | 
                                                        
@@ -171,12 +171,12 @@ discard block  | 
                                                    ||
| 171 | 171 | * @param int $limit [optional]  | 
                                                        
| 172 | 172 | * @return ArrayData  | 
                                                        
| 173 | 173 | */  | 
                                                        
| 174 | -	public function search(array $vars, $logSearch=true, $useFacets=true, $start=-1, $limit=-1) { | 
                                                        |
| 174 | +	public function search(array $vars, $logSearch = true, $useFacets = true, $start = -1, $limit = -1) { | 
                                                        |
| 175 | 175 |  		$qs_q   = $this->config()->get('qs_query'); | 
                                                        
| 176 | 176 |  		$qs_f   = $this->config()->get('qs_filters'); | 
                                                        
| 177 | 177 |  		$qs_ps  = $this->config()->get('qs_parent_search'); | 
                                                        
| 178 | 178 |  		$qs_t   = $this->config()->get('qs_title'); | 
                                                        
| 179 | -		$qs_sort= $this->config()->get('qs_sort'); | 
                                                        |
| 179 | +		$qs_sort = $this->config()->get('qs_sort'); | 
                                                        |
| 180 | 180 |  		if ($limit < 0) $limit  = $this->config()->get('page_size'); | 
                                                        
| 181 | 181 | if ($start < 0) $start = !empty($vars['start']) ? (int)$vars['start'] : 0; // as far as i can see, fulltextsearch hard codes 'start'  | 
                                                        
| 182 | 182 |  		$facets = $useFacets ? $this->config()->get('facets') : array(); | 
                                                        
@@ -187,7 +187,7 @@ discard block  | 
                                                    ||
| 187 | 187 |  		$sortOptions = $this->config()->get('sort_options'); | 
                                                        
| 188 | 188 | $sort = !empty($vars[$qs_sort]) ? $vars[$qs_sort] : '';  | 
                                                        
| 189 | 189 |  		if (!isset($sortOptions[$sort])) { | 
                                                        
| 190 | - $sort = current(array_keys($sortOptions));  | 
                                                        |
| 190 | + $sort = current(array_keys($sortOptions));  | 
                                                        |
| 191 | 191 | }  | 
                                                        
| 192 | 192 | |
| 193 | 193 | // figure out and scrub the filters  | 
                                                        
@@ -198,7 +198,7 @@ discard block  | 
                                                    ||
| 198 | 198 |  		if ($keywordRegex = $this->config()->get('keyword_filter_regex')) { | 
                                                        
| 199 | 199 | $keywords = preg_replace($keywordRegex, '', $keywords);  | 
                                                        
| 200 | 200 | }  | 
                                                        
| 201 | - $results = self::adapter()->searchFromVars($keywords, $filters, $facets, $start, $limit, $sort);  | 
                                                        |
| 201 | + $results = self::adapter()->searchFromVars($keywords, $filters, $facets, $start, $limit, $sort);  | 
                                                        |
| 202 | 202 | |
| 203 | 203 | // massage the results a bit  | 
                                                        
| 204 | 204 |  		if (!empty($keywords) && !$results->hasValue('Query')) $results->Query = $keywords; | 
                                                        
@@ -250,7 +250,7 @@ discard block  | 
                                                    ||
| 250 | 250 | * @param string $str  | 
                                                        
| 251 | 251 | * @return SS_Query  | 
                                                        
| 252 | 252 | */  | 
                                                        
| 253 | -	public function getSuggestQuery($str='') { | 
                                                        |
| 253 | +	public function getSuggestQuery($str = '') { | 
                                                        |
| 254 | 254 |  		$hasResults = 'CASE WHEN max("SearchLog"."NumResults") > 0 THEN 1 ELSE 0 END'; | 
                                                        
| 255 | 255 | $searchCount = 'count(distinct "SearchLog"."ID")';  | 
                                                        
| 256 | 256 | $q = new SQLQuery();  | 
                                                        
@@ -281,7 +281,7 @@ discard block  | 
                                                    ||
| 281 | 281 | * @param string $str  | 
                                                        
| 282 | 282 | * @return array  | 
                                                        
| 283 | 283 | */  | 
                                                        
| 284 | -	public function suggest($str='') { | 
                                                        |
| 284 | +	public function suggest($str = '') { | 
                                                        |
| 285 | 285 | $adapter = self::adapter();  | 
                                                        
| 286 | 286 |  		if ($adapter->hasMethod('suggest')) { | 
                                                        
| 287 | 287 | return $adapter->suggest($str);  | 
                                                        
@@ -327,7 +327,7 @@ discard block  | 
                                                    ||
| 327 | 327 | ? $results['products']->getTotalItems()  | 
                                                        
| 328 | 328 | : $results['products']->count();  | 
                                                        
| 329 | 329 | |
| 330 | - $products = array();  | 
                                                        |
| 330 | + $products = array();  | 
                                                        |
| 331 | 331 |  			foreach ($results['products'] as $prod) { | 
                                                        
| 332 | 332 | if (!$prod || !$prod->exists()) continue;  | 
                                                        
| 333 | 333 |  				$img = $prod->hasMethod('ProductImage') ? $prod->ProductImage() : $prod->Image(); | 
                                                        
@@ -177,11 +177,20 @@ discard block  | 
                                                    ||
| 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  | 
                                                    ||
| 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  | 
                                                    ||
| 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 | |
@@ -20,7 +20,7 @@  | 
                                                    ||
| 20 | 20 | |
| 21 | 21 | /**  | 
                                                        
| 22 | 22 | * @param SS_HTTPRequest $req  | 
                                                        
| 23 | - * @return string  | 
                                                        |
| 23 | + * @return SS_HTTPResponse  | 
                                                        |
| 24 | 24 | */  | 
                                                        
| 25 | 25 |  	public function search_suggest(SS_HTTPRequest $req) { | 
                                                        
| 26 | 26 | /** @var SS_HTTPResponse $response */  | 
                                                        
@@ -1,11 +1,11 @@  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | /**  | 
                                                        
| 3 | - * Adds SearchForm and results methods to the controller.  | 
                                                        |
| 4 | - *  | 
                                                        |
| 5 | - * @author Mark Guinn <[email protected]>  | 
                                                        |
| 6 | - * @date 08.29.2013  | 
                                                        |
| 7 | - * @package shop_search  | 
                                                        |
| 8 | - */  | 
                                                        |
| 3 | + * Adds SearchForm and results methods to the controller.  | 
                                                        |
| 4 | + *  | 
                                                        |
| 5 | + * @author Mark Guinn <[email protected]>  | 
                                                        |
| 6 | + * @date 08.29.2013  | 
                                                        |
| 7 | + * @package shop_search  | 
                                                        |
| 8 | + */  | 
                                                        |
| 9 | 9 | class ShopSearchControllerExtension extends Extension  | 
                                                        
| 10 | 10 |  { | 
                                                        
| 11 | 11 |  	private static $allowed_actions = array('SearchForm', 'results', 'search_suggest'); | 
                                                        
@@ -30,7 +30,7 @@ discard block  | 
                                                    ||
| 30 | 30 | // convert the search results into usable json for search-as-you-type  | 
                                                        
| 31 | 31 |  		if (ShopSearch::config()->search_as_you_type_enabled) { | 
                                                        
| 32 | 32 | $searchVars = $req->requestVars();  | 
                                                        
| 33 | - $searchVars[ ShopSearch::config()->qs_query ] = $searchVars['term'];  | 
                                                        |
| 33 | + $searchVars[ShopSearch::config()->qs_query] = $searchVars['term'];  | 
                                                        |
| 34 | 34 | unset($searchVars['term']);  | 
                                                        
| 35 | 35 | $results = ShopSearch::inst()->suggestWithResults($searchVars);  | 
                                                        
| 36 | 36 |  		} else { | 
                                                        
@@ -56,7 +56,7 @@ discard block  | 
                                                    ||
| 56 | 56 | */  | 
                                                        
| 57 | 57 |  	public function onAfterInit() { | 
                                                        
| 58 | 58 | $req = $this->owner->getRequest();  | 
                                                        
| 59 | -		$src = $req->requestVar( Config::inst()->get('ShopSearch', 'qs_source') ); | 
                                                        |
| 59 | +		$src = $req->requestVar(Config::inst()->get('ShopSearch', 'qs_source')); | 
                                                        |
| 60 | 60 |  		if ($src) { | 
                                                        
| 61 | 61 |  			$qs_q   = Config::inst()->get('ShopSearch', 'qs_query'); | 
                                                        
| 62 | 62 |  			$qs_f   = Config::inst()->get('ShopSearch', 'qs_filters'); | 
                                                        
@@ -1,11 +1,11 @@  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | /**  | 
                                                        
| 3 | - * Interface for shop search drivers.  | 
                                                        |
| 4 | - *  | 
                                                        |
| 5 | - * @author Mark Guinn <[email protected]>  | 
                                                        |
| 6 | - * @date 09.03.2013  | 
                                                        |
| 7 | - * @package shop_search  | 
                                                        |
| 8 | - */  | 
                                                        |
| 3 | + * Interface for shop search drivers.  | 
                                                        |
| 4 | + *  | 
                                                        |
| 5 | + * @author Mark Guinn <[email protected]>  | 
                                                        |
| 6 | + * @date 09.03.2013  | 
                                                        |
| 7 | + * @package shop_search  | 
                                                        |
| 8 | + */  | 
                                                        |
| 9 | 9 | interface ShopSearchAdapter  | 
                                                        
| 10 | 10 |  { | 
                                                        
| 11 | 11 | /**  | 
                                                        
@@ -17,5 +17,5 @@  | 
                                                    ||
| 17 | 17 | * @param string $sort [optional]  | 
                                                        
| 18 | 18 | * @return ArrayData - must contain at least 'Matches' with an list of data objects that match the search  | 
                                                        
| 19 | 19 | */  | 
                                                        
| 20 | - function searchFromVars($keywords, array $filters=array(), array $facetSpec=array(), $start=-1, $limit=-1, $sort='');  | 
                                                        |
| 20 | + function searchFromVars($keywords, array $filters = array(), array $facetSpec = array(), $start = -1, $limit = -1, $sort = '');  | 
                                                        |
| 21 | 21 | }  | 
                                                        
@@ -1,12 +1,12 @@  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | /**  | 
                                                        
| 3 | - * Pending some changes introduced to the core shop module, this will supply  | 
                                                        |
| 4 | - * some standard, easily overridable ajax features.  | 
                                                        |
| 5 | - *  | 
                                                        |
| 6 | - * @author Mark Guinn <[email protected]>  | 
                                                        |
| 7 | - * @date 07.21.2014  | 
                                                        |
| 8 | - * @package shop_search  | 
                                                        |
| 9 | - */  | 
                                                        |
| 3 | + * Pending some changes introduced to the core shop module, this will supply  | 
                                                        |
| 4 | + * some standard, easily overridable ajax features.  | 
                                                        |
| 5 | + *  | 
                                                        |
| 6 | + * @author Mark Guinn <[email protected]>  | 
                                                        |
| 7 | + * @date 07.21.2014  | 
                                                        |
| 8 | + * @package shop_search  | 
                                                        |
| 9 | + */  | 
                                                        |
| 10 | 10 | class ShopSearchAjax extends Extension  | 
                                                        
| 11 | 11 |  { | 
                                                        
| 12 | 12 | /**  | 
                                                        
@@ -17,7 +17,9 @@  | 
                                                    ||
| 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); | 
                                                        
@@ -38,7 +38,7 @@  | 
                                                    ||
| 38 | 38 | |
| 39 | 39 | $emptyString = self::config()->category_empty_string;  | 
                                                        
| 40 | 40 |  			if ($emptyString !== 'NONE') { | 
                                                        
| 41 | -				$catField->setEmptyString(_t('ShopSearch.'.$emptyString, $emptyString)); | 
                                                        |
| 41 | +				$catField->setEmptyString(_t('ShopSearch.' . $emptyString, $emptyString)); | 
                                                        |
| 42 | 42 | }  | 
                                                        
| 43 | 43 | |
| 44 | 44 | $fields->push($catField);  | 
                                                        
@@ -29,7 +29,9 @@ discard block  | 
                                                    ||
| 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  | 
                                                    ||
| 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 | |
@@ -18,7 +18,7 @@ discard block  | 
                                                    ||
| 18 | 18 | * @param string $sort [optional]  | 
                                                        
| 19 | 19 | * @return ArrayData  | 
                                                        
| 20 | 20 | */  | 
                                                        
| 21 | -	function searchFromVars($keywords, array $filters=array(), array $facetSpec=array(), $start=-1, $limit=-1, $sort='') { | 
                                                        |
| 21 | +	function searchFromVars($keywords, array $filters = array(), array $facetSpec = array(), $start = -1, $limit = -1, $sort = '') { | 
                                                        |
| 22 | 22 | $searchable = ShopSearch::get_searchable_classes();  | 
                                                        
| 23 | 23 | $matches = new ArrayList;  | 
                                                        
| 24 | 24 | |
@@ -32,13 +32,13 @@ discard block  | 
                                                    ||
| 32 | 32 | $filter = array();  | 
                                                        
| 33 | 33 | |
| 34 | 34 | // Use parametrized query if SilverStripe >= 3.2  | 
                                                        
| 35 | -			if(SHOP_SEARCH_IS_SS32){ | 
                                                        |
| 36 | -				foreach($keywordFields as $indexFields){ | 
                                                        |
| 35 | +			if (SHOP_SEARCH_IS_SS32) { | 
                                                        |
| 36 | +				foreach ($keywordFields as $indexFields) { | 
                                                        |
| 37 | 37 |  					$filter[] = array("MATCH ($indexFields) AGAINST (?)" => $keywords); | 
                                                        
| 38 | 38 | }  | 
                                                        
| 39 | 39 | $list = $list->whereAny($filter);  | 
                                                        
| 40 | 40 |  			} else { | 
                                                        
| 41 | -				foreach($keywordFields as $indexFields){ | 
                                                        |
| 41 | +				foreach ($keywordFields as $indexFields) { | 
                                                        |
| 42 | 42 |  					$filter[] = sprintf("MATCH ($indexFields) AGAINST ('%s')", Convert::raw2sql($keywords)); | 
                                                        
| 43 | 43 | }  | 
                                                        
| 44 | 44 | // join all the filters with an "OR" statement  | 
                                                        
@@ -78,7 +78,7 @@ discard block  | 
                                                    ||
| 78 | 78 | }  | 
                                                        
| 79 | 79 | }  | 
                                                        
| 80 | 80 | |
| 81 | -		if(count($indexList) === 0){ | 
                                                        |
| 81 | +		if (count($indexList) === 0) { | 
                                                        |
| 82 | 82 |  			throw new Exception("Class $className does not appear to have any fulltext indexes"); | 
                                                        
| 83 | 83 | }  | 
                                                        
| 84 | 84 | |