GPoll User Guide - 92 Downloads and Counting!
GPoll is extremely easy to use!
Download GPoll
Installation
Extract the zip file and copy its contents to your application folder. Execute the SQL queries in schema.sql.
This installation requires Datamapper 1.6.0 If you already have a default installation already installed, there's nothing to worry about. If not, rename application/config/default_datamapper.php to datamapper.php.
create()
Creates a new poll. Pass a string with the question that should be displayed. Returns the newly created object.
$p = new Poll();
$p->create('How Would You Rate GPoll?');
add_answer()
Adds an answer to the current poll object. You can pass it a string or an array.
$answers = array('Great', 'Decent', 'Bad');
$p->add_answer($answers);
// Or we can do this...
$p->add_answer('Great'); // id 1
$p->add_answer('Decent'); // id 2
$p->add_answer('Bad'); // id 3
display()
Returns the poll's question text.echo $p->display(); // will return 'How Would You Rate GPoll?'
answer()
Returns the answer's display text.$answer_id = 1; echo $p->answer($answer_id); // will return 'Great'
vote()
Voting is as simple as passing the answer's id. Returns an array. The 'status' index will return TRUE if the vote was successfully added. If it returns false, the 'msg' index will return the specified error messages. You can set those message in the config file.
$answer_id = $this->input->post('answer');
$result = $p->vote($answer_id);
if($result['status'])
{
// We put it in! (That's what she said)
}
else
{
echo $result['msg'];
}
reset_votes()
Resets the vote tally to zero for the current poll object.$p->reset_votes();
get_results()
Returns an array of the results of the poll. The index of each element is the answer's id. The value of each element of the total amount of votes.
$results = $p->get_results();
$a = new Poll_answer();
foreach($array as $key => $value)
{
echo $a->display($key) . ' has ' . $value . ' votes' . '<br>';
}
Configuration
Configuration variables are included in application/config/gpoll.php.$config['vote_span'] - Number of seconds a user must wait to vote again
$config['max_votes'] - Number of times a user can vote
$config['max_votes_message'] - Message if user has exceeded the $max_votes variable
$config['voted_already_message'] - Message if user has voted within the $vote_span amount of seconds
$config['success_message'] Message if user's vote was successful
$config['save_error_message'] - Message if we tried to save the vote but was unsuccessful
$config['no_answer_message'] - This should never happen