Ejemplo n.º 1
0
 /**
  * Imports data for the personalinformation artefact type, by looking for 
  * it in the persondata element
  */
 public static function import_author_data(PluginImport $importer, $persondataid)
 {
     if ($persondataid) {
         $composites = array();
         $person = $importer->get_entry_by_id($persondataid);
         $namespaces = $importer->get_namespaces();
         $ns = $importer->get_leap2a_namespace();
         $persondata = $person->xpath($namespaces[$ns] . ':persondata');
         foreach ($persondata as $item) {
             $leapattributes = PluginImportLeap::get_attributes($item, $ns);
             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 leap2:field attribute');
                 continue;
             }
             if ($leapattributes['field'] == 'dob') {
                 $composites['dateofbirth'] = (string) $item;
             }
             if ($leapattributes['field'] == 'gender') {
                 $gender = (string) $item;
                 if ($gender == '1') {
                     $composites['gender'] = 'male';
                 } else {
                     if ($gender == '2') {
                         $composites['gender'] = 'female';
                     } else {
                         $importer->trace('WARNING: gender found but not male or female - no gender stored for this user');
                     }
                 }
             }
             $maharaattributes = PluginImportLeap::get_attributes($item, PluginImportLeap::NS_MAHARA);
             if (isset($maharaattributes['field'])) {
                 if (in_array($maharaattributes['field'], array('placeofbirth', 'citizenship', 'visastatus', 'maritalstatus'))) {
                     $composites[$maharaattributes['field']] = (string) $item;
                 }
             }
         }
         if ($composites) {
             $importer->trace('Resume personal information:');
             $importer->trace($composites);
             $artefact = new ArtefactTypePersonalinformation(0, array('owner' => $importer->get('usr')));
             foreach ($composites as $key => $value) {
                 $artefact->set_composite($key, $value);
             }
             $artefact->commit();
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Attaches files to blog posts
  *
  * We look at the leap relationships to add attachments. Currently this 
  * looks explicitly for the has_attachment relationship.
  *
  * If importing an entry resulted in importing a new file (caused by the 
  * entry having out-of-line content), we attach that file to the entry.
  */
 public static function setup_relationships(SimpleXMLElement $entry, PluginImport $importer, $strategy, array $otherentries)
 {
     switch ($strategy) {
         case self::STRATEGY_IMPORT_AS_BLOG:
             foreach ($otherentries as $entryid) {
                 $blogpostentry = $importer->get_entry_by_id($entryid);
                 // Get all attachments this blogpost things are attached to it
                 // TODO: get all entries that think they're attached to the blogpost.
                 // I think we can only look for files, Mahara doesn't understand
                 // attaching something that isn't a file to a blogpost
                 foreach ($blogpostentry->link as $blogpostlink) {
                     $blogpost = null;
                     if ($importer->curie_equals($blogpostlink['rel'], PluginImportLeap::NS_LEAP, 'has_attachment') && isset($blogpostlink['href'])) {
                         if (!$blogpost) {
                             $artefactids = $importer->get_artefactids_imported_by_entryid((string) $blogpostentry->id);
                             $blogpost = new ArtefactTypeBlogPost($artefactids[0]);
                         }
                         $importer->trace("Attaching file {$blogpostlink['href']} to blog post {$blogpostentry->id}", PluginImportLeap::LOG_LEVEL_VERBOSE);
                         $artefactids = $importer->get_artefactids_imported_by_entryid((string) $blogpostlink['href']);
                         $blogpost->attach_file($artefactids[0]);
                     }
                     if ($blogpost) {
                         $blogpost->commit();
                     }
                 }
                 self::setup_outoflinecontent_relationship($blogpostentry, $importer);
             }
             break;
         case self::STRATEGY_IMPORT_AS_ENTRY:
             self::setup_outoflinecontent_relationship($entry, $importer);
             break;
         default:
             throw new ImportException($importer, 'TODO: get_string: unknown strategy chosen for importing entry');
     }
 }