I've placed the Moodle Choice Block in the Modules and plugins database here:
http://moodle.org/mod/data/view.php?d=13&rid=285
- should have done that in the first place!
- the new version now allows you to set a custom title for the block or use the name of the choice as the block name. - also tidied up a couple of hardcoded strings.

Dan
http://moodle.org/mod/data/view.php?d=13&rid=285
- should have done that in the first place!
- the new version now allows you to set a custom title for the block or use the name of the choice as the block name. - also tidied up a couple of hardcoded strings.
Dan
Hi Dan,
Just tested your choice block for 1.6. Fantastic work. I've added a choice to the main menu on my front page, then I've hidden the main menu block and have added the choice block. A great way to keep users coming to the front page. One little thing, in the block file (block_choice_block.php), line 61, you have the slashes backward instead of forward in the URL and I was getting a 404 Not Found error.
Thanks for the contribution
Chardelle
Just tested your choice block for 1.6. Fantastic work. I've added a choice to the main menu on my front page, then I've hidden the main menu block and have added the choice block. A great way to keep users coming to the front page. One little thing, in the block file (block_choice_block.php), line 61, you have the slashes backward instead of forward in the URL and I was getting a 404 Not Found error.
Thanks for the contribution
Chardelle
Hi Dan,
I don't know how familiar you are with the choice mod code, but before I go poking around, I wondered if you know how to change the results to show each response as a % of the total responses rather than as total number of responses. So, in my example shown here, rather than 1 and 1 it would say 50% and 50%. This might be a good option to have.
Nicole, here's a screenshot of the block before answering and after. This is for a poll set for only one answer, and with the block set to show the title as the question. You can give it a different title too. Note: I've changed the color of the graph from grey to blue to match my theme.
I don't know how familiar you are with the choice mod code, but before I go poking around, I wondered if you know how to change the results to show each response as a % of the total responses rather than as total number of responses. So, in my example shown here, rather than 1 and 1 it would say 50% and 50%. This might be a good option to have.
Nicole, here's a screenshot of the block before answering and after. This is for a poll set for only one answer, and with the block set to show the title as the question. You can give it a different title too. Note: I've changed the color of the graph from grey to blue to match my theme.

Hi Chardelle, thanks for testing! - I've fixed the bug with the latest download.
- to make the block show a percentage instead of the number of values, in mod\choice\lib.php replace line 624:
$returnfrm .= $column[$optionid];
with this:
$returnfrm .= $width."%";
I'll try to add this as a global setting to the choice module itself at some point.

Dan
- to make the block show a percentage instead of the number of values, in mod\choice\lib.php replace line 624:
$returnfrm .= $column[$optionid];
with this:
$returnfrm .= $width."%";
I'll try to add this as a global setting to the choice module itself at some point.
Dan
Hi Dan
Thanks, the only problem is that in line 614:
$width = 100 * ((float)$column[$optionid] / (float)$maxcolumn);
it looks like maxcolumn is the column with the largest number of answers and we need to divide by the total number of answers. I tried a couple of things but only got division by 0 errors. Is there something that adds up the total number of answers?
Thanks
Thanks, the only problem is that in line 614:
$width = 100 * ((float)$column[$optionid] / (float)$maxcolumn);
it looks like maxcolumn is the column with the largest number of answers and we need to divide by the total number of answers. I tried a couple of things but only got division by 0 errors. Is there something that adds up the total number of answers?
Thanks
oops - you're right! - I didn't look at that very well!
try this:
if ( $allanswers = get_records("choice_answers", "choiceid", $choice->id)) {
$responsecount = 0;
foreach ($allanswers as $aa) {
if (isstudent($courseid, $aa->userid) or isteacher($courseid, $aa->userid)) { //check to make sure user is enrolled in course.
$responsecount++;
}
}
} else {
$responsecount = 0;
}
and then
$returnfrm .= $column[$optionid] / $responsecount;
try this:
if ( $allanswers = get_records("choice_answers", "choiceid", $choice->id)) {
$responsecount = 0;
foreach ($allanswers as $aa) {
if (isstudent($courseid, $aa->userid) or isteacher($courseid, $aa->userid)) { //check to make sure user is enrolled in course.
$responsecount++;
}
}
} else {
$responsecount = 0;
}
and then
$returnfrm .= $column[$optionid] / $responsecount;
Hi Dan, just one thing..
This works only if I get rid of the if isstudent or isteacher code, with it I still get the old numbers--is that line really necessary?
I also added to this line:
$returnfrm .= round(100 * $column[$optionid] / $responsecount)."%";
I also aligned the table left, and it looks like this--whoopee!
One thing I'm wondering, if someone has not logged in (e.g. for the site homepage) should we make it so that it shows the results rather than the poll (more interesting) , then when/if they log in they can answer if they haven't already?
This works only if I get rid of the if isstudent or isteacher code, with it I still get the old numbers--is that line really necessary?
I also added to this line:
$returnfrm .= round(100 * $column[$optionid] / $responsecount)."%";
I also aligned the table left, and it looks like this--whoopee!
One thing I'm wondering, if someone has not logged in (e.g. for the site homepage) should we make it so that it shows the results rather than the poll (more interesting) , then when/if they log in they can answer if they haven't already?

