Random Polls

This forum is for general questions about extensions for Joomla! version 1.5.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
rhodesia1
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Wed Jul 30, 2008 4:05 pm

Random Polls

Post by rhodesia1 » Wed Jul 30, 2008 4:23 pm

I wanted to display a random poll in the one poll module, This was done in the previous versions of Joomla, but since upgrading it is apparent the code is different (like a whole bunch).

There was a hack, does anyone know how to do it on the 1.5 version?

The hack was:

Open modules/mod_polls.php and change line 32 from:

Code: Select all

. "\n AND p.published = 1";
to

Code: Select all

. "\n AND p.published = 1 ORDER BY RAND() LIMIT 1";
I notice on 1.5 it is a lot different, any one have any suggestions? It would be really nice to display a randomly selected poll in the one module, instead of creating a bunch of copies, especially if you wanted your home page to have a new poll every load or visit.

Thanks
Rhode

crashtackle
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 123
Joined: Tue Apr 17, 2007 10:34 am
Location: Durban, South Africa.

Re: Random Polls

Post by crashtackle » Thu Aug 28, 2008 1:55 pm

Just like to add my name to this request... it would be a huge help...

User avatar
philipissa
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Mon May 29, 2006 9:44 pm

Re: Random Polls

Post by philipissa » Sat Aug 30, 2008 8:12 pm

I needed the same thing, so I took a stab at this. My hack works fine, and random display can be turned on/off by using the admin console. Just keep in mind that any time you upgrade joomla you will have to reapply it.
Note - I made this hack to Joomla v1.5.4. I plan to upgrade to 1.5.6 (or whatever is the latest version) soon, and will test it out again then.

joomla_root/modules/mod_poll/mod_poll.xml
Find:

Code: Select all

<param name="id" type="poll" default="" label="Poll" description="PARAMMODULEPOLL" />
After, add:

Code: Select all

<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>
joomla_root/modules/mod_poll/mod_poll.php
Find:

Code: Select all

$poll   = modPollHelper::getPoll($params->get( 'id', 0 ));
Replace with:

Code: Select all

$random = $params->get('random', 0);
$poll   = modPollHelper::getPoll($params->get( 'id', 0 ), $random);
joomla_root/modules/mod_poll/helper.php
Find:

Code: Select all

function getPoll($id)
Replace with:

Code: Select all

function getPoll($id, $random = 0)
Find:

Code: Select all

$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:

Code: Select all

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
			;
Thanks,
Philip

emediately
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Sat Aug 08, 2009 5:37 am

Re: Random Polls

Post by emediately » Wed Aug 19, 2009 5:48 am

I have Joomla 1.5.9 and after doing that, i get an error on the pg:

DB function failed with error number 1065
Query was empty SQL=

:( Any other solutions?
philipissa wrote:I needed the same thing, so I took a stab at this. My hack works fine, and random display can be turned on/off by using the admin console. Just keep in mind that any time you upgrade joomla you will have to reapply it.
Note - I made this hack to Joomla v1.5.4. I plan to upgrade to 1.5.6 (or whatever is the latest version) soon, and will test it out again then.

joomla_root/modules/mod_poll/mod_poll.xml
Find:

Code: Select all

<param name="id" type="poll" default="" label="Poll" description="PARAMMODULEPOLL" />
After, add:

Code: Select all

<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>
joomla_root/modules/mod_poll/mod_poll.php
Find:

Code: Select all

$poll   = modPollHelper::getPoll($params->get( 'id', 0 ));
Replace with:

Code: Select all

$random = $params->get('random', 0);
$poll   = modPollHelper::getPoll($params->get( 'id', 0 ), $random);
joomla_root/modules/mod_poll/helper.php
Find:

Code: Select all

function getPoll($id)
Replace with:

Code: Select all

function getPoll($id, $random = 0)
Find:

Code: Select all

$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:

Code: Select all

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
			;
Thanks,
Philip

User avatar
Ghonjez
Joomla! Exemplar
Joomla! Exemplar
Posts: 8770
Joined: Sat Oct 18, 2008 3:02 am
Location: Mars
Contact:

Re: Random Polls

Post by Ghonjez » Thu Aug 20, 2009 11:58 am

Hi...

For create random poll, try this module :
Autopoll : http://extensions.joomla.org/extensions ... polls/6108

Hope helps :)

emediately
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Sat Aug 08, 2009 5:37 am

Re: Random Polls

Post by emediately » Thu Aug 20, 2009 11:42 pm

Thanks that worked!!
Ghonjez wrote:Hi...

For create random poll, try this module :
Autopoll : http://extensions.joomla.org/extensions ... polls/6108

Hope helps :)


Locked

Return to “Extensions for Joomla! 1.5”