User Picture

User Picture

από Brad Nielsen -
Αριθμός απαντήσεων: 3

Hi, I'm trying to the user picture to match to a course contact.

Currently I get the course contacts using the function from the coursecatlib.php:

$course->get_course_contacts() 

And then I cycle through the course contact list using:

foreach ($list_course_contacts as $userid => $coursecontact)

However, this doesn't return a user object, and I need a user object to use the function below:

$OUTPUT->user_picture($coursecontact, array('size' => 50))

what step am I missing?

cheers,

Brad

Μέσος όρος βαθμολογίας: -
Σε απάντηση σε Brad Nielsen

Re: User Picture

από Dominique Palumbo -
Φωτογραφία Particularly helpful Moodlers Φωτογραφία Plugin developers

hi,


in fact, the get_course_contacts cannot be used (directly).

you can add something like this this inside the foreach loop

  $sql = "
    SELECT *
      FROM {user}   t1
     WHERE id = :param1
  ";

  $params     = array('param1' => $userid->id);
  $user          = $DB->get_record_sql($sql, $params);

  $OUTPUT->user_picture($user, array('size' => 50));

I hope it's help


Σε απάντηση σε Dominique Palumbo

Re: User Picture

από Brad Nielsen -

Thanks for your reply Dominic. The get_course_contacts function works but it only returns the user id, username and role. 

I'm kind of surprised, if there is no function to get a complete user object based on a userid rather than having to use an SQL query.

Cheers

Brad