PDA

View Full Version : Modification to Quick Search: Restrict to 1 Year, Not a range



Claire Nicholson
November 28, 2014, 03:41 PM
Hello!

We're looking to make a change to the year selection option in the quick search. Unfortunately this isn't an option in the configuration settings.

We need to restrict this to 1 year that a user can search on, not a range of years.

Any ideas how this can be achieved?

Thanks!

Quinn

Viktor
November 29, 2014, 08:30 AM
Hello Claire,

You can try to change it yourself in code. Open file: ftp://templates>>your_template>>tpl>>blocks>>fields_refine.tpl

find code:



{if $field.Condition == 'years'}
<select name="f[{$field.Key}][from]" class="w70">
<option value="0">{$lang.from}</option>
{foreach from=$field.Values item='option' key='key'}
{if $field.Condition}
{assign var='key' value=$option.Key}
{/if}
<option {if $fVal.$fKey.from}{if $fVal.$fKey.from == $key}selected="selected"{/if}{/if} value="{if $field.Condition}{$option.Key}{else}{$key}{/if}">{$option.name}</option>
{/foreach}
</select><select name="f[{$field.Key}][to]" class="w70">
<option value="0">{$lang.to}</option>
{foreach from=$field.Values item='option' key='key'}
{if $field.Condition}
{assign var='key' value=$option.Key}
{/if}
<option {if $fVal.$fKey.to}{if $fVal.$fKey.to == $key}selected="selected"{/if}{/if} value="{if $field.Condition}{$option.Key}{else}{$key}{/if}">{$option.name}</option>
{/foreach}
</select>


and replace to:



{if $field.Condition == 'years'}
<select name="f[{$field.Key}]" class="w70">
<option value="0">{$lang.any}</option>
{foreach from=$field.Values item='option' key='key'}
{if $field.Condition}
{assign var='key' value=$option.Key}
{/if}
<option {if $fVal.$fKey}{if $fVal.$fKey== $key}selected="selected"{/if}{/if} value="{if $field.Condition}{$option.Key}{else}{$key}{/if}">{$option.name}</option>
{/foreach}
</select>


Also you should change same code in file: ftp://templates>>your_template>>tpl>>blocks>>fields_search.tpl

Then open file: ftp://includes>>classes>>rlSearch.class.php

find method: search and code:



if ( $form[$fKey]['Condition'] == 'years' )
{
if( $f['from'] )
{
$sql .= "AND `T1`.`{$fKey}` >= '".(int)$f['from']."' ";
}
if( $f['to'] )
{
$sql .= "AND `T1`.`{$fKey}` <= '".(int)$f['to']."' ";
}
}


and replace to:



if ( $form[$fKey]['Condition'] == 'years' )
{
if( $f > 0 )
{
$sql .= "AND `T1`.`{$fKey}` = '".(int)$f."' ";
}
}


save and check again. I hope it should work.

Claire Nicholson
December 2, 2014, 06:23 PM
Thank you, Viktor! I only had to make one small adjustment. The search results wasn't showing any results. I changed this instead and it works like a charm.

includes>>classes>>rlSearch.class.php



if ( $form[$fKey]['Condition'] == 'years' )
{
if( $f['from'] )
{
$sql .= "AND `T1`.`{$fKey}` >= '".(int)$f['from']."' ";
}
if( $f['to'] )
{
$sql .= "AND `T1`.`{$fKey}` <= '".(int)$f['to']."' ";
}
}


to



if ( $form[$fKey]['Condition'] == 'years' )
{
if( $f['from'] )
{
$sql .= "AND `T1`.`{$fKey}` >= '".(int)$f['from']."' ";
}

}


You're my boy, Viktor!

Cheers,

Quinn