src/Util/Caliper.php
public static function sensorCanvasPageView ($user, $application, $page,
            $timestamp=false, $name, $duration='PT5M30S') {

        $caliper = json_decode('{
            "@context" : "http://purl.imsglobal.org/ctx/caliper/v1/ViewEvent",
            "@type" : "http://purl.imsglobal.org/caliper/v1/ViewEvent",
            "action" : "viewed",
            "startedAtTime" : "Time.now.utc.to_i",
            "duration" : "PT5M30S",
            "actor" : {
                    "@id" : "user_id",
                    "@type" : "http://purl.imsglobal.org/caliper/v1/lis/Person"
            },
            "object" : {
                    "@id" : "context_url",
                    "@type" : "http://www.idpf.org/epub/vocab/structure/#volume",
                    "name" : "Test LTI Tool"
            },
            "edApp" : {
                    "@id" :"context_url",
                    "@type" : "http://purl.imsglobal.org/caliper/v1/SoftwareApplication",
                    "name" : "LTI Tool of All Things",
                    "properties" : {},
                    "lastModifiedTime" : "Time.now.utc.to_i"
            }
         }');

        if ( ! $timestamp ) $timestamp = time();
        $caliper->startedAtTime = $timestamp;
        $caliper->actor->{'@id'} = $user;
        $caliper->object->{'@id'} = $page;
        $caliper->edApp->{'@id'} = $application;
        $caliper->edApp->name = $name;
        $caliper->duration = $duration;
        $caliper = json_encode($caliper, JSON_PRETTY_PRINT);
        return $caliper;
    }
public static function sensorCanvasPageView ($user, $application, $page,
            $timestamp=false, $name, $duration='PT5M30S') {

        $caliper = json_decode('{
            "@context" : "http://purl.imsglobal.org/ctx/caliper/v1/ViewEvent",
            "@type" : "http://purl.imsglobal.org/caliper/v1/ViewEvent",
            "action" : "viewed",
            "startedAtTime" : "Time.now.utc.to_i",
            "duration" : "PT5M30S",
            "actor" : {
                    "@id" : "user_id",
                    "@type" : "http://purl.imsglobal.org/caliper/v1/lis/Person"
            },
            "object" : {
                    "@id" : "context_url",
                    "@type" : "http://www.idpf.org/epub/vocab/structure/#volume",
                    "name" : "Test LTI Tool"
            },
            "edApp" : {
                    "@id" :"context_url",
                    "@type" : "http://purl.imsglobal.org/caliper/v1/SoftwareApplication",
                    "name" : "LTI Tool of All Things",
                    "properties" : {},
                    "lastModifiedTime" : "Time.now.utc.to_i"
            }
         }');

        if ( ! $timestamp ) $timestamp = time();
        $caliper->startedAtTime = $timestamp;
        $caliper->actor->{'@id'} = $user;
        $caliper->object->{'@id'} = $page;
        $caliper->edApp->{'@id'} = $application;
        $caliper->edApp->name = $name;
        $caliper->duration = $duration;
        $caliper = json_encode($caliper, JSON_PRETTY_PRINT);
        return $caliper;
    }
public static function sensorCanvasPageView ( $ user , $ application , $ page , $ timestamp = false , $ name , $ duration = 'PT5M30S' ) { $ caliper = json_decode ( '{
            "@context" : "http://purl.imsglobal.org/ctx/caliper/v1/ViewEvent",
            "@type" : "http://purl.imsglobal.org/caliper/v1/ViewEvent",
            "action" : "viewed",
            "startedAtTime" : "Time.now.utc.to_i",
            "duration" : "PT5M30S",
            "actor" : {
                    "@id" : "user_id",
                    "@type" : "http://purl.imsglobal.org/caliper/v1/lis/Person"
            },
            "object" : {
                    "@id" : "context_url",
                    "@type" : "http://www.idpf.org/epub/vocab/structure/#volume",
                    "name" : "Test LTI Tool"
            },
            "edApp" : {
                    "@id" :"context_url",
                    "@type" : "http://purl.imsglobal.org/caliper/v1/SoftwareApplication",
                    "name" : "LTI Tool of All Things",
                    "properties" : {},
                    "lastModifiedTime" : "Time.now.utc.to_i"
            }
         }' ) ; if ( ! $ timestamp ) $ timestamp = time ( ) ; $ caliper -> startedAtTime = $ timestamp ; $ caliper -> actor -> { '@id' } = $ user ; $ caliper -> object -> { '@id' } = $ page ; $ caliper -> edApp -> { '@id' } = $ application ; $ caliper -> edApp -> name = $ name ; $ caliper -> duration = $ duration ; $ caliper = json_encode ( $ caliper , JSON_PRETTY_PRINT ) ; return $ caliper ; }
This is just a test method to return properly formatted JSON for the Canvas prototype Caliper

This is just a starting point to lay some initial groundwork.

@param $application string This is the name of the application - typically it is
the base domain name of the application like https://lti-tools.dr-chuck.com/tsugi/
@param $page This is the url of page of that was viewed.
@param $duration This is the duration of the activity on the page.
This is just a test method to return properly formatted JSON for the Canvas prototype Caliper