Add a "profile_field_Class" in the list of students

Add a "profile_field_Class" in the list of students

von F S -
Anzahl Antworten: 6

Could you please let me know how to let the list of students when taking attendance display an extra field.

I need to know to which class each student belongs (profile_field_class) and see their father name also (profile_field_father)

Please help

Als Antwort auf F S

Re: Add a "profile_field_Class" in the list of students

von Barry Oosthuizen -
Are these (profile_field_class & profile_field_father) from tables/fields you've added yourself to the database or are they from using the custom user profile fields feature in Moodle?

You could add an extra column in the report.php file like this:

Find this code in the attforblock/report.php file:

$table->head[] = $fullnamehead;
$table->align[] = 'left';
$table->size[] = '';

and add something like the following below it:

$table->head[] = 'Class (or Father's Name)';
$table->align[] = 'left';
$table->size[] = '';

Then you need to use a function to get the custom user profile fields.
Find this code in the attforblock/report.php file:

foreach($students as $student) {
$table->data[$student->id][] = print_user_picture($student->id, $course->id, $student->picture, 20, true, true);
$table->data[$student->id][] = "<a href=\"view.php?id=$id&amp;student={$student->id}\">".fullname($student).'</a>';

Now add your code to retrieve the Class/Father's Name data below the above code.
Maybe one of the functions in user/profile/lib.php will help for this.
Als Antwort auf F S

Re: Add a "profile_field_Class" in the list of students

von Barry Oosthuizen -
actually, you need to edit the attendances.php file to display the extra info on the page where you take attendance. I would imagine something similar to what I described before should do the trick.
Als Antwort auf Barry Oosthuizen

Re: Add a "profile_field_Class" in the list of students

von F S -

thank you for your help, but unfortunately i could not succeed in displaying the profile fields in the list of students.

the fields i add are custom (eg. class, which becomes profile_field_class)

Als Antwort auf F S

Re: Add a "profile_field_Class" in the list of students

von Barry Oosthuizen -
Hi,

sorry I've been a bit busy. Here is a solution if you still need one:

  • Add the following line of code to the attendances.php (near the top of the page):
require_once('profilelib.php');
  • In the attendances.php file find the following code:
$statuses = get_statuses($course->id);
  • Add this line above it:
$tabhead[] = 'Class'; // change 'Class' to whatever you want to call this column
  • Find the following line of code:
$table->data[$student->id][] = "<a href=\"view.php?id=$id&amp;student={$student->id}\">".((!$att && $update) ? '<font color="red"><b>' : '').fullname($student).((!$att && $update) ? '</b></font>' : '').'</a>';
  • Add this line below it:
$table->data[$student->id][] = profile_display_fields($student->id);
  • Drop the attached profilelib.php file into your mod/attforblock folder.




Als Antwort auf Barry Oosthuizen

Re: Add a "profile_field_Class" in the list of students

von F S -
Thanks a lot Mr. Barry ... your instructions helped me a lot, but I think there is something wrong because the code shows automatically the first custom profile field only, so how can i specify which custom field I want to display?
Als Antwort auf F S

Re: Add a "profile_field_Class" in the list of students

von Barry Oosthuizen -
Hi F S,

Try doing this in the attendances.php file:

  • Add another header the same way you added one for 'Class'.

Then find this code in the attendances.php file:

  • $table->data[$student->id][] = profile_display_fields($student->id);

And change it to:

$profilefields = get_records_select('user_info_data', 'userid='.$student->id, '', 'data');

foreach($profilefields as $field) {

$table->data[$student->id][] = $field->data;}


This solution will add a data in a column for each custom profile field you have. If you have more than the 2 custom fields and you only want to use two specific ones you'll need to go about it a bit differently:

Something like:

// this is for the first profile field. Change '1' to whatever datafield id corresponds to the field you want to use

$profilefield1 = get_records_select('user_info_data', 'userid='.$student->id." AND fieldid='1'", '', 'data');

foreach($profilefield1 as $field) {

$table->data[$student->id][] = $field->data;}

// this is for the first profile field. Change '2' to whatever fieldid corresponds to the field you want to use

$profilefield2 = get_records_select('user_info_data', 'userid='.$student->id." AND fieldid='2'", '', 'data');

foreach($profilefield2 as $field) {

$table->data[$student->id][] = $field->data;}


I haven't tested the second solution so if you need to use it just let me know if it gives you any problems.