Skip to content
This repository was archived by the owner on Jul 17, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 32 additions & 30 deletions components/com_jsolr/site/models/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct($config = array())
{
parent::__construct($config);

$this->context = $this->option.'.'.$this->name;
$this->context = $this->option . '.' . $this->name;

JFactory::getApplication()->setUserState('com_jsolr.search.results', null);

Expand Down Expand Up @@ -159,25 +159,25 @@ public function getQuery()
$query
->addFilterQuery(
array(
'key'=>'access',
'query'=>'access_i:'.'('.$access.') OR null'));
'key' => 'access',
'query' => 'access_i:' . '(' . $access . ') OR null'));
}
}

if ($lang = $this->getState('query.lang')) {
$query
->addFilterQuery(
array(
'key'=>'lang',
'query'=>'lang_s:('.$lang. " OR *)"));
'key' => 'lang',
'query' => 'lang_s:(' . $lang . " OR *)"));
}

if ($fq = $params->get('fq')) {
$query
->addFilterQuery(
array(
'key'=>'param_fq',
'query'=>$fq));
'key' => 'param_fq',
'query' => $fq));
}

if ($pf = $params->get('pf')) {
Expand Down Expand Up @@ -246,7 +246,7 @@ public function getQuery()

JFactory::getApplication()->setUserState('com_jsolr.search.results', $this->cache[$store]);
} catch (Exception $e) {
JLog::add($e->getCode().' '.$e->getMessage(), JLog::ERROR, 'jsolr');
JLog::add($e->getCode() . ' ' . $e->getMessage(), JLog::ERROR, 'jsolr');
JLog::add((string)$e, JLog::ERROR, 'jsolr');

throw $e;
Expand Down Expand Up @@ -358,38 +358,38 @@ public function getPagination()
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id An identifier string to generate the store id.
* @param string $id An identifier string to generate the store id.
*
* @return string A store id.
*/
protected function getStoreId($id = '')
{
// Add some of the querying params to the store id.
$id .= ':'.$this->getState('query.q');
$id .= ':' . $this->getState('query.q');

if ($params = $this->getState('params')) {
$id .= ':'.$params->get('fq');
$id .= ':' . $params->get('fq');
}

if ($dimension = $this->getState('query.dimension')) {
$id .= ':'.$dimension;
$id .= ':' . $dimension;
}

// Add the list state to the store id.
$id .= ':'.$this->getState('list.start');
$id .= ':'.$this->getState('list.limit');
$id .= ':'.$this->getState('list.ordering');
$id .= ':'.$this->getState('list.direction');
$id .= ':' . $this->getState('list.start');
$id .= ':' . $this->getState('list.limit');
$id .= ':' . $this->getState('list.ordering');
$id .= ':' . $this->getState('list.direction');

return md5($this->context.':'.$id);
return md5($this->context . ':' . $id);
}

/**
* Method to get the search form.
*
* @param array $data An optional array of data for the form to
* @param array $data An optional array of data for the form to
* interrogate.
* @param bool $loadData True if the form is to load its own data
* @param bool $loadData True if the form is to load its own data
* (default case), false if not.
*
* @return JForm A JForm object on success, false on failure.
Expand All @@ -400,23 +400,23 @@ public function getForm($data = array(), $loadData = true)
return $this->form;
}

$context = $this->get('option').'.'.$this->getName();
$context = $this->get('option') . '.' . $this->getName();

// load a custom form xml based on the dimension alias.
$source = 'search';

if ($alias = $this->getState('query.dimension')) {
if ($table = $this->fetchDimension($alias)) {
$template = JFactory::getApplication()->getTemplate();
$overridePath = JPATH_ROOT.'/templates/'.$template.'/html/com_jsolr/forms/'.$table->alias.'.xml';
$overridePath = JPATH_ROOT . '/templates/' . $template . '/html/com_jsolr/forms/' . $table->alias . '.xml';

if (JFile::exists($overridePath)) {
$source = $table->alias;
}
}
}

$this->form = $this->loadForm($context, $source, array('load_data'=>$loadData));
$this->form = $this->loadForm($context, $source, array('load_data' => $loadData));

if (empty($this->form)) {
return false;
Expand All @@ -439,7 +439,7 @@ protected function loadFormData()
$data = $query;
}

$context = $this->get('option').'.'.$this->getName();
$context = $this->get('option') . '.' . $this->getName();

if (version_compare(JVERSION, "3.0", "ge")) {
$this->preprocessData($this->get('context'), $data);
Expand All @@ -451,7 +451,7 @@ protected function loadFormData()
/**
* Get's the language, either from the item or from the Joomla environment.
*
* @param bool $includeRegion True if the region should be included, false
* @param bool $includeRegion True if the region should be included, false
* otherwise. E.g. If true, en-AU would be returned, if false, just en
* would be returned.
*
Expand All @@ -467,12 +467,12 @@ protected function getLanguage($lang, $includeRegion = true)
}

if ($includeRegion) {
$result = $lang;
$result = $lang;
} else {
$parts = explode('-', $lang);

// just return the xx part of the xx-XX language.
$result = JArrayHelper::getValue($parts, 0);
$result = JArrayHelper::getValue($parts, 0);
}

if (empty($result)) {
Expand All @@ -493,7 +493,9 @@ public function getAppliedFacetFilters()

foreach ($this->getForm()->getFieldset('facets') as $facet) {
if (array_search("JSolr\Form\Fields\Facetable", class_implements($facet)) !== false) {
if ($facet->value) {
if (isset($facet->value)) {
$fields[] = $facet;
} else {
$fields[] = $facet;
}
}
Expand Down Expand Up @@ -571,7 +573,7 @@ public function getDimensions()
/**
* Fetch the dimension based on the alias.
*
* @param string $alias The dimension alias.
* @param string $alias The dimension alias.
*
* @return JSolrTableDimension The dimension record or null if no record
* is found.
Expand All @@ -580,7 +582,7 @@ private function fetchDimension($alias)
{
$table = $this->getTable('Dimension', 'JSolrTable');

if ($table->load(array('alias'=>$alias))) {
if ($table->load(array('alias' => $alias))) {
return $table;
} else {
return null;
Expand All @@ -607,7 +609,7 @@ public function getDimensionTemplate()
if ($alias = $this->getState('query.dimension')) {
if ($table = $this->fetchDimension($alias)) {
$template = JFactory::getApplication()->getTemplate();
$overridePath = JPATH_ROOT.'/templates/'.$template.'/html/com_jsolr/search/results_'.$table->alias.'.php';
$overridePath = JPATH_ROOT . '/templates/' . $template . '/html/com_jsolr/search/results_' . $table->alias . '.php';

if (JFile::exists($overridePath)) {
$tmpl = $table->alias;
Expand Down