RusticiSoftware / TinCanPHP

PHP library for the Experience API (Tin Can API)
http://rusticisoftware.github.io/TinCanPHP/
Apache License 2.0
87 stars 80 forks source link

Context Object - possible inconsistency with specification #79

Open GrantBailey opened 8 years ago

GrantBailey commented 8 years ago

The xAPI specification's description of the properties of the Context Object (see https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#requirements-10) is as follows:

In apparent contravention of the specification the PHP xAPI library allows the 'revision' and 'platform' properties where the Statement's Object is other than Activity. Example:

$activity = new TinCan\Activity ( [ 'id' => 'http://www.baileyandireland.com/tincan/meeting/16-10-16', 'objectType' => 'Agent', 'name' => 'Andrew Downes', 'mbox' => 'mailto:andrew@example.co.uk' ] ); $context = new TinCan\Context ( [ 'registration' => 'ec531277-b57b-4c15-8d91-d292c5b2b8f7', 'instructor' => [ 'name' => 'Andrew Downes', 'account' => [ 'homePage' => 'http://www.example.com', 'name' => '13936749' ], 'objectType' => 'Agent' ], 'team' => [ 'name' => 'Team PB', 'mbox' => 'mailto:teampb@example.com', 'objectType' => 'Group' ], 'contextActivities' => [ 'parent' => [ 'id' => 'http://www.example.com/meetings/series/267', 'objectType' => 'Activity' ], 'grouping' => [ 'id' => 'http://example.adlnet.gov/xapi/example/Algebra1' ], 'category' => [ 'id' => 'http://www.example.com/meetings/categories/teammeeting', 'objectType' => 'Activity', 'definition' => [ 'name' => [ 'en-US' => 'team meeting' ], 'description' => [ 'en-US' => 'A category of meeting used for regular team meetings.' ], 'type' => 'http://example.com/expapi/activities/meetingcategory' ], ],
'other' => [ [ 'id' => 'http://www.example.com/meetings/occurances/34257', 'objectType' => 'Activity' ], [ 'id' => 'http://www.example.com/meetings/occurances/3425567', 'objectType' => 'Activity' ] ] ], 'revision' => 'Updated in Dec 2015', 'platform' => 'Example virtual meeting software', 'language' => 'en', 'statement' => [ 'objectType' => 'StatementRef', 'id' => '6690e6c9-3ef0-4ed3-8b37-7f3964730bee' ], 'extensions' => [ 'http://example.com/profiles/meetings/activitydefinitionextensions/room' => [ 'name' => 'Kilby', 'id' => 'http://example.com/rooms/342' ] ] ] );

garemoko commented 8 years ago

You're trying to cast what looks like an agent object (but with an id property) as a TinCan\Activity.

I'm surprised that isn't erroring, but maybe it's just ignoring the properties it doesn't need and simply using the id to build an activity.

$activity = new TinCan\Activity (
[ 
'id' => 'http://www.baileyandireland.com/tincan/meeting/16-10-16',
'objectType' => 'Agent',
'name' => 'Andrew Downes',
'mbox' => 'mailto:andrew@example.co.uk'
]
);

Try this instead:

$object = new TinCan\Agent (
[ 
'objectType' => 'Agent',
'name' => 'Andrew Downes',
'mbox' => 'mailto:andrew@example.co.uk'
]
);
brianjmiller commented 8 years ago

This actually appears to be an issue with semver breakage in the specification between 1.0.0 and 1.0.1.

1.0.0 Version:

The revision property MUST NOT be used if the Statement's Object is an Agent or Group. The platform property MUST NOT be used if the Statement's Object is an Agent or Group.

1.0.1+ Version:

The revision property MUST only be used if the Statement's Object is an Activity. The platform property MUST only be used if the Statement's Object is an Activity.

Not that it will necessarily matter for this lib. In general the library doesn't do any validation of objects leaving that to the LRS, but I could in this case see us checking during Statement serialization whether those properties exist/should be included in the Context.

GrantBailey commented 8 years ago

Andrew, Brian: Thanks once again for the clarifications. Hopefully I will be on the right track now!