SimplePortal

Customization => Custom Coding => Topic started by: Dzonny on June 18, 2014, 06:03:02 PM

Title: 2 or 3 most recent polls?
Post 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
Title: Re: 2 or 3 most recent polls?
Post by: emanuele on June 18, 2014, 06:51:09 PM
If it is *any* poll, you could just grab the IDs from the db:
Code: [Select]
$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}.
Title: Re: 2 or 3 most recent polls?
Post by: Dzonny on July 06, 2014, 08:05:15 AM
Thanks for your answer Ema!
However I'm not sure where can I use the code you provided and how?

Thanks for your help!
Title: Re: 2 or 3 most recent polls?
Post by: Dzonny on July 14, 2014, 07:42:24 AM
Anyone can suggest how to deal with this please? :)
Title: Re: 2 or 3 most recent polls?
Post by: andy on July 14, 2014, 11:16:49 PM
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.
Title: Re: 2 or 3 most recent polls?
Post by: Dzonny on July 18, 2014, 08:38:35 AM
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.
Title: Re: 2 or 3 most recent polls?
Post by: andy on July 19, 2014, 02:16:09 AM
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.
Title: Re: 2 or 3 most recent polls?
Post by: oNLy1 on July 26, 2014, 04:09:24 AM
not sure how much this will help but here is the SSI code

most recent poll
Code: [Select]
ssi_recentPoll();
most voted in poll
Code: [Select]
ssi_topPoll();
to slectiviely show a single poll (change '$topicID' with the ID #)
Code: [Select]
ssi_showPoll($topicID);
you could put two or three together, example
Code: [Select]
ssi_recentPoll();
ssi_topPoll();

ssi_showPoll(181);

again, not sure how much that helps but could be a good place to start?
Title: Re: 2 or 3 most recent polls?
Post by: [SiNaN] on July 27, 2014, 08:20:17 AM
You could modify the original function a little bit to achieve this.

Sources/PortalBlocks.php

Code: (Find) [Select]
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);
}

Code: (Replace) [Select]
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)
{

Code: (Find) [Select]
', $txt['poll_cannot_see'];
Code: (Replace) [Select]
', $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.
SimplePortal 2.3.8 © 2008-2024, SimplePortal