Beispiel #1
0
 /**
  * Import data about the feed author.
  *
  * If we have a persondata element for them, we can import lots of
  * different information about them into Mahara's profile section.
  * Otherwise, we can only import some very basic information from the
  * <author> element.
  *
  * TODO: Refactor this to combine it with add_import_entry_request_author_data()
  *
  * @param PluginImportLeap $importer The importer
  * @param string $persondataid       The ID of the person entry corresponding
  *                                   to the author, if there is one
  */
 public static function import_author_data(PluginImportLeap $importer, $persondataid)
 {
     $namespaces = $importer->get_namespaces();
     $ns = $namespaces[$importer->get_leap2a_namespace()];
     if ($persondataid) {
         // Grab all the leap:persondata elements and import them
         $person = $importer->get_entry_by_id($persondataid);
         // The introduction comes from the entry content
         if (!self::$personcontentblank) {
             $introduction = new ArtefactTypeIntroduction(0, array('owner' => $importer->get('usr')));
             $introduction->set('title', PluginImportLeap::get_entry_content($person, $importer));
             $introduction->commit();
         }
         // Most of the rest of the profile data comes from leap:persondata elements
         $persondata = $person->xpath($ns . ':persondata');
         foreach ($persondata as $item) {
             $leapattributes = PluginImportLeap::get_attributes($item, $importer->get_leap2a_namespace());
             if (isset($leapattributes['field'])) {
                 self::import_persondata($importer, $item, $leapattributes);
             } 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;
             }
         }
         // The information about someone's name is much more comprehensive
         // in Leap than what Mahara has, so we have to piece it together
         self::import_namedata($importer, $persondata);
         // People can have address info associated with them
         $addressdata = $person->xpath($ns . ':spatial');
         if (is_array($addressdata) && 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]');
         $author = $author[0];
         if (!isset($author->name)) {
             throw new ImportException($importer, 'TODO: get_string: <author> must include <name> - http://wiki.cetis.ac.uk/2009-03/Leap2A_relationships#Author');
         }
         $name = (string) $author->name;
         if (false !== strpos($name, ' ')) {
             list($firstname, $lastname) = explode(' ', $name, 2);
             self::create_artefact($importer, 'firstname', trim($firstname));
             self::create_artefact($importer, 'lastname', trim($lastname));
         } else {
             // Blatant assumtion that the <name> is a first name
             self::create_artefact($importer, 'firstname', trim($name));
         }
         if (isset($author->email)) {
             self::create_artefact($importer, 'email', (string) $author->email);
         }
         if (isset($author->uri)) {
             $uri = (string) $author->uri;
             if (preg_match('#^https?://#', $uri)) {
                 self::create_artefact($importer, 'officialwebsite', (string) $author->uri);
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Custom hook to import data about the feed author.
  *
  * If we have a persondata element for them, we can import lots of 
  * different information about them into Mahara's profile section. 
  * Otherwise, we can only import some very basic information from the 
  * <author> element.
  *
  * @param PluginImport $importer The importer
  */
 public static function import_author_data(PluginImport $importer)
 {
     if (self::$persondataid) {
         // Grab all the leap:persondata elements and import them
         $person = $importer->get_entry_by_id(self::$persondataid);
         // The introduction comes from the entry content
         $introduction = new ArtefactTypeIntroduction(0, array('owner' => $importer->get('usr')));
         $introduction->set('title', PluginImportLeap::get_entry_content($person, $importer));
         $introduction->commit();
         // Most of the rest of the profile data comes from leap:persondata elements
         $persondata = $person->xpath('leap:persondata');
         foreach ($persondata as $item) {
             $leapattributes = array();
             foreach ($item->attributes(PluginImportLeap::NS_LEAP) as $key => $value) {
                 $leapattributes[$key] = (string) $value;
             }
             if (!isset($leapattributes['field'])) {
                 // '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;
             }
             self::import_persondata($importer, $item, $leapattributes);
         }
         // The information about someone's name is much more comprehensive
         // in LEAP than what Mahara has, so we have to piece it together
         self::import_namedata($importer, $persondata);
         // People can have address info associated with them
         $addressdata = $person->xpath('leap:spatial');
         if (count($addressdata) == 1) {
             self::import_addressdata($importer, $addressdata[0]);
         }
     } else {
         $author = $importer->get('xml')->xpath('//a:feed/a:author[1]');
         $author = $author[0];
         if (!isset($author->name)) {
             throw new ImportException($importer, 'TODO: get_string: <author> must include <name> - http://wiki.cetis.ac.uk/2009-03/LEAP2A_relationships#Author');
         }
         $name = (string) $author->name;
         if (false !== strpos($name, ' ')) {
             list($firstname, $lastname) = explode(' ', $name, 2);
             self::create_artefact($importer, 'firstname', trim($firstname));
             self::create_artefact($importer, 'lastname', trim($lastname));
         } else {
             // Blatant assumtion that the <name> is a first name
             self::create_artefact($importer, 'firstname', trim($name));
         }
         if (isset($author->email)) {
             self::create_artefact($importer, 'email', (string) $author->email);
         }
         if (isset($author->uri)) {
             $uri = (string) $author->uri;
             if (preg_match('#^https?://#', $uri)) {
                 self::create_artefact($importer, 'officialwebsite', (string) $author->uri);
             }
         }
     }
 }