Getting parent learning context information
NOTE: This applies to WebCT Vista 3.x. In Vista 4/CE 6, the getParent and getChildren methods were added to the ContextSDK to retrieve information about parent and child learning contexts.
A question that comes up often is:
"I have a section learning context object. How do I get information about it's parent course?"
Until recently, the answer was always:
"Query the RPT_LEARNING_CONTEXT view in the reporting interfaces."
This isn't always convenient nor even possible in some cases. There is an alternative however, that uses only SDK calls. Note that the procedure described here is a bit of a workaround and there is NO GUARANTEE IT WILL WORK in future versions of the SDK.
In a nutshell, here is how it works:
First, it assumes that the session user is enrolled in the section for which you want the parent course.
- Use the FileManager web service's getRootFolders method.
- Loop through the list of folders until you find the one that matches the section. (Compare the LearningCtxtVO's label to the FileManagerFolder's path)
- When you find the matching folder, remove the start of the folder's path from "/webct/WebCT Server" down to (and including) the institution name. Then remove the section name from the end of the folder's path. The resulting string will look something like this: /My Group/My Course
Here you already have your course name, but what if you want more, like the LCID?
- Pass the resulting string to the Context web service's getLearningContextIdByPath method and voilà! You have the LCID of the course.
To get the actual learning context VO, pass the LCID to the getLearningContext method.
Here is some PHP code to demonstrate. $fm and $context are the FileManager and Context proxies respectively.
$roots = $fm->getRootFolders($session); print "<pre>"; foreach($roots as $root) { $path = $root->path; print $path; $parts = explode("/", $path); // find a section if($parts=="Section Content") { // chop off path from server down to institution array_splice($parts, 0, 6); // chop off the section name and section content array_splice($parts, 2, 2); $fixedPath = "/" . implode("/", $parts); $lcid = $context->getLearningContextIdByPath($session, $fixedPath); print "Course LCID: $lcid\n"; $lc = $context->getLearningContext($session, $lcid); var_dump($lc); } print "\n"; } print "</pre>";
| This article originally authored by Paul Monk on the WebCT DevNet |
Comments (1)
23 Oct 2007
Stephen Vickers says:
The method I use to get the details of a parent learning context (e.g. the cours...The method I use to get the details of a parent learning context (e.g. the course from within a section) is to use the getParentLcId() method of the com.webct.platform.sdkext.authmoduledata.LearningContextVO object. This returns the ID of the parent learning context which can then be used to get its LearningContextVO object. This seems to me to be a lot simpler than the looping method described on this page.
My only outstanding query in relation to this solution (reported in Case #472522, 23 July 2007) is that under AP2 a section can now have two parents in the learning context hierarchy (a course and a term), so does the getParentLcId() method guarantee to return the course (rather than the term).