pre_get_listings_listpage_query

Filter Hook Listings List

Filter the listings query.

Parameters

$listingsRepository

(ListingsRepositoryComponent)

$params

(array) associative array with contextual data

You need to have a working knowledge of Hooks before you get started.

Boilerplate Code

Use the boilerplate code to start using the filter, and add your own logic to modify the first argument and return it.

Clickfwd\Hook\Filter::add('pre_get_listings_listpage_query', function($listingsRepository, $params) 
{
  // Uncomment line below to view available data passed into hook
  // For JReviews 3.x and earlier use dd instead of fwd_dd
  // fwd_dd($listingsRepository, $params);
  
  return $listingsRepository;
});
Development & Support
Customizations are not included with support. We provide this information to make it easier for developers to extend the functionality. From time to time we may have some availability for custom work. Get in touch to see if there's an opportunity to work together.

Examples

JReviews uses the listing ID as secondary ordering by default because it can be found in the same database table as the featured status. This example changes that to use the real creation date which can lead to decreased performance because it uses an ORDER BY statement with cross-table columns.

To use the modified date, replace _LISTING_CREATE_DATE with _LISTING_MODIFIED.

Clickfwd\Hook\Filter::add('pre_get_listings_listpage_query', function($ListingsRepository, $params)
{
	$model = $ListingsRepository->getModel();
 
	if (! isset($model->order['featured']))
	{
    	return $ListingsRepository;
	}
 
    $model->order['featured'] = 'Field.featured DESC, Listing.'.EverywhereComContentModel::_LISTING_CREATE_DATE.' DESC';
  
  	return $ListingsRepository;
}, 10);

This example can lead to decreased performance because it uses an ORDER BY statement with cross-table columns. This will become more noticeable in sites with a large number of listings.

function featured_most_recent_transactions_ordering($ListingsRepository, $params)
{
    $model = $ListingsRepository->getModel();
 
	if (! isset($model->order['featured']) )
	{
  		return $ListingsRepository;      
	}
  
    $ListingsRepository->joins('LEFT JOIN #__jreviews_paid_orders AS PaidOrder ON Listing.'.$model::_LISTING_ID.' = PaidOrder.listing_id AND PaidOrder.order_amount > 0 AND order_active = 1');

    $model->order['featured'] = 'Field.featured DESC, PaidOrder.order_created DESC';

    $ListingsRepository->group('Field.contentid');
  
  	return $ListingsRepository;
}
 
Clickfwd\Hook\Filter::add('pre_get_listings_listpage_query', 'featured_most_recent_transactions_ordering', 10);
 
// Count query needs to be filtered to prevent duplicate rows in results

function featured_most_recent_transactions_ordering_count($ListingsRepository, $params)
{
    $model = $ListingsRepository->getModel();
 
    if (! isset($model->order['featured']) )
    {
  		return $ListingsRepository;
    }
 
    $ListingsRepository->countColumn('DISTINCT Field.contentid')->group('', true);
    
  	return $ListingsRepository;
}
 
Clickfwd\Hook\Filter::add('pre_get_listings_listpage_query_count', 'featured_most_recent_transactions_ordering_count', 10);

Source

  • /controllers/categories_controller.php