weird - that might cause problems if you have students who respond to the choice, but then unenrol from the course - their data is still stored in Moodle so the screen will still use their data to calculate the %
nice work!
- good idea about showing the stats instead of the form when the user hasn't logged in. - I'll add that to my task list.

Dan
*edit* if you replace $courseid with $course->id in the function I posted earlier, the isteacher, isstudent stuff should work.
nice work!
- good idea about showing the stats instead of the form when the user hasn't logged in. - I'll add that to my task list.
Dan
*edit* if you replace $courseid with $course->id in the function I posted earlier, the isteacher, isstudent stuff should work.
Hi Chardelle,
I wondered who would ask for this first!
There are 2 options for this, I'm not sure which one will be the best.
the first option is just to include the html entered in the actual choice in the top of the choice block, - the second is to have an html box in the block config to allow something different to be used in the content from the content used in the choice itself.
I suppose there's a third option allowing both - but I'd prefer to keep the interface simple.
what would your preference be?

Dan
I wondered who would ask for this first!
There are 2 options for this, I'm not sure which one will be the best.
the first option is just to include the html entered in the actual choice in the top of the choice block, - the second is to have an html box in the block config to allow something different to be used in the content from the content used in the choice itself.
I suppose there's a third option allowing both - but I'd prefer to keep the interface simple.
what would your preference be?
Dan
In reply to Ger Tielemans
Error of Moodle Choice module and the Block needs update too!
i have a problem.
I want to use the "Limit option" of the moodle choice
the problem was recently fixed and i want to incorporate the changes in the block
which changes the core moodle choice module.
the developer who fixed it stated in the latest changelog of 1.6.3:
what do i do ?
if the choice is changed to the moodle one the block doesn't work.
any ideas?
I want to use the "Limit option" of the moodle choice
the problem was recently fixed and i want to incorporate the changes in the block
which changes the core moodle choice module.
the developer who fixed it stated in the latest changelog of 1.6.3:
2006-10-16 Monday 07:56 danmarsden * mod/choice/lib.php: Fix for MDL-6550 - patch from Graeme Byrne thanks! :-) + a bit of a tidy - get rid of all those tabs! :-)MDL-6550
what do i do ?
if the choice is changed to the moodle one the block doesn't work.
any ideas?
In reply to aggelos panagiotakis
Re: Error of Moodle Choice module and the Block needs update too!
由Dan Marsden發表於
Hi There,
I'm guessing you are referring to the Choice Block not working in this instance? - the actual choice itself should still work!
I'm not in at work today but I will investigate further tomorrow when I'm in!
bounce me an e-mail if it's the actual choice not working, and I'll get on it straight away.
thanks!

Dan
I'm guessing you are referring to the Choice Block not working in this instance? - the actual choice itself should still work!
I'm not in at work today but I will investigate further tomorrow when I'm in!
bounce me an e-mail if it's the actual choice not working, and I'll get on it straight away.
thanks!
Dan
In reply to Dan Marsden
Απάντηση: Re: Error of Moodle Choice module and the Block needs update too!
Hi dan,
yes it's the Choice Block not working in this instance.the choice block is replacing files in the moodle mod folder, and i guess that has to include the resent change for the known bug. I also did a quick diff between files of the latest standar moodle (1.6.3+) and show that major differences are using echo or a variable named "returnfm" for showing output and that it has a Constant for displaying the side block.Propably The fix on the Limit Bug is not included.
Is it really nessassary to replace core moodle files?
Thank you and congrats for your work,
agelos
yes it's the Choice Block not working in this instance.the choice block is replacing files in the moodle mod folder, and i guess that has to include the resent change for the known bug. I also did a quick diff between files of the latest standar moodle (1.6.3+) and show that major differences are using echo or a variable named "returnfm" for showing output and that it has a Constant for displaying the side block.Propably The fix on the Limit Bug is not included.
Is it really nessassary to replace core moodle files?
Thank you and congrats for your work,
agelos
In reply to aggelos panagiotakis
Απάντηση: Re: Error of Moodle Choice module and the Block needs update too!
i think i fixed the problem, see and download the attachment here :
http://moodle.org/mod/forum/discuss.php?d=57008
http://moodle.org/mod/forum/discuss.php?d=57008
Hi Wez,
doesn't surprise me! - I haven't had a chance to test it in 1.8 - we don't use it internally (yet) so I've been a bit slack with it! - I'm on holiday over the next 3 weeks (kids holidays) but I will try to have a look at it sometime after then (unless someone beats me to it!)
DAn