/** * Get the id of the entry reflected on by a comment entry */ public static function get_referent_entryid(SimpleXMLElement $entry, PluginImportLeap $importer) { foreach ($entry->link as $link) { if ($importer->curie_equals($link['rel'], $importer->get_leap2a_namespace(), 'reflects_on') && isset($link['href'])) { return (string) $link['href']; } } // Shouldn't happen -- this was checked when offering the strategy throw new ImportException($importer, 'TODO: get_string: cannot find an entry for a comment to comment on'); }
/** * Get name fields from imported namedata */ private static function get_namefields(PluginImportLeap $importer, array $persondata) { $namefields = array('full_name' => false, 'legal_family_name' => false, 'legal_given_name' => false, 'preferred_family_name' => false, 'preferred_given_name' => false, 'family_name_first' => false, 'name_prefix' => false, 'name_suffix' => false); foreach ($persondata as $item) { $leapattributes = PluginImportLeap::get_attributes($item, $importer->get_leap2a_namespace()); if (isset($leapattributes['field'])) { if (in_array($leapattributes['field'], array_keys($namefields))) { // legal_given_name is allowed to occur any number of times if ($leapattributes['field'] == 'legal_given_name' && $namefields['legal_given_name'] != '') { $namefields['legal_given_name'] .= ' ' . (string) $item; } else { $namefields[$leapattributes['field']] = (string) $item; } } } else { // 'Field' is required // http://wiki.cetis.ac.uk/2009-03/Leap2A_personal_data#field $importer->trace('WARNING: persondata element did not have leap:field attribute'); continue; } } $familynamefirst = $namefields['family_name_first'] == 'yes' ? true : false; // Try to guess reasonable values for first/last names if they're not set if ($namefields['legal_given_name'] === false && $namefields['preferred_given_name'] !== false) { $namefields['legal_given_name'] = $namefields['preferred_given_name']; } if ($namefields['legal_family_name'] === false && $namefields['preferred_family_name'] !== false) { $namefields['legal_family_name'] = $namefields['preferred_family_name']; } // This is _an_ algorithm for parsing this info, I'm not saying it's the _best_ one ;) if ($familynamefirst) { $firstname = (string) $namefields['legal_given_name'] . ' ' . (string) $namefields['name_suffix']; $lastname = (string) $namefields['name_prefix'] . (string) $namefields['legal_family_name']; $preferredname = (string) $namefields['preferred_family_name'] . ' ' . (string) $namefields['preferred_given_name']; } else { $firstname = (string) $namefields['name_prefix'] . ' ' . (string) $namefields['legal_given_name']; $lastname = (string) $namefields['legal_family_name'] . ' ' . (string) $namefields['name_suffix']; $preferredname = (string) $namefields['preferred_given_name'] . ' ' . (string) $namefields['preferred_family_name']; } return array('firstname' => trim($firstname), 'lastname' => trim($lastname), 'preferredname' => trim($preferredname)); }
/** * Given an entry, see if it's attached to one of the special selections * representing a Mahara resume group. If so, return the display order it * should have in that group. * * We look for the special Mahara selections only, because entries could be * in more than one selection, with different display orders in each. * * @param SimpleXMLElement $entry The entry to check * @param PluginImportLeap $importer The importer * @param string $selectiontype The type of selection we're checking to * see if the entry is part of - one of the * special Mahara resume selections * @return int The display order of the element in the selection, should it * be in one - else null */ private static function get_display_order_for_entry(SimpleXMLElement $entry, PluginImportLeap $importer, $selectiontype) { static $cache = array(); $found = false; foreach ($entry->link as $link) { if ($importer->curie_equals($link['rel'], $importer->get_leap2a_namespace(), 'is_part_of') && isset($link['href'])) { $href = (string) $link['href']; if (isset($cache[$href])) { $found = true; } else { if ($potentialselection = $importer->get_entry_by_id($href)) { if (PluginImportLeap::is_rdf_type($potentialselection, $importer, 'selection')) { if (PluginImportLeap::is_correct_category_scheme($potentialselection, $importer, 'selection_type', 'Grouping')) { if (count($potentialselection->xpath('mahara:artefactplugin[@mahara:type="' . $selectiontype . '"]')) == 1) { $cache[$href] = true; $found = true; } } } } } if ($found) { $leapattributes = $importer->get_attributes($link, $importer->get_leap2a_namespace()); $displayorder = isset($leapattributes['display_order']) && intval($leapattributes['display_order']) > 0 ? $leapattributes['display_order'] : ''; return $displayorder; } } } }
/** * Returns a list of entry IDs that are children of this folder * * If necessary, this method can act recursively to find children at all * levels under this folder * * TODO: protection against circular references * * @param SimpleXMLElement $entry The folder to get children for * @param PluginImportLeap $importer The importer * @param boolean $recurse Whether to return children at all levels below this folder * @return array A list of the entry IDs of children in this folder */ private static function get_children_of_folder(SimpleXMLElement $entry, PluginImportLeap $importer, $recurse = false) { $children = array(); // Get entries that this folder feels are a part of it foreach ($entry->link as $link) { if ($importer->curie_equals($link['rel'], $importer->get_leap2a_namespace(), 'has_part') && isset($link['href'])) { $child = $importer->get_entry_by_id((string) $link['href']); if ($child) { if (self::is_file($child, $importer) || self::is_folder($child, $importer)) { $children[] = (string) $link['href']; } else { $importer->trace("NOTICE: Child {$child->id} of folder {$entry->id} won't be imported by the file plugin because it is not a file or folder"); } } else { $importer->trace("WARNING: folder {$entry->id} claims to have child {$link['href']} which does not exist"); } } } if ($recurse) { foreach ($children as $childid) { $child = $importer->get_entry_by_id($childid); if (self::is_folder($child, $importer)) { $children = array_merge($children, self::get_children_of_folder($child, $importer, true)); } } } return $children; }