/** * prepare the package ready to be passed off to the portfolio plugin * * @return void */ public function prepare_package() { $entries = $this->exportdata['entries']; $aliases = array(); $categories = array(); if (is_array($this->exportdata['aliases'])) { foreach ($this->exportdata['aliases'] as $alias) { if (!array_key_exists($alias->entryid, $aliases)) { $aliases[$alias->entryid] = array(); } $aliases[$alias->entryid][] = $alias->alias; } } if (is_array($this->exportdata['categoryentries'])) { foreach ($this->exportdata['categoryentries'] as $cat) { if (!array_key_exists($cat->entryid, $categories)) { $categories[$cat->entryid] = array(); } $categories[$cat->entryid][] = $cat->name; } } if ($this->get('exporter')->get('formatclass') == PORTFOLIO_FORMAT_SPREADSHEET) { $csv = glossary_generate_export_csv($entries, $aliases, $categories); $this->exporter->write_new_file($csv, clean_filename($this->cm->name) . '.csv', false); return; } else { if ($this->get('exporter')->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) { $ids = array(); // keep track of these to make into a selection later global $USER, $DB; $writer = $this->get('exporter')->get('format')->leap2a_writer($USER); $format = $this->exporter->get('format'); $filename = $this->get('exporter')->get('format')->manifest_name(); foreach ($entries as $e) { $content = glossary_entry_portfolio_caller::entry_content($this->course, $this->cm, $this->glossary, $e, array_key_exists($e->id, $aliases) ? $aliases[$e->id] : array(), $format); $entry = new portfolio_format_leap2a_entry('glossaryentry' . $e->id, $e->concept, 'entry', $content); $entry->author = $DB->get_record('user', array('id' => $e->userid), 'id,firstname,lastname,email'); $entry->published = $e->timecreated; $entry->updated = $e->timemodified; if (!empty($this->keyedfiles[$e->id])) { $writer->link_files($entry, $this->keyedfiles[$e->id], 'glossaryentry' . $e->id . 'file'); foreach ($this->keyedfiles[$e->id] as $file) { $this->exporter->copy_existing_file($file); } } if (!empty($categories[$e->id])) { foreach ($categories[$e->id] as $cat) { // this essentially treats them as plain tags // leap has the idea of category schemes // but I think this is overkill here $entry->add_category($cat); } } $writer->add_entry($entry); $ids[] = $entry->id; } $selection = new portfolio_format_leap2a_entry('wholeglossary' . $this->glossary->id, get_string('modulename', 'glossary'), 'selection'); $writer->add_entry($selection); $writer->make_selection($selection, $ids, 'Grouping'); $content = $writer->to_xml(); } } $this->exporter->write_new_file($content, $filename, true); }
public function prepare_package() { $entries = $this->exportdata['entries']; $aliases = array(); $categories = array(); if (is_array($this->exportdata['aliases'])) { foreach ($this->exportdata['aliases'] as $alias) { if (!array_key_exists($alias->entryid, $aliases)) { $aliases[$alias->entryid] = array(); } $aliases[$alias->entryid][] = $alias->alias; } } if (is_array($this->exportdata['categoryentries'])) { foreach ($this->exportdata['categoryentries'] as $cat) { if (!array_key_exists($cat->entryid, $categories)) { $categories[$cat->entryid] = array(); } $categories[$cat->entryid][] = $cat->name; } } $csv = glossary_generate_export_csv($entries, $aliases, $categories); return $this->exporter->write_new_file($csv, clean_filename($this->cm->name) . '.csv', false); }