Web Services get_my_module_grade

Web Services get_my_module_grade

by Andrew Parry -
Number of replies: 4

Good Afternoon All,

I'am hoping that someone will be able to help me with the usage of the get_my_module_grade function.

I'm using Visual Basic/ Visual Studio 2010 and can create & retrieve user and also course results but I'm required to get the results from a Module level.

the function is described as.

get_my_module_grade(client As Integer, sesskey As String, id as Integer, type as String)

I do not fully understand what the id as integer and the type as string variables require. Is this the primary id of the module? Documentation says that it is the activityID? 

If someone could elaborate on this that would make my week!

Also, once this project is complete i will be uploading an example of how to use the webservices with VB.

 

Regards - Andrew 

 

 

Average of ratings: -
In reply to Andrew Parry

Re: Web Services get_my_module_grade

by Patrick Pollet -

 

Here are the PHPdocs comments for this operation in wspp/mdl_base_server.class.php 

/**
* retrieve my grade to an activity
* @param int $client
* @param string $sesskey
* @param int $activityid
* @param string $activitytype
* @return gradeItemRecord[]
*/

Aside usual client and sesskey used for authentication, the int id is indeed the activity id as found in table mdl_course_module and the string type is the type of activity (i.e. the module name) as found in table mdl_module such as 'forum', 'chat', 'wiki' ...

See actual code in function get_module_grades  near lines 4930 in wspp/server.class.php  

HTH

In reply to Patrick Pollet

Re: Web Services get_my_module_grade

by Andrew Parry -

Thankyou patrick for the quick response,

Unfortunetly our Moodle instance is remotely hosted and we do not have access to the database. Although i have requested the details of the 2 tables you mentioned from out provider.

I have tried all of the following strings, assign, assignment, book, chat, choice, data, feedback, folder, forum, glossary, imscp, label, lesson, lti, page, quiz, resource, scorm, survey, url, wiki, workshop.

So my guess is that i have the wrong id. I have taken the id from the URL from moodle and stuck it in the following code.

Dim s AsNew MoodleWS.MoodleWSPortTypeClient()

Dim lr As MoodleWS.loginReturn = s.login("****", "*****")

 Dim userModules As MoodleWS.getModuleGradesReturn

 userModules = s.get_my_module_grade(lr.client, lr.sessionkey, "60612", "choice")

 For i = 0 To userModules.grades.Length - 1

 Console.WriteLine(userModules.grades(i).userid.ToString())

 Next

 It returns the following error for all string types.

<faultcode>MOODLE:error</faultcode>
<faultstring>Wspp Base Server :activity choice with id 60612 unknown.</faultstring>

 

In reply to Andrew Parry

Re: Web Services get_my_module_grade

by Patrick Pollet -

Argh, I suspect there is something wrong in my code ;-(

If you have access to source code of wspp/server.class.php, could you try replacing near line 4938 

the call to get_coursemodule_from_instance by get_coursemodule_from_id  as below :

// rev 04/04/2013 see https://moodle.org/mod/forum/post.php?reply=981346
//if (!$cm = get_coursemodule_from_instance($activitytype,$activityid, 0)) {
if (!$cm = get_coursemodule_from_id($activitytype,$activityid, 0)) {

 

Cheers

 

In reply to Patrick Pollet

Re: Web Services get_my_module_grade

by Patrick Pollet -

@andrew

   the operation get_my_module grade (and the related get_my_quiz_grade, get_my_assignment_grade...) were indeed broken due to confusion between course's module id and instance id. You have to send if activity id, as it appear is the URL, like you did.  Internally my code should have used this id to get the course module instance and use that instanceid to fetch grades ... 

    A revised version tested against Moodle 2.4.3 is on github https://github.com/patrickpollet/moodlews with also minor revisions to get_my_courses due to database changes in Moodle 2.4 and PHP strict standard errors when Moodle was in full debug mode and 'display errors onscreen' activated.

Cheers.