problem with search on moodle.org

problem with search on moodle.org

by John Ryan -
Number of replies: 8
I have written a block for use in my college. The block no longer works in 1.7 because I use the table user_students which is no longer present.

I have just tried to search on this site(moodle.org) using the search term

user_students 1.7

I received a page with code including an SQL query (a very long one)

"array(3) { [0]=> array(4) { ["file"]=> string(35) "/var/www/html/moodle/lib/dmllib.php" ["line"]=> int(354) ["function"]=> string(17) "get_recordset_sql" ["args"]=> array(1) { [0]=> &string(1599) "SELECT COUNT(*) FROM forum_posts p, forum_discussions d, user u WHERE ((p.message LIKE '%user_students%') OR (p.subject LIKE '%user_students%') ) AND ((p.message LIKE '%1.7%') OR (p.subject LIKE '%1.7%') ) AND p.discussion = d.id AND p.userid = u.id AND ((d.forum = 820) OR (d.forum = 27) ...... "

and an error message saying "this SQL relies on obsolete tables ....." which funny enough is the message I get when I try to use my block in 1.7!

I cannot find in 1.7 code how to get a list of students (or teachers) on a particular course. In particular I need to know which students have enrolled themselves on to a course and which have been enrolled via the external database enrolment table. This information was contained in the user_students table.

Thanks

John Ryan
Average of ratings: -
In reply to John Ryan

Re: problem with search on moodle.org

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi John,

Regarding searching for user_students on Moodle.org, Eloy has kindly just fixed this in CVS ("Prevent some false-positives detecting uses of old user_XXX tables").
In reply to John Ryan

user_students table gone, replaced with role_assignments

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi, John.

In Moodle 1.7 "students" and "teachers" are a hazy notion that we can no longer rely on.

user_students and user_teachers have been replaced with role_assignments, which has a similar structure plus a roleid field so you know which role was assigned.

You can join this to the "role" table if you like to get more information about each role.

Each role has a shortname which you *could* use to just get those who are a "student" but this method would be effectively hardcoded for your site, as these shortnames can be changed by admins in the general case.

The other method is to get_users_by_capability() which will find all the people who can view the course, for example.
In reply to Martin Dougiamas

Re: user_students table gone, replaced with role_assignments

by John Ryan -
Martin,

I can't find get_users_by_capability in dmlib, datalib, moodlelib or weblib so I don't know what parameters it takes.

On a separate point, I defined a new Role, called DBStudent which is an exact copy of the Student Role. I then used this as the default role for students who enrol via the database.

However, when I "logged in as" one of these students using the "Login as" from the user profile I got a list of all course categories rather than "my courses". When I logged in to a course I knew that student was enrolled on I got the correct list of courses in My courses. My courses is correct when I returned to the site level.

Is this a bug (perhaps minor -unless it hides a deeper problem of course!)?
or have I missed something with the setting up of the new roles?

Actually I've changed my mind -if it is a bug then it is not minor as students mainly want the "my courses" to be correct when first logged in as this is the point at which they mainly require it.


In reply to John Ryan

Re: user_students table gone, replaced with role_assignments

by Douglas Dixon -
All of the function related to user capabilities and permissions is located in /lib/accesslib.php. I hope this helps.
In reply to John Ryan

Re: user_students table gone, replaced with role_assignments

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Without checking it right now I think that, as Douglas said, the function is in accesslib. If you're working on Moodle code I strongly suggest getting used to the 'global search' facilities of your editor (or using one like Eclipse which automatically will jump to a function definition when you ctrl-click on the name) because it can be tough to find things otherwise!

There were various bugs in get_users_by_capability and the legacy get_course_students, which I think were still there in 1.7 release. You can also see these if you set up a 'per-student' wiki; the wiki works, but if you go into it as admin or teacher, the dropdown list shows you other users not just the ones on the course. On our site it showed about 20,000 users - 10% of our userbase - making it a pretty hefty dropdown smile

The good news is that I believe the get_users_by_capability bugs have been fixed on the stable branch. So while 1.7 release might still have the bugs, the 'stable' version probably doesn't. In other words, assuming you're running stable rather than development code, make sure you're using a recent stable version rather than 1.7 itself.

The get_course_students legacy function in deprecatedlib is, I think, still broken. I posted a bug and a possible fix in MDL-7592. We are running that fix in our code, but I wasn't certain that all issues were considered in my fix since I found the code difficult to understand, so I didn't want to check it into Moodle core (esp the stable branch) without getting the go-ahead from moodle.com folks.

--sam
In reply to Martin Dougiamas

Re: user_students table gone, replaced with role_assignments

by Michael Penney -
How are you planning on handling this with the Assignment submissions list?

Are the gradebook graded roles going be a long term solution to showing only students? (we have a project that requires a 'classlist' fucntion that only shows students, of course this was easy in 1.6, we're trying to figure out the best way to update this for 1.7+).
In reply to Michael Penney

Re: user_students table gone, replaced with role_assignments

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
In the quiz, there is am 'mod/quiz:attempt' capability, which is only given to students. But by controlling which people have that capability, you control who is allowed to do the quiz.