Exemplo n.º 1
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     require_once get_config('docroot') . 'artefact/lib.php';
     $smarty = smarty_core();
     $configdata = $instance->get('configdata');
     $data = array();
     $data['socialprofiles'] = array();
     // add in the selected email address
     if (!empty($configdata['email'])) {
         $configdata['artefactids'][] = $configdata['email'];
     }
     $viewowner = get_field('view', 'owner', 'id', $instance->get('view'));
     // Get data about the profile fields in this blockinstance
     if (!empty($configdata['artefactids'])) {
         foreach ($configdata['artefactids'] as $id) {
             try {
                 $artefact = artefact_instance_from_id($id);
                 if (is_a($artefact, 'ArtefactTypeProfile') && $artefact->get('owner') == $viewowner) {
                     $rendered = $artefact->render_self(array('link' => true));
                     $artefacttype = $artefact->get('artefacttype');
                     if ($artefacttype == 'socialprofile') {
                         if (get_record('blocktype_installed', 'active', 1, 'name', 'socialprofile', 'artefactplugin', 'internal')) {
                             $data['socialprofiles'][] = array('link' => ArtefactTypeSocialprofile::get_profile_link($artefact->get('title'), $artefact->get('note')), 'title' => $artefact->get('title'), 'description' => $artefact->get('description'), 'note' => $artefact->get('note'));
                         }
                     } else {
                         $data[$artefacttype] = $rendered['html'];
                     }
                 }
             } catch (ArtefactNotFoundException $e) {
                 log_debug('Artefact not found when rendering a block instance. ' . 'There might be a bug with deleting artefacts of this type? ' . 'Original error follows:');
                 log_debug($e->getMessage());
             }
         }
         // Sort social profiles alphabetically (in ASC order)
         $description = array();
         foreach ($data['socialprofiles'] as $key => $row) {
             $description[$key] = $row['description'];
         }
         array_multisort($description, SORT_ASC, $data['socialprofiles']);
     }
     // Work out the path to the thumbnail for the profile image
     if (!empty($configdata['profileicon'])) {
         $downloadpath = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $configdata['profileicon'];
         $downloadpath .= '&maxwidth=80';
         $smarty->assign('profileiconpath', $downloadpath);
         $smarty->assign('profileiconalt', get_string('profileimagetext', 'mahara', display_default_name(get_user($viewowner))));
     }
     // Override the introduction text if the user has any for this
     // particular blockinstance
     if (!empty($configdata['introtext'])) {
         $data['introduction'] = $configdata['introtext'];
     }
     $smarty->assign('profileinfo', $data);
     return $smarty->fetch('blocktype:profileinfo:content.tpl');
 }