How to restrict delete activity after particular time

How to restrict delete activity after particular time

by Monika Gujar -
Number of replies: 6

Hello all,

Now what happening is, if I am creating activity using my plugin then we can delete it at any time. But my plugin is based on time. So, I need to restrict this deleting. I have 2 parameters as StartDateTime and CurrentDateTime . And what I want to do is, if StartDateTime <= CurrentDateTime then I don't want to allow to delete that activity.

Is it possible?

It will be great if we can hide the delete option.

Posted the same problem for edit...

Average of ratings: -
In reply to Monika Gujar

Re: How to restrict delete activity after particular time

by Dominique Palumbo -
Picture of Particularly helpful Moodlers Picture of Plugin developers
Hi,

if you add the following code in lib.php the delete for your plugin will be invisible all the time in the contect menu.
But with the id of the activity ($cm->id and all cminfo) you can get the date, check it, and put condition.
Not elegant but it's work...

function tgwhiteboard_cm_info_view(cm_info $cm)  {
    $cm->set_after_link("<script>
        window.addEventListener('DOMContentLoaded', (event) => {
            var container = document.querySelector('#module-".$cm->id."');
            var childNode = container.querySelector('.editing_delete');
           childNode.style.display = 'none';
        });
      </script>
    ");
}

In reply to Dominique Palumbo

Re: How to restrict delete activity after particular time

by Monika Gujar -
Hey,
Thanks... but nothing changed after adding this code.
In reply to Monika Gujar

Re: How to restrict delete activity after particular time

by Dominique Palumbo -
Picture of Particularly helpful Moodlers Picture of Plugin developers
Hi,

I just copy it as it is in the lib.php of the old version of your plugin and the delete item in the menu doesn't exist anymore.
Which theme do you use ? Or is something else you want to do ?

Dominique
In reply to Dominique Palumbo

Re: How to restrict delete activity after particular time

by Monika Gujar -
Attached is my lib.php
Help me, if mistaken
In reply to Monika Gujar

Re: How to restrict delete activity after particular time

by Dominique Palumbo -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi,

it seems it's just a little copy/paste problem.

I do the modifications, just compare with your original file to see the differences and specially if you have modify it.

In this example it remove the delete all the time... You'll have to add code to check date and time but you already have it.

Dominique

In reply to Dominique Palumbo

Re: How to restrict delete activity after particular time

by Monika Gujar -
after adding the same code I am not able to delete any session, where I wanted to restrict the session from deleting for a particular time. But thanks smile atleast we can stop the session from deleting