Book Image

Learning Joomla! 1.5 Extension Development

Book Image

Learning Joomla! 1.5 Extension Development

Overview of this book

Table of Contents (17 chapters)
Learning Joomla! 1.5 Extension Development
Credits
About the Author
About the Reviewer
Preface

Mixing it up


Our module is great at highlighting the latest opinions for our diners, but our frequent visitors may want to see the past reviews. Let's fix that with some adjustments to the helper function that retrieves the reviews. Go to the getReviews() function in the /modules/mod_reviews/helper.php file and make the code changes highlighted below:

$items = $params->get('items', 1);
$random = $params->get('random', 0);

$db =& JFactory::getDBO();
$query = "SELECT id, name, quicktake FROM #__reviews WHERE published = '1' ORDER BY review_date DESC";
if ($random)
{
$db->setQuery( $query );
}
else
{
$db->setQuery( $query, 0, $items );
}

$rows = $db->loadObjectList();
if ($random)
{
shuffle($rows);
$rows = array_slice($rows, 0, $items);
}

foreach ($rows as &$row)
{
$row->link = modReviewsHelper::makeReviewLink($row);
}
return $rows;

First, the value of the random parameter is extracted and stored in $random. When we originally went to the database to register this...