Get user data within activities in course

Get user data within activities in course

by Adrian Perez Rodriguez -
Number of replies: 8

Hello everybody

I am looking for an easy way to check if there is user data stored in the course activities. By user data I mean a real submission to a assignment, a forum post/discussion and so on.

I've checked the Privacy API and fiddled around with get_context_for_userid and get_users_in_context, but they return the user ID even if a user has just visited a forum activity.

Any ideas how to solve this? I know I could use some core methods like get_user_submissions for assignments. It would be really cool to handle all this with the Privacy API, since all core plugins have this implemented. It would make programming what I want to achieve extremely easy.

Thanks for your help,
Adrian

Average of ratings: -
In reply to Adrian Perez Rodriguez

Re: Get user data within activities in course

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
The Privacy API is not designed to handle this and will likely give you the 'wrong' results for what you're after.
Average of ratings: Useful (1)
In reply to Andrew Lyons

Re: Get user data within activities in course

by Adrian Perez Rodriguez -
Okay I was already thinking that maybe it will not be possible that way. But with that Privacy API in the end you delete these records? So somewhere you fetch the "real" user data and not only the metadata, logs?
In reply to Adrian Perez Rodriguez

Re: Get user data within activities in course

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Well, what do you consider user data? If a user visits an activity, that creates a log entry, which is use data. As you say, both privacy API and backup system would agree on that.

So, I think inevtably, if you want something else, the definition will have to be activity-specific.
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Get user data within activities in course

by Adrian Perez Rodriguez -
Thanks Tim.

Yes I agree. But as I mentioned in my first post, I mean in this case: By user data I mean a real submission to a assignment, a forum post/discussion and so on.

What we want to do is check courses, if there is some data stored in the activities. These courses will be duplicated and should be clean before duplicating. Can it be that only in wikis, glossaries and databases the "user data" will be copied?

Greets,
Adrian
In reply to Adrian Perez Rodriguez

Re: Get user data within activities in course

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
In reply to Marcus Green

Re: Get user data within activities in course

by Adrian Perez Rodriguez -

Thanks for sharing the link Marcus.

Will take this as a note so that once the courses are identified, we can clean them up if necessary according to this manual.

Cheers,
Adrian

In reply to Adrian Perez Rodriguez

Re: Get user data within activities in course

by Ken Task -
Picture of Particularly helpful Moodlers

There is a moosh command for 'course_info' and one can point it to a single course ID.   Not indepth detail, but maybe enough for your needs.

Example: course ID 13

13    Art II: Graphic Design & Illustration I - Letterman

running moosh pointed at course ID renders info:

Course ID: 13
No of contexts: 283
Context by level:
    CONTEXT_MODULE (70):    279
    CONTEXT_BLOCK (80):    4
Context by module:
    assign (1):    101
    folder (8):    11
    forum (9):    1
    label (12):    46
    page (15):    5
    resource (17):    43
    url (20):    72
Number of role capability overwrites: 0
Role capability overwrites by context:
Number of local role assignments: 0
Locally assigned roles by context:
Number of enrolled users: 1
Users enrolled by role:
    editingteacher (3):    1
Number of groups: 0
Group statistics:
    Min number of members in a group:    0
    Max number of members in a group:    0
    Avg number of members in a group:    0
Course modinfo size: 534550
Number of sections: 16
Section statistics:
    Sections visible:    5
    Sections hidden:    11
    Min number of modules in a section:    1
    Max number of modules in a section:    57
    Avg number of modules in a section:    17
Number of grades: 0
Number of log entries: 1
Number of files: 13941
Total file size: 10012126809
Cache build time: 0.036978960037231

Tells me only one user currently enrolled ... no students ... looks like admin doesn't need to run reset on that course and thus could be archived ... however one does that.  Since this is a command line only utility don't have to build anything gui (no customsql report to create) and will use less resources of server even in 'primetime' of site usage.

That help?

'SoS', Ken