SimplePortal
Customization => Blocks and Modifications => Block Requests => Topic started 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.
-
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
-
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 :)
-
You can use these codes in a PHP block:
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.
-
You can use these codes in a PHP block:
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.
-
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.
-
No problem i made it :)
-
Share?
-
Poll block supports 3 types as a definite, recent, or random poll in 2.2.
2.2 is not out yet though.