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();
         }
     }
 }