Blocks to only show over specific dates

Blocks to only show over specific dates

by Kay Patterson -
Number of replies: 6

version information

release  = '2.1.1+ (Build: 20110925)'

It is so useful that you are able to set resources and activities to show over specific times or other criteria set to the student or whoever is logged in.

Is there any way this criteria could be set for blocks also, it is not part of the normal functionality - is anyone working on this or is there a way to do it?

If there is no work on this or the resulting work is monstrous (for me) then is there a way I could set the code in my simple html blocks to show one set of html over a specific period of time and another when that period is not true?

This latter setup suggestion (if possible) is a bit of a step dpwn from the true functionality I would like to achieve but .. it would do for now.

Looking forward to hearing from you.

Many Thanks

Kay

Average of ratings: -
In reply to Kay Patterson

Re: Blocks to only show over specific dates

by Rosario Carcò -

You could use PHP or Javascript to check the dates and then decide what to show.

The whole block is rendered on the SERVER, so if you do not want to display it at all, you must use PHP on the servers' side.

If you only want to decide what should be displayed inside the Block, i.e. after it was rendered on the server and sent to the Client-Browser, you could use JavaScript to decide what portions to display.

Rosario

In reply to Rosario Carcò

Re: Blocks to only show over specific dates

by Kay Patterson -

Not sure I understand all of that?

Is there a way you could spell that out like I am really really simple?

I know my way round moodle as an interface fairly well but I'm not sure what you mean by

The whole block is rendered on the SERVER,

and pretty much the rest to be honest

The Javascript bit I understood and I think I could maybe work that out errrm possibly.

Sorry to be dense.

Kay

In reply to Kay Patterson

Re: Blocks to only show over specific dates

by Rosario Carcò -

Maybe you want to have a look at my emptyTestBlock Code I published here:

http://dev.moodle.org/course/view.php?id=2$

to show how a Block works/has to be programmed (you have to search for emptyTestBlock in the Forums there). This will give you a sense for SERVER-SIDE code. Which means that a program is executed on the server directly gathering all needed data from its database. The Server and the program, i.e. php-script has to RENDER the gathered Data and then send it to the clients' internet browser for display. Gathering Data and Rendering are typical serverside-tasks.

On the other end, you have your internet-browser working as CLIENT, as opposed to the SERVER on the other end of the line. Fortunately or strangely, you can even program your internet-browser to execute program-code on its side. Typically you use a programming language called JavaScript.

There are many online web-sites to show/teach you how to program with JavaScript. If your Server sends such JavaScript to the internet-browser, that code can be executed locally on the users' computer, e.g. when the user clicks a button or a link.

Your serverside php-program can not only gather data and send HTML-formatted Text to be displayed on a client, it can also compose JavaScript, i.e. a program or many many functions to be used and executed on the client.

Please click on my sitenavigation to show up in a popUp window here:

https://moodle.fhnw.ch/moodleTest/

And if you inspect the HTML- and JavaScript-Code I composed on the Moodle server with php, you will see, that I sent the client a function to open that popUp-window. It is actually this JavaScript-construct that opens the popUp-Window:

<a title="sitenavigation: Show in a Pop-Up-Window" onclick="this.target='popup'; return openpopup('/file.php/1/sess_48pVxxCvLL_sitenavigation.html', 'sitenavigationPopUp', 'menubar,toolbar,location,status,scrollbars,resizable,width=1024,height=768', 0);" href="https://moodle.fhnw.ch/moodleTest/1/sess_48pVxxCvLL_sitenavigation.html" target="sitenavigationPopUp">

And this is how I programmed my Block to display/render/send the above line to the client browser:

        $this->sitenavigationcontent->text = '<a title="' . get_string('showinpopupwindow','block_sitenavigation') .
                              '" href="' . $CFG->wwwroot  . $sitenavigationfile .
                              '" target="sitenavigationPopUp" '.
                              "onclick=\"this.target='popup'; ".
                              "return openpopup('/file.php" . $sitenavigationfile ."', 'sitenavigationPopUp', ".
                              "'menubar,toolbar,location,status,scrollbars,resizable,width=1024,height=768', 0);\">" .
                              get_string('showinpopupwindow','block_sitenavigation') . "</a>";

To be honest, openpopup() was programmed by the Moodle Core Programmers. So I did not invent/program it. I actually only prepared everything so that when the link is clicked on, the function gets called to show the data I gathered on the server and that should be displayed in the popUp-window. But you could also invent/program your own JavaScript Code/functions and send them to your clients. This is how the Moodle Programmers did it in one of their libraries and how it gets transferred to the client browser:

 342      <script type=\"text/javascript\">
 343      <!--
 344          function openpopup(url,name,options,fullscreen) {
 345            fullurl = \"".$CFG->httpswwwroot."\" + url;
 346            windowobj = window.open(fullurl,name,options);
 347            if (fullscreen) {
 348              windowobj.moveTo(0,0);
 349              windowobj.resizeTo(screen.availWidth,screen.availHeight);
 350            }
 351            windowobj.focus();
 352            return false;
 353          }
 354   // -->
 355      </script>";

Rosario

Average of ratings: Useful (1)
In reply to Kay Patterson

Re: Blocks to only show over specific dates

by Rosario Carcò -

I hope my previous post doesn't scare you. It is quite a steep learning curve, if you wanted to learn how to program an own Block in Moodle. Lets return to your basic question:

>>
If there is no work on this or the resulting work is monstrous (for me) then is there a way I could set the code in my simple html blocks to show one set of html over a specific period of time and another when that period is not true?
>>

There is a built-in Block called HTML in Moodle ready to use. So everything you put in there DOES NOT COME from the Moodle-Server.

If you wanted to display or check values that are stored in the Moodle servers' database, you would have to program your own Moodle Block. And again, you would then be able to decide what to display directly on the server, in your Blocks' php-code. In this case I would not suggest to do it by client side JavaScript.

Rosario

Average of ratings: Useful (1)
In reply to Rosario Carcò

Re: Blocks to only show over specific dates

by Kay Patterson -

Thank you so very much for that response I am sorry I didn't respond earlier but I think it got lost in my moodle stream. I'll have a go with what you have put there.

Thanks again.

Kay

In reply to Kay Patterson

Re: Blocks to only show over specific dates

by Rosario Carcò -

You are welcome. I am actually busy with other Moodle-programming tasks, but as soon as you know

- what to display

- and how to set up the dates you would like to use for displaying or not

we could start coding that block together.

Rosario