From 0e4b7bc4d9966020e5546bc5c39a9853c0e1bca7 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Fri, 27 Oct 2017 12:22:55 +0400 Subject: Event registration is added --- classes/handler.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/classes/handler.php b/classes/handler.php index 5bc5473..6cf1cc1 100644 --- a/classes/handler.php +++ b/classes/handler.php @@ -28,8 +28,6 @@ defined("MOODLE_INTERNAL") || die(); require_once($CFG->libdir . "/filelib.php"); -use curl; - /** * Defines how to work with events. * @@ -100,9 +98,29 @@ class handler { * @param object $callback */ private static function send($data, $callback) { - $curl = new curl(); + $curl = new \curl(); $curl->setHeader(array("Content-Type: application/$callback->type")); $curl->post($callback->url, json_encode($data)); - return $curl->getResponse(); + $response = $curl->getResponse(); + self::logger($callback, $response); + return $response; + } + + /** + * Event logging. + * + * @param array $response + * @param object $callback + */ + private static function logger($callback, $response) { + $event = \local_webhooks\event\response_get::create(array( + "context" => \context_system::instance(0), + "objectid" => $callback->id, + "other" => array( + "status" => $response["HTTP/1.1"] + ) + )); + + $event->trigger(); } } \ No newline at end of file -- cgit v1.2.3