Button action event

Button action event

by John Wilson -
Number of replies: 3

Hi everyone:

I'm want to add a button in my module and users can call the custom function by clicking the button. How to connect onclick event with calling function.

Further more, is there anything like listener in Moodle?  I want my function called automatically under specified conditions.

Thanks in advance.

Average of ratings: -
In reply to John Wilson

Re: Button action event

by Benjamin Ellis -
Picture of Particularly helpful Moodlers
Hi,

For the OnClick, you will need to incorporate Javascript into the module page - See Javascript modules - https://docs.moodle.org/dev/Javascript_Modules

As for listeners, you need the Events API - see https://docs.moodle.org/dev/Events_API.

Cheers
In reply to Benjamin Ellis

回复: Re: Button action event

by John Wilson -
Hi, Benjamin

In fact, I'm want to call a python script in custome function, which is about Machine Learning. Can I use "shell_exec()" to call it in my function?

By the way, if I want to call the script automatically on a deadline, is there any event related to this in Moodle? Or do I need to define it in modulename / classes / event?

Many thanks for your help.
In reply to John Wilson

Re: 回复: Re: Button action event

by Benjamin Ellis -
Picture of Particularly helpful Moodlers
Hi,

I suppose you could do that - I would be very careful about the data coming form the client - if you do use that.

As for calling the script, why would you want to call it from Moodle if you can just set up a cron (scheduled task) to run the python script directly? If you do need it to be run from Moodle then look at the Tasks API - https://docs.moodle.org/dev/Task_API

Cheers