gpt4 book ai didi

Subscribing to the event of the "quiz" module of the Moodle CMS from its own plugin(从Moodle CMS自有插件订阅Moodle CMS的“测验”模块活动)

转载 作者:bug小助手 更新时间:2023-10-28 09:42:45 24 4
gpt4 key购买 nike



Good afternoon, I am developing my own plugin (folder: local) for the Moodle platform version "2023042400" - (4.2.2+) on the Windows platform.

下午好,我正在为Windows平台上的Moodle平台版本“2023042400”-(4.2.2+)开发我自己的插件(文件夹:Local)。


There was such a need to subscribe to the event of the standard module "quiz" called "Send everything and finish". I have a need to get all the wrong answers after completing the test and give out additional information in the interface, but for now I will be happy only to sign the data.

因此需要订阅名为“发送所有内容并完成”的标准模块“测验”事件。我需要在完成测试后得到所有错误的答案,并在界面上提供额外的信息,但目前我只会高兴地签署数据。


The programming language used is "PHP".

使用的编程语言是“PHP”。



P.S. I am new to this environment, so I will be happy to describe the solution in detail.



Path to file: \local\adaptive_quiz\version.php:

文件路径:\LOCAL\ADAPTIAL_QUZ\version.php:


<?php
defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023090900; //version of plugin
$plugin->requires = 2023042400; //version of moodle
$plugin->pluginname = 'Adaptive Quiz';
$plugin->component = 'local_adaptive_quiz';

I tried to do a lot of things that Chat GPT advised me to do:

我试着做了很多Chat GPT建议我做的事情:



  • Study the CMS Moodle source code. I have studied. I realized that the CMS creates through, like, the single_button class after it finds this form in JS or the subscribe to event button, but I didn't understand how to subscribe to the event and get the data myself.

  • Subscribe to the prepared event through the name of the method, nothing happened.

  • Subscribe via $handlers, but he also didn't call the method.



I check the method through error_log, it is checked by me every time through the callback method - before_footer. Here before_footer works fine.



Path: \local\adaptive_quiz\lib.php:

路径:\LOCAL\ADAPTIAL_QUZ\lib.php:


code that checks the plugin for operability:

检查插件可操作性的代码:


<?php
function local_adaptive_quiz_before_footer(){
error_log('лог сработал');
return \core\notification::add('Plugin Local adaptive quiz is worked! v8',
\core\output\notification::NOTIFY_SUCCESS);
}

code with variable "$handlers":

带有变量“$Handler”的代码:


//code that checks the plugin for operability...

function local_adaptive_quiz_after_submit($attemptid) {
error_log('local_adaptive_quiz_after_submit worked');

//Answer of users...
$user_responses = "ответы пользователя";

echo json_encode($user_responses);
}

$handlers = array(
'quiz_attempt_submitted' => array(
'handlerfile' => '\local\adaptive_quiz\lib.php',
'handlerfunction' => 'local_adaptive_quiz_after_submit',
'schedule' => 'instant',
),
);

更多回答

I don't understand, what is your question ? Also, chat gpt is fine and dandy but so limited to answer questions about moodle development... It'll be far more usefull and quicker to look at the moodle dev website and its documentation which is ultra complete.

我不明白,你的问题是什么?此外,聊天gpt也不错,但仅限于回答有关moodle开发的问题。浏览moodle dev网站及其超级完整的文档会更有用、更快捷。

@Veterini. My question is that my plugin was supposed to subscribe to the "test completion" event, but it didn't respond at all. I wanted to know how to do it right

@维特里尼。我的问题是,我的插件应该订阅“测试完成”事件,但它根本没有响应。我想知道怎么才能做对

If your solution works it's fine but it would be better to follow moodle's way more straightfully (in my own opinion ^^). It can be a hassle some time but in the long run it simplify the work. First a link to the event API on the official documentation : docs.moodle.org/dev/Events_API From what i see your way doesn't use the API as it should. You should have a corresponding file for each event in local/yourplugin/classes/event. The event API has all the built in function that records event the right way into moodle. Can you retrieve your event in the logs event page ?

如果你的解决方案奏效,那很好,但更直接地遵循Moodle的方法会更好(在我看来^)。这在一段时间内可能会很麻烦,但从长远来看,它会简化工作。首先,在官方文档中有一个指向事件API的链接:docs.moodle.org/dev/Events_api,在我看来,它并没有使用应该使用的API。您应该在local/you plugin/Class/Event中为每个事件都有一个对应的文件。Event API具有以正确方式将事件记录到moodle中的所有内置函数。您是否可以在日志事件页中检索您的事件?

it may interest you to check events in this widely used plugin : github.com/academic-moodle-cooperation/moodle-mod_offlinequiz/…

您可能有兴趣查看这个广泛使用的插件中的事件:github.com/academic-moodle-cooperation/moodle-mod_offlinequiz/…

@Veterini oooh thank you very much

@维特里尼:哦,非常感谢

优秀答案推荐

The answer turned out to be quite simple. It was necessary to create using the following path \local\{name_your_plugin}\db\events.php, following code:

答案原来很简单。必须使用以下路径创建:\local\{name_Your_plugin}\db\events.php,代码如下:


 $observers = array(
array(
'eventname' =>'\mod_quiz\event\attempt_submitted', //name of event
'includefile' => '\local\adaptive_quiz\classes\attempt_event_submitted_observer.php', //file containing the callback function
'callback' =>'observe_one', //callback function
'internal' => false
),
);

And along the path (\local\adaptive_quiz\classes\attempt_event_submitted_observer.php) that we wrote create a callback function:

并沿着我们编写的路径(\local\adaptive_quiz\classes\attempt_event_submitted_observer.php)创建一个回调函数:


function observe_one($event) {
echo '<h1>observe_one is worked</h1>';
}

The main thing is that you need to check the function through the student account. Otherwise the function does not work.

最重要的是,你需要通过学生账号来查看功能。否则,该函数不起作用。


更多回答

But Moodle feels like it is overwriting the message, I checked the function through error_log(), so it works.

但Moodle感觉它正在覆盖消息,我通过error_log()检查了该函数,因此它可以工作。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com