SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: josh4596 on March 30, 2015, 11:07:52 AM

Title: Latest Poll x3?
Post by: josh4596 on March 30, 2015, 11:07:52 AM
I'd like to have the poll block showing the latest polls from a specific board, but have one that's able to show 3 polls horizontally. Could I modify the already existing poll block to do that? and if so where do I find that code? If not I'd greatly appreciate anyone able to help with this. Thank you
Title: Re: Latest Poll x3?
Post by: josh4596 on March 30, 2015, 03:40:37 PM
I found this written by SiNaN but it doesn't load the polls at all, just a blank block and it causes everything under the block preview to not even load. Am I doing something wrong? Those poll-ids are the topic id's the poll is tied to.

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

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

$poll_ids = array(15, 16, 17);
$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);

I know I could use blocks in blocks but I'd rather not update 3 blocks every time I post a new poll. If I have to I will, but if I can get this working first I'd be very happy. Thanks again any help is appreciated.
SimplePortal 2.3.8 © 2008-2024, SimplePortal