Reputation: 238
I want to control actions, which user doing in test(click on answer, finish test and other)? Is it possible?
I think, that for this task need to create plugin? Am i right? And dear community, can you help me some material - how develop plugin? Maybe can recomend some sites ot articles? Cause now I don`t understand this process.
For example, I know that plugin need to install in Moodle? But where create plugin before installing? In moodle also? But how export created in Moodle plugin to installing package?
For me very important question - how create installation package with plugin, that other users can install it.
Sorry for a lot question, and thanks for help.
Upvotes: 0
Views: 5855
Reputation: 10221
These are the developer docs - https://docs.moodle.org/dev/Main_Page
Depends which plugin you need to develop - https://docs.moodle.org/dev/Plugin_types
If its part of a course then you will need to develop an activity module - https://docs.moodle.org/dev/Activity_modules
Or if not, then you will probably want a local plugin - https://docs.moodle.org/dev/Local_plugins
UPDATE:
Use a local plugin and respond to one of the quiz events.
https://docs.moodle.org/dev/Event_2#Event_observers
This is an overview:
Create a local plugin - https://docs.moodle.org/dev/Local_plugins
Then in local/yourpluginname/db/events/php
have something like
defined('MOODLE_INTERNAL') || die();
$observers = array(
array(
'eventname' => '\mod_quiz\event\attempt_submitted',
'includefile' => '/local/yourpluginname/locallib.php',
'callback' => 'local_yourpluginname_attempt_submitted',
'internal' => false
),
);
This will respond to the attempt_submitted
event when a user submits a quiz. I'm guessing this is the event that you will need to use. If not, then there are others here /mod/quiz/classes/event/
Then in /local/yourpluginname/locallib.php
have something like
/**
* Handle the quiz_attempt_submitted event.
*
* @global moodle_database $DB
* @param mod_quiz\event\attempt_submitted $event
* @return boolean
*/
function local_yourpluginname_attempt_submitted(mod_quiz\event\attempt_submitted $event) {
global $DB;
$course = $DB->get_record('course', array('id' => $event->courseid));
$attempt = $event->get_record_snapshot('quiz_attempts', $event->objectid);
$quiz = $event->get_record_snapshot('quiz', $attempt->quiz);
$cm = get_coursemodule_from_id('quiz', $event->get_context()->instanceid, $event->courseid);
if (!($course && $quiz && $cm && $attempt)) {
// Something has been deleted since the event was raised. Therefore, the
// event is no longer relevant.
return true;
}
// Your code here to send the data to an external server.
return true;
}
That should get you started.
Upvotes: 4