Logstore plugin get referring page URL

Logstore plugin get referring page URL

by jerrett fowler -
Number of replies: 9

Hi there,

I'm creating a logstore tool and I've gotten everything so far that I need from the logstore events except for the referring URL. Like if you open a course and it sends a "viewed course" event, it doesn't send anything but a number of the course number, but in order to decipher the unique URL that this probably came from requires a bunch of deciphering, which might be a bit tedious. I am prepared to write a function that can possibly decipher and extrapolate a possible URL but it would be very nice if there were a function available to logstore plugins that allowed this to be pulled.


Any ideas?


Thanks!

Average of ratings: -
In reply to jerrett fowler

Re: Logstore plugin get referring page URL

by jerrett fowler -

Just pushing this back to the top in case someone knows something.

In reply to jerrett fowler

Re: Logstore plugin get referring page URL

by Andrew Downes -

I ended up doing something like:

$CFG->wwwroot . '/mod/quiz/view.php?id='. $quiz->id

I guess this is what you're referring to as the tedious method as you have to work this out for every time of event. I don;t know if there is something in events that stores this; have you looked in the database? If it's not in the database, then you won't be able to get it!  

Average of ratings: Useful (1)
In reply to Andrew Downes

Re: Logstore plugin get referring page URL

by Neill Magill -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

You should be able to get a url for an event by doing something like:

$url = core\event\base::restore($data, $logextra)->get_url();


Average of ratings: Useful (1)
In reply to Neill Magill

Re: Logstore plugin get referring page URL

by jerrett fowler -

Hi Neill, I'm going to try this as soon as I get some time, hopefully in the next week. Thank you!

In reply to Neill Magill

Re: Logstore plugin get referring page URL

by jerrett fowler -

What is the $logextra supposed to be? Is it required?

In reply to jerrett fowler

Re: Logstore plugin get referring page URL

by Neill Magill -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

This is the description from the PHP Docs: @param array $logextra the format is standardised by logging API

The only reference to extra information in the Logging API docs seems to be: 

The log store plugin(s) stores the event data optionally including extra information such as remote IP or original logged-in-as user id

The standard logstore uses it like this:

public function get_events_select($selectwhere, array $params, $sort, $limitfrom, $limitnum) {
        global $DB;

        $sort = self::tweak_sort_by_id($sort);

        $events = array();
        $records = $DB->get_records_select('logstore_standard_log', $selectwhere, $params, $sort, '*', $limitfrom, $limitnum);

        foreach ($records as $data) {
            $extra = array('origin' => $data->origin, 'ip' => $data->ip, 'realuserid' => $data->realuserid);
            $data = (array)$data;
            $id = $data['id'];
            $data['other'] = unserialize($data['other']);
            if ($data['other'] === false) {
                $data['other'] = array();
            }
            unset($data['origin']);
            unset($data['ip']);
            unset($data['realuserid']);
            unset($data['id']);

            $event = \core\event\base::restore($data, $extra);
            // Add event to list if it's valid.
            if ($event) {
                $events[$id] = $event;
            }
        }

        return $events;
    }

Average of ratings: Useful (1)
In reply to Neill Magill

Re: Logstore plugin get referring page URL

by jerrett fowler -

I managed to get your idea to work. Thank you for that.

Where are these docs you speak of? I never found anything in Moodle's documentation.

In reply to Andrew Downes

Re: Logstore plugin get referring page URL

by jerrett fowler -

Hi Andrew,

That's exactly what I am currently doing for mod_scorm. Hopefully Neill's idea below will help me out!

I'll let you both know progress on this as soon as I get a bit of time to work on implementing it.