Is there a function to get the "teachers" given an idcurse?

Is there a function to get the "teachers" given an idcurse?

Miguel Angel Miranda發表於
Number of replies: 8

Is there a function in Moodle that gets the records with the teachers (iduser) given a curseid?  ... or .. it has to be done?.

thanks in advance for any link or tip  to answer this issue.

評比平均分數: -
In reply to Miguel Angel Miranda

Re: Is there a function to get the "teachers" given an idcurse?

Martin Dougiamas發表於
Core developers的相片 Documentation writers的相片 Moodle HQ的相片 Particularly helpful Moodlers的相片 Plugin developers的相片 Testers的相片
Since roles are dynamic, and there can be many "teacher roles", you just need to pick the capability that is relevant for you in that context.

eg:


$context = get_context_instance(CONTEXT_COURSE, $courseid);

$users = get_context_users_bycap($context, 'moodle/course:update');

print_object($users);

In reply to Martin Dougiamas

Re: Is there a function to get the "teachers" given an idcurse?

Jamie Pratt發表於
I searched the code in Moodle HEAD and found no uses of get_context_users_bycap. Although it seems it is a much simpler and more efficient function than the get_users_by_capability function get_users_by_capability is commonly used but get_context_users_bycap is not.

I notice in the comments for the get_context_users_bycap that it is marked "Draft". But it is included in the comments at the top of accesslib.php as one of the functions that is identified as being part of the public api, whereas get_users_by_capability is not! I guess this is a mistake.
In reply to Jamie Pratt

Re: Is there a function to get the "teachers" given an idcurse?

Jamie Pratt發表於
Looking more into get_context_users_bycap which I would like to be able to use in the quiz reports code as it is more simple. It :
  • doesn't support the default role (I guess this is not relevant in many cases)
  • it cannot exclude users that have doanything permission (but this would be easily added I think).
  • it looks like it won't calculate permissions correctly if negative permissions are used?? I say this as get_users_by_capability is doing something much more complex to calculate permissions when there are relevant negative permission assignments.
In reply to Jamie Pratt

Re: Is there a function to get the "teachers" given an idcurse?

Martín Langhoff發表於

Jamie and Eloy caught me via Skype, here's some quick notes about this

  • I tried to make get_context_users_bycap() simpler/faster but it is flawed, and should be removed. Nothing uses it anyway (thank $deity!).
  • get_users_by_capability() does the right thing. Sometimes, the right thing can be done relatively efficiently, other times it's a mess of SQL work and PHP post-processing. get_users_by_capability() is used in many perf-critical parts - and has been tuned to work as well as possible with large numbers of users/roles careful! 微笑

The best fix I can think of for that Jamie wants is to teach gubc to store the resulting user ids in a temporary results table. We have trouble with temptables on MSSQL and Ora, so it should be a "static" temp results table with a "transaction id" of sorts. This will work relatively well for the code-paths where most of the work is in SQL - for the cases where we filter stuff in PHP, it will be... ugh.

We could have a better solution if we had portable mechanisms for

  • Temp tables
  • Stored procedures
  • Hierarchical data handling in SQL

Any enhancement in these 3 aspects would make gubc (and other parts of accesslib) much more maintainable and scalable. Right now optimising accesslib means mostly working around the limitations of portable SQL in those areas.

In reply to Martín Langhoff

Re: Is there a function to get the "teachers" given an idcurse?

Martin Dougiamas發表於
Core developers的相片 Documentation writers的相片 Moodle HQ的相片 Particularly helpful Moodlers的相片 Plugin developers的相片 Testers的相片
Thanks, ML, I only just found that function relatively recently and I assumed it was a fully finished replacement. I'll delete get_context_users_bycap and get_context_users_byrole now to avoid confusion! MDL-13261

I hope no-one was using it in 3rd party code ... 傷心
In reply to Martin Dougiamas

Re: Is there a function to get the "teachers" given an idcurse?

Anthony Borrow發表於
Core developers的相片 Plugin developers的相片 Testers的相片
I searched CONTRIB for both the get_context_users_bycap and get_context_users_byrole functions and did not find any occurrences. Your question reminded me that one of the reasons why I like to encourage folks to use Moodle's CVS server to maintain their CONTRIB code is precisely so that you and the other developers can do such searches and assess the impact that a potential code change may have. Peace - Anthony
In reply to Martin Dougiamas

Re: Is there a function to get the "teachers" given an idcurse?

Jamie Pratt發表於
So get_context_users_bycap will be removed from accesslib soon. Martin Langhoff suggested I remove it completely as it apparently is flawed in many ways. Instead of get_context_users_bycap, get_users_by_capability should be used as follows :

 $context = get_context_instance(CONTEXT_COURSE, $courseid);
 $users = get_users_by_capability($context, 'moodle/course:update');
 print_object($users);
In reply to Miguel Angel Miranda

Re: Is there a function to get the "teachers" given an idcurse?

Miguel Angel Miranda發表於

Thank a lot for your help!

.. greetings from Puerto Vallarta, México (here is 10:30 am Mon 28 )!.