public static function get_import_strategies_for_entry(SimpleXMLElement $entry, PluginImportLeap $importer) { $strategies = array(); if (PluginImportLeap::is_rdf_type($entry, $importer, 'entry') && $entry->xpath('mahara:artefactplugin[@mahara:type="annotation"]')) { // Check that the entry has something that reflects on it. $otherentries = array(); foreach ($entry->link as $link) { // Don't include the view it reflects_on. if ($importer->curie_equals($link['rel'], $importer->get_leap2a_namespace(), 'reflected_on_by') && isset($link['href'])) { // These should be the feedback. $otherentries[] = (string) $link['href']; } } // Annotation may not have anything reflecting on it. $strategies[] = array('strategy' => self::STRATEGY_IMPORT_AS_ANNOTATION, 'score' => 100, 'other_required_entries' => $otherentries); } else { if (PluginImportLeap::is_rdf_type($entry, $importer, 'entry') && $entry->xpath('mahara:artefactplugin[@mahara:type="annotationfeedback"]')) { // Check that the entry 'reflects_on' something $otherentries = array(); foreach ($entry->link as $link) { if ($importer->curie_equals($link['rel'], $importer->get_leap2a_namespace(), 'reflects_on') && isset($link['href'])) { // This should be the annotation. $otherentries[] = (string) $link['href']; } } if (count($otherentries) == 1) { // Annotation feedback should only reflect on 1 item. $strategies[] = array('strategy' => self::STRATEGY_IMPORT_AS_ANNOTATION_FEEDBACK, 'score' => 90, 'other_required_entries' => $otherentries); } } } return $strategies; }
public static function get_import_strategies_for_entry(SimpleXMLElement $entry, PluginImportLeap $importer) { $strategies = array(); // Mahara can't handle html plans yet, so don't claim to be able to import them. if (PluginImportLeap::is_rdf_type($entry, $importer, 'plan') && (empty($entry->content['type']) || (string) $entry->content['type'] == 'text')) { $strategies[] = array('strategy' => self::STRATEGY_IMPORT_AS_PLAN, 'score' => 90, 'other_required_entries' => array()); } return $strategies; }
public static function get_import_strategies_for_entry(SimpleXMLElement $entry, PluginImportLeap $importer) { $strategies = array(); if (PluginImportLeap::is_rdf_type($entry, $importer, 'entry') && $entry->xpath('mahara:artefactplugin[@mahara:type="comment"]')) { // Check that the entry 'reflects_on' something $otherentries = array(); foreach ($entry->link as $link) { if ($importer->curie_equals($link['rel'], $importer->get_leap2a_namespace(), 'reflects_on') && isset($link['href'])) { $otherentries[] = (string) $link['href']; } } if (count($otherentries) == 1) { $strategies[] = array('strategy' => self::STRATEGY_IMPORT_AS_COMMENT, 'score' => 100, 'other_required_entries' => array()); } } return $strategies; }
public static function get_import_strategies_for_entry(SimpleXMLElement $entry, PluginImportLeap $importer) { $strategies = array(); if (PluginImportLeap::is_rdf_type($entry, $importer, 'selection')) { if (PluginImportLeap::is_correct_category_scheme($entry, $importer, 'selection_type', 'Blog')) { $score = 100; } else { // the blog plugin can either fall back to importing single entries // or handle the case where things are a selection that have no other strategies either. // however, in the case where the otherrequiredentries for the selection have a higher strategy elsewhere, // we need to still fallback to importing a selection post as a blog post by itself, to avoid dataloss. $score = 20; // other things *can* be imported as blogs } $otherrequiredentries = array(); // Get entries that this blog/selection 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'])) { $otherrequiredentries[] = (string) $link['href']; } } // TODO: Get entries that feel they should be a part of this blog/selection // We can compare the lists and perhaps warn if they're different // $otherentries = $importer->xml->xpath('//a:feed/a:entry/a:link[@rel="leap:is_part_of" and @href="' . $entryid . '"]/../a:id'); $otherrequiredentries = array_unique($otherrequiredentries); $strategies[] = array('strategy' => self::STRATEGY_IMPORT_AS_BLOG, 'score' => $score, 'other_required_entries' => $otherrequiredentries); if ($score == 20) { $strategies[] = array('strategy' => self::STRATEGY_IMPORT_AS_ENTRY, 'score' => 10, 'other_required_entries' => array()); } } else { // The blog can import any entry as a literal blog post // Get files that this blogpost/catchall feels are a part of it $otherrequiredentries = array(); foreach ($entry->link as $link) { if ($importer->curie_equals($link['rel'], '', 'enclosure') && isset($link['href'])) { $otherrequiredentries[] = (string) $link['href']; } } $strategies[] = array('strategy' => self::STRATEGY_IMPORT_AS_ENTRY, 'score' => 10, 'other_required_entries' => $otherrequiredentries); } return $strategies; }
/** * The profile importer tries to import raw profile fields using the * strategy mechanism, but most of the useful profile information is stored * in the person entry corresponding to the author. * * The persondata entry is not actually imported using a strategy, because * we need to be able to import basic data from the <author> element if * it's not present too. So all the person importing is handled in import_author_data() */ public static function get_import_strategies_for_entry(SimpleXMLElement $entry, PluginImportLeap $importer) { if (self::$personcontentblank === null) { self::$personcontentblank = true; if ($persondataid = $importer->get('persondataid')) { self::$personcontentblank = !(string) $importer->get_entry_by_id($persondataid)->content; } } $isentry = PluginImportLeap::is_rdf_type($entry, $importer, 'entry'); if ($isentry && self::$personcontentblank && PluginImportLeap::is_correct_category_scheme($entry, $importer, 'common_item', 'Personalstatement')) { return array(array('strategy' => self::STRATEGY_IMPORT_AS_INTRODUCTION, 'score' => 100, 'other_required_entries' => array())); } // If it's a raw entry with the right mahara:plugin and mahara:type // we should be able to import it $correctplugintype = count($entry->xpath('mahara:artefactplugin[@mahara:plugin="internal"]')) == 1; if ($isentry && $correctplugintype) { return array(array('strategy' => self::STRATEGY_IMPORT_AS_PROFILE_FIELD, 'score' => 100, 'other_required_entries' => array())); } return array(); }
/** * 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 whether the given entry is a folder * * @param SimpleXMLElement $entry The entry to check * @param PluginImportLeap $importer The importer * @return boolean Whether the entry is a folder */ private static function is_folder(SimpleXMLElement $entry, PluginImportLeap $importer) { static $cache = array(); $id = (string) $entry->id; if (isset($cache[$id])) { return $cache[$id]; } return $cache[$id] = PluginImportLeap::is_rdf_type($entry, $importer, 'selection') && PluginImportLeap::is_correct_category_scheme($entry, $importer, 'selection_type', 'Folder'); }