How to make a Teacher Only block

How to make a Teacher Only block

by Mr. Marc -
Number of replies: 11

How can I make a block with different resourses in it for teachers and only teachers can see it.  Each course would have this block but it would have different resourses in it depending on the course.

Can any one point me in the right direction?

Thank you for your help in advance!!!

Marc

Average of ratings: -
In reply to Mr. Marc

Re: How to make a Teacher Only block

by Dave Kichler -
I have made some changes to the current block system that allows for this type of behaviour. I like to call it role specific capabilities (really it doesn't implement the capabilities feature at all). Basically it allows an admin (or any course manager) to specify which roles the block should appear for. This way you could have a block which only teachers see, or only students, or any combination of roles.

Its not really a "modular" extension, more of a patch really. I made some basic changes to a couple files and created a couple more. I have attached a zip with all the files you need to implement the functionality, simply extract the zip into your Moodle home directory. I have had a little bit of feedback on the functionality and have already fixed a couple bugs but if you find something else funny, please let me know! Hope this helps

dk
In reply to Dave Kichler

Re: How to make a Teacher Only block

by Mr. Marc -
Thank you Dave I will if I find anything!!!
In reply to Dave Kichler

Re: How to make a Teacher Only block

by Carl Hodkinson -

Hi Dave

With great anticipation I tried this your new version and unfortunately have this error;

Notice: Trying to get property of non-object in /data1/moodle/blocks/moodleblock.class.php on line 688

When editing the b locks, the same appears for each of the check boxes too. Wish I knew something about php so I could help you iron out the bugs I find! sad Still, if I can keep finding them.....

Carl

In reply to Carl Hodkinson

Re: How to make a Teacher Only block

by Dave Kichler -
Carl,

While all those notices (notices beat errors anyday smile ) may look like something has gone terribly wrong, they are actually absolutely harmless and are simply a product of implementing the functionality.

To explain a little more: Basically I added several properties to the configuration data to specify which roles the block will support. These properties are represented by the check boxes you see on the configuration page. The role specific capability is based around checking against these properties each time the block is printed or the configuration edited. If it so happens that you have not yet edited the configuration at all, then these properties are not set and really do not even exist yet (remember the data is only recorded once you access and save the configuration settings). Since the block checks for them every time it prints itself, those notices are just the program telling you it can't find the properties that haven't been created yet. If you were to check off each of the role boxes, all of the properties would be set and written into the config data and those notices would disappear.

I realize I could write a script to add these properties to the config data of every existing block instance in the DB but I'm still struggling to find time to refine the capability itself. There is still some gray area I am working on such as the lack of roles for My Moodle pages. For most uses though, this version should be just fine for now.

PS. My solution to the problem was to turn off debug wink

dk
In reply to Dave Kichler

Re: How to make a Teacher Only block

by Carl Hodkinson -
Dave

Sorry not replied before but I've been on holiday.

Thanks for the explanation. i see what you mean - I must say that I abandoned using the functionality, but now I know that the notice was not all that bad I'll start using it again.

I think I'll do what you did. I do easy solutions!

Carl
In reply to Dave Kichler

Re: How to make a Teacher Only block

by Dave Rule -
I implemented this solution, and tried it on the site admin block. Now my Site admin block is missing.... any suggestions? I'd really like my block back!

Thanks!
In reply to Dave Rule

Re: How to make a Teacher Only block

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Have you lost your editing rights on the front page altogether? I mean - can you not retrieve the site admin block from the add block option? What happens if you log in and then you physically type http://YOURMOODE.com/admin/blocks.php Can you see an instance of your site admin block there?
In reply to Dave Rule

Re: How to make a Teacher Only block

by Dave Rule -
Nevermind, I found dug around until I found the page where you set the user groups, and fixed it!

Does this work for the Site Admin block? When I activate the function the Site Admin block disappears. And when I use it in other blocks to limit it to only certain groups, I still appears for everyone. (ie. I checked off only admin and course creators, but students can see the block).

am I missing a step?

In reply to Dave Rule

Re: How to make a Teacher Only block

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Dave -I haven't looked at the resource earlier on in this thread but if you are wanting to make a block visible to only a certain set of users - such as teachers - then you can do this with roles - in the docs there is information here - and a screencast in the quoted forum thread iirc