SimplePortal
Customization => Custom Coding => Topic started by: Dzonny on June 18, 2014, 06:03:02 PM
-
Hey all,
Is it possible to add two or three most recent polls on portal? I'm currently using custom php block to show 3 hidden poll blocks on my portal with custom poll IDs. I would like to show 3 most recent polls if it's possible though.
Any help would be appreciated.
Regards,
Dzonny
-
If it is *any* poll, you could just grab the IDs from the db:
$smcFunc['db_query']('', '
SELECT id_poll
FROM {db_prefix}polls
ORDER BY id_poll DESC
LIMIT 3',
array()
);
Of course this doesn't check for permissions (you wrote "hidden poll" so I assumed the polls are in hidden boards for some reason), if you need permissions, though, you have to join boards and use {query_see_board}.
-
Thanks for your answer Ema!
However I'm not sure where can I use the code you provided and how?
Thanks for your help!
-
Anyone can suggest how to deal with this please? :)
-
I guess that code will work in a Simple Portal custom php block.
If you are not sure what to do using custom code there is a default poll block. You need to read up about using blocks - see the documentation about them and try experimenting with blocks.
http://simpleportal.net/index.php?action=docs;area=working_with_blocks
I recommend choosing the best solution available rather than trying to customize everything exactly as you want - which usually mean lots of time and headaches.
-
Hm, i don't think this can be placed in custom php block by itself. The code ema gave is just a sql query, apart from that there must be formatted output for showing actual data.
-
Yes you are right - I didnt look at it closely.
As I said, sometimes best to take the easy solution even though not perfect. Use the standard block for polls or keep trying to get the custom code.
Not many volunteers here so best to expect it will take time for custom coding.
-
not sure how much this will help but here is the SSI code
most recent poll
ssi_recentPoll();
most voted in poll
ssi_topPoll();
to slectiviely show a single poll (change '$topicID' with the ID #)
ssi_showPoll($topicID);
you could put two or three together, example
ssi_recentPoll();
ssi_topPoll();
ssi_showPoll(181);
again, not sure how much that helps but could be a good place to start?
-
You could modify the original function a little bit to achieve this.
Sources/PortalBlocks.php
LIMIT 1',
array(
'boards_allowed_list' => $boardsAllowed,
'not_locked' => 0,
'is_approved' => 1,
'recycle_enable' => $modSettings['recycle_board'],
'type' => $type == 1 ? 'p.id_poll DESC' : 'RAND()',
)
);
list ($topic) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
}
LIMIT {int:limit}',
array(
'boards_allowed_list' => $boardsAllowed,
'not_locked' => 0,
'is_approved' => 1,
'recycle_enable' => $modSettings['recycle_board'],
'type' => $type == 1 ? 'p.id_poll DESC' : 'RAND()',
'limit' => $type == 1 ? 3 : 1,
)
);
$topics = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$topics[] = $row['id_topic'];
$smcFunc['db_free_result']($request);
}
foreach ($topics as $topic)
{
', $txt['poll_cannot_see'];
', $txt['poll_cannot_see'];
}
Change 3 in the first replace as the number of recent polls you want to be displayed.
Then just create a new Poll block with the Type set as Recent.