Exemplo n.º 1
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     $configdata = $instance->get('configdata');
     $type = isset($configdata['displaytype']) ? $configdata['displaytype'] : 'texticon';
     $showicon = $type == 'icononly' || $type == 'texticon' ? true : false;
     $showtext = $type == 'textonly' || $type == 'texticon' ? true : false;
     $owner = $instance->get('view_obj')->get('owner');
     // Whether to include email button
     if (isset($configdata['displayemail']) && $configdata['displayemail']) {
         $email = get_field('artefact_internal_profile_email', 'email', 'principal', 1, 'owner', $owner);
     } else {
         $email = false;
     }
     if (!isset($configdata['artefactids']) || empty($configdata['artefactids'])) {
         // When we first come into this block, it will have
         // no social profiles configured yet.
         $configdata['artefactids'] = array(0);
     }
     // Include selected social profiles
     $sql = 'SELECT title, description, note FROM {artefact}
         WHERE id IN (' . join(',', $configdata['artefactids']) . ')
             AND owner = ? AND artefacttype = ?
         ORDER BY description ASC';
     if (!($data = get_records_sql_array($sql, array($owner, 'socialprofile')))) {
         $data = array();
     }
     safe_require('artefact', 'internal');
     $data = ArtefactTypeSocialprofile::get_profile_icons($data);
     $smarty = smarty_core();
     $smarty->assign('showicon', $showicon);
     $smarty->assign('showtext', $showtext);
     $smarty->assign('profiles', $data);
     $smarty->assign('email', $email);
     return $smarty->fetch('blocktype:socialprofile:content.tpl');
 }
 public static function getRecordDataById($type, $id)
 {
     global $USER;
     $sql = 'SELECT  a.id, a.artefacttype, a.parent, a.owner, a.title, a.description, a.institution, a.group, a.author,
     p.artefacttype AS parent_artefacttype, p.title AS parent_title, p.description  AS parent_description, a.license,
     afi.width, afi.height, a.note
     FROM {artefact} a
     LEFT OUTER JOIN {artefact} p ON p.id = a.parent
     LEFT OUTER JOIN {artefact_file_image} afi ON afi.artefact = a.id
     WHERE a.id = ?';
     $record = get_record_sql($sql, array($id));
     if (!$record) {
         return false;
     }
     $record->title = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->title));
     $record->description = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->description));
     // If user is owner
     if ($USER->get('id') == $record->owner) {
         switch ($record->artefacttype) {
             case 'image':
             case 'video':
             case 'audio':
             case 'file':
                 $record->link = 'artefact/file';
                 if (isset($record->parent) && intval($record->parent) > 0) {
                     $record->link .= '/index.php?folder=' . $record->parent;
                 }
                 break;
             case 'blogpost':
                 if (isset($record->parent) && intval($record->parent) > 0) {
                     $record->link = 'artefact/blog/view/index.php?id=' . $record->parent;
                 }
                 break;
             case 'blog':
                 $record->link = 'artefact/blog/view/index.php';
                 if ($USER->get_account_preference('multipleblogs')) {
                     $record->link .= '?id=' . $record->id;
                 }
                 break;
             case 'coverletter':
             case 'personalinformation':
                 $record->link = 'artefact/resume/index.php';
                 break;
             case 'educationhistory':
             case 'employmenthistory':
                 $record->link = 'artefact/resume/employment.php';
                 break;
             case 'book':
             case 'certification':
             case 'membership':
                 $record->link = 'artefact/resume/achievements.php';
                 break;
             case 'academicgoal':
             case 'careergoal':
             case 'personalgoal':
             case 'personalinformation':
             case 'academicskill':
             case 'personalskill':
             case 'workskill':
                 $record->link = 'artefact/resume/goalsandskills.php';
                 break;
             case 'interest':
                 $record->link = 'artefact/resume/interests.php';
                 break;
             case 'plan':
                 $record->link = 'artefact/plans/plan.php?id=' . $record->id;
                 break;
             case 'task':
                 if (isset($record->parent) && intval($record->parent) > 0) {
                     $record->link = 'artefact/plans/plan.php?id=' . $record->parent;
                 }
                 break;
             case 'socialprofile':
                 $record->note = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->note));
                 $socialprofile = new ArtefactTypeSocialprofile($record->id);
                 $icons = $socialprofile->get_profile_icons(array($record));
                 if (!empty($icons)) {
                     $record->link = $icons[0]->link;
                     $record->icon = $icons[0]->icon;
                 }
                 break;
         }
     }
     // VIEWS get all the views the artefact is included into.
     // artefact parents are folder, blog, plan, cpd
     $sql = 'SELECT COALESCE(v.id, vp.id) AS id, COALESCE(v.title, vp.title) AS title
     FROM {artefact} a
     LEFT OUTER JOIN {view_artefact} va ON va.artefact = a.id
     LEFT OUTER JOIN {view} v ON v.id = va.view
     LEFT OUTER JOIN {artefact} parent ON parent.id = a.parent
     LEFT OUTER JOIN {view_artefact} vap ON vap.artefact = parent.id
     LEFT OUTER JOIN {view} vp ON vp.id = vap.view
     WHERE a.id = ?';
     $views = get_records_sql_array($sql, array($id));
     if ($views) {
         $record_views = array();
         foreach ($views as $view) {
             if (isset($view->id)) {
                 $record_views[$view->id] = $view->title;
             }
         }
         $record_views = self::views_by_artefact_acl_filter($record_views);
         $record->views = $record_views;
     }
     //  Tags
     $tags = get_records_array('artefact_tag', 'artefact', $id);
     if ($tags != false) {
         foreach ($tags as $tag) {
             $record->tags[] = $tag->tag;
         }
     } else {
         $record->tags = null;
     }
     //  Created by
     if (intval($record->author) > 0) {
         $record->createdby = get_record('usr', 'id', $record->author);
         $record->createdbyname = display_name($record->createdby);
     }
     //  Thumb
     if ($record->artefacttype == 'image') {
         if (isset($record->width) && isset($record->height) && intval($record->width) > 0 && intval($record->height) > 0) {
             if ($record->width > $record->height) {
                 $size = '80x' . intval($record->height * 80 / $record->width);
             } else {
                 $size = intval($record->width * 80 / $record->height) . 'x80';
             }
         }
         $record->thumb = ArtefactTypeImage::get_icon(array('id' => $id, 'size' => $size));
     }
     return $record;
 }