Moodle Choice Block V1

Moodle Choice Block V1

by Dan Marsden -
Number of replies: 24
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
here's the first iteration of the Choice Block - replace the files in the attached zip inside your Moodle install - this is only compatible with Moodle 1.6.
Average of ratings: -
In reply to Dan Marsden

Moodle Choice Block V1.1

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
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! smile

- 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.

smile

Dan
In reply to Dan Marsden

Re: Moodle Choice Block V1.1

by N Hansen -
Can you post a screenshot or two? Some of us aren't yet running 1.6.
In reply to N Hansen

Re: Moodle Choice Block V1.1

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Hi there, - I've got a couple of screenshots attached to the code via the link above - I'll try to create a couple of the configuration and create a teacher help doc for creating them.

smile

Dan
In reply to Dan Marsden

Re: Moodle Choice Block V1.1

by Chardelle Busch -
Picture of Core developers
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
In reply to Chardelle Busch

Re: Moodle Choice Block V1.1

by Chardelle Busch -
Picture of Core developers
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.
Attachment choice.gif
In reply to Chardelle Busch

Re: Moodle Choice Block V1.1

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
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.

smile

Dan
In reply to Dan Marsden

Re: Moodle Choice Block V1.1

by Chardelle Busch -
Picture of Core developers
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

In reply to Chardelle Busch

Re: Moodle Choice Block V1.1

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
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;
In reply to Dan Marsden

Re: Moodle Choice Block V1.1

by Chardelle Busch -
Picture of Core developers
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?
Attachment choiceblock.gif
In reply to Chardelle Busch

Re: Moodle Choice Block V1.1

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
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.

smile

Dan

*edit* if you replace $courseid with $course->id in the function I posted earlier, the isteacher, isstudent stuff should work.

In reply to Dan Marsden

Re: Moodle Choice Block V1.1

by Chardelle Busch -
Picture of Core developers
Yes, replacing $courseid with $course->id worked. 

Thanks
In reply to Chardelle Busch

Re: Moodle Choice Block V1.1

by Chardelle Busch -
Picture of Core developers
Hi again Dan,

I thought I would mention that I realized that if you have the choice set to always show results, then the results do show up (below the choice options) if a user is not logged in or has not yet answered (a little duh on my part).
In reply to Chardelle Busch

Re: Moodle Choice Block V1.1

by Chardelle Busch -
Picture of Core developers
Hi Dan,

If I want to give my block a name, like Monthly Poll, then how can I get the question (from choice->text) to show up in the block? I tried addint something like to CHOICE_PUBLISH_ANON_MINI:     

if ($choice->text) {
        format_text($choice->text, $choice->format);
    }
but it didn't worksad.
In reply to Chardelle Busch

Re: Moodle Choice Block V1.1

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Hi Chardelle,

I wondered who would ask for this first! smile

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?

smile

Dan
In reply to Dan Marsden

Re: Moodle Choice Block V1.1

by Chardelle Busch -
Picture of Core developers
Hi Dan,

I was just trying to do something easy, but really it would be best to have a block config option to be able to enter "intro" text at the top of the block since the choice text might be too long, etc.

That would be great, thanks.


In reply to Chardelle Busch

Re: Moodle Choice Block V1.1

by Ger Tielemans -
Why neglect the choice modul and (even worse) the choice block my CSS?
In reply to Ger Tielemans

Error of Moodle Choice module and the Block needs update too!

by aggelos panagiotakis -
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:
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!

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
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!

smile

Dan
In reply to Dan Marsden

Απάντηση: Re: Error of Moodle Choice module and the Block needs update too!

by aggelos panagiotakis -
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
In reply to Dan Marsden

Re: Moodle Choice Block V1

by Wez Morris -
Is anybody else's choice block looking a bit funky in 1.8? The options appear above the block itself and the choice text isn't displayed

Thanks
Wez
In reply to Wez Morris

Re: Moodle Choice Block V1

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

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!)

smile

DAn

In reply to Dan Marsden

Re: Moodle Choice Block V1

by Linda Harrison -
Recently saw the Choice Block in another college's Moodle - but they are using 1.6 . . . did you ever get anywhere with 1.8?  The dowload seems to indicate it is only compatible with 1.6 and we are using 1.8 (but hope to move to 1.9 over the summer!).
In reply to Linda Harrison

Re: Moodle Choice Block V1

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Hi Linda,

I only ever used this in a 1.6 install - wouldn't be very hard to upgrade it so it worked with moodle 1.9 though, but it isn't likely I'll get any time to spend on this without funding sorry!

thanks!

smile

Dan