Skip to content

Commit

Permalink
GH-490 Fix error when viewing logs
Browse files Browse the repository at this point in the history
This is fixed here by adding a method that checks for the data type of the other data and always returns it as object.
  • Loading branch information
davidszkiba committed May 16, 2024
1 parent 0fe579b commit 67392cd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
22 changes: 18 additions & 4 deletions classes/event/attempt_completed.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public static function get_name() {
*/
public function get_description() {
$data = $this->data;
$otherarray = json_decode($data['other']);
$other = $this->get_other_data();

$catscaleid = $otherarray->catscaleid;
$catscaleid = $other->catscaleid;
$linktoscale = catscale::get_link_to_catscale($catscaleid);
$data['catscalelink'] = $linktoscale;

$data['attemptid'] = $otherarray->attemptid;
$data['userid'] = $otherarray->userid;
$data['attemptid'] = $other->attemptid;
$data['userid'] = $other->userid;
$data['catscalelink'] = $linktoscale;
return get_string('complete_attempt_description', 'local_catquiz', $data);
}
Expand All @@ -87,4 +87,18 @@ public function get_description() {
public function get_url() {
return new moodle_url('');
}

/**
* Returns the 'other' data as object
* @return mixed
*/
private function get_other_data() {
if (is_array($this->data['other'])) {
return (object) $this->data['other'];
}
if (is_string($this->data['other'])) {
return json_decode($this->data['other']);
}
return $this->data['other'];
}
}
29 changes: 20 additions & 9 deletions classes/event/feedbacktab_clicked.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,22 @@ public static function get_name() {
* @return string
*/
public function get_description() {
$data = $this->data;
$otherarray = json_decode($data['other']);
$other = $this->get_other_data();
$url = new moodle_url('manage_catscales.php', [
'attemptid' => $otherarray->attemptid,
'attemptid' => $other->attemptid,
], 'lcq_quizattempts');
$attemptlink = html_writer::link(
$url,
get_string('feedbacksheader', 'local_catquiz', $otherarray->attemptid),
get_string('feedbacksheader', 'local_catquiz', $other->attemptid),
// Open the attempt in a new tab, otherwise the link does not work because it just appends an anchor.
['target' => '_blank']
);
return get_string(
'feedback_tab_clicked_description',
'local_catquiz',
[
'userid' => $otherarray->userid,
'feedback_translated' => $otherarray->feedback_translated,
'userid' => $other->userid,
'feedback_translated' => $other->feedback_translated,
'attemptlink' => $attemptlink,
]
);
Expand All @@ -88,10 +87,22 @@ public function get_description() {
* @return object
*/
public function get_url() {
$data = $this->data;
$otherarray = json_decode($data['other']);
return new moodle_url('manage_catscales.php', [
'attemptid' => $otherarray->attemptid,
'attemptid' => $this->get_other_data()->attemptid,
], 'lcq_quizattempts');
}

/**
* Returns the 'other' data as object
* @return mixed
*/
private function get_other_data() {
if (is_array($this->data['other'])) {
return (object) $this->data['other'];
}
if (is_string($this->data['other'])) {
return json_decode($this->data['other']);
}
return $this->data['other'];
}
}

0 comments on commit 67392cd

Please sign in to comment.