Joomla 1.5 – Random Poll

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,

  1. This information was found at http://forum.joomla.org/viewtopic.php?f=471&t=312127
  2. you might need to reapply this modification after a Joomla update
  3. 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.

  1. Open <server root directory>\modules\mod_poll\mod_poll.xml
  2. Find -<param name=”id” type=”poll” default=”” label=”Poll” description=”PARAMMODULEPOLL” />
  3. 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>
  4. Open <server root directory>\modules\mod_poll\ mod_poll.php
  5. Find –
    $poll   = modPollHelper::getPoll($params->get( 'id', 0 ));
  6. Replace with –
    $random = $params->get('random', 0);
    $poll   = modPollHelper::getPoll($params->get( 'id', 0 ), $random);
  7. Open <server root directory>\modules\mod_poll\helper.php
  8. Find –
    function getPoll($id)
  9. Replace with –
    function getPoll($id, $random = 0)
  10. 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'
             ;
    
  11. 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
    ;
 

Was this article helpful?

Related Articles