SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: techprince on January 07, 2009, 02:32:59 PM

Title: Polls Block with these changes.
Post by: techprince on January 07, 2009, 02:32:59 PM
I need a poll block with these changes :

1) IDs text field with multiple id separated by comma.
2) A RND (Random) Function which will iterate through all these ids.
3) Find all polls in which user didnt voted and all polls for guests, then display randomly.
4) A board ids field allowing multiple board ids from which polls to find.

Title: Re: Polls Block with these changes.
Post by: ディン1031 on January 08, 2009, 06:45:51 AM
This is a nice idea :), i will think about it.

1) Possible? But should the pols shown in one block?
2) Automatic with 1) or is this something seperate?
But at point 3... this could be heavy querys... and will be not easy. The Guest Vote work only in SMF2.
4) Hmmm a random poll from a board id, or the latest or the first?

Bye
DIN1031
Title: Re: Polls Block with these changes.
Post by: techprince on January 10, 2009, 07:19:45 PM
1 for 2, they are not separate.
3rd will require more lines of code and will generate resource and time consuming queries so exclude it.
But 4th must include a drop down list with random & latest :)
Title: Re: Polls Block with these changes.
Post by: [SiNaN] on February 02, 2009, 09:41:31 AM
You can use these codes in a PHP block:

Code: [Select]
global $db_prefix, $user_info, $boarddir, $ID_MEMBER;

require_once($boarddir . '/SSI.php');

$poll_ids = array(1, 2, 3);
$boardsAllowed = boardsAllowedTo('poll_view');

$request = db_query("
SELECT t.ID_TOPIC
FROM ({$db_prefix}polls AS p, {$db_prefix}boards AS b, {$db_prefix}topics AS t)
LEFT JOIN {$db_prefix}log_polls AS lp ON (lp.ID_POLL = p.ID_POLL AND lp.ID_MEMBER = $ID_MEMBER)
WHERE p.votingLocked = 0
AND lp.ID_CHOICE IS NULL
AND t.ID_POLL = p.ID_POLL
AND b.ID_BOARD = t.ID_BOARD
AND $user_info[query_see_board]" . (!in_array(0, $boardsAllowed) ? "
AND b.ID_BOARD IN (" . implode(', ', $boardsAllowed) . ")" : '') . "
AND t.ID_TOPIC IN (" . implode(', ', $poll_ids) . ")" . "
ORDER BY RAND()
LIMIT 1", __FILE__, __LINE__);
list ($poll) = mysql_fetch_row($request);
mysql_free_result($request);

if (empty($poll))
{
$request = db_query("
SELECT t.ID_TOPIC
FROM ({$db_prefix}polls AS p, {$db_prefix}boards AS b, {$db_prefix}topics AS t)
WHERE t.ID_POLL = p.ID_POLL
AND b.ID_BOARD = t.ID_BOARD
AND $user_info[query_see_board]" . (!in_array(0, $boardsAllowed) ? "
AND b.ID_BOARD IN (" . implode(', ', $boardsAllowed) . ")" : '') . "
AND t.ID_TOPIC IN (" . implode(', ', $poll_ids) . ")" . "
ORDER BY RAND()
LIMIT 1", __FILE__, __LINE__);
list ($poll) = mysql_fetch_row($request);
mysql_free_result($request);
}

if (empty($poll))
{
echo 'There are no polls to show!';
return;
}

ssi_showPoll($poll);

You don't need board ids, because you already give the topic ids to look for.
Title: Re: Polls Block with these changes.
Post by: techprince on February 16, 2009, 07:41:22 AM
You can use these codes in a PHP block:

Code: [Select]
global $db_prefix, $user_info, $boarddir, $ID_MEMBER;

require_once($boarddir . '/SSI.php');

$poll_ids = array(1, 2, 3);
$boardsAllowed = boardsAllowedTo('poll_view');

$request = db_query("
SELECT t.ID_TOPIC
FROM ({$db_prefix}polls AS p, {$db_prefix}boards AS b, {$db_prefix}topics AS t)
LEFT JOIN {$db_prefix}log_polls AS lp ON (lp.ID_POLL = p.ID_POLL AND lp.ID_MEMBER = $ID_MEMBER)
WHERE p.votingLocked = 0
AND lp.ID_CHOICE IS NULL
AND t.ID_POLL = p.ID_POLL
AND b.ID_BOARD = t.ID_BOARD
AND $user_info[query_see_board]" . (!in_array(0, $boardsAllowed) ? "
AND b.ID_BOARD IN (" . implode(', ', $boardsAllowed) . ")" : '') . "
AND t.ID_TOPIC IN (" . implode(', ', $poll_ids) . ")" . "
ORDER BY RAND()
LIMIT 1", __FILE__, __LINE__);
list ($poll) = mysql_fetch_row($request);
mysql_free_result($request);

if (empty($poll))
{
$request = db_query("
SELECT t.ID_TOPIC
FROM ({$db_prefix}polls AS p, {$db_prefix}boards AS b, {$db_prefix}topics AS t)
WHERE t.ID_POLL = p.ID_POLL
AND b.ID_BOARD = t.ID_BOARD
AND $user_info[query_see_board]" . (!in_array(0, $boardsAllowed) ? "
AND b.ID_BOARD IN (" . implode(', ', $boardsAllowed) . ")" : '') . "
AND t.ID_TOPIC IN (" . implode(', ', $poll_ids) . ")" . "
ORDER BY RAND()
LIMIT 1", __FILE__, __LINE__);
list ($poll) = mysql_fetch_row($request);
mysql_free_result($request);
}

if (empty($poll))
{
echo 'There are no polls to show!';
return;
}

ssi_showPoll($poll);

You don't need board ids, because you already give the topic ids to look for.

Poll IDs :| How about Board IDs to choose Polls from.
Title: Re: Polls Block with these changes.
Post by: Jade Elizabeth on February 16, 2009, 11:06:39 AM
You want a random poll block like I do, don't you?

One that grabs the latest poll from a specified board? Or from the entire forum?

Yeah. I want that :P.
Title: Re: Polls Block with these changes.
Post by: techprince on February 16, 2009, 04:37:34 PM
No problem i made it :)
Title: Re: Polls Block with these changes.
Post by: Jade Elizabeth on February 16, 2009, 05:02:38 PM
Share?
Title: Re: Polls Block with these changes.
Post by: [SiNaN] on February 19, 2009, 12:48:23 PM
Poll block supports 3 types as a definite, recent, or random poll in 2.2.

2.2 is not out yet though.