Commit 059abac7 authored by Nigel McNie's avatar Nigel McNie
Browse files

Export and import default profile icon relation.



At export time, we export a few links in our persondata element that
point to profile icons. The icons themselves link to the persondata
element. In lieu of anything better, we're currently using 'related' for
this.

At import time, we look at links in the persondata element, and the
first 'related' one we come across that is a profile icon, we set as the
default.

This conforms with what the list people were doing, so at least for this
version of the spec we'll be doing it consistently with the others.
Signed-off-by: default avatarNigel McNie <nigel@catalyst.net.nz>
parent cb567e83
......@@ -93,6 +93,13 @@ class LeapExportElementFolder extends LeapExportElement {
}
class LeapExportElementImage extends LeapExportElementFile { }
class LeapExportElementProfileIcon extends LeapExportElementFile { }
class LeapExportElementProfileIcon extends LeapExportElementFile {
public function add_links() {
parent::add_links();
$this->add_generic_link('artefactinternal', 'related');
}
}
?>
......@@ -269,10 +269,6 @@ class LeapImportFile extends LeapImportArtefactPlugin {
if (!rename($basedir . $olddir . $id, $basedir . $newdir . $id)) {
throw new ImportException($importer, 'TODO: get_string: was unable to move profile icon');
}
// Unconditionally set as default, even if there is more than one
$importer->get('usrobj')->profileicon = $id;
$importer->get('usrobj')->commit();
}
$artefact->commit();
......
......@@ -44,9 +44,11 @@ class LeapExportElementInternal extends LeapExportElement {
}
public function assign_smarty_vars() {
$user = $this->get('exporter')->get('user');
$userid = $user->get('id');
$this->smarty->assign('artefacttype', 'internal');
$this->smarty->assign('artefactplugin', 'internal');
$this->smarty->assign('title', display_name($this->get('exporter')->get('user'), $this->get('exporter')->get('user')));
$this->smarty->assign('title', display_name($user, $user));
// If this ID is changed, you'll have to change it in author.tpl too
$this->smarty->assign('id', 'portfolio:artefactinternal');
$this->smarty->assign('leaptype', $this->get_leap_type());
......@@ -82,6 +84,21 @@ class LeapExportElementInternal extends LeapExportElement {
}
$this->smarty->assign('persondata', $persondata);
$this->smarty->assign('spacialdata', $spacialdata);
// Grab profile icons and link to them, making sure the default is first
if ($icons = get_column_sql("SELECT id
FROM {artefact}
WHERE artefacttype = 'profileicon'
AND owner = ?
ORDER BY id = (
SELECT profileicon FROM {usr} WHERE id = ?
) DESC, id", array($userid, $userid))) {
foreach ($icons as $icon) {
$icon = artefact_instance_from_id($icon);
$this->add_artefact_link($icon, 'related');
}
$this->smarty->assign('links', $this->links);
}
}
public function get_template_path() {
......
......@@ -235,6 +235,24 @@ class LeapImportInternal extends LeapImportArtefactPlugin {
if (count($addressdata) == 1) {
self::import_addressdata($importer, $addressdata[0]);
}
// Set default profile icon. We look at rel="related" links on this
// element, and take the first one that we turned into a profile
// icon to be the default. In future versions of the spec, we may use
// a "depicts" type relationship to explicitly identify them.
foreach ($person->link as $link) {
if ($importer->curie_equals($link['rel'], '', 'related') && isset($link['href'])) {
$artefactids = $importer->get_artefactids_imported_by_entryid((string)$link['href']);
if (count($artefactids) == 1 && $potentialicon = artefact_instance_from_id($artefactids[0])) {
if ($potentialicon->get('artefacttype') == 'profileicon') {
$importer->get('usrobj')->profileicon = $potentialicon->get('id');
$importer->get('usrobj')->commit();
// The first one we find in the export is the profile icon
break;
}
}
}
}
}
else {
$author = $importer->get('xml')->xpath('//a:feed/a:author[1]');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment