What should deprecated function be replaced by ?

What should deprecated function be replaced by ?

by Valery Fremaux -
Number of replies: 7

Is there any documentation about changing coding strategy for knowing all students or teachers in a course. In other words, what should be the alternative to old (deprecated) get_course_students(), get_course_teachers().

In extention, if some roles are cloned from legacy student and/or teachers, should that alternative be able to keep such users in the student (resp. teacher) list ?

Average of ratings: -
In reply to Valery Fremaux

Re: What should deprecated function be replaced by ?

by Petr Kalis -
HI
I would like to see this informations too. Some "best practices" when you want to get rid of depecated functions. I saw some advices here and there, but i cannot find any central page in documentation sad.
PK
In reply to Petr Kalis

Re: What should deprecated function be replaced by ?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The two main sources of information are http://docs.moodle.org/en/Development:Roles - especially the Programming Interface section, and all the PHPdocumentor comments in lib/accesslib.php. The thing to be careful of when looking at accesslib is to distinguish functions that are part of the public interface, and which it is safe to call, and the internal-only functions.

As Valery says, you don't know if there is more than one 'Student' role these days, so the best thing is to identify a suitable capability, and then use get_users_by_capability
In reply to Tim Hunt

Re: What should deprecated function be replaced by ?

by Valery Fremaux -

Thanks TIm,

is there any relationship (sure there is !!) with the moodle/legacy:student and related legacy capabilities, i.e, is it a good practice to map additional roles to that legacy position in the system only assigning to 'em the adequate legacy capability ?

As a consequence, do deprecated calls get_course_student() and related know about that ?  

In reply to Valery Fremaux

Re: What should deprecated function be replaced by ?

by Matt Gibson -
Hi Valery,

I'm not sure about the docs, but I did the get_course_students() like this (aiming for a comma separated list of student ids).


//$students = $this->get_course_students($course->id); // depreacted - needs replacing


global $CFG;
$students = '';
$commacount = 0;
$studentroles = $CFG->gradebookroles;
$studentroles = explode($studentroles, ',');
$course_context = get_context_instance(CONTEXT_COURSE, $course->id);
foreach($studentroles as $studentrole) {

$tempstudents = get_role_users($studentrole, $course_context, true);
foreach ($tempstudents as $tempstudent) {
if ($commacount != 0) {$students .= ',';}
$students .= $tempstudent->id;
$commacount++;
}
}


In reply to Matt Gibson

Re: What should deprecated function be replaced by ?

by Matt Gibson -
Is there some way to make this editor indent that I've missed?? mixed
In reply to Matt Gibson

Re: What should deprecated function be replaced by ?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Choose preformatted from the styles dropdown menu.
In reply to Matt Gibson

Re: What should deprecated function be replaced by ?

by Valery Fremaux -

I fear we have all a local and context dependent ethnomethod to get rid of the rigidity implied in old deprecated get_course_students(...). These methods still are very usefull user status queries that are involved in many module scenarii.

I suggest H.Q. and core designers rehabilitate such functions, letting have the restricted meaning they will have. My question about moodle/legacy:student role wasn't so ingenuous : could'nt we status that this capability could map any role with student-like responsibilities to any custom role ? So could get_course_student be implemented a very simple way : checking availability of moodle/legacy:student in this course context and retreiving all users will have such condition verified. We could ensure ascendent portability of major code sections without bothering with such upgrades to follow.

NB : such a solution for all legacy roles, indeed !