From a0bb27773f0802a71f181985267403c183616adf Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 16 Feb 2017 18:41:58 +0800 Subject: [PATCH] #80 Fixed user picture not displaying on PDF --- element/userpicture/classes/element.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/element/userpicture/classes/element.php b/element/userpicture/classes/element.php index 6be7473..8e40337 100644 --- a/element/userpicture/classes/element.php +++ b/element/userpicture/classes/element.php @@ -113,21 +113,20 @@ class element extends \mod_customcert\element { $context = \context_user::instance($user->id); - // Prepare file record object. - $fileinfo = array( - 'component' => 'user', - 'filearea' => 'icon', - 'itemid' => 0, - 'contextid' => $context->id, - 'filepath' => '/', - 'filename' => 'f1.png'); - - // Get file. + // Get files in the user icon area. $fs = get_file_storage(); - $file = $fs->get_file($fileinfo['contextid'], $fileinfo['component'], $fileinfo['filearea'], - $fileinfo['itemid'], $fileinfo['filepath'], $fileinfo['filename']); + $files = $fs->get_area_files($context->id, 'user', 'icon', 0); - // Show image. + // Get the file we want to display. + $file = null; + foreach ($files as $filefound) { + if (!$filefound->is_directory()) { + $file = $filefound; + break; + } + } + + // Show image if we found one. if ($file) { $contenthash = $file->get_contenthash(); $l1 = $contenthash[0] . $contenthash[1];