Ejemplo n.º 1
0
 public static function get_import_strategies_for_entry(SimpleXMLElement $entry, PluginImport $importer)
 {
     $strategies = array();
     // TODO: when the xpath has an error in it, count(error) == 1 also.. so should check return type
     $correctrdftype = count($entry->xpath('rdf:type[' . $importer->curie_xpath('@rdf:resource', PluginImportLeap::NS_LEAPTYPE, 'selection') . ']')) == 1;
     $correctcategoryscheme = count($entry->xpath('a:category[(' . $importer->curie_xpath('@scheme', PluginImportLeap::NS_CATEGORIES, 'selection_type#') . ') and @term="Blog"]')) == 1;
     if ($correctrdftype && $correctcategoryscheme) {
         $otherrequiredentries = array();
         // Get entries that this blog feels are a part of it
         foreach ($entry->link as $link) {
             if ($importer->curie_equals($link['rel'], PluginImportLeap::NS_LEAP, 'has_part') && isset($link['href'])) {
                 $otherrequiredentries[] = (string) $link['href'];
             }
         }
         // TODO: Get entries that feel they should be a part of this blog.
         // 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' => 100, 'other_required_entries' => $otherrequiredentries);
     } else {
         // The blog can import any entry as a literal blog post
         $strategies[] = array('strategy' => self::STRATEGY_IMPORT_AS_ENTRY, 'score' => 10, 'other_required_entries' => array());
     }
     return $strategies;
 }
Ejemplo n.º 2
0
 /**
  * Returns whether the given entry is a folder
  *
  * @param SimpleXMLElement $entry The entry to check
  * @param PluginImport $importer  The importer
  * @return boolean Whether the entry is a folder
  */
 private static function is_folder(SimpleXMLElement $entry, PluginImport $importer)
 {
     static $cache = array();
     $id = (string) $entry->id;
     if (isset($cache[$id])) {
         return $cache[$id];
     }
     $correctrdftype = count($entry->xpath('rdf:type[' . $importer->curie_xpath('@rdf:resource', PluginImportLeap::NS_LEAPTYPE, 'selection') . ']')) == 1;
     $correctcategoryscheme = count($entry->xpath('a:category[(' . $importer->curie_xpath('@scheme', PluginImportLeap::NS_CATEGORIES, 'selection_type#') . ') and @term="Folder"]')) == 1;
     return $cache[$id] = $correctrdftype && $correctcategoryscheme;
 }
Ejemplo n.º 3
0
 /**
  * The profile importer has two strategies it can use for certain entries.
  *
  * The profile importer attempts to "reserve" the persondata entry 
  * representing the user being imported (if one exists).
  *
  * 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 importing is handled in one custom hook 
  * - import_author_data()
  *
  * The importer also tries to reserve raw entries with mahara:plugin="internal"
  * - these can be used to populate some of our profile fields that aren't 
  * explicitly mapped in LEAP2A.
  */
 public static function get_import_strategies_for_entry(SimpleXMLElement $entry, PluginImport $importer)
 {
     $strategies = array();
     if (is_null(self::$persondataid)) {
         $author = $importer->get('xml')->xpath('//a:feed/a:author[1]');
         $author = $author[0];
         if (isset($author->uri) && $importer->get_entry_by_id((string) $author->uri)) {
             self::$persondataid = (string) $author->uri;
         } else {
             self::$persondataid = false;
         }
     }
     // TODO: also check other element has the right leaptype (person)
     //$correctrdftype = count($entry->xpath('rdf:type['
     //    . $importer->curie_xpath('@rdf:resource', PluginImportLeap::NS_LEAPTYPE, 'selection') . ']')) == 1;
     if ((string) $entry->id == self::$persondataid) {
         $strategies[] = array('strategy' => self::STRATEGY_DUMMY, 'score' => 100, 'other_required_entries' => array());
     } else {
         // If it's a raw entry with the right mahara:plugin and mahara:type
         // we should be able to import it
         $correctrdftype = count($entry->xpath('rdf:type[' . $importer->curie_xpath('@rdf:resource', PluginImportLeap::NS_LEAPTYPE, 'entry') . ']')) == 1;
         $correctplugintype = count($entry->xpath('mahara:artefactplugin[@mahara:plugin="internal"]')) == 1;
         if ($correctrdftype && $correctplugintype) {
             $strategies[] = array('strategy' => self::STRATEGY_IMPORT_AS_PROFILE_FIELD, 'score' => 100, 'other_required_entries' => array());
         }
     }
     return $strategies;
 }