Skip to content

Commit

Permalink
Merge pull request #30 from talview/restrict_callback_on_noproctor
Browse files Browse the repository at this point in the history
restrict callback trigger on no proctor
  • Loading branch information
devang1281 authored Sep 4, 2023
2 parents 515083b + ed473f0 commit 5ab4bc8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
51 changes: 28 additions & 23 deletions classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
* @copyright 2014 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

interface CustomThrowable extends \Throwable
{

Expand All @@ -45,7 +44,9 @@ class CustomException extends \Exception implements CustomThrowable
{

}
class quizaccess_proctor_observer {

class quizaccess_proctor_observer
{

/** @var int indicates that course module was created */
const CM_CREATED = 0;
Expand Down Expand Up @@ -82,19 +83,6 @@ public static function store(\core\event\base $event)
return;
}
$eventdata = new \stdClass();
switch ($event->eventname) {
case '\core\event\course_module_created':
$eventdata->action = self::CM_CREATED;
break;
case '\core\event\course_module_updated':
$eventdata->action = self::CM_UPDATED;
break;
case '\core\event\course_module_deleted':
$eventdata->action = self::CM_DELETED;
break;
default:
return;
}
$quiz = $DB->get_record('quiz', array('id' => $event->other['instanceid']));
$quiz_proctor_settings = $DB->get_record('quizaccess_proctor', array('quizid' => $event->other['instanceid']));
$eventdata->quiz_title = $event->other['name'];
Expand All @@ -113,6 +101,21 @@ public static function store(\core\event\base $event)
$eventdata->timemodified = $quiz->timemodified;
$eventdata->timecreated = $quiz->timecreated;
$eventdata->userid = $event->userid;
switch ($event->eventname) {
case '\core\event\course_module_created':
if ($quiz_proctor_settings->proctortype === 'noproctor')
return;
$eventdata->action = self::CM_CREATED;
break;
case '\core\event\course_module_updated':
$eventdata->action = self::CM_UPDATED;
break;
case '\core\event\course_module_deleted':
$eventdata->action = self::CM_DELETED;
break;
default:
return;
}
try {
$auth_response = self::generate_auth_token($api_base_url, $auth_payload);
if (!$auth_response) {
Expand All @@ -128,11 +131,11 @@ public static function store(\core\event\base $event)
}



private static function generate_auth_token($api_base_url, $payload) {
private static function generate_auth_token($api_base_url, $payload)
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $api_base_url.'/auth',
CURLOPT_URL => $api_base_url . '/auth',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
Expand Down Expand Up @@ -161,10 +164,11 @@ private static function generate_auth_token($api_base_url, $payload) {
}
}

private static function send_quiz_details($api_base_url, $token, $eventdata) {
private static function send_quiz_details($api_base_url, $token, $eventdata)
{
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $api_base_url.'/quiz',
CURLOPT_URL => $api_base_url . '/quiz',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
Expand All @@ -173,7 +177,7 @@ private static function send_quiz_details($api_base_url, $token, $eventdata) {
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($eventdata),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer ".$token,
"Authorization: Bearer " . $token,
"Content-Type: application/json"
],
]);
Expand All @@ -194,8 +198,9 @@ private static function send_quiz_details($api_base_url, $token, $eventdata) {
}
}

public static function capture_error (\Throwable $err) {
\Sentry\init(['dsn' => 'https://61facdc5414c4c73ab2b17fe902bf9ba@o286634.ingest.sentry.io/5304587' ]);
public static function capture_error(\Throwable $err)
{
\Sentry\init(['dsn' => 'https://61facdc5414c4c73ab2b17fe902bf9ba@o286634.ingest.sentry.io/5304587']);
\Sentry\captureException($err);
}
}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023082901;
$plugin->version = 2023090402;
$plugin->requires = 2020061500;
$plugin->release = '1.2.0 (Build: 2023082901)';
$plugin->release = '1.2.0 (Build: 2023090402)';
$plugin->component = 'quizaccess_proctor';
$plugin->maturity = MATURITY_STABLE;

Expand Down

0 comments on commit 5ab4bc8

Please sign in to comment.