Insert idnumber into Feedback teacher email

Insert idnumber into Feedback teacher email

por Paul Hughes -
Número de respostas: 3

Hi,

I am really struggling with this. I am happy to pay someone to help - but can't find any developer who can help me.

We use the feedback module for students to email us at a certain point. We have students with the same name, so need the email from the feedback module to include the optional field "idnumber" in the subject  line. We use this optional field in the student profile to record their Student ID number.

Could somebody please tell me how to modify the code of the lib.php file to do this? I can get it to add the userid (as that string is already used in lib.php) but can't get it to add idnumber - presumably as I need to somehow get this from the database?? 

If anyone can help I would be most grateful. If you get in touch directly I can contact and arrange payment, or if someone helps out of the goodness of their heart I will make a donation to charity - not looking for work for free, but can;t find anyone competent!

Many thanks in anticipation.


Média das avaliações:  -
Em resposta à Paul Hughes

Re: Insert idnumber into Feedback teacher email

por Aaron StClair -

You say the userid is already available in lib.php, but there are hundreds of those in moodle... Can you be more specific as to the lib file you are referring to? How is the userid declared in there?

My guess would be that you have access to a $user object inside that lib.php file. If not you can get the current user by gaining access to the global $USER object.

global $USER;

Once you have access to either of these user objects you should be able to obtain the idnumber field by simply using:

$idnumber = $user->idnumber;
// or
$idnumber = $USER->idnumber;

You can then include the $idnumber the same way you've included the userid.


Given that the above doesn't work for some reason, you can manually pull the record from the database.

Refer to this documentation: https://docs.moodle.org/dev/Data_manipulation_API#moodle_database::get_records.28.29

global $DB;
$idnumber = $DB->get_records_sql('SELECT idnumber FROM mdl_user WHERE id = ?', array($userid));

You can then include the $idnumber the same way you've included the userid.

Média das avaliações: Useful (1)
Em resposta à Aaron StClair

Re: Insert idnumber into Feedback teacher email

por Davo Smith -
Imagem de Core developers Imagem de Particularly helpful Moodlers Imagem de Peer reviewers Imagem de Plugin developers

Please don't encourage the use of get_records_sql in situations like this (especially as it will return an object containing the idnumber, rather than the idnumber) and certainly don't ever hard-code the prefix into the SQL (write {user} not mdl_user)

The correct method would be either:

$info = $DB->get_record('user', array('id' => $userid), 'idnumber');
$idnumber = $info->idnumber;

OR, even better:

$idnumber = $DB->get_field('user', 'idnumber', array('id' => $userid));


Média das avaliações: Useful (1)
Em resposta à Davo Smith

Re: Insert idnumber into Feedback teacher email

por Paul Hughes -

Guys,

This is perfect. Thank you both very much for taking the time to reply - it is very much appreciated and worked perfectly.

I just made a £50 donation to Cancer Research for your troubles.

Have a great weekend.

Anexo Screen Shot 2016-10-14 at 08.59.03.png
Média das avaliações: Useful (1)