Polls are great user driven features to help a website feel more interactive for the audience, but when it comes to the default install of Joomla it only allows one Poll to be used at a time and requires an administrator to manually change the poll which is being presented. This doesn’t always suit the purpose of the website so thankfully there is a simple modification that can be made which will allow you to enable and disable random polls from the Joomla administration console.
Polls are wonderful user driven features to help a website feel more interactive for the audience, but when it comes to the default install of Joomla it only allows one Poll to be used at a time and requires an administrator to manually change the poll which is being presented. This doesn’t always suit the purpose of the website so thankfully there is a simple modification that can be made which will allow you to enable and disable random polls from the Joomla administration console.
Please note,
- This information was found at http://forum.joomla.org/viewtopic.php?f=471&t=312127
- you might need to reapply this modification after a Joomla update
- the modification has been tested on Joomla 1.5.7 but there are no garentees it will continue to work on future versions.
How to enable random polls in Joomla 1.5
This modification requires a very simple change to three of the Joomla php or zml files, therefore you will need access to the files on the server (through cPanel, web disk, FTP etc).
As with any modification with server files DONT FORGET TO BACK UP BEFORE MODIFYING!!!!
When completed you will be able to use the Joomla administration console to enable and disable the random poll feature.
- Open <server root directory>\modules\mod_poll\mod_poll.xml
- Find -<param name=”id” type=”poll” default=”” label=”Poll” description=”PARAMMODULEPOLL” />
- Add after –
<param name="random" type="radio" default="0" label="Random Poll?" description="Displays random poll"> <option value="1">Yes</option> <option value="0">No</option> </param>
- Open <server root directory>\modules\mod_poll\ mod_poll.php
- Find –
$poll = modPollHelper::getPoll($params->get( 'id', 0 ));
- Replace with –
$random = $params->get('random', 0); $poll = modPollHelper::getPoll($params->get( 'id', 0 ), $random);
- Open <server root directory>\modules\mod_poll\helper.php
- Find –
function getPoll($id)
- Replace with –
function getPoll($id, $random = 0)
- Find –
$query = 'SELECT id, title,' .' CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(\':\', id, alias) ELSE id END as slug ' .' FROM #__polls' .' WHERE id = '.(int) $id .' AND published = 1' ;
- Replace with –
if ($random == 1) { $where = ' WHERE published = 1 ORDER BY RAND() LIMIT 1'; } else { $where = ' WHERE id = '.(int) $id .' AND published = 1'; } $query = 'SELECT id, title,' .' CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(\':\', id, alias) ELSE id END as slug ' .' FROM #__polls' . $where ;