예제 #1
0
파일: lib.php 프로젝트: Br3nda/mahara
 /**
  * Returns a list of entry IDs that are children of this folder
  *
  * If necessary, this method can act recursively to find children at all 
  * levels under this folder
  *
  * TODO: protection against circular references
  *
  * @param SimpleXMLElement $entry The folder to get children for
  * @param PluginImport $importer  The importer
  * @param boolean $recurse        Whether to return children at all levels below this folder
  * @return array A list of the entry IDs of children in this folder
  */
 private static function get_children_of_folder(SimpleXMLElement $entry, PluginImport $importer, $recurse = false)
 {
     $children = array();
     // Get entries that this folder 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'])) {
             $child = $importer->get_entry_by_id((string) $link['href']);
             if ($child) {
                 if (self::is_file($child, $importer) || self::is_folder($child, $importer)) {
                     $children[] = (string) $link['href'];
                 } else {
                     $importer->trace("NOTICE: Child {$child->id} of folder {$entry->id} won't be imported by the file plugin because it is not a file or folder");
                 }
             } else {
                 $importer->trace("WARNING: folder {$entry->id} claims to have child {$link['href']} which does not exist");
             }
         }
     }
     if ($recurse) {
         foreach ($children as $childid) {
             $child = $importer->get_entry_by_id($childid);
             if (self::is_folder($child, $importer)) {
                 $children = array_merge($children, self::get_children_of_folder($child, $importer, true));
             }
         }
     }
     return $children;
 }
예제 #2
0
파일: lib.php 프로젝트: Br3nda/mahara
 /**
  * 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');
     }
 }
예제 #3
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();
         }
     }
 }
예제 #4
0
파일: lib.php 프로젝트: Br3nda/mahara
 /**
  * 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);
             }
         }
     }
 }