public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $configdata = $instance->get('configdata'); $viewid = $instance->get('view'); $wwwroot = get_config('wwwroot'); $files = array(); if (isset($configdata['artefactids']) && is_array($configdata['artefactids'])) { foreach ($configdata['artefactids'] as $artefactid) { try { $artefact = $instance->get_artefact_instance($artefactid); } catch (ArtefactNotFoundException $e) { continue; } $file = array('id' => $artefactid, 'title' => $artefact->get('title'), 'description' => $artefact->get('description'), 'size' => $artefact->get('size'), 'ctime' => $artefact->get('ctime'), 'artefacttype' => $artefact->get('artefacttype'), 'iconsrc' => call_static_method(generate_artefact_class_name($artefact->get('artefacttype')), 'get_icon', array('id' => $artefactid, 'viewid' => $viewid)), 'downloadurl' => $wwwroot); if ($artefact instanceof ArtefactTypeProfileIcon) { $file['downloadurl'] .= 'thumb.php?type=profileiconbyid&id=' . $artefactid; } else { if ($artefact instanceof ArtefactTypeFile) { $file['downloadurl'] .= 'artefact/file/download.php?file=' . $artefactid . '&view=' . $viewid; } } $file['is_image'] = $artefact instanceof ArtefactTypeImage ? true : false; $files[] = $file; } } $smarty = smarty_core(); $smarty->assign('viewid', $instance->get('view')); $smarty->assign('files', $files); return $smarty->fetch('blocktype:filedownload:filedownload.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { $userid = $instance->get_view()->get('owner'); if (!$userid) { return ''; } $smarty = smarty_core(); // Get viewable views $views = array(); if ($allviews = get_records_select_array('view', "\"owner\" = ? AND type NOT IN ('profile', 'dashboard')", array($userid))) { foreach ($allviews as $view) { if (can_view_view($view->id)) { $views[$view->id] = $view; $view->artefacts = array(); } } } if ($views) { $viewidlist = implode(', ', array_map(create_function('$a', 'return (int)$a->id;'), $views)); $artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin FROM {view_artefact} va INNER JOIN {artefact} a ON va.artefact = a.id INNER JOIN {artefact_installed_type} t ON a.artefacttype = t.name WHERE va.view IN (' . $viewidlist . ') GROUP BY 1, 2, 3, 4, 5 ORDER BY a.title, va.artefact', ''); if ($artefacts) { foreach ($artefacts as $artefactrec) { safe_require('artefact', $artefactrec->plugin); // Perhaps I shouldn't have to construct the entire // artefact object to render the name properly. $classname = generate_artefact_class_name($artefactrec->artefacttype); $artefactobj = new $classname(0, array('title' => $artefactrec->title)); $artefactobj->set('dirty', false); if (!$artefactobj->in_view_list()) { continue; } $artname = $artefactobj->display_title(30); if (strlen($artname)) { $views[$artefactrec->view]->artefacts[] = array('id' => $artefactrec->artefact, 'title' => $artname); } } } $tags = get_records_select_array('view_tag', 'view IN (' . $viewidlist . ')'); if ($tags) { foreach ($tags as &$tag) { $views[$tag->view]->tags[] = $tag->tag; } } } $smarty->assign('VIEWS', $views); return $smarty->fetch('blocktype:myviews:myviews.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $configdata = $instance->get('configdata'); $result = ''; if (isset($configdata['artefactids']) && is_array($configdata['artefactids'])) { foreach ($configdata['artefactids'] as $artefactid) { try { $artefact = $instance->get_artefact_instance($artefactid); } catch (ArtefactNotFoundException $e) { continue; } $icondata = array('id' => $artefactid, 'viewid' => $instance->get('view')); $detailsurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefactid . '&view=' . $instance->get('view'); if ($artefact instanceof ArtefactTypeProfileIcon) { require_once 'file.php'; $downloadurl = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $artefactid; $size = filesize(get_dataroot_image_path('artefact/file/profileicons/', $artefactid)); } else { if ($artefact instanceof ArtefactTypeFile) { $downloadurl = get_config('wwwroot') . 'artefact/file/download.php?file=' . $artefactid . '&view=' . $icondata['viewid']; $size = $artefact->get('size'); } } $result .= '<div title="' . hsc($artefact->get('title')) . '">'; $result .= '<div class="fl"><a href="' . hsc($downloadurl) . '">'; $result .= '<img src="' . hsc(call_static_method(generate_artefact_class_name($artefact->get('artefacttype')), 'get_icon', $icondata)) . '" alt=""></a></div>'; $result .= '<div style="margin-left: 30px;">'; $result .= '<h4><a href="' . hsc($detailsurl) . '">' . str_shorten_text($artefact->get('title'), 20) . '</a></h4>'; $description = $artefact->get('description'); if ($description) { $result .= '<p style="margin: 0;"><strong>' . hsc($description) . '</strong></p>'; } $result .= '' . display_size($size) . ' | ' . strftime(get_string('strftimedaydate'), $artefact->get('ctime')); $result .= '</div>'; $result .= '</div>'; } } return $result; }
function set_profile_field($userid, $field, $value) { safe_require('artefact', 'internal'); // this is a special case that replaces the primary email address with the // specified one if ($field == 'email') { try { $email = artefact_instance_from_type('email', $userid); } catch (ArtefactNotFoundException $e) { $email = new ArtefactTypeEmail(); $email->set('owner', $userid); } $email->set('title', $value); $email->commit(); } else { $classname = generate_artefact_class_name($field); $profile = new $classname(0, array('owner' => $userid)); $profile->set('title', $value); $profile->commit(); } }
public function copy_for_new_owner($user, $group, $institution) { $data = $this->copy_data(); $data->owner = $user; $data->group = $group; $data->institution = $institution; $data->parent = null; $classname = generate_artefact_class_name($data->artefacttype); safe_require('artefact', get_field('artefact_installed_type', 'plugin', 'name', $data->artefacttype)); $copy = new $classname(0, (object) $data); $this->copy_extra($copy); $copy->commit(); return $copy->get('id'); }
/** * Optional method. If specified, allows the blocktype class to munge the * artefactchooser element data before it's templated */ public static function artefactchooser_get_element_data($artefact) { $folderdata = ArtefactTypeFileBase::artefactchooser_folder_data($artefact); $artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id)); $artefact->hovertitle = $artefact->description; $path = $artefact->parent ? ArtefactTypeFileBase::get_full_path($artefact->parent, $folderdata->data) : ''; $artefact->description = str_shorten_text($folderdata->ownername . $path . $artefact->title, 30); return $artefact; }
public function get_goals_and_skills($type = '') { global $USER; switch ($type) { case 'goals': $artefacts = array('personalgoal', 'academicgoal', 'careergoal'); break; case 'skills': $artefacts = array('personalskill', 'academicskill', 'workskill'); break; default: $artefacts = array('personalgoal', 'academicgoal', 'careergoal', 'personalskill', 'academicskill', 'workskill'); } $data = array(); foreach ($artefacts as $artefact) { $record = get_record('artefact', 'artefacttype', $artefact, 'owner', $USER->get('id')); if ($record) { $record->exists = 1; // Add attachments $files = ArtefactType::attachments_from_id_list(array($record->id)); if ($files) { safe_require('artefact', 'file'); foreach ($files as &$file) { $file->icon = call_static_method(generate_artefact_class_name($file->artefacttype), 'get_icon', array('id' => $file->attachment)); $record->files[] = $file; } $record->count = count($files); } else { $record->count = 0; } } else { $record = new stdClass(); $record->artefacttype = $artefact; $record->exists = 0; $record->count = 0; } $data[] = $record; } return $data; }
public static function artefactchooser_get_element_data($artefact) { $artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id)); return $artefact; }
static function get_forms(array $compositetypes) { require_once get_config('libroot') . 'pieforms/pieform.php'; $compositeforms = array(); foreach ($compositetypes as $compositetype) { $elements = call_static_method(generate_artefact_class_name($compositetype), 'get_addform_elements'); $elements['submit'] = array('type' => 'submit', 'value' => get_string('save')); $elements['compositetype'] = array('type' => 'hidden', 'value' => $compositetype); $cform = array('name' => 'add' . $compositetype, 'plugintype' => 'artefact', 'pluginname' => 'resume', 'elements' => $elements, 'jsform' => true, 'successcallback' => 'compositeform_submit', 'jssuccesscallback' => 'compositeSaveCallback'); $compositeforms[$compositetype] = pieform($cform); } return $compositeforms; }
/** * This function returns a list of posts in a given blog. * * @param integer * @param integer * @param integer * @param array */ public static function get_posts($id, $limit, $offset, $viewoptions = null) { $results = array('limit' => $limit, 'offset' => $offset); // If viewoptions is null, we're getting posts for the my blogs area, // and we should get all posts & show drafts first. Otherwise it's a // blog in a view, and we should only get published posts. $from = "\n FROM {artefact} a LEFT JOIN {artefact_blog_blogpost} bp ON a.id = bp.blogpost\n WHERE a.artefacttype = 'blogpost' AND a.parent = ?"; if (!is_null($viewoptions)) { if (isset($viewoptions['before'])) { $from .= " AND a.ctime < '{$viewoptions['before']}'"; } $from .= ' AND bp.published = 1'; } $results['count'] = count_records_sql('SELECT COUNT(*) ' . $from, array($id)); $data = get_records_sql_assoc(' SELECT a.id, a.title, a.description, a.author, a.authorname, ' . db_format_tsfield('a.ctime', 'ctime') . ', ' . db_format_tsfield('a.mtime', 'mtime') . ', a.locked, bp.published, a.allowcomments ' . $from . ' ORDER BY bp.published ASC, a.ctime DESC, a.id DESC', array($id), $offset, $limit); if (!$data) { $results['data'] = array(); return $results; } // Get the attached files. $postids = array_map(create_function('$a', 'return $a->id;'), $data); $files = ArtefactType::attachments_from_id_list($postids); if ($files) { safe_require('artefact', 'file'); foreach ($files as &$file) { $params = array('id' => $file->attachment); if (!empty($viewoptions['viewid'])) { $params['viewid'] = $viewoptions['viewid']; } $file->icon = call_static_method(generate_artefact_class_name($file->artefacttype), 'get_icon', $params); $data[$file->artefact]->files[] = $file; } } if ($tags = ArtefactType::tags_from_id_list($postids)) { foreach ($tags as &$at) { $data[$at->artefact]->tags[] = $at->tag; } } foreach ($data as &$post) { // Format dates properly if (is_null($viewoptions)) { // My Blogs area: create forms for changing post status & deleting posts. $post->changepoststatus = ArtefactTypeBlogpost::changepoststatus_form($post->id, $post->published); $post->delete = ArtefactTypeBlogpost::delete_form($post->id, $post->title); } else { $by = $post->author ? display_default_name($post->author) : $post->authorname; $post->postedby = get_string('postedbyon', 'artefact.blog', $by, format_date($post->ctime)); // Get comment counts if (!empty($viewoptions['countcomments'])) { safe_require('artefact', 'comment'); require_once get_config('docroot') . 'lib/view.php'; $view = new View($viewoptions['viewid']); $artefact = artefact_instance_from_id($post->id); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, null, false); $post->commentcount = $commentcount; $post->comments = $comments; } } $post->ctime = format_date($post->ctime, 'strftimedaydatetime'); $post->mtime = format_date($post->mtime); // Ensure images in the post have the right viewid associated with them if (!empty($viewoptions['viewid'])) { safe_require('artefact', 'file'); $post->description = ArtefactTypeFolder::append_view_url($post->description, $viewoptions['viewid']); } } $results['data'] = array_values($data); return $results; }
$a = artefact_instance_from_id($artefact); $type = $a->get('artefacttype'); // Set correct redirect when user clicks Cancel button... if ($type == 'languagediploma' || $type == 'languageexperience') { // Find language diploma's or linguistic experience's parent for redirect... $sql = 'SELECT aeo.id, aeo.artefact FROM {artefact_europass_otherlanguage} aeo JOIN {artefact_europass_' . $type . '} ar ON ar.languageid = aeo.id WHERE ar.id = ? AND ar.artefact = ?'; $parent = get_record_sql($sql, array($id, $artefact)); $goto = 'viewcomposite.php?id=' . $parent->id . '&artefact=' . $parent->artefact; } else { $goto = 'languages.php'; } $tabs = PluginArtefactEuropass::composite_tabs(); define('EUROPASS_SUBPAGE', $tabs[$type]); if ($a->get('owner') != $USER->get('id')) { throw new AccessDeniedException(get_string('notartefactowner', 'error')); } $elements = call_static_method(generate_artefact_class_name($type), 'get_addform_elements'); $elements['submit'] = array('type' => 'submitcancel', 'value' => array(get_string('save'), get_string('cancel')), 'goto' => get_config('wwwroot') . 'artefact/europass/' . $goto); $elements['compositetype'] = array('type' => 'hidden', 'value' => $type); $cform = array('name' => 'add' . $type, 'plugintype' => 'artefact', 'pluginname' => 'europass', 'elements' => $elements, 'successcallback' => 'langcompositeformedit_submit'); $a->populate_form($cform, $id, $type); $compositeform = pieform($cform); $smarty = smarty(); $smarty->assign('compositeform', $compositeform); $smarty->assign('composite', $type); $smarty->assign('PAGEHEADING', TITLE); $smarty->assign('SUBPAGENAV', PluginArtefactEuropass::submenu_items()); $smarty->display('artefact:europass:editcomposite.tpl');
} } foreach ($data as $id => $n) { $n->deleteform = pieform(deletenote_form($id, $n)); } } // Get the attached files. $noteids = array(); if ($data) { $noteids = array_keys($data); } $files = ArtefactType::attachments_from_id_list($noteids); if ($files) { safe_require('artefact', 'file'); foreach ($files as $file) { $file->icon = call_static_method(generate_artefact_class_name($file->artefacttype), 'get_icon', array('id' => $file->attachment)); $data[$file->artefact]->files[] = $file; } } // Add Attachments count for each Note if ($data) { foreach ($data as $item) { $item->count = isset($item->files) ? count($item->files) : 0; } } $pagination = build_pagination(array('id' => 'notes_pagination', 'url' => $baseurl, 'datatable' => 'notes', 'count' => $count, 'limit' => $limit, 'offset' => $offset)); $js = ' jQuery(function($) { $("a.notetitle").click(function(e) { e.preventDefault(); $("#" + this.id + "_desc").toggleClass("hidden");
protected static function self_search_make_links($data) { $wwwroot = get_config('wwwroot'); if ($data['count']) { foreach ($data['data'] as &$result) { switch ($result['type']) { case 'artefact': safe_require('artefact', get_field('artefact_installed_type', 'plugin', 'name', $result['artefacttype'])); $result['links'] = call_static_method(generate_artefact_class_name($result['artefacttype']), 'get_links', $result['id']); break; case 'view': $result['links'] = array('_default' => $wwwroot . 'view/view.php?id=' . $result['id'], get_string('editviewinformation') => $wwwroot . 'view/editmetadata.php?viewid=' . $result['id'], get_string('editview') => $wwwroot . 'view/edit.php?viewid=' . $result['id'], get_string('editaccess') => $wwwroot . 'view/editaccess.php?viewid=' . $result['id']); break; default: break; } } } }
static function get_forms(array $compositetypes, $languageid = 0) { require_once get_config('libroot') . 'pieforms/pieform.php'; $compositeforms = array(); foreach ($compositetypes as $compositetype) { $elements = call_static_method(generate_artefact_class_name($compositetype), 'get_addform_elements'); $elements['submit'] = array('type' => 'submit', 'value' => get_string('save')); $elements['compositetype'] = array('type' => 'hidden', 'value' => $compositetype); // Set language for language diploma(s) or linguistic experience(s)... if ($languageid > 0) { $elements['languageid'] = array('type' => 'hidden', 'value' => $languageid); } $cform = array('name' => 'add' . $compositetype, 'plugintype' => 'artefact', 'pluginname' => 'europass', 'elements' => $elements, 'jsform' => true, 'successcallback' => 'langcompositeform_submit', 'jssuccesscallback' => 'compositeSaveCallback'); $compositeforms[$compositetype] = pieform($cform); } return $compositeforms; }
/** * Add an import request of an interactive import entry as an Mahara view+collection or artefact. * For view import * If the entry is for Profile or Dashboard page, the decision is APPEND(default), IGNORE or REPLACE * If there is a duplicated view (same title and description), the decision is APPEND(default), IGNORE, REPLACE, or ADDNEW * If else, the decision is IGNORE, or ADDNEW(default) * For artefact import * If there are duplicated artefacts, the decision is IGNORE * If ELSE If there is $entrytype NOT is_singular, e.g. an user may have up to 5 email addresses * the decision is ADDNEW(default) or IGNORE * If there is $entrytype is_singular, * the decision is REPLACE(default) or APPEND * Also update the list of * - duplicated artefacts which have same artefacttype and content * - existing artefacts which have same artefacttype but the content may be different to the entry data * * @param string $importid ID of the import * @param string $entryid ID of the entry * @param string $strategy Strategy of entry import * @param string $plugin * @param array $entrydata Data the entry including the following fields: * owner ID of the user who imports the entry (required) * type (required) * parent ID of the parent entry (e.g. the blog entryid of the blogpost entry). * content (required) * - title (required) * @return updated DB table 'import_entry_requests' */ public static function add_import_entry_request($importid, $entryid, $strategy, $plugin, $entrydata) { $duplicatedartefactids = array(); $existingartefactids = array(); $title = $entrydata['content']['title']; if ($plugin === 'core') { // For view import $decision = PluginImport::DECISION_ADDNEW; } else { safe_require('artefact', $plugin); $classname = generate_artefact_class_name($entrydata['type']); if ($duplicatedartefactids = call_static_method($classname, 'get_duplicated_artefacts', $entrydata)) { $decision = PluginImport::DECISION_IGNORE; } else { if (isset($entrydata['defaultdecision'])) { $decision = $entrydata['defaultdecision']; } else { $existingartefactids = call_static_method($classname, 'get_existing_artefacts', $entrydata); if (call_static_method($classname, 'is_singular') && !empty($existingartefactids)) { if ($entrydata['type'] == 'email') { $decision = PluginImport::DECISION_ADDNEW; } else { $decision = PluginImport::DECISION_REPLACE; } } else { $decision = PluginImport::DECISION_ADDNEW; } } } } // Update DB table if (!record_exists_select('import_entry_requests', 'importid = ? AND entryid = ? AND ownerid = ? AND entrytype = ? AND entrytitle = ?', array($importid, $entryid, $entrydata['owner'], $entrydata['type'], $title))) { return insert_record('import_entry_requests', (object) array('importid' => $importid, 'entryid' => $entryid, 'strategy' => $strategy, 'plugin' => $plugin, 'ownerid' => $entrydata['owner'], 'entrytype' => $entrydata['type'], 'entryparent' => isset($entrydata['parent']) ? $entrydata['parent'] : null, 'entrytitle' => $title, 'entrycontent' => serialize($entrydata['content']), 'duplicateditemids' => serialize($duplicatedartefactids), 'existingitemids' => serialize($existingartefactids), 'decision' => $decision)); } return false; }
/** * Create a new artefact from import entry requests as a Mahara artefact * * @param object $entry_request The entry request * @param int $parent The ID of parent artefact * @return int The ID of new artefact * =0 if no artefact is created */ public static function create_artefact_from_request($importer, $entry_request, $parent = null) { $aid = 0; switch ($entry_request->decision) { case PluginImport::DECISION_IGNORE: $duplicatedids = unserialize($entry_request->duplicateditemids); if (!empty($duplicatedids)) { $aid = $duplicatedids[0]; } break; case PluginImport::DECISION_REPLACE: $existingids = unserialize($entry_request->existingitemids); if (!empty($existingids)) { $aid = self::replace_artefact_content_from_request($entry_request, $existingids[0]); } break; case PluginImport::DECISION_APPEND: $existingids = unserialize($entry_request->existingitemids); if (!empty($existingids)) { $aid = self::append_artefact_content_from_request($entry_request, $existingids[0]); } break; case PluginImport::DECISION_ADDNEW: default: $classname = generate_artefact_class_name($entry_request->entrytype); $content = unserialize($entry_request->entrycontent); $content['owner'] = $entry_request->ownerid; if (isset($parent)) { $content['parent'] = $parent; } $a = new $classname(0, $content); $a->commit(); $aid = $a->get('id'); break; } if ($aid) { $importer->add_artefactmapping($entry_request->entryid, $aid); } return $aid; }
/** * Gets the new/edit activities pieform * */ public static function get_form($parent, $activity = null) { require_once get_config('libroot') . 'pieforms/pieform.php'; $elements = call_static_method(generate_artefact_class_name('activity'), 'get_activityform_elements', $parent, $activity); $elements['submit'] = array('type' => 'submitcancel', 'class' => 'btn-primary', 'value' => array(get_string('saveactivity', 'artefact.cpds'), get_string('cancel')), 'goto' => get_config('wwwroot') . 'artefact/cpds/cpd.php?id=' . (int) $parent); $activityform = array('name' => empty($activity) ? 'addactivities' : 'editactivity', 'plugintype' => 'artefact', 'pluginname' => 'activity', 'validatecallback' => array(generate_artefact_class_name('activity'), 'validate'), 'successcallback' => array(generate_artefact_class_name('activity'), 'submit'), 'elements' => $elements); return pieform($activityform); }
/** * Gets the new/edit tasks pieform * */ public static function get_form($parent, $task = null) { require_once get_config('libroot') . 'pieforms/pieform.php'; require_once 'license.php'; $elements = call_static_method(generate_artefact_class_name('task'), 'get_taskform_elements', $parent, $task); $elements['submit'] = array('type' => 'submitcancel', 'value' => array(get_string('savetask', 'artefact.plans'), get_string('cancel')), 'goto' => get_config('wwwroot') . 'artefact/plans/plan.php?id=' . $parent); $taskform = array('name' => empty($task) ? 'addtasks' : 'edittask', 'plugintype' => 'artefact', 'pluginname' => 'task', 'validatecallback' => array(generate_artefact_class_name('task'), 'validate'), 'successcallback' => array(generate_artefact_class_name('task'), 'submit'), 'elements' => $elements); return pieform($taskform); }
function profileform_submit(Pieform $form, $values) { global $SESSION; global $USER; global $element_list; global $profilefields; require_once 'embeddedimage.php'; db_begin(); $now = db_format_timestamp(time()); $email_errors = array(); $lockedfields = locked_profile_fields(); foreach ($element_list as $element => $type) { if (isset($lockedfields[$element]) && !$USER->get('admin')) { continue; } if ($element == 'email') { if (!isset($values['email']['unsent'])) { $values['email']['unsent'] = array(); } // find new addresses foreach ($values['email']['unsent'] as $email) { if (in_array($email, $profilefields['email']['validated']) || in_array($email, $profilefields['email']['unvalidated'])) { continue; } $key = get_random_key(); $key_url = get_config('wwwroot') . 'artefact/internal/validate.php?email=' . rawurlencode($email) . '&key=' . $key; $key_url_decline = $key_url . '&decline=1'; try { $sitename = get_config('sitename'); email_user((object) array('id' => $USER->get('id'), 'username' => $USER->get('username'), 'firstname' => $USER->get('firstname'), 'lastname' => $USER->get('lastname'), 'preferredname' => $USER->get('preferredname'), 'admin' => $USER->get('admin'), 'staff' => $USER->get('staff'), 'email' => $email), null, get_string('emailvalidation_subject', 'artefact.internal'), get_string('emailvalidation_body1', 'artefact.internal', $USER->get('firstname'), $email, $sitename, $key_url, $sitename, $key_url_decline)); } catch (EmailException $e) { $email_errors[] = $email; } insert_record('artefact_internal_profile_email', (object) array('owner' => $USER->get('id'), 'email' => $email, 'verified' => 0, 'key' => $key, 'expiry' => db_format_timestamp(time() + 86400))); } // remove old addresses foreach ($profilefields['email']['validated'] as $email) { if (in_array($email, $values['email']['validated'])) { continue; } if (!empty($values['email']['unvalidated']) && in_array($email, $values['email']['unvalidated'])) { continue; } $artefact_id = get_field('artefact_internal_profile_email', 'artefact', 'email', $email, 'owner', $USER->get('id')); delete_records('artefact_internal_profile_email', 'email', $email, 'owner', $USER->get('id')); if ($artefact_id) { $artefact = new ArtefactTypeEmail($artefact_id); $artefact->delete(); // this is unset here to force the destructor to run now, // rather than script exit time where it doesn't like // throwing exceptions properly unset($artefact); } } foreach ($profilefields['email']['unvalidated'] as $email) { if (in_array($email, $values['email']['validated']) || isset($values['email']['unvalidated']) && in_array($email, $values['email']['unvalidated'])) { continue; } delete_records('artefact_internal_profile_email', 'email', $email, 'owner', $USER->get('id')); } if ($profilefields['email']['default'] != $values['email']['default']) { update_record('artefact_internal_profile_email', (object) array('principal' => 0), (object) array('owner' => $USER->get('id'), 'email' => $profilefields['email']['default'])); update_record('artefact_internal_profile_email', (object) array('principal' => 1), (object) array('owner' => $USER->get('id'), 'email' => $values['email']['default'])); update_record('usr', (object) array('email' => $values['email']['default']), (object) array('id' => $USER->get('id'))); $USER->email = $values['email']['default']; $USER->commit(); } } else { if ($element == 'maildisabled') { continue; } else { if ($element == 'socialprofile') { continue; } else { if (!isset($profilefields[$element]) || $values[$element] != $profilefields[$element]) { if ($element == 'introduction') { $newintroduction = EmbeddedImage::prepare_embedded_images($values[$element], 'profileintrotext', $USER->get('id')); $values[$element] = $newintroduction; } $classname = generate_artefact_class_name($element); $profile = new $classname(0, array('owner' => $USER->get('id'))); $profile->set('title', $values[$element]); $profile->commit(); } } } } } try { db_commit(); } catch (Exception $e) { profileform_reply($form, PIEFORM_ERR, get_string('profilefailedsaved', 'artefact.internal')); } handle_event('updateuser', $USER->get('id')); if (count($email_errors)) { profileform_reply($form, PIEFORM_ERR, array('message' => get_string('emailingfailed', 'artefact.internal', join(', ', $email_errors)))); } profileform_reply($form, PIEFORM_OK, get_string('profilesaved', 'artefact.internal')); }
public static function get_extra_view_info(&$viewdata, $getartefacts = true) { if ($viewdata) { // Get view owner details for display $owners = array(); $groups = array(); $institutions = array(); foreach ($viewdata as $v) { if ($v->owner && !isset($owners[$v->owner])) { $owners[$v->owner] = (int) $v->owner; } else { if ($v->group && !isset($groups[$v->group])) { $groups[$v->group] = (int) $v->group; } else { if (strlen($v->institution) && !isset($institutions[$v->institution])) { $institutions[$v->institution] = $v->institution; } } } } $viewidlist = join(',', array_map('intval', array_keys($viewdata))); if ($getartefacts) { $artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin FROM {view_artefact} va INNER JOIN {artefact} a ON va.artefact = a.id INNER JOIN {artefact_installed_type} t ON a.artefacttype = t.name WHERE va.view IN (' . $viewidlist . ') GROUP BY va.view, va.artefact, a.title, a.artefacttype, t.plugin ORDER BY a.title, va.artefact', ''); if ($artefacts) { foreach ($artefacts as $artefactrec) { safe_require('artefact', $artefactrec->plugin); $classname = generate_artefact_class_name($artefactrec->artefacttype); $artefactobj = new $classname(0, array('title' => $artefactrec->title)); $artefactobj->set('dirty', false); if (!$artefactobj->in_view_list()) { continue; } $artname = $artefactobj->display_title(30); if (strlen($artname)) { $viewdata[$artefactrec->view]->artefacts[] = array('id' => $artefactrec->artefact, 'title' => $artname); } } } } $tags = get_records_select_array('view_tag', 'view IN (' . $viewidlist . ')'); if ($tags) { foreach ($tags as &$tag) { $viewdata[$tag->view]->tags[] = $tag->tag; } } if (!empty($owners)) { $owners = get_records_select_assoc('usr', 'id IN (' . join(',', $owners) . ')', null, '', 'id,username,firstname,lastname,preferredname,admin,staff,studentid,email,profileicon'); } if (!empty($groups)) { $groups = get_records_select_assoc('group', 'id IN (' . join(',', $groups) . ')', null, '', 'id,name'); } if (!empty($institutions)) { $institutions = get_records_assoc('institution', '', '', '', 'name,displayname'); $institutions['mahara']->displayname = get_config('sitename'); } foreach ($viewdata as &$v) { $v->shortdescription = str_shorten_html(str_replace('<br />', ' ', $v->description), 100, true); if ($v->owner) { $v->sharedby = View::owner_name($v->ownerformat, $owners[$v->owner]); $v->user = $owners[$v->owner]; } else { if ($v->group) { $v->sharedby = $groups[$v->group]->name; } else { if ($v->institution) { $v->sharedby = $institutions[$v->institution]->displayname; } } } $v = (array) $v; } } }
/** * Save a profile field. * Exception is 'socialprofile' field. It is made up of 2 fields: * socialprofile_profileurl, * socialprofile_profiletype * @param int $userid * @param string $field * @param string (or array for socialprofile) $value * @param int $new - Whether the user is new (avoid unnecessary queries) */ function set_profile_field($userid, $field, $value, $new = FALSE) { safe_require('artefact', 'internal'); // this is a special case that replaces the primary email address with the // specified one if ($field == 'email') { if (!$new) { try { $email = artefact_instance_from_type('email', $userid); } catch (ArtefactNotFoundException $e) { // We'll create a new artefact then. } } if (!isset($email)) { $email = new ArtefactTypeEmail(0, null, TRUE); $email->set('owner', $userid); } $email->set('title', $value); $email->commit(); } else { if ($field == 'socialprofile') { if (in_array($value['socialprofile_profiletype'], ArtefactTypeSocialprofile::$socialnetworks)) { $desc = get_string($value['socialprofile_profiletype'], 'artefact.internal'); $type = $value['socialprofile_profiletype']; } else { $desc = $value['socialprofile_profiletype']; $type = 'website'; } $classname = generate_artefact_class_name($field); $profile = new $classname(0, array('owner' => $userid), $new); $profile->set('title', $value['socialprofile_profileurl']); $profile->set('description', $desc); $profile->set('note', $type); $profile->commit(); } else { $classname = generate_artefact_class_name($field); $profile = new $classname(0, array('owner' => $userid), $new); $profile->set('title', $value); $profile->commit(); } } }
/** * Render import entry requests for Mahara user's profile fields * @param PluginImportLeap $importer * @return HTML code for displaying user's profile fields and choosing how to import them */ public static function render_import_entry_requests(PluginImportLeap $importer) { $importid = $importer->get('importertransport')->get('importid'); $profilefields = array('profile' => array('legend' => get_string('aboutme', 'artefact.internal'), 'fields' => array('firstname', 'lastname', 'studentid', 'preferredname', 'introduction')), 'contact' => array('legend' => get_string('contact', 'artefact.internal'), 'fields' => array('email', 'maildisabled', 'officialwebsite', 'personalwebsite', 'blogaddress', 'address', 'town', 'city', 'country', 'homenumber', 'businessnumber', 'mobilenumber', 'faxnumber')), 'messaging' => array('legend' => get_string('messaging', 'artefact.internal'), 'fields' => array('socialprofile')), 'general' => array('legend' => get_string('general'), 'fields' => array('occupation', 'industry'))); // Get import entry requests for Mahara profile fields $profilegroups = array(); foreach ($profilefields as $gr_key => $group) { $profilegroup = array(); $profilegroup['id'] = $gr_key; $profilegroup['legend'] = $group['legend']; foreach ($group['fields'] as $f) { if ($iers = get_records_select_array('import_entry_requests', 'importid = ? AND entrytype = ?', array($importid, $f))) { $profilefieldvalues = array(); foreach ($iers as $ier) { $profilefieldvalue = unserialize($ier->entrycontent); $profilefieldvalue['id'] = $ier->id; $profilefieldvalue['decision'] = $ier->decision; $classname = generate_artefact_class_name($f); $profilefieldvalue['html'] = $classname::render_import_entry_request($profilefieldvalue); if (is_string($ier->duplicateditemids)) { $ier->duplicateditemids = unserialize($ier->duplicateditemids); } if (is_string($ier->existingitemids)) { $ier->existingitemids = unserialize($ier->existingitemids); } $profilefieldvalue['disabled'][PluginImport::DECISION_IGNORE] = false; if (!empty($ier->duplicateditemids)) { $duplicated_pfield = artefact_instance_from_id($ier->duplicateditemids[0]); $profilefieldvalue['duplicateditem']['id'] = $duplicated_pfield->get('id'); $res = $duplicated_pfield->render_self(array()); $profilefieldvalue['duplicateditem']['html'] = $res['html']; $profilefieldvalue['disabled'][PluginImport::DECISION_ADDNEW] = true; $profilefieldvalue['disabled'][PluginImport::DECISION_APPEND] = true; $profilefieldvalue['disabled'][PluginImport::DECISION_REPLACE] = true; } else { if (!empty($ier->existingitemids)) { foreach ($ier->existingitemids as $id) { $existing_pfield = artefact_instance_from_id($id); $res = $existing_pfield->render_self(array()); $profilefieldvalue['existingitems'][] = array('id' => $existing_pfield->get('id'), 'html' => $res['html']); } if ($f == 'email') { $profilefieldvalue['disabled'][PluginImport::DECISION_ADDNEW] = false; $profilefieldvalue['disabled'][PluginImport::DECISION_APPEND] = true; $profilefieldvalue['disabled'][PluginImport::DECISION_REPLACE] = true; } else { $is_singular = call_static_method(generate_artefact_class_name($ier->entrytype), 'is_singular'); $profilefieldvalue['disabled'][PluginImport::DECISION_ADDNEW] = $is_singular; $profilefieldvalue['disabled'][PluginImport::DECISION_APPEND] = !$is_singular; $profilefieldvalue['disabled'][PluginImport::DECISION_REPLACE] = !$is_singular; } } else { $profilefieldvalue['disabled'][PluginImport::DECISION_ADDNEW] = false; $profilefieldvalue['disabled'][PluginImport::DECISION_APPEND] = true; $profilefieldvalue['disabled'][PluginImport::DECISION_REPLACE] = true; } } $profilefieldvalues[] = $profilefieldvalue; } $profilegroup['fields'][$f] = $profilefieldvalues; } } $profilegroups[] = $profilegroup; } $smarty = smarty_core(); $smarty->assign_by_ref('displaydecisions', $importer->get('displaydecisions')); $smarty->assign_by_ref('profilegroups', $profilegroups); return $smarty->fetch('artefact:internal:import/profilefields.tpl'); }
function build_portfolio_search_html(&$data) { global $THEME; $artefacttypes = get_records_assoc('artefact_installed_type'); require_once 'view.php'; require_once 'collection.php'; foreach ($data->data as &$item) { $item->ctime = format_date($item->ctime); if ($item->type == 'view') { $item->typestr = get_string('view'); $item->icon = $THEME->get_image_url('page'); $v = new View(0, (array) $item); $v->set('dirty', false); $item->url = $v->get_url(); } else { if ($item->type == 'collection') { $item->typestr = get_string('Collection', 'collection'); $item->icon = $THEME->get_image_url('collection'); $c = new Collection(0, (array) $item); $item->url = $c->get_url(); } else { // artefact safe_require('artefact', $artefacttypes[$item->artefacttype]->plugin); $links = call_static_method(generate_artefact_class_name($item->artefacttype), 'get_links', $item->id); $item->url = $links['_default']; $item->icon = call_static_method(generate_artefact_class_name($item->artefacttype), 'get_icon', array('id' => $item->id)); if ($item->artefacttype == 'task') { $item->typestr = get_string('Task', 'artefact.plans'); } else { $item->typestr = get_string($item->artefacttype, 'artefact.' . $artefacttypes[$item->artefacttype]->plugin); } } } } $data->baseurl = get_config('wwwroot') . 'tags.php' . (is_null($data->tag) ? '' : '?tag=' . urlencode($data->tag)); $data->sortcols = array('name', 'date'); $data->filtercols = array('all' => get_string('tagfilter_all'), 'file' => get_string('tagfilter_file'), 'image' => get_string('tagfilter_image'), 'text' => get_string('tagfilter_text'), 'view' => get_string('tagfilter_view'), 'collection' => get_string('tagfilter_collection')); $smarty = smarty_core(); $smarty->assign_by_ref('data', $data->data); $smarty->assign('owner', $data->owner->id); $data->tablerows = $smarty->fetch('portfoliosearchresults.tpl'); $pagination = build_pagination(array('id' => 'results_pagination', 'class' => 'center', 'url' => $data->baseurl . ($data->sort == 'name' ? '' : '&sort=' . $data->sort) . ($data->filter == 'all' ? '' : '&type=' . $data->filter), 'jsonscript' => 'json/tagsearch.php', 'datatable' => 'results', 'count' => $data->count, 'limit' => $data->limit, 'offset' => $data->offset, 'jumplinks' => 6, 'numbersincludeprevnext' => 2, 'numbersincludefirstlast' => false, 'resultcounttextsingular' => get_string('result'), 'resultcounttextplural' => get_string('results'))); $data->pagination = $pagination['html']; $data->pagination_js = $pagination['javascript']; }
/** * Render import entry requests for Mahara user's resume fields * @param PluginImportLeap $importer * @return HTML code for displaying user's resume fields and choosing how to import them */ public static function render_import_entry_requests(PluginImportLeap $importer) { safe_require('artefact', 'resume'); $importid = $importer->get('importertransport')->get('importid'); $resumefields = array('introduction' => array('legend' => get_string('introduction', 'artefact.resume'), 'fields' => array('coverletter', 'personalinformation')), 'employment' => array('legend' => get_string('educationandemployment', 'artefact.resume'), 'fields' => array('educationhistory', 'employmenthistory')), 'achievements' => array('legend' => get_string('achievements', 'artefact.resume'), 'fields' => array('certification', 'book', 'membership')), 'goals' => array('legend' => get_string('goals', 'artefact.resume'), 'fields' => array('personalgoal', 'academicgoal', 'careergoal')), 'skills' => array('legend' => get_string('skills', 'artefact.resume'), 'fields' => array('personalskill', 'academicskill', 'workskill')), 'interests' => array('legend' => get_string('interests', 'artefact.resume'), 'fields' => array('interests'))); $resumecompositefields = array('book', 'certificattion', 'educationhistory', 'employmenthistory', 'membership'); // Get import entry requests for Mahara resume fields $resumegroups = array(); foreach ($resumefields as $gr_key => $group) { $resumegroup = array(); $resumegroup['id'] = $gr_key; $resumegroup['legend'] = $group['legend']; foreach ($group['fields'] as $f) { if ($iers = get_records_select_array('import_entry_requests', 'importid = ? AND entrytype = ?', array($importid, $f))) { $resumefieldvalues = array(); $fieldname = $f == 'url' ? get_string('bookurl', 'artefact.resume') : get_string($f, 'artefact.resume'); foreach ($iers as $ier) { $resumefieldvalue = unserialize($ier->entrycontent); $classname = generate_artefact_class_name($f); $resumefieldvalue['id'] = $ier->id; $resumefieldvalue['decision'] = $ier->decision; $resumefieldvalue['html'] = $classname::render_import_entry_request($resumefieldvalue); if (is_string($ier->duplicateditemids)) { $ier->duplicateditemids = unserialize($ier->duplicateditemids); } if (is_string($ier->existingitemids)) { $ier->existingitemids = unserialize($ier->existingitemids); } $resumefieldvalue['disabled'][PluginImport::DECISION_IGNORE] = false; if (!empty($ier->duplicateditemids)) { $duplicated_rfield = artefact_instance_from_id($ier->duplicateditemids[0]); $resumefieldvalue['duplicateditem']['id'] = $duplicated_rfield->get('id'); $res = $duplicated_rfield->render_self(array()); $resumefieldvalue['duplicateditem']['html'] = $res['html']; $resumefieldvalue['disabled'][PluginImport::DECISION_ADDNEW] = true; $resumefieldvalue['disabled'][PluginImport::DECISION_APPEND] = true; $resumefieldvalue['disabled'][PluginImport::DECISION_REPLACE] = true; } else { if (!empty($ier->existingitemids)) { if (in_array($f, $resumecompositefields)) { $existing_rfield = artefact_instance_from_id($ier->existingitemids[0]); $res = $existing_rfield->render_self(array()); $resumefieldvalue['existingitems'][] = array('id' => $existing_rfield->get('id'), 'html' => $res['html']); } else { foreach ($ier->existingitemids as $id) { $existing_rfield = artefact_instance_from_id($id); $res = $existing_rfield->render_self(array()); $resumefieldvalue['existingitems'][] = array('id' => $existing_rfield->get('id'), 'html' => $res['html']); } } // Composite artefacts: There's just one "artefact" and then multiple entries // in an associated artefact_resume_* table. So, you want to disable everything // except for "Append" if (in_array($ier->entrytype, ArtefactTypeResumeComposite::get_composite_artefact_types())) { $resumefieldvalue['disabled'][PluginImport::DECISION_ADDNEW] = true; $resumefieldvalue['disabled'][PluginImport::DECISION_APPEND] = false; $resumefieldvalue['disabled'][PluginImport::DECISION_REPLACE] = true; } else { $is_singular = call_static_method(generate_artefact_class_name($ier->entrytype), 'is_singular'); $resumefieldvalue['disabled'][PluginImport::DECISION_ADDNEW] = $is_singular; $resumefieldvalue['disabled'][PluginImport::DECISION_APPEND] = !$is_singular; $resumefieldvalue['disabled'][PluginImport::DECISION_REPLACE] = !$is_singular; } } else { if (in_array($ier->entrytype, ArtefactTypeResumeComposite::get_composite_artefact_types())) { $resumefieldvalue['disabled'][PluginImport::DECISION_ADDNEW] = true; $resumefieldvalue['disabled'][PluginImport::DECISION_APPEND] = false; $resumefieldvalue['disabled'][PluginImport::DECISION_REPLACE] = true; } else { $resumefieldvalue['disabled'][PluginImport::DECISION_ADDNEW] = false; $resumefieldvalue['disabled'][PluginImport::DECISION_APPEND] = true; $resumefieldvalue['disabled'][PluginImport::DECISION_REPLACE] = true; } } } $resumefieldvalues[] = $resumefieldvalue; } $resumegroup['fields'][$fieldname] = $resumefieldvalues; } } $resumegroups[] = $resumegroup; } $smarty = smarty_core(); $smarty->assign_by_ref('displaydecisions', $importer->get('displaydecisions')); $smarty->assign_by_ref('resumegroups', $resumegroups); return $smarty->fetch('artefact:resume:import/resumefields.tpl'); }
public static function get_form($artefact = array()) { require_once get_config('libroot') . 'pieforms/pieform.php'; //$elements = call_static_method(generate_artefact_class_name('flexifact'), 'get_form_elements', $artefact); $titledefault = ''; $elements['title'] = array('type' => 'text', 'defaultvalue' => $titledefault, 'title' => get_string('title', 'artefact.flexifact'), 'size' => 30, 'rules' => array('required' => TRUE)); $elements['submit'] = array('type' => 'submitcancel', 'value' => array(get_string('save', 'artefact.flexifact'), get_string('cancel')), 'goto' => '/artefact/flexifact/index.php'); $artefactform = array('name' => empty($artefact) ? 'create' : 'edit', 'plugintype' => 'artefact', 'pluginname' => 'flexifact', 'validatecallback' => array(generate_artefact_class_name('flexifact'), 'validate'), 'successcallback' => array(generate_artefact_class_name('flexifact'), 'submit'), 'elements' => $elements); return pieform($artefactform); }
public function render_self($options) { $smarty = smarty_core(); $smarty->assign('title', $this->get('title')); $smarty->assign('description', $this->get('description')); $smarty->assign('tags', $this->get('tags')); $smarty->assign('owner', $this->get('owner')); $smarty->assign('viewid', isset($options['viewid']) ? $options['viewid'] : 0); $smarty->assign('simpledisplay', isset($options['simpledisplay']) ? $options['simpledisplay'] : false); $smarty->assign('folderid', $this->get('id')); $smarty->assign('downloadfolderzip', get_config_plugin('blocktype', 'folder', 'folderdownloadzip') ? !empty($options['folderdownloadzip']) : false); if ($childrecords = $this->folder_contents()) { $sortorder = isset($options['sortorder']) && $options['sortorder'] == 'desc' ? 'my_files_cmp_desc' : 'my_files_cmp'; usort($childrecords, array('ArtefactTypeFileBase', $sortorder)); $children = array(); foreach ($childrecords as &$child) { $c = artefact_instance_from_id($child->id); $child->title = $child->hovertitle = $c->get('title'); $child->date = format_date(strtotime($child->mtime), 'strfdaymonthyearshort'); $child->iconsrc = call_static_method(generate_artefact_class_name($child->artefacttype), 'get_icon', array('id' => $child->id, 'viewid' => isset($options['viewid']) ? $options['viewid'] : 0)); } $smarty->assign('children', $childrecords); } return array('html' => $smarty->fetch('artefact:file:folder_render_self.tpl'), 'javascript' => null); }
public static function get_extra_view_info(&$viewdata, $getartefacts = true, $gettags = true) { if ($viewdata) { // Get view owner details for display $owners = array(); $groups = array(); $institutions = array(); foreach ($viewdata as $v) { if (!empty($v->owner) && !isset($owners[$v->owner])) { $owners[$v->owner] = (int) $v->owner; } else { if (!empty($v->group) && !isset($groups[$v->group])) { $groups[$v->group] = (int) $v->group; } else { if (!empty($v->institution) && !isset($institutions[$v->institution])) { $institutions[$v->institution] = $v->institution; } } } } $viewidlist = join(',', array_map('intval', array_keys($viewdata))); if ($getartefacts) { $artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin FROM {view_artefact} va INNER JOIN {artefact} a ON va.artefact = a.id INNER JOIN {artefact_installed_type} t ON a.artefacttype = t.name WHERE va.view IN (' . $viewidlist . ') GROUP BY va.view, va.artefact, a.title, a.artefacttype, t.plugin ORDER BY a.title, va.artefact', array()); if ($artefacts) { foreach ($artefacts as $artefactrec) { safe_require('artefact', $artefactrec->plugin); $classname = generate_artefact_class_name($artefactrec->artefacttype); $artefactobj = new $classname(0, array('title' => $artefactrec->title)); $artefactobj->set('dirty', false); if (!$artefactobj->in_view_list()) { continue; } $artname = $artefactobj->display_title(30); if (strlen($artname)) { $viewdata[$artefactrec->view]->artefacts[] = array('id' => $artefactrec->artefact, 'title' => $artname); } } } } if ($gettags) { $tags = get_records_select_array('view_tag', 'view IN (' . $viewidlist . ')'); if ($tags) { foreach ($tags as &$tag) { $viewdata[$tag->view]->tags[] = $tag->tag; } } } if (!empty($owners)) { global $USER; $userid = $USER->get('id'); $fields = array('id', 'username', 'firstname', 'lastname', 'preferredname', 'admin', 'staff', 'studentid', 'email', 'profileicon', 'urlid', 'suspendedctime'); if (count($owners) == 1 && isset($owners[$userid])) { $owners = array($userid => new StdClass()); foreach ($fields as $f) { $owners[$userid]->{$f} = $USER->get($f); } } else { $owners = get_records_select_assoc('usr', 'id IN (' . join(',', array_fill(0, count($owners), '?')) . ')', $owners, '', join(',', $fields)); } } if (!empty($groups)) { require_once 'group.php'; $groups = get_records_select_assoc('group', 'id IN (' . join(',', $groups) . ')', null, '', 'id,name,urlid'); } if (!empty($institutions)) { $institutions = get_records_assoc('institution', '', '', '', 'name,displayname'); $institutions['mahara']->displayname = get_config('sitename'); } $wwwroot = get_config('wwwroot'); $needsubdomain = get_config('cleanurlusersubdomains'); foreach ($viewdata as &$v) { $v->anonymous = FALSE; if (!empty($v->owner)) { $v->sharedby = View::owner_name($v->ownerformat, $owners[$v->owner]); $v->user = $owners[$v->owner]; // Get a real view object so we can do the checks. $view_obj = new View($v->id); $v->anonymous = $view_obj->is_anonymous(); $v->staff_or_admin = $view_obj->is_staff_or_admin_for_page(); } else { if (!empty($v->group)) { $v->sharedby = $groups[$v->group]->name; $v->groupdata = $groups[$v->group]; } else { if (!empty($v->institution)) { $v->sharedby = $institutions[$v->institution]->displayname; } } } $v = (array) $v; // Now that we have the owner & group records, create a temporary View object // so that we can use display_title_editing and get_url methods. $view = new View(0, $v); $view->set('dirty', false); $v['displaytitle'] = $view->display_title_editing(); $v['url'] = $view->get_url(false); $v['fullurl'] = $needsubdomain ? $view->get_url(true) : $wwwroot . $v['url']; } } }
public function render_self($options) { $smarty = smarty_core(); $smarty->assign('title', $this->get('title')); $smarty->assign('description', $this->get('description')); $smarty->assign('viewid', isset($options['viewid']) ? $options['viewid'] : 0); $smarty->assign('simpledisplay', isset($options['simpledisplay']) ? $options['simpledisplay'] : false); if ($childrecords = $this->folder_contents()) { $this->add_to_render_path($options); usort($childrecords, array('ArtefactTypeFileBase', 'my_files_cmp')); $children = array(); foreach ($childrecords as &$child) { $c = artefact_instance_from_id($child->id); $child->title = $child->hovertitle = $c->get('title'); if (!empty($options['simpledisplay'])) { $child->title = str_shorten_text($child->title, 20); } $child->date = format_date(strtotime($child->mtime), 'strfdaymonthyearshort'); $child->iconsrc = call_static_method(generate_artefact_class_name($child->artefacttype), 'get_icon', array('id' => $child->id, 'viewid' => isset($options['viewid']) ? $options['viewid'] : 0)); } $smarty->assign('children', $childrecords); } return array('html' => $smarty->fetch('artefact:file:folder_render_self.tpl'), 'javascript' => null); }
require_once 'pieforms/pieform/elements/calendar.php'; require_once get_config('docroot') . 'artefact/lib.php'; safe_require('artefact', 'resume'); safe_require('artefact', 'file'); if (!PluginArtefactResume::is_active()) { throw new AccessDeniedException(get_string('plugindisableduser', 'mahara', get_string('resume', 'artefact.resume'))); } define('TITLE', get_string('resume', 'artefact.resume')); $id = param_integer('id', 0); $type = param_variable('type', ''); if ($id > 0) { $artefact = artefact_instance_from_id($id); $type = $artefact->get('artefacttype'); } else { if ($id == 0 && !empty($type)) { $classname = generate_artefact_class_name($type); try { $artefact = artefact_instance_from_type($type); } catch (Exception $e) { $artefact = new $classname(0, array('owner' => $USER->get('id'))); $artefact->commit(); } } else { throw new ArtefactNotFoundException(get_string('cannotfindcreateartefact', 'artefact.resume')); } } if ($artefact->get('owner') != $USER->get('id')) { throw new AccessDeniedException(get_string('notartefactowner', 'error')); } $folder = param_integer('folder', 0); $browse = (int) param_variable('browse', 0);
public function render_self($options) { global $USER; $suffix = '_' . substr(md5(microtime()), 0, 4); $smarty = smarty_core(); $smarty->assign('hidetitle', true); $smarty->assign('suffix', $suffix); $type = $this->get('artefacttype'); $othertable = 'artefact_resume_' . $type; $owner = $USER->get('id'); $sql = 'SELECT ar.*, a.owner FROM {artefact} a JOIN {' . $othertable . '} ar ON ar.artefact = a.id WHERE a.owner = ? AND a.artefacttype = ? ORDER BY ar.displayorder'; if (!empty($options['viewid'])) { if (!can_view_view($options['viewid'])) { throw new AccessDeniedException(); } require_once 'view.php'; $v = new View($options['viewid']); $owner = $v->get('owner'); } if (!($data = get_records_sql_array($sql, array($owner, $type)))) { $data = array(); } // Give the artefact type a chance to format the data how it sees fit $data = call_static_method(generate_artefact_class_name($type), 'format_render_self_data', $data); $smarty->assign('rows', $data); $content = array('html' => $smarty->fetch('artefact:resume:fragments/' . $type . '.tpl'), 'javascript' => $this->get_showhide_composite_js()); return $content; }