Event Listeners in PHP or Moodle?

Event Listeners in PHP or Moodle?

by Frederico Alves -
Number of replies: 0

Hello, I'm a Junior developer currently working as a volunteer so I can gain experience. The stack I'm familiar with is MERN. So PHP and Moodle has been an interesting experience for me so far. I'm very new to both.

I'm currently helping the team build analytics for the quizzes to better aid the students with their studies. I just finished adding some bootstrap progress bars for different areas of the quiz. But now we would like to generate a table to sum up the time spent in different areas of the quiz.

Our table is very simple, it consists of 3 columns, the questionattemptid, questionstart, questionend, those last two would be timestamps.

My plan is to have a variable be assigned a timestamp when the page is rendered, that would be the question start, and then another variable be assigned a timestamp when the "Next Question" button is clicked on following a SQL Insert into the table.

at the html/mod/quiz/attempt.php , I passed the $DB variable into the echo $output->attempt_page , so I could use the database in attempt_page function inside the renderer.php file.

I did a var_dump of a simple SQL $DB->get_records_sql('SHOW TABLES;'); and it works, but the problem now is this I don't know how to do a  Onclick do this.

I'm used to it using JQuery with Express and Node.js, or in React, but I have no clue in PHP.

I thought about passing a script to $output, something like
$output .= "<script type="text/javascript">
                      $(document).ready(function(){
                              $("button").click(function(){
                                    do something..........
                                 }
                          }
                      </script>
                     "
But the problem is, I'm sure that I won't be able to use $DB in there and send data to the database. Or is it possible to run php code inside the script or HTML?

Again, I'm very new to PHP, I'm learning as I'm going.

Not sure if this is helpful but, the release the team is using is 3.7.2+, build: 20191004 , version = 2019052002.06

Thank you.

Average of ratings: -