Just a simple straw poll

There is a tendancy to over-engineer solutions in the Moodle community sometimes, and this tends to lead to confusing interfaces or even worse something that doesn’t work as it should.

I’ve spent most of the last few months writing local plugins for Moodle; the kind that have eight tables in the database and make your mind melt as you work on them. So when I found a bit of time I decided to create a simple straw poll block which would “just work”.

straw poll
A simple straw poll

A straw poll is a simple thing, and because it is in a block we know that there should be a limited number of questions. Equally I felt it was overkill to support the exporting of complex spreadsheets to show the results. A total and a percentage should be enough for any straw poll, and if you want more than that there is the wonderful Choice activity!

So I decided that the Questions and the Responses could all be held directly in the block configuration meaning the only table that would needed in the database would be for responses. This is more efficient since block configuration is already loaded and it cuts down the number of DB queries Moodle needs to do.

straw poll config
The configuration for the example poll shown above. Only the red fields need to be filled out.

The configuration for the block is very simple, with one text box for the question, six text boxes for possible options, and a few extra options to control how the user will interact with the block. The empty options are simply ignored by the block and responses cannot be submitted for them.

I will be submitting a Beta of this block to Moodle.org soon, but if you would like to try it out now you can download it from my GitHub repository.

7 thoughts on “Just a simple straw poll”

  1. Hi Mark! Nice block. Really nice. Love the buttons and User Interface. BTW, I had to change the extracted folder name to “straw_poll” in order for Moodle 2.5 to diagnose and to install the block. Cheers, Frankie Kam.

  2. BTW, in order for me to install your block in Moodle 2.5, I ALSO had to edit the file edit_form.php. Apparently all the code in that file is on line 1. And there’s a // comment code on line 1! So I had to manually move your code statements down to the next line until the last // commented statement was on a line on its own. Then the block worked. BTW, here’s the corrected edit_form.php file: http://alturl.com/ts8ye
    Cheers, Frankie Kam.

  3. I’m afraid that GitHub has decided to add the -master on the end of that folder name since it is the master branch. moodle/blocks/straw_poll is correct.

    I haven’t seen your problem with edit_form but I will keep an eye on it. Since this version predates Moodle 2.5 there could well be issues with compatibility there. I will be reviewing and updating all my plugins for 2.5 shortly.

    1. Yes you could do by changing the edit form and the references to 6/7 throughout the block_straw_poll.php file. I thought 6 was about the maximum someone would want on a block but there is no technical limit there AFAIK.

  4. Thanks for this block. I know this thread is a little old but I was wondering if anyone could help me. I have renamed the folder and successfully installed the block. The problem is noone is allowed access to it even though they have permission to do it.
    “Sorry, you don’t have permission to take part in this poll.” is the message we all see.

Leave a Reply