Ejemplo n.º 1
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');
     }
 }