Restricting database activity to view only - date specified but not time

Restricting database activity to view only - date specified but not time

by Gordon McLeod -
Number of replies: 3

Hi,

I've setup a 2.4 database activity that students are supposed to complete as part of a multi-activity workflow. They must add an entry to the database by a specific time on a set day - after which the database is to switch to view-only mode and the students use it as reference for their next task. Unfortunately the "available from" and "read only from" admin settings only allow you to input a date, which differs from most Moodle restriction fields there are no settings for a time within that date.

Can anyone confirm when the restriction comes into place? I'm anticipating that it happens at Midnight as the date switches onto the specified date (unfortunately not the time I wanted). Can anyone suggest a way around this without the manual intervention of me pressing the button at the correct time on the correct day? Think I'll need to submit a tracker request to have timestamp added to the view-only field (if it hasn't already been requested).

Thanks, Gordon.

 

 

Average of ratings: -
In reply to Gordon McLeod

Re: Restricting database activity to view only - date specified but not time

by Itamar Tzadok -

Yes, the restriction is applied at midnight, that is 00:00 on the specified day. There is probably no foolproof workaround. You can add javascript to the instance to prevent editing but javascript can be turned off on the client side.

Submit a tracker request for future versions. Afaict it is not likely to be changed in released versions as it is not necessarily a bug.

At any rate, it seems like a fairly easy fix which you can try to apply to your installation. Basically, change the date_selector in the module settings form to date_time_selector.

So, in mod/data/mod_form.php around line 29, change

        $mform->addElement('date_selector', 'timeavailablefrom', get_string('availablefromdate', 'data'), array('optional'=>true));

        $mform->addElement('date_selector', 'timeavailableto', get_string('availabletodate', 'data'), array('optional'=>true));

        $mform->addElement('date_selector', 'timeviewfrom', get_string('viewfromdate', 'data'), array('optional'=>true));

        $mform->addElement('date_selector', 'timeviewto', get_string('viewtodate', 'data'), array('optional'=>true));

to

        $mform->addElement('date_time_selector', 'timeavailablefrom', get_string('availablefromdate', 'data'), array('optional'=>true));

        $mform->addElement('date_time_selector', 'timeavailableto', get_string('availabletodate', 'data'), array('optional'=>true));

        $mform->addElement('date_time_selector', 'timeviewfrom', get_string('viewfromdate', 'data'), array('optional'=>true));

        $mform->addElement('date_time_selector', 'timeviewto', get_string('viewtodate', 'data'), array('optional'=>true));

hth smile

In reply to Itamar Tzadok

Re: Restricting database activity to view only - date specified but not time

by Gordon McLeod -

Thanks Itamar,

I'll plan accordingly for the midnight limitation. The code change looks very straightforward. Unfortunately in my current post I don't have backend access to the live site so the IT change request process grinds slowly. I've added a tracker request in the hope that it filters through to core eventually - https://tracker.moodle.org/browse/MDL-43129

Regards, Gordon.

p.s. - Are there any plans to incorporate the enhanced dataform functionality into core database (or even replace database with dataform)?

In reply to Gordon McLeod

Re: Restricting database activity to view only - date specified but not time

by Itamar Tzadok -

Afaik there are no plans to replace. Functionality is added to core Database module based on community interest and contributions as with other modules and components. smile